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_boxtype.cxx
Go to the documentation of this file.
1 //
2 // "$Id$"
3 //
4 // Box drawing code for the Fast Light Tool Kit (FLTK).
5 //
6 // Copyright 1998-2015 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 
24 // Box drawing code for the common box types and the table of
25 // boxtypes. Other box types are in separate files so they are not
26 // linked in if not used.
27 
28 #include <FL/Fl.H>
29 #include <FL/Fl_Widget.H>
30 #include <FL/fl_draw.H>
31 #include <config.h>
32 
34 
35 static const uchar active_ramp[24] = {
42 static const uchar inactive_ramp[24] = {
43  43, 43, 44, 44,
44  44, 45, 45, 46,
45  46, 46, 47, 47,
46  48, 48, 48, 49,
47  49, 49, 50, 50,
48  51, 51, 52, 52};
49 static int draw_it_active = 1;
50 
59 
61 
70  return (draw_it_active ? c : fl_inactive(c));
71 }
72 
94 
107 void fl_frame(const char* s, int x, int y, int w, int h) {
108  const uchar *g = fl_gray_ramp();
109  if (h > 0 && w > 0) for (;*s;) {
110  // draw top line:
111  fl_color(g[(int)*s++]);
112  fl_xyline(x, y, x+w-1);
113  y++; if (--h <= 0) break;
114  // draw left line:
115  fl_color(g[(int)*s++]);
116  fl_yxline(x, y+h-1, y);
117  x++; if (--w <= 0) break;
118  // draw bottom line:
119  fl_color(g[(int)*s++]);
120  fl_xyline(x, y+h-1, x+w-1);
121  if (--h <= 0) break;
122  // draw right line:
123  fl_color(g[(int)*s++]);
124  fl_yxline(x+w-1, y+h-1, y);
125  if (--w <= 0) break;
126  }
127 }
128 
141 void fl_frame2(const char* s, int x, int y, int w, int h) {
142  const uchar *g = fl_gray_ramp();
143  if (h > 0 && w > 0) for (;*s;) {
144  // draw bottom line:
145  fl_color(g[(int)*s++]);
146  fl_xyline(x, y+h-1, x+w-1);
147  if (--h <= 0) break;
148  // draw right line:
149  fl_color(g[(int)*s++]);
150  fl_yxline(x+w-1, y+h-1, y);
151  if (--w <= 0) break;
152  // draw top line:
153  fl_color(g[(int)*s++]);
154  fl_xyline(x, y, x+w-1);
155  y++; if (--h <= 0) break;
156  // draw left line:
157  fl_color(g[(int)*s++]);
158  fl_yxline(x, y+h-1, y);
159  x++; if (--w <= 0) break;
160  }
161 }
162 
164 void fl_no_box(int, int, int, int, Fl_Color) {}
165 
167 void fl_flat_box(int x, int y, int w, int h, Fl_Color c) {
168  fl_rectf(x, y, w, h, Fl::box_color(c));
169 }
170 
172 void fl_thin_down_frame(int x, int y, int w, int h, Fl_Color) {
173  fl_frame2("WWHH",x,y,w,h);
174 }
175 
177 void fl_thin_down_box(int x, int y, int w, int h, Fl_Color c) {
178  fl_thin_down_frame(x,y,w,h,c);
180  fl_rectf(x+1, y+1, w-2, h-2);
181 }
182 
184 void fl_thin_up_frame(int x, int y, int w, int h, Fl_Color) {
185  fl_frame2("HHWW",x,y,w,h);
186 }
187 
189 void fl_thin_up_box(int x, int y, int w, int h, Fl_Color c) {
190  fl_thin_up_frame(x,y,w,h,c);
192  fl_rectf(x+1, y+1, w-2, h-2);
193 }
194 
196 void fl_up_frame(int x, int y, int w, int h, Fl_Color) {
197 #if BORDER_WIDTH == 1
198  fl_frame2("HHWW",x,y,w,h);
199 #else
200 #if BORDER_WIDTH == 2
201  fl_frame2("AAWWMMTT",x,y,w,h);
202 #else
203  fl_frame("AAAAWWJJUTNN",x,y,w,h);
204 #endif
205 #endif
206 }
207 
208 #define D1 BORDER_WIDTH
209 #define D2 (BORDER_WIDTH+BORDER_WIDTH)
210 
212 void fl_up_box(int x, int y, int w, int h, Fl_Color c) {
213  fl_up_frame(x,y,w,h,c);
215  fl_rectf(x+D1, y+D1, w-D2, h-D2);
216 }
217 
219 void fl_down_frame(int x, int y, int w, int h, Fl_Color) {
220 #if BORDER_WIDTH == 1
221  fl_frame2("WWHH",x,y,w,h);
222 #else
223 #if BORDER_WIDTH == 2
224  fl_frame2("WWMMPPAA",x,y,w,h);
225 #else
226  fl_frame("NNTUJJWWAAAA",x,y,w,h);
227 #endif
228 #endif
229 }
230 
232 void fl_down_box(int x, int y, int w, int h, Fl_Color c) {
233  fl_down_frame(x,y,w,h,c);
235  fl_rectf(x+D1, y+D1, w-D2, h-D2);
236 }
237 
239 void fl_engraved_frame(int x, int y, int w, int h, Fl_Color) {
240  fl_frame("HHWWWWHH",x,y,w,h);
241 }
242 
244 void fl_engraved_box(int x, int y, int w, int h, Fl_Color c) {
245  fl_engraved_frame(x,y,w,h,c);
247  fl_rectf(x+2, y+2, w-4, h-4);
248 }
249 
251 void fl_embossed_frame(int x, int y, int w, int h, Fl_Color) {
252  fl_frame("WWHHHHWW",x,y,w,h);
253 }
254 
256 void fl_embossed_box(int x, int y, int w, int h, Fl_Color c) {
257  fl_embossed_frame(x,y,w,h,c);
259  fl_rectf(x+2, y+2, w-4, h-4);
260 }
261 
266 void fl_rectbound(int x, int y, int w, int h, Fl_Color bgcolor) {
268  fl_rect(x, y, w, h);
269  Fl::set_box_color(bgcolor);
270  fl_rectf(x+1, y+1, w-2, h-2);
271 }
272 #define fl_border_box fl_rectbound
277 void fl_border_frame(int x, int y, int w, int h, Fl_Color c) {
279  fl_rect(x, y, w, h);
280 }
281 
283 
284 static struct {
287  int set;
288 } fl_box_table[256] = {
289 // must match list in Enumerations.H!!!
290  {fl_no_box, 0,0,0,0,1},
291  {fl_flat_box, 0,0,0,0,1}, // FL_FLAT_BOX
292  {fl_up_box, D1,D1,D2,D2,1},
293  {fl_down_box, D1,D1,D2,D2,1},
294  {fl_up_frame, D1,D1,D2,D2,1},
295  {fl_down_frame, D1,D1,D2,D2,1},
296  {fl_thin_up_box, 1,1,2,2,1},
297  {fl_thin_down_box, 1,1,2,2,1},
298  {fl_thin_up_frame, 1,1,2,2,1},
299  {fl_thin_down_frame, 1,1,2,2,1},
300  {fl_engraved_box, 2,2,4,4,1},
301  {fl_embossed_box, 2,2,4,4,1},
302  {fl_engraved_frame, 2,2,4,4,1},
303  {fl_embossed_frame, 2,2,4,4,1},
304  {fl_border_box, 1,1,2,2,1},
305  {fl_border_box, 1,1,5,5,0}, // _FL_SHADOW_BOX
306  {fl_border_frame, 1,1,2,2,1},
307  {fl_border_frame, 1,1,5,5,0}, // _FL_SHADOW_FRAME
308  {fl_border_box, 1,1,2,2,0}, // _FL_ROUNDED_BOX
309  {fl_border_box, 1,1,2,2,0}, // _FL_RSHADOW_BOX
310  {fl_border_frame, 1,1,2,2,0}, // _FL_ROUNDED_FRAME
311  {fl_flat_box, 0,0,0,0,0}, // _FL_RFLAT_BOX
312  {fl_up_box, 3,3,6,6,0}, // _FL_ROUND_UP_BOX
313  {fl_down_box, 3,3,6,6,0}, // _FL_ROUND_DOWN_BOX
314  {fl_up_box, 0,0,0,0,0}, // _FL_DIAMOND_UP_BOX
315  {fl_down_box, 0,0,0,0,0}, // _FL_DIAMOND_DOWN_BOX
316  {fl_border_box, 1,1,2,2,0}, // _FL_OVAL_BOX
317  {fl_border_box, 1,1,2,2,0}, // _FL_OVAL_SHADOW_BOX
318  {fl_border_frame, 1,1,2,2,0}, // _FL_OVAL_FRAME
319  {fl_flat_box, 0,0,0,0,0}, // _FL_OVAL_FLAT_BOX
320  {fl_up_box, 4,4,8,8,0}, // _FL_PLASTIC_UP_BOX
321  {fl_down_box, 2,2,4,4,0}, // _FL_PLASTIC_DOWN_BOX
322  {fl_up_frame, 2,2,4,4,0}, // _FL_PLASTIC_UP_FRAME
323  {fl_down_frame, 2,2,4,4,0}, // _FL_PLASTIC_DOWN_FRAME
324  {fl_up_box, 2,2,4,4,0}, // _FL_PLASTIC_THIN_UP_BOX
325  {fl_down_box, 2,2,4,4,0}, // _FL_PLASTIC_THIN_DOWN_BOX
326  {fl_up_box, 2,2,4,4,0}, // _FL_PLASTIC_ROUND_UP_BOX
327  {fl_down_box, 2,2,4,4,0}, // _FL_PLASTIC_ROUND_DOWN_BOX
328  {fl_up_box, 2,2,4,4,0}, // _FL_GTK_UP_BOX
329  {fl_down_box, 2,2,4,4,0}, // _FL_GTK_DOWN_BOX
330  {fl_up_frame, 2,2,4,4,0}, // _FL_GTK_UP_FRAME
331  {fl_down_frame, 2,2,4,4,0}, // _FL_GTK_DOWN_FRAME
332  {fl_up_frame, 1,1,2,2,0}, // _FL_GTK_THIN_UP_FRAME
333  {fl_down_frame, 1,1,2,2,0}, // _FL_GTK_THIN_DOWN_FRAME
334  {fl_up_box, 1,1,2,2,0}, // _FL_GTK_THIN_ROUND_UP_BOX
335  {fl_down_box, 1,1,2,2,0}, // _FL_GTK_THIN_ROUND_DOWN_BOX
336  {fl_up_box, 2,2,4,4,0}, // _FL_GTK_ROUND_UP_BOX
337  {fl_down_box, 2,2,4,4,0}, // _FL_GTK_ROUND_DOWN_BOX
338  {fl_up_box, 2,2,4,4,0}, // _FL_GLEAM_UP_BOX
339  {fl_down_box, 2,2,4,4,0}, // _FL_GLEAM_DOWN_BOX
340  {fl_up_frame, 2,2,4,4,0}, // _FL_GLEAM_UP_FRAME
341  {fl_down_frame, 2,2,4,4,0}, // _FL_GLEAM_DOWN_FRAME
342  {fl_up_box, 2,2,4,4,0}, // _FL_GLEAM_THIN_UP_BOX
343  {fl_down_box, 2,2,4,4,0}, // _FL_GLEAM_THIN_DOWN_BOX
344  {fl_up_box, 2,2,4,4,0}, // _FL_GLEAM_ROUND_UP_BOX
345  {fl_down_box, 2,2,4,4,0}, // _FL_GLEAM_ROUND_DOWN_BOX
346  {fl_up_box, 3,3,6,6,0}, // FL_FREE_BOX+0
347  {fl_down_box, 3,3,6,6,0}, // FL_FREE_BOX+1
348  {fl_up_box, 3,3,6,6,0}, // FL_FREE_BOX+2
349  {fl_down_box, 3,3,6,6,0}, // FL_FREE_BOX+3
350  {fl_up_box, 3,3,6,6,0}, // FL_FREE_BOX+4
351  {fl_down_box, 3,3,6,6,0}, // FL_FREE_BOX+5
352  {fl_up_box, 3,3,6,6,0}, // FL_FREE_BOX+6
353  {fl_down_box, 3,3,6,6,0} // FL_FREE_BOX+7
354 };
355 
360 int Fl::box_dx(Fl_Boxtype t) {return fl_box_table[t].dx;}
361 
385 int Fl::box_dy(Fl_Boxtype t) {return fl_box_table[t].dy;}
386 
391 int Fl::box_dw(Fl_Boxtype t) {return fl_box_table[t].dw;}
392 
397 int Fl::box_dh(Fl_Boxtype t) {return fl_box_table[t].dh;}
398 
405  if (!fl_box_table[t].set) {
406  fl_box_table[t].f = f;
407  fl_box_table[t].set = 1;
408  }
409 }
410 
413  return fl_box_table[t].f;
414 }
417  uchar a, uchar b, uchar c, uchar d) {
418  fl_box_table[t].f = f;
419  fl_box_table[t].set = 1;
420  fl_box_table[t].dx = a;
421  fl_box_table[t].dy = b;
422  fl_box_table[t].dw = c;
423  fl_box_table[t].dh = d;
424 }
427  fl_box_table[to] = fl_box_table[from];
428 }
429 
436 void fl_draw_box(Fl_Boxtype t, int x, int y, int w, int h, Fl_Color c) {
437  if (t && fl_box_table[t].f) fl_box_table[t].f(x,y,w,h,c);
438 }
439 
440 //extern Fl_Widget *fl_boxcheat; // hack set by Fl_Window.cxx
442 void Fl_Widget::draw_box() const {
443  if (box_) draw_box((Fl_Boxtype)box_, x_, y_, w_, h_, color_);
444  draw_backdrop();
445 }
448  if (align() & FL_ALIGN_IMAGE_BACKDROP) {
449  const Fl_Image *img = image();
450  // if there is no image, we will not draw the deimage either
451  if (img && deimage() && !active_r())
452  img = deimage();
453  if (img)
454  ((Fl_Image*)img)->draw(x_+(w_-img->w())/2, y_+(h_-img->h())/2);
455  }
456 }
459  draw_box(t, x_, y_, w_, h_, c);
460 }
462 void Fl_Widget::draw_box(Fl_Boxtype t, int X, int Y, int W, int H, Fl_Color c) const {
464  fl_box_table[t].f(X, Y, W, H, c);
465  draw_it_active = 1;
466 }
467 
468 //
469 // End of "$Id$".
470 //
Fl_Widget.H
inactive_ramp
static const uchar inactive_ramp[24]
Definition: fl_boxtype.cxx:42
Fl::draw_box_active
static int draw_box_active()
Definition: fl_boxtype.cxx:58
Fl_Box_Draw_F
void() Fl_Box_Draw_F(int x, int y, int w, int h, Fl_Color color)
Definition: Fl.H:89
Fl.H
Fl::box_color
static Fl_Color box_color(Fl_Color)
Definition: fl_boxtype.cxx:69
active_ramp
static const uchar active_ramp[24]
Definition: fl_boxtype.cxx:35
fl_rectbound
void fl_rectbound(int x, int y, int w, int h, Fl_Color bgcolor)
Definition: fl_boxtype.cxx:266
Fl_Widget::align
Fl_Align align() const
Definition: Fl_Widget.H:348
fl_rectf
void fl_rectf(int x, int y, int w, int h)
Definition: fl_draw.H:206
Fl_Widget::x_
int x_
Definition: Fl_Widget.H:107
Fl_Widget::draw_box
void draw_box() const
Definition: fl_boxtype.cxx:442
Fl_Widget::h_
int h_
Definition: Fl_Widget.H:107
Fl_Color
unsigned int Fl_Color
Definition: Enumerations.H:934
fl_engraved_box
void fl_engraved_box(int x, int y, int w, int h, Fl_Color c)
Definition: fl_boxtype.cxx:244
Fl_Image::h
void h(int H)
Definition: Fl_Image.H:80
fl_border_frame
void fl_border_frame(int x, int y, int w, int h, Fl_Color c)
Definition: fl_boxtype.cxx:277
draw_it_active
static int draw_it_active
Definition: fl_boxtype.cxx:49
Fl::box_dx
static int box_dx(Fl_Boxtype)
Definition: fl_boxtype.cxx:360
Fl_Boxtype
Fl_Boxtype
Definition: Enumerations.H:603
Fl_Image
Base class for image caching and drawing.
Definition: Fl_Image.H:55
fl_up_frame
void fl_up_frame(int x, int y, int w, int h, Fl_Color)
Definition: fl_boxtype.cxx:196
fl_color
void fl_color(Fl_Color c)
Definition: fl_draw.H:52
D1
#define D1
Definition: fl_boxtype.cxx:208
fl_flat_box
void fl_flat_box(int x, int y, int w, int h, Fl_Color c)
Definition: fl_boxtype.cxx:167
H
static int H
Definition: Fl_Tooltip.cxx:76
Fl_Widget::draw_backdrop
void draw_backdrop() const
Definition: fl_boxtype.cxx:447
Fl_Widget::color_
Fl_Color color_
Definition: Fl_Widget.H:110
Fl_Image::w
void w(int W)
Definition: Fl_Image.H:76
fl_thin_down_box
void fl_thin_down_box(int x, int y, int w, int h, Fl_Color c)
Definition: fl_boxtype.cxx:177
b
long b
Definition: jpegint.h:397
FL_BLACK
const Fl_Color FL_BLACK
Definition: Enumerations.H:956
fl_border_box
#define fl_border_box
Definition: fl_boxtype.cxx:272
Fl::box_dh
static int box_dh(Fl_Boxtype)
Definition: fl_boxtype.cxx:397
Fl::set_boxtype
static void set_boxtype(Fl_Boxtype, Fl_Box_Draw_F *, uchar, uchar, uchar, uchar)
Definition: fl_boxtype.cxx:416
fl_embossed_box
void fl_embossed_box(int x, int y, int w, int h, Fl_Color c)
Definition: fl_boxtype.cxx:256
Fl::box_dw
static int box_dw(Fl_Boxtype)
Definition: fl_boxtype.cxx:391
Fl::set_box_color
static void set_box_color(Fl_Color)
Definition: fl_boxtype.cxx:93
fl_internal_boxtype
void fl_internal_boxtype(Fl_Boxtype t, Fl_Box_Draw_F *f)
Definition: fl_boxtype.cxx:404
dw
uchar dw
Definition: fl_boxtype.cxx:286
Fl::box_dy
static int box_dy(Fl_Boxtype)
Definition: fl_boxtype.cxx:385
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_inactive
Fl_Color fl_inactive(Fl_Color c)
Definition: fl_color.cxx:423
Fl_Widget::active_r
int active_r() const
Definition: Fl_Widget.cxx:265
Fl_Widget::y_
int y_
Definition: Fl_Widget.H:107
fl_box_table
static struct @37 fl_box_table[256]
D2
#define D2
Definition: fl_boxtype.cxx:209
fl_up_box
void fl_up_box(int x, int y, int w, int h, Fl_Color c)
Definition: fl_boxtype.cxx:212
fl_yxline
void fl_yxline(int x, int y, int y1)
Definition: fl_draw.H:270
fl_gray_ramp
const uchar * fl_gray_ramp()
Definition: fl_boxtype.cxx:60
Fl::get_boxtype
static Fl_Box_Draw_F * get_boxtype(Fl_Boxtype)
Definition: fl_boxtype.cxx:412
fl_no_box
void fl_no_box(int, int, int, int, Fl_Color)
Definition: fl_boxtype.cxx:164
fl_engraved_frame
void fl_engraved_frame(int x, int y, int w, int h, Fl_Color)
Definition: fl_boxtype.cxx:239
fl_draw_box
void fl_draw_box(Fl_Boxtype t, int x, int y, int w, int h, Fl_Color c)
Definition: fl_boxtype.cxx:436
x
int x
Definition: test.c:73
Fl_Widget::w_
int w_
Definition: Fl_Widget.H:107
dy
uchar dy
Definition: fl_boxtype.cxx:286
y
int y
Definition: test.c:74
set
int set
Definition: fl_boxtype.cxx:287
FL_GRAY_RAMP
#define FL_GRAY_RAMP
Definition: Enumerations.H:976
fl_thin_up_frame
void fl_thin_up_frame(int x, int y, int w, int h, Fl_Color)
Definition: fl_boxtype.cxx:184
f
Fl_Box_Draw_F * f
Definition: fl_boxtype.cxx:285
Y
static int Y
Definition: Fl_Tooltip.cxx:76
fl_down_box
void fl_down_box(int x, int y, int w, int h, Fl_Color c)
Definition: fl_boxtype.cxx:232
fl_thin_down_frame
void fl_thin_down_frame(int x, int y, int w, int h, Fl_Color)
Definition: fl_boxtype.cxx:172
fl_frame
void fl_frame(const char *s, int x, int y, int w, int h)
Definition: fl_boxtype.cxx:107
Fl_Widget::box_
uchar box_
Definition: Fl_Widget.H:114
fl_thin_up_box
void fl_thin_up_box(int x, int y, int w, int h, Fl_Color c)
Definition: fl_boxtype.cxx:189
uchar
unsigned char uchar
Definition: fl_types.h:30
fl_down_frame
void fl_down_frame(int x, int y, int w, int h, Fl_Color)
Definition: fl_boxtype.cxx:219
Fl_Widget::deimage
Fl_Image * deimage()
Definition: Fl_Widget.H:533
dh
uchar dh
Definition: fl_boxtype.cxx:286
dx
uchar dx
Definition: fl_boxtype.cxx:286
fl_frame2
void fl_frame2(const char *s, int x, int y, int w, int h)
Definition: fl_boxtype.cxx:141
Fl_Widget::image
Fl_Image * image()
Definition: Fl_Widget.H:514
fl_embossed_frame
void fl_embossed_frame(int x, int y, int w, int h, Fl_Color)
Definition: fl_boxtype.cxx:251
FL_ALIGN_IMAGE_BACKDROP
const Fl_Align FL_ALIGN_IMAGE_BACKDROP
Definition: Enumerations.H:857
fl_rect
void fl_rect(int x, int y, int w, int h)
Definition: fl_draw.H:201