[fltk/fltk] Add functions for drawing rounded rectangles to the drawing api (#262)
Webb Hinton
Jul 20, 2021
Rounded rectangles have become a critical part of modern GUI design. However, FLTK provides minimal support for drawing rounded rectangles. The current Box api provides no means of setting a custom radius for RoundedFrames, which leaves it up to the programmer to design a custom solution. So, I think we could save people time by providing a method for drawing rounded rectangles.
Such a method already exists in fl_rounded_box:
staticvoidrbox(int fill, int x, int y, int w, int h) {
int i;
int rs, rsy;
rs = w*2/5; rsy = h*2/5;
if (rs > rsy) rs = rsy; // use smaller radiusif (rs > RS) rs = RS;
if (rs == 5) rs = 4; // use only even sizes for small corners (STR #2943)if (rs == 7) rs = 8; // note: 8 is better than 6 (really)if (fill) fl_begin_polygon(); elsefl_begin_loop();
for (i=0; i<RN; i++)
fl_vertex_r(x + offset[RN-i-1]*rs, y + offset[i] * rs);
for (i=0; i<RN; i++)
fl_vertex_r(x + offset[i]*rs, y + h-1 - offset[RN-i-1] * rs);
for (i=0; i<RN; i++)
fl_vertex_r(x + w-1 - offset[RN-i-1]*rs, y + h-1 - offset[i] * rs);
for (i=0; i<RN; i++)
fl_vertex_r(x + w-1 - offset[i]*rs, y + offset[RN-i-1] * rs);
if (fill) fl_end_polygon(); elsefl_end_loop();
}
While it's nice to be able to set the global radius size, we might also want to have rounded frames with different radiuses.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.
Comments are owned by the poster. All other content is copyright 1998-2025 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.