fltk  1.3.5-source
About: FLTK (Fast Light Tool Kit) is a cross-platform C++ GUI toolkit for UNIX/Linux (X11), Microsoft Windows, and MacOS X.
  Fossies Dox: fltk-1.3.5-source.tar.bz2  ("inofficial" and yet experimental doxygen-generated source code documentation)  

fl_gleam.cxx
Go to the documentation of this file.
1 //
2 // "$Id$"
3 //
4 // "Gleam" scheme box drawing routines for the Fast Light Tool Kit (FLTK).
5 //
6 // Copyright 1998-2018 by Bill Spitzak and others.
7 //
8 // This library is free software. Distribution and use rights are outlined in
9 // the file "COPYING" which should have been included with this file. If this
10 // file is missing or damaged, see the license at:
11 //
12 // http://www.fltk.org/COPYING.php
13 //
14 // Please report all bugs and problems on the following page:
15 //
16 // http://www.fltk.org/str.php
17 //
18 // These box types provide a sort of Clearlooks Glossy scheme
19 // for FLTK.
20 //
21 // Copyright 2001-2005 by Colin Jones.
22 //
23 // Modified 2012-2013 by Edmanuel Torres
24 // This is a new version of the fl_gleam. The gradients are on the top
25 // and the bottom, the text area looks like in the classic FLTK way.
26 //
27 
28 #include <FL/Fl.H>
29 #include <FL/fl_draw.H>
30 
31 /*
32  Implementation notes:
33 
34  All box types have 2 pixel wide borders, there is no distinction
35  of "thin" box types, hence Fl::box_dx() = Fl::box_dy() = 2,
36  Fl::box_dw() = Fl::box_dh() = 4 for all box types.
37 
38  All coordinates of function calls (x, y, w, h) describe the full
39  box size with borders, i.e. the original box coordinates.
40  The interior (background) of the box is drawn with reduced size.
41  This is adjusted only in function shade_rect_top_bottom().
42 
43  Note: There is one pixel "leaking" out of the box border at each
44  corner which is currently not drawn in a full box redraw.
45 */
46 
47 // Standard box drawing code
48 
49 static void gleam_color(Fl_Color c) {
51 }
52 
53 /* Draw the shaded background of the box.
54 
55  This is called before the box frame (border) is drawn.
56  The interior of the box (shaded background) should be inset by two
57  pixels, hence width and height should be reduced by 4 (border size).
58  Since not all pixels of the border are drawn (border lines are shorter
59  by one or two pixels on each side) setting other offsets (+1, -2 instead
60  of +2, -4) would leak the box background color instead of the parent
61  widget's background color.
62  Note: the original implementation was maybe equivalent to using +1 and -2
63  for offset and width, respectively instead of +2 and -4. It is not clear
64  whether this was intended or by accident.
65 */
66 
67 static void shade_rect_top_bottom(int x, int y, int w, int h, Fl_Color fg1, Fl_Color fg2, float th) {
68  // calculate background size w/o borders
69  x += 2; y += 2; w -= 4; h -= 4;
70  // draw the shiny background using maximum limits
71  int h_top = ((h/2) < (20) ? (h/2) : (20)); // min(h/2, 20);
72  int h_bottom = ((h/6) < (15) ? (h/6) : (15)); // min(h/6, 15);
73  int h_flat = h - h_top - h_bottom;
74  float step_size_top = h_top > 1 ? (0.999f/float(h_top)) : 1;
75  float step_size_bottom = h_bottom > 1 ? (0.999f/float(h_bottom)) : 1;
76  // draw the gradient at the top of the widget
77  float k = 1;
78  for (int i = 0; i < h_top; i++, k -= step_size_top) {
79  gleam_color(fl_color_average(fl_color_average(fg1, fg2, th), fg1, k));
80  fl_xyline(x, y+i, x+w-1);
81  }
82 
83  // draw a "flat" rectangle in the middle area of the box
84  gleam_color(fg1);
85  fl_rectf(x, y + h_top, w, h_flat);
86 
87  // draw the gradient at the bottom of the widget
88  k = 1;
89  for (int i = 0; i < h_bottom; i++, k -= step_size_bottom) {
90  gleam_color(fl_color_average(fg1, fl_color_average(fg1, fg2, th), k));
91  fl_xyline(x, y+h_top+h_flat+i, x+w-1);
92  }
93 }
94 
95 // See shade_rect_top_bottom()
96 static void shade_rect_top_bottom_up(int x, int y, int w, int h, Fl_Color bc, float th) {
97  shade_rect_top_bottom(x, y, w, h, bc, FL_WHITE, th);
98 }
99 
100 // See shade_rect_top_bottom()
101 static void shade_rect_top_bottom_down(int x, int y, int w, int h, Fl_Color bc, float th) {
102  shade_rect_top_bottom(x, y, w, h, bc, FL_BLACK, th);
103 }
104 
105 // Draw box borders. Color arguments:
106 // - fg1: outer border line (left, right, top, bottom)
107 // - fg2: inner border line (left, right)
108 // - lc : inner border line (top, bottom)
109 
110 static void frame_rect(int x, int y, int w, int h, Fl_Color fg1, Fl_Color fg2, Fl_Color lc) {
111  // outer border line:
112  gleam_color(fg1);
113  fl_xyline(x+1, y, x+w-2); // top
114  fl_yxline(x+w-1, y+1, y+h-2); // right
115  fl_xyline(x+1, y+h-1, x+w-2); // bottom
116  fl_yxline(x, y+1, y+h-2); // left
117 
118  // inner border line (left, right):
119  gleam_color(fg2);
120  fl_yxline(x+1, y+2, y+h-3); // left
121  fl_yxline(x+w-2, y+2, y+h-3); // right
122 
123  // inner border line (top, bottom):
124  gleam_color(lc);
125  fl_xyline(x+2, y+1, x+w-3); // top
126  fl_xyline(x+2, y+h-2, x+w-3); // bottom
127 }
128 
129 // Draw box borders with different colors (up/down effect).
130 
131 static void frame_rect_up(int x, int y, int w, int h, Fl_Color bc, Fl_Color lc, float th1, float th2) {
132  frame_rect(x, y, w, h, fl_color_average(fl_darker(bc), FL_BLACK, th1), fl_color_average(bc, FL_WHITE, th2), lc);
133 }
134 
135 static void frame_rect_down(int x, int y, int w, int h, Fl_Color bc, Fl_Color lc, float th1, float th2) {
136  frame_rect(x,y,w,h,fl_color_average(bc, FL_WHITE, th1), fl_color_average(FL_BLACK, bc, th2), lc);
137 }
138 
139 // Draw the different box types. These are the actual box drawing functions.
140 
141 static void up_frame(int x, int y, int w, int h, Fl_Color c) {
142  frame_rect_up(x, y, w, h, c, fl_color_average(c, FL_WHITE, .25f), .55f, .05f);
143 }
144 
145 static void up_box(int x, int y, int w, int h, Fl_Color c) {
146  shade_rect_top_bottom_up(x, y, w, h, c, .15f);
147  frame_rect_up(x, y, w, h, c, fl_color_average(c, FL_WHITE, .05f), .15f, .05f);
148 }
149 
150 static void thin_up_box(int x, int y, int w, int h, Fl_Color c) {
151  shade_rect_top_bottom_up(x, y, w, h, c, .25f);
152  frame_rect_up(x, y, w, h, c, fl_color_average(c, FL_WHITE, .45f), .25f, .15f);
153 }
154 
155 static void down_frame(int x, int y, int w, int h, Fl_Color c) {
156  frame_rect_down(x, y, w, h, fl_darker(c), fl_darker(c), .25f, .95f);
157 }
158 
159 static void down_box(int x, int y, int w, int h, Fl_Color c) {
160  shade_rect_top_bottom_down(x, y, w, h, c, .65f);
161  frame_rect_down(x, y, w, h, c, fl_color_average(c, FL_BLACK, .05f), .05f, .95f);
162 }
163 
164 static void thin_down_box(int x, int y, int w, int h, Fl_Color c) {
165  shade_rect_top_bottom_down(x, y, w, h, c, .85f);
166  frame_rect_down(x, y, w, h, c, fl_color_average(c, FL_BLACK, .45f), .35f, 0.85f);
167 }
168 
170 
180  return _FL_GLEAM_UP_BOX;
181 }
182 
183 
184 //
185 // End of "$Id$".
186 //
Fl_Box_Draw_F
void() Fl_Box_Draw_F(int x, int y, int w, int h, Fl_Color color)
Definition: Fl.H:89
gleam_color
static void gleam_color(Fl_Color c)
Definition: fl_gleam.cxx:49
Fl.H
fl_rectf
void fl_rectf(int x, int y, int w, int h)
Definition: fl_draw.H:206
Fl_Color
unsigned int Fl_Color
Definition: Enumerations.H:934
up_box
static void up_box(int x, int y, int w, int h, Fl_Color c)
Definition: fl_gleam.cxx:145
Fl_Boxtype
Fl_Boxtype
Definition: Enumerations.H:603
FL_WHITE
const Fl_Color FL_WHITE
Definition: Enumerations.H:971
shade_rect_top_bottom_down
static void shade_rect_top_bottom_down(int x, int y, int w, int h, Fl_Color bc, float th)
Definition: fl_gleam.cxx:101
fl_darker
Fl_Color fl_darker(Fl_Color c)
Definition: Enumerations.H:994
_FL_GLEAM_ROUND_DOWN_BOX
gleam version of FL_ROUND_DOWN_BOX
Definition: Enumerations.H:660
_FL_GLEAM_ROUND_UP_BOX
gleam version of FL_ROUND_UP_BOX
Definition: Enumerations.H:659
thin_up_box
static void thin_up_box(int x, int y, int w, int h, Fl_Color c)
Definition: fl_gleam.cxx:150
down_box
static void down_box(int x, int y, int w, int h, Fl_Color c)
Definition: fl_gleam.cxx:159
fl_internal_boxtype
void fl_internal_boxtype(Fl_Boxtype, Fl_Box_Draw_F *)
Definition: fl_boxtype.cxx:404
thin_down_box
static void thin_down_box(int x, int y, int w, int h, Fl_Color c)
Definition: fl_gleam.cxx:164
frame_rect
static void frame_rect(int x, int y, int w, int h, Fl_Color fg1, Fl_Color fg2, Fl_Color lc)
Definition: fl_gleam.cxx:110
FL_BLACK
const Fl_Color FL_BLACK
Definition: Enumerations.H:956
Fl::set_box_color
static void set_box_color(Fl_Color)
Definition: fl_boxtype.cxx:93
fl_xyline
void fl_xyline(int x, int y, int x1)
Definition: fl_draw.H:255
fl_draw.H
utility header to pull drawing functions together
_FL_GLEAM_UP_FRAME
gleam version of FL_UP_FRAME
Definition: Enumerations.H:655
fl_yxline
void fl_yxline(int x, int y, int y1)
Definition: fl_draw.H:270
up_frame
static void up_frame(int x, int y, int w, int h, Fl_Color c)
Definition: fl_gleam.cxx:141
x
int x
Definition: test.c:73
frame_rect_up
static void frame_rect_up(int x, int y, int w, int h, Fl_Color bc, Fl_Color lc, float th1, float th2)
Definition: fl_gleam.cxx:131
fl_define_FL_GLEAM_UP_BOX
Fl_Boxtype fl_define_FL_GLEAM_UP_BOX()
Definition: fl_gleam.cxx:171
_FL_GLEAM_DOWN_FRAME
gleam version of FL_DOWN_FRAME
Definition: Enumerations.H:656
y
int y
Definition: test.c:74
shade_rect_top_bottom
static void shade_rect_top_bottom(int x, int y, int w, int h, Fl_Color fg1, Fl_Color fg2, float th)
Definition: fl_gleam.cxx:67
f
Fl_Box_Draw_F * f
Definition: fl_boxtype.cxx:285
shade_rect_top_bottom_up
static void shade_rect_top_bottom_up(int x, int y, int w, int h, Fl_Color bc, float th)
Definition: fl_gleam.cxx:96
_FL_GLEAM_THIN_UP_BOX
gleam version of FL_THIN_UP_BOX
Definition: Enumerations.H:657
frame_rect_down
static void frame_rect_down(int x, int y, int w, int h, Fl_Color bc, Fl_Color lc, float th1, float th2)
Definition: fl_gleam.cxx:135
_FL_GLEAM_DOWN_BOX
gleam version of FL_DOWN_BOX
Definition: Enumerations.H:654
fl_color_average
Fl_Color fl_color_average(Fl_Color c1, Fl_Color c2, float weight)
Definition: fl_color.cxx:402
down_frame
static void down_frame(int x, int y, int w, int h, Fl_Color c)
Definition: fl_gleam.cxx:155
_FL_GLEAM_UP_BOX
gleam version of FL_UP_BOX
Definition: Enumerations.H:653
_FL_GLEAM_THIN_DOWN_BOX
gleam version of FL_THIN_DOWN_BOX
Definition: Enumerations.H:658