mirror of
https://github.com/fltk/fltk.git
synced 2026-06-06 00:22:42 +08:00
Patch from Carl - inactive and contrast functions.
git-svn-id: file:///fltk/svn/fltk/trunk@241 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
+6
-2
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// "$Id: Enumerations.H,v 1.10 1999/01/13 15:56:22 mike Exp $"
|
||||
// "$Id: Enumerations.H,v 1.11 1999/01/25 20:43:03 mike Exp $"
|
||||
//
|
||||
// Enumerations for the Fast Light Tool Kit (FLTK).
|
||||
//
|
||||
@@ -279,6 +279,10 @@ enum Fl_Color { // standard colors
|
||||
|
||||
Fl_Color inactive(Fl_Color c);
|
||||
Fl_Color contrast(Fl_Color fg, Fl_Color bg);
|
||||
Fl_Color fl_color_average(Fl_Color c1, Fl_Color c2, float weight);
|
||||
inline Fl_Color fl_lighter(Fl_Color c) { return fl_color_average(c, FL_WHITE, .67f); }
|
||||
inline Fl_Color fl_darker(Fl_Color c) { return fl_color_average(c, FL_BLACK, .67f); }
|
||||
|
||||
#define FL_NUM_GRAY 24
|
||||
inline Fl_Color fl_gray_ramp(int i) {return (Fl_Color)(i+FL_GRAY_RAMP);}
|
||||
#define FL_NUM_RED 5
|
||||
@@ -347,5 +351,5 @@ enum Fl_Damage {
|
||||
#endif
|
||||
|
||||
//
|
||||
// End of "$Id: Enumerations.H,v 1.10 1999/01/13 15:56:22 mike Exp $".
|
||||
// End of "$Id: Enumerations.H,v 1.11 1999/01/25 20:43:03 mike Exp $".
|
||||
//
|
||||
|
||||
+22
-20
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// "$Id: fl_color.cxx,v 1.11 1999/01/19 19:10:39 mike Exp $"
|
||||
// "$Id: fl_color.cxx,v 1.12 1999/01/25 20:43:05 mike Exp $"
|
||||
//
|
||||
// Color functions for the Fast Light Tool Kit (FLTK).
|
||||
//
|
||||
@@ -316,25 +316,27 @@ void Fl::get_color(Fl_Color i, uchar &red, uchar &green, uchar &blue) {
|
||||
blue = uchar(c>>8);
|
||||
}
|
||||
|
||||
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 inactive(Fl_Color c) {
|
||||
// cache because it is like to ask for the same color a lot:
|
||||
static Fl_Color cache_from = FL_GRAY;
|
||||
static Fl_Color cache_to = FL_GRAY;
|
||||
if (c == cache_from) return cache_to;
|
||||
cache_from = c;
|
||||
// do a 33% mix between this color and FL_GRAY:
|
||||
unsigned rgb1 = fl_cmap[c];
|
||||
unsigned rgb2 = fl_cmap[FL_GRAY];
|
||||
uchar r = (uchar)((((uchar)(rgb1>>24)) + ((uchar)(rgb2>>24))*2)/3);
|
||||
uchar g = (uchar)((((uchar)(rgb1>>16)) + ((uchar)(rgb2>>16))*2)/3);
|
||||
uchar b = (uchar)((((uchar)(rgb1>> 8)) + ((uchar)(rgb2>> 8))*2)/3);
|
||||
// and find the closest color in gray ramp or color cube:
|
||||
if (r == g && r == b) // get it out of gray ramp
|
||||
cache_to = fl_gray_ramp(r*FL_NUM_GRAY/256);
|
||||
else // get it out of color cube:
|
||||
cache_to =
|
||||
fl_color_cube(r*FL_NUM_RED/256,g*FL_NUM_GREEN/256,b*FL_NUM_BLUE/256);
|
||||
return cache_to;
|
||||
return fl_color_average(c, FL_GRAY, .33f);
|
||||
}
|
||||
|
||||
Fl_Color contrast(Fl_Color fg, Fl_Color bg) {
|
||||
@@ -349,5 +351,5 @@ Fl_Color contrast(Fl_Color fg, Fl_Color bg) {
|
||||
}
|
||||
|
||||
//
|
||||
// End of "$Id: fl_color.cxx,v 1.11 1999/01/19 19:10:39 mike Exp $".
|
||||
// End of "$Id: fl_color.cxx,v 1.12 1999/01/25 20:43:05 mike Exp $".
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user