diff options
| -rw-r--r-- | FL/Enumerations.H | 9 | ||||
| -rw-r--r-- | src/fl_color.cxx | 23 | ||||
| -rw-r--r-- | src/fl_color_win32.cxx | 23 |
3 files changed, 48 insertions, 7 deletions
diff --git a/FL/Enumerations.H b/FL/Enumerations.H index 4420c186e..2ed927d9e 100644 --- a/FL/Enumerations.H +++ b/FL/Enumerations.H @@ -1,5 +1,5 @@ // -// "$Id: Enumerations.H,v 1.7 1999/01/05 17:57:47 mike Exp $" +// "$Id: Enumerations.H,v 1.8 1999/01/07 16:40:57 mike Exp $" // // Enumerations for the Fast Light Tool Kit (FLTK). // @@ -277,7 +277,10 @@ enum Fl_Color { // standard colors FL_COLOR_CUBE = 56 }; -Fl_Color inactive(Fl_Color c); +Fl_Color fl_color_average(Fl_Color color1, Fl_Color color2, float weight); +inline Fl_Color inactive(Fl_Color c) { return fl_color_average(c, FL_GRAY, .33); } +inline Fl_Color fl_lighter(Fl_Color c) { return fl_color_average(c, FL_WHITE, .67); } +inline Fl_Color fl_darker(Fl_Color c) { return fl_color_average(c, FL_BLACK, .67); } Fl_Color contrast(Fl_Color fg, Fl_Color bg); #define FL_NUM_GRAY 24 inline Fl_Color fl_gray_ramp(int i) {return (Fl_Color)(i+FL_GRAY_RAMP);} @@ -347,5 +350,5 @@ enum Fl_Damage { #endif // -// End of "$Id: Enumerations.H,v 1.7 1999/01/05 17:57:47 mike Exp $". +// End of "$Id: Enumerations.H,v 1.8 1999/01/07 16:40:57 mike Exp $". // diff --git a/src/fl_color.cxx b/src/fl_color.cxx index 592b0b519..805004900 100644 --- a/src/fl_color.cxx +++ b/src/fl_color.cxx @@ -1,5 +1,5 @@ // -// "$Id: fl_color.cxx,v 1.6 1999/01/05 17:57:48 mike Exp $" +// "$Id: fl_color.cxx,v 1.7 1999/01/07 16:40:58 mike Exp $" // // Color functions for the Fast Light Tool Kit (FLTK). // @@ -294,6 +294,25 @@ Fl_Color inactive(Fl_Color c) { return i; } +Fl_Color fl_color_average(Fl_Color color1, Fl_Color color2, float weight) { + Fl_Color avg; + unsigned rgb1 = fl_cmap[color1]; + unsigned rgb2 = fl_cmap[color2]; + uchar r, g, b; + + r = (uchar)(((uchar)(rgb1>>24))*weight + ((uchar)(rgb2>>24))*(1-weight)); + g = (uchar)(((uchar)(rgb1>>16))*weight + ((uchar)(rgb2>>16))*(1-weight)); + b = (uchar)(((uchar)(rgb1>>8))*weight + ((uchar)(rgb2>>8))*(1-weight)); + + if (r == g && r == b) { // get it out of gray ramp + avg = fl_gray_ramp(r*FL_NUM_GRAY/256); + } else { // get it out of color cube: + avg = fl_color_cube(r*FL_NUM_RED/256,g*FL_NUM_GREEN/256,b*FL_NUM_BLUE/256); + } + + return avg; +} + Fl_Color contrast(Fl_Color fg, Fl_Color bg) { if (bright(fl_cmap[bg])) { if (bright(fl_cmap[fg])) @@ -353,5 +372,5 @@ void Fl::get_color(Fl_Color i, uchar &red, uchar &green, uchar &blue) { #endif // -// End of "$Id: fl_color.cxx,v 1.6 1999/01/05 17:57:48 mike Exp $". +// End of "$Id: fl_color.cxx,v 1.7 1999/01/07 16:40:58 mike Exp $". // diff --git a/src/fl_color_win32.cxx b/src/fl_color_win32.cxx index 8da810183..d6012a56b 100644 --- a/src/fl_color_win32.cxx +++ b/src/fl_color_win32.cxx @@ -1,5 +1,5 @@ // -// "$Id: fl_color_win32.cxx,v 1.10 1999/01/05 17:57:48 mike Exp $" +// "$Id: fl_color_win32.cxx,v 1.11 1999/01/07 16:40:58 mike Exp $" // // WIN32 color functions for the Fast Light Tool Kit (FLTK). // @@ -166,6 +166,25 @@ Fl_Color inactive(Fl_Color c) { return i; } +Fl_Color fl_color_average(Fl_Color color1, Fl_Color color2, float weight) { + Fl_Color avg; + unsigned rgb1 = fl_cmap[color1]; + unsigned rgb2 = fl_cmap[color2]; + uchar r, g, b; + + r = (uchar)(((uchar)(rgb1>>24))*weight + ((uchar)(rgb2>>24))*(1-weight)); + g = (uchar)(((uchar)(rgb1>>16))*weight + ((uchar)(rgb2>>16))*(1-weight)); + b = (uchar)(((uchar)(rgb1>>8))*weight + ((uchar)(rgb2>>8))*(1-weight)); + + if (r == g && r == b) { // get it out of gray ramp + avg = fl_gray_ramp(r*FL_NUM_GRAY/256); + } else { // get it out of color cube: + avg = fl_color_cube(r*FL_NUM_RED/256,g*FL_NUM_GREEN/256,b*FL_NUM_BLUE/256); + } + + return avg; +} + Fl_Color contrast(Fl_Color fg, Fl_Color bg) { // bright/dark is decided based on high bit of green: if (fl_cmap[bg] & 0x800000) { @@ -252,5 +271,5 @@ fl_select_palette(void) #endif // -// End of "$Id: fl_color_win32.cxx,v 1.10 1999/01/05 17:57:48 mike Exp $". +// End of "$Id: fl_color_win32.cxx,v 1.11 1999/01/07 16:40:58 mike Exp $". // |
