diff options
| author | Albrecht Schlosser <albrechts.fltk@online.de> | 2023-12-02 19:34:29 +0100 |
|---|---|---|
| committer | Albrecht Schlosser <albrechts.fltk@online.de> | 2023-12-02 19:34:29 +0100 |
| commit | 9950c8e082c55dd1e3cd9311446a75b3c047eae3 (patch) | |
| tree | 69b5e34f64a60ff2799191ae85db9ead4260d1ad /src/Fl_Light_Button.cxx | |
| parent | 0aa8e28be0af167929e72267c6e1d5588bc9c3ed (diff) | |
Improve contrast of check marks and radio buttons (#443)
- add fl_draw_radio(...) to standardize radio button drawing
- src/Fl_Light_Button.cxx: use fl_contrast() to determine color of
radio button and check (light) button check marks, and use
new fl_draw_radio() method
- src/Fl_Menu.cxx: same as src/Fl_Light_Button.cxx and use
fl_draw_check() instead of "manually" drawing the check mark
(forgotten in an earlier update)
Diffstat (limited to 'src/Fl_Light_Button.cxx')
| -rw-r--r-- | src/Fl_Light_Button.cxx | 45 |
1 files changed, 22 insertions, 23 deletions
diff --git a/src/Fl_Light_Button.cxx b/src/Fl_Light_Button.cxx index 9658be15a..98ef910e6 100644 --- a/src/Fl_Light_Button.cxx +++ b/src/Fl_Light_Button.cxx @@ -32,6 +32,16 @@ void Fl_Light_Button::draw() { Fl_Color col = value() ? (active_r() ? selection_color() : fl_inactive(selection_color())) : color(); + // determine the color of the check mark or radio button (circle) + + Fl_Color check_color = selection_color(); // default = selection color + if (Fl::is_scheme("gtk+")) + check_color = FL_SELECTION_COLOR; // exception for gtk+ + if (!active_r()) + check_color = fl_inactive(check_color); + // select a color with enough contrast + check_color = fl_contrast(check_color, FL_BACKGROUND2_COLOR); + int W = labelsize(); // check mark box size if (W > 25) W = 25; // limit box size int bx = Fl::box_dx(box()); // box frame width @@ -42,8 +52,11 @@ void Fl_Light_Button::draw() { int cy = y() + dy; // check mark box y-position int cw = 0; // check mark box width and height - if (down_box()) { - // draw other down_box() styles: + // FIXME: the *box type* of the widget determines the drawing style: + // (a) down_box() == 0: Fl_Light_Button style + // (b) down_box() != 0: other button styles + + if (down_box()) { // draw "other" button styles (b): switch (down_box()) { case FL_DOWN_BOX : case FL_UP_BOX : @@ -53,14 +66,11 @@ void Fl_Light_Button::draw() { draw_box(down_box(), cx, cy, W, W, FL_BACKGROUND2_COLOR); if (value()) { // Check mark... - if (Fl::is_scheme("gtk+")) { - col = FL_SELECTION_COLOR; - } // Calculate box position and size cx += Fl::box_dx(down_box()); cy += Fl::box_dy(down_box()); cw = W - Fl::box_dw(down_box()); - fl_draw_check(Fl_Rect(cx, cy, cw, cw), col); + fl_draw_check(Fl_Rect(cx, cy, cw, cw), check_color); } break; case _FL_ROUND_DOWN_BOX : @@ -68,27 +78,16 @@ void Fl_Light_Button::draw() { // Radio button... draw_box(down_box(), x()+dx, y()+dy, W, W, FL_BACKGROUND2_COLOR); if (value()) { + + // Draw round check mark of radio button + int tW = (W - Fl::box_dw(down_box())) / 2 + 1; if ((W - tW) & 1) tW++; // Make sure difference is even to center int tdx = dx + (W - tW) / 2; int tdy = dy + (W - tW) / 2; + fl_draw_radio(x() + tdx - 1, y() + tdy - 1, tW + 2, check_color); - if (Fl::is_scheme("gtk+")) { - fl_color(FL_SELECTION_COLOR); - tW --; - fl_pie(x() + tdx - 1, y() + tdy - 1, tW + 3, tW + 3, 0.0, 360.0); - fl_color(fl_color_average(FL_WHITE, FL_SELECTION_COLOR, 0.2f)); - } else { - fl_color(col); - } - - fl_draw_circle(x() + tdx, y() + tdy, tW, fl_color()); - - if (Fl::is_scheme("gtk+")) { - fl_color(fl_color_average(FL_WHITE, FL_SELECTION_COLOR, 0.5)); - fl_arc(x() + tdx, y() + tdy, tW + 1, tW + 1, 60.0, 180.0); - } - } + } // Radio button: if (value()) break; default : draw_box(down_box(), x()+dx, y()+dy, W, W, col); @@ -96,7 +95,7 @@ void Fl_Light_Button::draw() { } lx = dx + W + 2; } else { - // if down_box() is zero, draw light button style: + // if down_box() is zero, draw light button style (a): int hh = h()-2*dy - 2; int ww = W/2+1; int xx = dx; |
