Fix box background drawing for deactivated widgets (STR #2907).

Two new static methods have been introduced:

  - Fl::box_color(Fl_Color c) returns the bg color dependent on the
    widget's state (inactive_r()).
  - Fl::set_box_color(Fl_Color c) sets the correct bg color dependent
    on the widget's state by calling fl_color(Fl::box_color(c)).


git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@10781 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
Albrecht Schlosser 2015-07-09 00:10:44 +00:00
parent 349f326933
commit 4cea3aee0c
10 changed files with 87 additions and 38 deletions

View File

@ -39,6 +39,9 @@ CHANGES IN FLTK 1.3.4 RELEASED: ??? ?? ????
Bug fixes
- Several box types were not drawn correctly when deactivated.
The background color for deactivated widgets is now correct:
fl_inactive(color()) (STR #2907).
- Reading of .pbm image files is fixed: 1 is now interpreted as
black, and images of width a multiple of 8 are correctly read.
Note: if you relied on the faulty behavior you may need to fix
@ -47,12 +50,11 @@ CHANGES IN FLTK 1.3.4 RELEASED: ??? ?? ????
scheme's background (STR #3059). This was a regression since
FLTK 1.3.0.
- Fl_Text_Display: style buffer colors are no longer manipulated by
fl_contrast() for normal text drawing (fltk.coredev thread
started 04/08/15, Subject: "RFC: Fl_Text_Display style buffer color weirdness")
fl_contrast() for normal text drawing (fltk.coredev thread started
04/08/15, Subject: "RFC: Fl_Text_Display style buffer color weirdness")
- Fl_Tree::deactivate() now affects draw color of items (must have
ABI 1.3.3 or higher enabled). For icons to draw deactivated,
enable ABI 1.3.4. (test/tree has a 'deactivate tree' button)
- Fixed possible bad border effect when a set of radio menu items
is located first in its menu (STR #3176): Fl_Menu_Item::set_only()
is deprecated and replaced by Fl_Menu_::set_only(Fl_Menu_item*).

View File

@ -1092,7 +1092,10 @@ public:
static int box_dy(Fl_Boxtype);
static int box_dw(Fl_Boxtype);
static int box_dh(Fl_Boxtype);
static int draw_box_active();
static Fl_Color box_color(Fl_Color);
static void set_box_color(Fl_Color);
// back compatibility:
/** \addtogroup fl_windows

View File

@ -49,13 +49,49 @@ static const uchar inactive_ramp[24] = {
static int draw_it_active = 1;
/**
Determines if the current draw box is active or inactive.
If inactive, the box color is changed by the inactive color.
Determines if the currently drawn box is active or inactive.
If inactive, the box color should be changed to the inactive color.
\see Fl::box_color(Fl_Color c)
*/
int Fl::draw_box_active() { return draw_it_active; }
const uchar *fl_gray_ramp() {return (draw_it_active?active_ramp:inactive_ramp)-'A';}
/**
Gets the drawing color to be used for the background of a box.
This method is only useful inside box drawing code. It returns the
color to be used, either fl_inactive(c) if the widget is inactive_r()
or \p c otherwise.
*/
Fl_Color Fl::box_color(Fl_Color c) {
return (draw_it_active ? c : fl_inactive(c));
}
/**
Sets the drawing color for the box that is currently drawn.
This method sets the current drawing color fl_color() depending on
the widget's state to either \p c or fl_inactive(c).
It should be used whenever a box background is drawn in the box (type)
drawing code instead of calling fl_color(Fl_Color bg) with the
background color \p bg, usually Fl_Widget::color().
This method is only useful inside box drawing code. Whenever a box is
drawn with one of the standard box drawing methods, a static variable
is set depending on the widget's current state - if the widget is
inactive_r() then the internal variable is false (0), otherwise it
is true (1). This is faster than calling Fl_Widget::active_r()
because the state is cached.
\see Fl::draw_box_active()
\see Fl::box_color(Fl_Color)
*/
void Fl::set_box_color(Fl_Color c) { fl_color(box_color(c)); }
/**
Draws a series of line segments around the given box.
The string \p s must contain groups of 4 letters which specify one of 24
@ -127,6 +163,11 @@ void fl_frame2(const char* s, int x, int y, int w, int h) {
/** Draws a box of type FL_NO_BOX */
void fl_no_box(int, int, int, int, Fl_Color) {}
/** Draws a box of type FL_FLAT_BOX */
void fl_flat_box(int x, int y, int w, int h, Fl_Color c) {
fl_rectf(x, y, w, h, Fl::box_color(c));
}
/** Draws a frame of type FL_THIN_DOWN_FRAME */
void fl_thin_down_frame(int x, int y, int w, int h, Fl_Color) {
fl_frame2("WWHH",x,y,w,h);
@ -135,7 +176,7 @@ void fl_thin_down_frame(int x, int y, int w, int h, Fl_Color) {
/** Draws a box of type FL_THIN_DOWN_BOX */
void fl_thin_down_box(int x, int y, int w, int h, Fl_Color c) {
fl_thin_down_frame(x,y,w,h,c);
fl_color(draw_it_active ? c : fl_inactive(c));
Fl::set_box_color(c);
fl_rectf(x+1, y+1, w-2, h-2);
}
@ -147,7 +188,7 @@ void fl_thin_up_frame(int x, int y, int w, int h, Fl_Color) {
/** Draws a box of type FL_THIN_UP_BOX */
void fl_thin_up_box(int x, int y, int w, int h, Fl_Color c) {
fl_thin_up_frame(x,y,w,h,c);
fl_color(draw_it_active ? c : fl_inactive(c));
Fl::set_box_color(c);
fl_rectf(x+1, y+1, w-2, h-2);
}
@ -170,7 +211,7 @@ void fl_up_frame(int x, int y, int w, int h, Fl_Color) {
/** Draws a box of type FL_UP_BOX */
void fl_up_box(int x, int y, int w, int h, Fl_Color c) {
fl_up_frame(x,y,w,h,c);
fl_color(draw_it_active ? c : fl_inactive(c));
Fl::set_box_color(c);
fl_rectf(x+D1, y+D1, w-D2, h-D2);
}
@ -190,7 +231,8 @@ void fl_down_frame(int x, int y, int w, int h, Fl_Color) {
/** Draws a box of type FL_DOWN_BOX */
void fl_down_box(int x, int y, int w, int h, Fl_Color c) {
fl_down_frame(x,y,w,h,c);
fl_color(c); fl_rectf(x+D1, y+D1, w-D2, h-D2);
Fl::set_box_color(c);
fl_rectf(x+D1, y+D1, w-D2, h-D2);
}
/** Draws a frame of type FL_ENGRAVED_FRAME */
@ -201,7 +243,7 @@ void fl_engraved_frame(int x, int y, int w, int h, Fl_Color) {
/** Draws a box of type FL_ENGRAVED_BOX */
void fl_engraved_box(int x, int y, int w, int h, Fl_Color c) {
fl_engraved_frame(x,y,w,h,c);
fl_color(draw_it_active ? c : fl_inactive(c));
Fl::set_box_color(c);
fl_rectf(x+2, y+2, w-4, h-4);
}
@ -213,7 +255,7 @@ void fl_embossed_frame(int x, int y, int w, int h, Fl_Color) {
/** Draws a box of type FL_EMBOSSED_BOX */
void fl_embossed_box(int x, int y, int w, int h, Fl_Color c) {
fl_embossed_frame(x,y,w,h,c);
fl_color(draw_it_active ? c : fl_inactive(c));
Fl::set_box_color(c);
fl_rectf(x+2, y+2, w-4, h-4);
}
@ -222,9 +264,9 @@ 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.
*/
void fl_rectbound(int x, int y, int w, int h, Fl_Color bgcolor) {
fl_color(draw_it_active ? FL_BLACK : fl_inactive(FL_BLACK));
Fl::set_box_color(FL_BLACK);
fl_rect(x, y, w, h);
fl_color(draw_it_active ? bgcolor : fl_inactive(bgcolor));
Fl::set_box_color(bgcolor);
fl_rectf(x+1, y+1, w-2, h-2);
}
#define fl_border_box fl_rectbound /**< allow consistent naming */
@ -233,7 +275,7 @@ void fl_rectbound(int x, int y, int w, int h, Fl_Color bgcolor) {
Draws a frame of type FL_BORDER_FRAME.
*/
void fl_border_frame(int x, int y, int w, int h, Fl_Color c) {
fl_color(draw_it_active ? c : fl_inactive(c));
Fl::set_box_color(c);
fl_rect(x, y, w, h);
}
@ -246,7 +288,7 @@ static struct {
} fl_box_table[256] = {
// must match list in Enumerations.H!!!
{fl_no_box, 0,0,0,0,1},
{fl_rectf, 0,0,0,0,1}, // FL_FLAT_BOX
{fl_flat_box, 0,0,0,0,1}, // FL_FLAT_BOX
{fl_up_box, D1,D1,D2,D2,1},
{fl_down_box, D1,D1,D2,D2,1},
{fl_up_frame, D1,D1,D2,D2,1},
@ -266,7 +308,7 @@ static struct {
{fl_border_box, 1,1,2,2,0}, // _FL_ROUNDED_BOX
{fl_border_box, 1,1,2,2,0}, // _FL_RSHADOW_BOX
{fl_border_frame, 1,1,2,2,0}, // _FL_ROUNDED_FRAME
{fl_rectf, 0,0,0,0,0}, // _FL_RFLAT_BOX
{fl_flat_box, 0,0,0,0,0}, // _FL_RFLAT_BOX
{fl_up_box, 3,3,6,6,0}, // _FL_ROUND_UP_BOX
{fl_down_box, 3,3,6,6,0}, // _FL_ROUND_DOWN_BOX
{fl_up_box, 0,0,0,0,0}, // _FL_DIAMOND_UP_BOX
@ -274,7 +316,7 @@ static struct {
{fl_border_box, 1,1,2,2,0}, // _FL_OVAL_BOX
{fl_border_box, 1,1,2,2,0}, // _FL_OVAL_SHADOW_BOX
{fl_border_frame, 1,1,2,2,0}, // _FL_OVAL_FRAME
{fl_rectf, 0,0,0,0,0}, // _FL_OVAL_FLAT_BOX
{fl_flat_box, 0,0,0,0,0}, // _FL_OVAL_FLAT_BOX
{fl_up_box, 4,4,8,8,0}, // _FL_PLASTIC_UP_BOX
{fl_down_box, 2,2,4,4,0}, // _FL_PLASTIC_DOWN_BOX
{fl_up_frame, 2,2,4,4,0}, // _FL_PLASTIC_UP_FRAME

View File

@ -32,7 +32,8 @@ static void fl_diamond_up_box(int x,int y,int w,int h,Fl_Color bgcolor) {
h &= -2;
int x1 = x+w/2;
int y1 = y+h/2;
fl_color(bgcolor); fl_polygon(x+3, y1, x1,y+3, x+w-3,y1, x1,y+h-3);
Fl::set_box_color(bgcolor);
fl_polygon(x+3, y1, x1,y+3, x+w-3,y1, x1,y+h-3);
const uchar *g = fl_gray_ramp();
fl_color(g[(int)'W']); fl_line(x+1, y1, x1, y+1, x+w-1, y1);
fl_color(g[(int)'U']); fl_line(x+2, y1, x1, y+2, x+w-2, y1);
@ -55,7 +56,8 @@ static void fl_diamond_down_box(int x,int y,int w,int h,Fl_Color bgcolor) {
fl_color(g[(int)'W']); fl_line(x+2, y1, x1, y+h-2, x+w-2, y1);
fl_color(g[(int)'U']); fl_line(x+1, y1, x1, y+h-1, x+w-1, y1);
fl_color(g[(int)'S']); fl_line(x+0, y1, x1, y+h-0, x+w-0, y1);
fl_color(bgcolor); fl_polygon(x+3, y1, x1,y+3, x+w-3,y1, x1,y+h-3);
Fl::set_box_color(bgcolor);
fl_polygon(x+3, y1, x1,y+3, x+w-3,y1, x1,y+h-3);
fl_color(g[(int)'A']); fl_loop(x+3, y1, x1, y+3, x+w-3, y1, x1, y+h-3);
}

View File

@ -30,8 +30,7 @@
static void gleam_color(Fl_Color c) {
if (Fl::draw_box_active()) fl_color(c);
else fl_color(fl_inactive(c));
Fl::set_box_color(c);
}
static void shade_rect_top_bottom(int x, int y, int w, int h, Fl_Color fg1, Fl_Color fg2, float th) {

View File

@ -30,11 +30,9 @@ extern void fl_internal_boxtype(Fl_Boxtype, Fl_Box_Draw_F*);
static void gtk_color(Fl_Color c) {
if (Fl::draw_box_active()) fl_color(c);
else fl_color(fl_inactive(c));
Fl::set_box_color(c);
}
static void gtk_up_frame(int x, int y, int w, int h, Fl_Color c) {
gtk_color(fl_color_average(FL_WHITE, c, 0.5));
fl_xyline(x + 2, y + 1, x + w - 3);
@ -204,7 +202,7 @@ static void draw(int which, int x,int y,int w,int h, int inset)
}
static void gtk_round_up_box(int x, int y, int w, int h, Fl_Color c) {
fl_color(c);
gtk_color(c);
draw(FILL, x, y, w, h, 2);
gtk_color(fl_color_average(FL_BLACK, c, 0.025f));
@ -235,7 +233,7 @@ static void gtk_round_up_box(int x, int y, int w, int h, Fl_Color c) {
}
static void gtk_round_down_box(int x, int y, int w, int h, Fl_Color c) {
fl_color(c);
gtk_color(c);
draw(FILL, x, y, w, h, 2);
gtk_color(fl_color_average(FL_BLACK, c, 0.05f));

View File

@ -24,12 +24,12 @@
#include <FL/fl_draw.H>
static void fl_oval_flat_box(int x, int y, int w, int h, Fl_Color c) {
fl_color(c);
Fl::set_box_color(c);
fl_pie(x, y, w, h, 0, 360);
}
static void fl_oval_frame(int x, int y, int w, int h, Fl_Color c) {
fl_color(c);
Fl::set_box_color(c);
fl_arc(x, y, w, h, 0, 360);
}

View File

@ -75,7 +75,7 @@ extern const uchar* fl_gray_ramp();
void fl_round_down_box(int x, int y, int w, int h, Fl_Color bgcolor) {
const uchar *g = fl_gray_ramp();
draw(FILL, x, y, w, h, 2, bgcolor);
draw(FILL, x, y, w, h, 2, Fl::box_color(bgcolor));
draw(UPPER_LEFT, x+1, y, w-2, h, 0, (Fl_Color)g[(int)'N']);
draw(UPPER_LEFT, x+1, y, w-2, h, 1, (Fl_Color)g[(int)'H']);
draw(UPPER_LEFT, x, y, w, h, 0, (Fl_Color)g[(int)'N']);
@ -89,7 +89,7 @@ void fl_round_down_box(int x, int y, int w, int h, Fl_Color bgcolor) {
void fl_round_up_box(int x, int y, int w, int h, Fl_Color bgcolor) {
const uchar *g = fl_gray_ramp();
draw(FILL, x, y, w, h, 2, bgcolor);
draw(FILL, x, y, w, h, 2, Fl::box_color(bgcolor));
draw(LOWER_RIGHT, x+1, y, w-2, h, 0, (Fl_Color)g[(int)'H']);
draw(LOWER_RIGHT, x+1, y, w-2, h, 1, (Fl_Color)g[(int)'N']);
draw(LOWER_RIGHT, x, y, w, h, 1, (Fl_Color)g[(int)'H']);

View File

@ -46,15 +46,18 @@ static void rbox(int fill, int x, int y, int w, int h) {
}
static void fl_rflat_box(int x, int y, int w, int h, Fl_Color c) {
fl_color(c); rbox(1, x, y, w, h); rbox(0, x, y, w, h);
Fl::set_box_color(c);
rbox(1, x, y, w, h); rbox(0, x, y, w, h);
}
static void fl_rounded_frame(int x, int y, int w, int h, Fl_Color c) {
fl_color(c); rbox(0, x, y, w, h);
Fl::set_box_color(c);
rbox(0, x, y, w, h);
}
static void fl_rounded_box(int x, int y, int w, int h, Fl_Color c) {
fl_color(c); rbox(1, x, y, w, h);
Fl::set_box_color(c);
rbox(1, x, y, w, h);
fl_color(FL_BLACK); rbox(0, x, y, w, h);
}

View File

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