Improve method to draw boxes of type FL_BORDER_BOX and FL_SHADOW_BOX (#1089)

These types of boxes frame a background with a rectangular frame of another color.
The previous procedure to draw them was not robust to GUI rescaling creating cases
where space between the border and the background was not drawn.
The new drawing procedure for these boxes first paints the whole area (frame included)
with the background color and next draws the frame over the just painted rectangle.
No uncolored space is possible.
It was also necessary to very slightly modify Fl_Scalable_Graphics_Driver::rect()
used by the Windows and X11 (no Cairo) backends to make sure fl_rect(x,y,w,h)
exactly frames fl_rectf(x,y,w,h) without drawing outside the filled area.
This commit is contained in:
ManoloFLTK 2024-10-15 18:02:48 +02:00
parent a5f28b3984
commit 957fa1fe37
3 changed files with 11 additions and 7 deletions

View File

@ -751,10 +751,11 @@ Fl_Scalable_Graphics_Driver::Fl_Scalable_Graphics_Driver() : Fl_Graphics_Driver(
void Fl_Scalable_Graphics_Driver::rect(int x, int y, int w, int h) void Fl_Scalable_Graphics_Driver::rect(int x, int y, int w, int h)
{ {
if (w > 0 && h > 0) { if (w > 0 && h > 0) {
int s = (int)scale()/2; int s = (int)scale();
rect_unscaled(this->floor(x) + s, this->floor(y) + s, int d = s / 2;
this->floor(x + w - 1) - this->floor(x), rect_unscaled(this->floor(x) + d, this->floor(y) + d,
this->floor(y + h - 1) - this->floor(y)); this->floor(x + w) - this->floor(x) - s,
this->floor(y + h) - this->floor(y) - s);
} }
} }

View File

@ -267,10 +267,13 @@ void fl_embossed_box(int x, int y, int w, int h, Fl_Color c) {
Equivalent to drawing a box of type FL_BORDER_BOX. Equivalent to drawing a box of type FL_BORDER_BOX.
*/ */
void fl_rectbound(int x, int y, int w, int h, Fl_Color bgcolor) { void fl_rectbound(int x, int y, int w, int h, Fl_Color bgcolor) {
// New algorithm (see Discussion #1089):
// 1) draw with adequate bg color a filled rectangle that covers also the rectangle border
// 2) draw with adequate border color the rectangle border overwriting what was drawn at 1)
Fl::set_box_color(bgcolor);
fl_rectf(x, y, w, h);
Fl::set_box_color(FL_BLACK); Fl::set_box_color(FL_BLACK);
fl_rect(x, y, w, h); fl_rect(x, y, w, h);
Fl::set_box_color(bgcolor);
fl_rectf(x+1, y+1, w-2, h-2);
} }
#define fl_border_box fl_rectbound /**< allow consistent naming */ #define fl_border_box fl_rectbound /**< allow consistent naming */

View File

@ -32,7 +32,7 @@ static void fl_shadow_frame(int x, int y, int w, int h, Fl_Color c) {
static void fl_shadow_box(int x, int y, int w, int h, Fl_Color c) { static void fl_shadow_box(int x, int y, int w, int h, Fl_Color c) {
Fl::set_box_color(c); Fl::set_box_color(c);
fl_rectf(x+1,y+1,w-2-BW,h-2-BW); fl_rectf(x,y,w-BW,h-BW);
fl_shadow_frame(x,y,w,h,FL_GRAY0); fl_shadow_frame(x,y,w,h,FL_GRAY0);
} }