Menu

#2523 [PATCH] Unreadable zoom-in using dark backgrounds

None
closed-fixed
nobody
None
2022-07-11
2022-05-04
Ian
No

I was doing some experiments with dark mode graphs and realized that the zoom selection box is not visible (black on black) in wxt if the background is set to #000000. So here's a patch:

diff --git a/src/wxterminal/wxt_gui.cpp b/src/wxterminal/wxt_gui.cpp
index 20efa9ae3..caac6e2c1 100644
--- a/src/wxterminal/wxt_gui.cpp
+++ b/src/wxterminal/wxt_gui.cpp
@@ -1088,14 +1088,18 @@ void wxtPanel::DrawToDC(wxDC &dc, wxRegion &region)

 #ifdef USE_MOUSE
        if (wxt_zoombox) {
-               tmp_pen = wxPen(wxT("black"), 1, wxPENSTYLE_SOLID);
-               tmp_pen.SetCap( wxCAP_ROUND );
-               dc.SetPen( tmp_pen );
 #ifndef __WXOSX_COCOA__
                /* wx 2.9 Cocoa bug workaround, which has no logical functions support */
 #if (GTK_MAJOR_VERSION < 3)
+               tmp_pen = wxPen(wxT("white"), 1, wxPENSTYLE_SOLID);
+               tmp_pen.SetCap( wxCAP_ROUND );
+               dc.SetPen( tmp_pen );
                dc.SetLogicalFunction( wxINVERT );
 #endif
+#else
+               tmp_pen = wxPen(wxT("black"), 1, wxPENSTYLE_SOLID);
+               tmp_pen.SetCap( wxCAP_ROUND );
+               dc.SetPen( tmp_pen );
 #endif
                dc.DrawLine( zoom_x1, zoom_y1, mouse_x, zoom_y1 );
                dc.DrawLine( mouse_x, zoom_y1, mouse_x, mouse_y );

Details:
system: gnuplot 5.4 patchlevel 3 (Arch Linux)
patched branch: gnuplot branch-5-4-stable

Testing process:

$ gnuplot -e "set term wxt background '#000000'" -c demo/airfoil.dem

Verified that the zoom selection box is not visible (black on black)

$ gnuplot -e "set term wxt" -c demo/airfoil.dem

Verified that the zoom selection box is visible (black on white).

Patched the file src/wxterminal/wxt_gui.cpp and compiled src/gnuplot is the patched version

$ ./src/gnuplot -e "set term wxt background '#000000'" -c demo/airfoil.dem

Verified that the zoom selection box is now visible (white on black).

$ ./src/gnuplot -e "set term wxt" -c demo/airfoil.dem

Verified that the zoom selection box is still visible (different blending mode though).
I'm not able to test in a macOS environment.
I can provide screenshots and other details if required

Discussion

  • Ethan Merritt

    Ethan Merritt - 2022-05-05

    I may be mis-reading this patch, but it seems to me that it has no effect on systems using gtk3/wxgtk3, which I thought would include all current linux distros. Certainly it has no effect on my test machines here. Is your Arch linux version still using gtk2?

    Please show the output of ldd ./gnuplot.

    I think a more robust approach would be to choose the zoombox/ruler/rubberband color based specifically on the known background. Something like:

    diff --git a/src/wxterminal/wxt_gui.cpp b/src/wxterminal/wxt_gui.cpp
    index 9f131b576..fa1ba7878 100644
    --- a/src/wxterminal/wxt_gui.cpp
    +++ b/src/wxterminal/wxt_gui.cpp
    @@ -1099,15 +1099,15 @@ void wxtPanel::DrawToDC(wxDC &dc, wxRegion &region)
    
     #ifdef USE_MOUSE
         if (wxt_zoombox) {
    -        tmp_pen = wxPen(wxT("black"), 1, wxPENSTYLE_SOLID);
    +        double ntsc = 0.299 * wxt_rgb_background.r + 0.587 * wxt_rgb_background.g
    +                + 0.114 * wxt_rgb_background.b;
    +        if (ntsc < 0.5)
    +            tmp_pen = wxPen(wxT("white"), 1, wxPENSTYLE_SOLID);
    +        else
    +            tmp_pen = wxPen(wxT("black"), 1, wxPENSTYLE_SOLID);
             tmp_pen.SetCap( wxCAP_ROUND );
             dc.SetPen( tmp_pen );
    -#ifndef __WXOSX_COCOA__
    -        /* wx 2.9 Cocoa bug workaround, which has no logical functions support */
    -#if (GTK_MAJOR_VERSION < 3)
    -        dc.SetLogicalFunction( wxINVERT );
    -#endif
    -#endif
    +
             dc.DrawLine( zoom_x1, zoom_y1, mouse_x, zoom_y1 );
             dc.DrawLine( mouse_x, zoom_y1, mouse_x, mouse_y );
             dc.DrawLine( mouse_x, mouse_y, zoom_x1, mouse_y );
    

    The same is presumably needed for the ruler and the rubber band.

     
  • Ian

    Ian - 2022-05-05

    You are correct. it's missing the "else" part because I misread the "< 3" part, I wasn't so sure about it, hence the bug report.

    I created a gist here to avoid the clutter with the requested ldd ouput
    Indeed, it seems I managed to compile to gtk2 (thus < 3) which explains everything.

    I'm having trouble to apply your patch (copying) directly but I will simply modify the lines and see if the problem persists.

     
  • Ian

    Ian - 2022-05-05

    Your patch seems to work here
    I did a git reset --hard and then modified the nearby lines.
    Then I did a ./prepare & ./configure & make -j4

    Typing $ ./src/gnuplot -e "set term wxt background '#000000'" -c demo/airfoil.dem I checked the zoom box and it was visible (white on black)

    Typing $ gnuplot -e "set term wxt" -c demo/airfoil.demI checked the zoom box and it was visible (same shade as before, black with that blueish thing)

    Heres the patch:

    diff --git a/src/wxterminal/wxt_gui.cpp b/src/wxterminal/wxt_gui.cpp
    index 20efa9ae3..169e8f418 100644
    --- a/src/wxterminal/wxt_gui.cpp
    +++ b/src/wxterminal/wxt_gui.cpp
    @@ -1088,15 +1088,15 @@ void wxtPanel::DrawToDC(wxDC &dc, wxRegion &region)
    
     #ifdef USE_MOUSE
        if (wxt_zoombox) {
    -       tmp_pen = wxPen(wxT("black"), 1, wxPENSTYLE_SOLID);
    +       double ntsc = 0.299 * wxt_rgb_background.r
    +                   + 0.587 * wxt_rgb_background.g
    +                   + 0.114 * wxt_rgb_background.b;
    +       if (ntsc < 0.5)
    +           tmp_pen = wxPen(wxT("white"), 1, wxPENSTYLE_SOLID);
    +       else
    +           tmp_pen = wxPen(wxT("black"), 1, wxPENSTYLE_SOLID);
            tmp_pen.SetCap( wxCAP_ROUND );
            dc.SetPen( tmp_pen );
    -#ifndef __WXOSX_COCOA__
    -       /* wx 2.9 Cocoa bug workaround, which has no logical functions support */
    -#if (GTK_MAJOR_VERSION < 3)
    -       dc.SetLogicalFunction( wxINVERT );
    -#endif
    -#endif
            dc.DrawLine( zoom_x1, zoom_y1, mouse_x, zoom_y1 );
            dc.DrawLine( mouse_x, zoom_y1, mouse_x, mouse_y );
            dc.DrawLine( mouse_x, mouse_y, zoom_x1, mouse_y );
    @@ -1127,15 +1127,15 @@ void wxtPanel::DrawToDC(wxDC &dc, wxRegion &region)
        }
    
        if (wxt_ruler) {
    -       tmp_pen = wxPen(wxT("black"), 1, wxPENSTYLE_SOLID);
    -       tmp_pen.SetCap(wxCAP_BUTT);
    +       double ntsc = 0.299 * wxt_rgb_background.r
    +                   + 0.587 * wxt_rgb_background.g
    +                   + 0.114 * wxt_rgb_background.b;
    +       if (ntsc < 0.5)
    +           tmp_pen = wxPen(wxT("white"), 1, wxPENSTYLE_SOLID);
    +       else
    +           tmp_pen = wxPen(wxT("black"), 1, wxPENSTYLE_SOLID);
    +       tmp_pen.SetCap( wxCAP_ROUND );
            dc.SetPen( tmp_pen );
    -#ifndef __WXOSX_COCOA__
    -       /* wx 2.9 Cocoa bug workaround, which has no logical functions support */
    -#if (GTK_MAJOR_VERSION < 3)
    -       dc.SetLogicalFunction( wxINVERT );
    -#endif
    -#endif
     #ifdef __WXMSW__
            dc.DrawLine(0, (int)wxt_ruler_y, plot.device_xmax, (int)wxt_ruler_y);
            dc.DrawLine((int)wxt_ruler_x, 0, (int)wxt_ruler_x, plot.device_ymax);
    @@ -1146,15 +1146,15 @@ void wxtPanel::DrawToDC(wxDC &dc, wxRegion &region)
        }
    
        if (wxt_ruler && wxt_ruler_lineto) {
    -       tmp_pen = wxPen(wxT("black"), 1, wxPENSTYLE_SOLID);
    -       tmp_pen.SetCap(wxCAP_BUTT);
    +       double ntsc = 0.299 * wxt_rgb_background.r
    +                   + 0.587 * wxt_rgb_background.g
    +                   + 0.114 * wxt_rgb_background.b;
    +       if (ntsc < 0.5)
    +           tmp_pen = wxPen(wxT("white"), 1, wxPENSTYLE_SOLID);
    +       else
    +           tmp_pen = wxPen(wxT("black"), 1, wxPENSTYLE_SOLID);
    +       tmp_pen.SetCap( wxCAP_ROUND );
            dc.SetPen( tmp_pen );
    -#ifndef __WXOSX_COCOA__
    -       /* wx 2.9 Cocoa bug workaround, which has no logical functions support */
    -#if (GTK_MAJOR_VERSION < 3)
    -       dc.SetLogicalFunction( wxINVERT );
    -#endif
    -#endif
            dc.DrawLine((int)wxt_ruler_x, (int)wxt_ruler_y, mouse_x, mouse_y);
            dc.SetLogicalFunction( wxCOPY );
        }
    
     
  • Ethan Merritt

    Ethan Merritt - 2022-05-05

    OK. So your system gnuplot is linked against
    libwx_gtk3u_core-3.0.so.0 => /usr/lib/libwx_gtk3u_core-3.0.so.0 (0x00007fb09746d000)
    but your patched local gnuplot is linked against
    libwx_gtk2u_core-3.0.so.0 => /usr/lib/libwx_gtk2u_core-3.0.so.0 (0x00007f0ca295a000)

    Is this intentional?

    Given the number of changes between gtk2 and gtk3 I suspect there are other visible differences in behavior of the two gnuplot executables. It was a right pain trying to find all the places that broke during the gtk 2.8->2.9->3.0 transition (not to mention the 2.9 variant that Mac OS spawned off). I am far from convinced we caught them all at the time. <gripe mode="" on=""> And now gtk4 is appearing over the horizon </gripe>.

    Anyhow, I'll apply this change to both 5.4 and 5.5. Thanks for testing, particularly since it was on top of a library version I'm not testing any more.

     
  • Ian

    Ian - 2022-05-06

    It wasn't intentional I just took the easiest path in order to compile it and fix the bug. Since I didn't know anything about gnuplot src code I didn't tinkered with any kind of option just the bare minimum to find the code responsible for the zoombox. After a few threads in wx foruns to understand what happened to macOS and that it was related to cairo not supporting some logical function... well I gave up and just tried to patch it and file a bug report.

    gtk4, qt6... how amusing

    I'm glad to help anyway.

     
  • Ethan Merritt

    Ethan Merritt - 2022-05-10
    • status: open --> pending-fixed
    • Group: -->
    • Priority: -->
     
  • Ethan Merritt

    Ethan Merritt - 2022-07-11
    • Status: pending-fixed --> closed-fixed
     

Log in to post a comment.