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_draw.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_draw.cxx')
| -rw-r--r-- | src/fl_draw.cxx | 71 |
1 files changed, 61 insertions, 10 deletions
diff --git a/src/fl_draw.cxx b/src/fl_draw.cxx index bfd1c67fd..b0598245f 100644 --- a/src/fl_draw.cxx +++ b/src/fl_draw.cxx @@ -594,25 +594,76 @@ void fl_draw_check(Fl_Rect bb, Fl_Color col) { /** Draw a potentially small, filled circle using a given color. - This function draws using \p color a filled circle bounded by rectangle <tt>(x, y, d, d)</tt>. + This function draws a filled circle bounded by rectangle + <tt>(x, y, d, d)</tt> using color \p color - This function is the same as <tt>fl_pie(x, y, d, d, 0, 360)</tt> except with some systems - that don't draw small circles well. In that situation, the circle diameter \p d is converted - from FLTK units to pixels and this function approximates a filled circle by drawing several - filled rectangles if the converted diameter is ≤ 6 pixels. + This function is the same as <tt>fl_pie(x, y, d, d, 0, 360)</tt> except + with some systems that don't draw small circles well. In that situation, + the circle diameter \p d is converted from FLTK units to pixels and this + function approximates a filled circle by drawing several filled + rectangles if the converted diameter is ≤ 6 pixels. - \param[in] x,y coordinates of top left of the bounding box - \param[in] d diameter == width and height of the bounding box in FLTK units - \param[in] color drawing color + The current drawing color fl_color() is preserved across the call. + + \param[in] x,y coordinates of top left of the bounding box + \param[in] d diameter == width and height of the bounding box in FLTK units + \param[in] color the color used to draw the circle \since 1.4.0 */ void fl_draw_circle(int x, int y, int d, Fl_Color color) { #define DEBUG_DRAW_CIRCLE (0) // bit 1 = draw bounding box (green) -#if (DEBUG_DRAW_CIRCLE & 1) +#if (DEBUG_DRAW_CIRCLE & 0) Fl_Color current = fl_color(); - fl_rectf(x0, y0, d, d, FL_GREEN); + fl_rectf(x, y, d, d, FL_GREEN); fl_color(current); #endif fl_graphics_driver->draw_circle(x, y, d, color); } + +/** + Draw a round check mark (circle) of a radio button. + + This draws only the round "radio button mark", it does not draw the + (also typically round) box of the radio button. + + Call this only if the radio button is \c ON. + + This method draws a scheme specific "circle" with a particular light effect + if the scheme is gtk+. For all other schemes this function draws a simple, + small circle. + + The \c color must be chosen by the caller so it has enough contrast with + the background. + + The bounding box of the circle is the rectangle <tt>(x, y, d, d)</tt>. + + The current drawing color fl_color() is preserved across the call. + + \param[in] x,y coordinates of top left of the bounding box + \param[in] d diameter == width and height of the bounding box in FLTK units + \param[in] color the base color used to draw the circle + + \since 1.4.0 +*/ +void fl_draw_radio(int x, int y, int d, Fl_Color color) { + + Fl_Color current = fl_color(); + +#if (0) // DEBUG: draw bounding box + fl_color(fl_lighter(FL_RED)); + fl_rectf(x, y, d, d); +#endif + + if (Fl::is_scheme("gtk+")) { + fl_color(color); + fl_pie(x, y, d, d, 0.0, 360.0); + Fl_Color icol = fl_color_average(FL_WHITE, color, 0.2f); + fl_draw_circle(x + 2, y + 2, d - 4, icol); + fl_color(fl_color_average(FL_WHITE, color, 0.5)); + fl_arc(x + 1, y + 1, d - 1, d - 1, 60.0, 180.0); + } else { + fl_draw_circle(x + 1, y + 1, d - 2, color); + } + fl_color(current); +} |
