source: rtems-graphics-toolkit/fltk-1.1.10/src/fl_boxtype.cxx @ 513eea1

Last change on this file since 513eea1 was 513eea1, checked in by Joel Sherrill <joel.sherrill@…>, on 01/09/10 at 22:43:24

2010-01-08 Joel Sherrill <joel.sherrill@…>

fltk 1.1.10. imported

  • ORIGIN: Updated.
  • Property mode set to 100644
File size: 9.7 KB
Line 
1//
2// "$Id$"
3//
4// Box drawing code for the Fast Light Tool Kit (FLTK).
5//
6// Copyright 1998-2006 by Bill Spitzak and others.
7//
8// This library is free software; you can redistribute it and/or
9// modify it under the terms of the GNU Library General Public
10// License as published by the Free Software Foundation; either
11// version 2 of the License, or (at your option) any later version.
12//
13// This library is distributed in the hope that it will be useful,
14// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16// Library General Public License for more details.
17//
18// You should have received a copy of the GNU Library General Public
19// License along with this library; if not, write to the Free Software
20// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
21// USA.
22//
23// Please report all bugs and problems on the following page:
24//
25//     http://www.fltk.org/str.php
26//
27
28// Box drawing code for the common box types and the table of
29// boxtypes.  Other box types are in seperate files so they are not
30// linked in if not used.
31
32#include <FL/Fl.H>
33#include <FL/Fl_Widget.H>
34#include <FL/fl_draw.H>
35#include <config.h>
36
37////////////////////////////////////////////////////////////////
38
39static uchar active_ramp[24] = {
40  FL_GRAY_RAMP+0, FL_GRAY_RAMP+1, FL_GRAY_RAMP+2, FL_GRAY_RAMP+3,
41  FL_GRAY_RAMP+4, FL_GRAY_RAMP+5, FL_GRAY_RAMP+6, FL_GRAY_RAMP+7,
42  FL_GRAY_RAMP+8, FL_GRAY_RAMP+9, FL_GRAY_RAMP+10,FL_GRAY_RAMP+11,
43  FL_GRAY_RAMP+12,FL_GRAY_RAMP+13,FL_GRAY_RAMP+14,FL_GRAY_RAMP+15,
44  FL_GRAY_RAMP+16,FL_GRAY_RAMP+17,FL_GRAY_RAMP+18,FL_GRAY_RAMP+19,
45  FL_GRAY_RAMP+20,FL_GRAY_RAMP+21,FL_GRAY_RAMP+22,FL_GRAY_RAMP+23};
46static uchar inactive_ramp[24] = {
47  43, 43, 44, 44,
48  44, 45, 45, 46,
49  46, 46, 47, 47,
50  48, 48, 48, 49,
51  49, 49, 50, 50,
52  51, 51, 52, 52};
53static int draw_it_active = 1;
54
55int Fl::draw_box_active() { return draw_it_active; }
56
57uchar *fl_gray_ramp() {return (draw_it_active?active_ramp:inactive_ramp)-'A';}
58
59void fl_frame(const char* s, int x, int y, int w, int h) {
60  uchar *g = fl_gray_ramp();
61  if (h > 0 && w > 0) for (;*s;) {
62    // draw top line:
63    fl_color(g[*s++]);
64    fl_xyline(x, y, x+w-1);
65    y++; if (--h <= 0) break;
66    // draw left line:
67    fl_color(g[*s++]);
68    fl_yxline(x, y+h-1, y);
69    x++; if (--w <= 0) break;
70    // draw bottom line:
71    fl_color(g[*s++]);
72    fl_xyline(x, y+h-1, x+w-1);
73    if (--h <= 0) break;
74    // draw right line:
75    fl_color(g[*s++]);
76    fl_yxline(x+w-1, y+h-1, y);
77    if (--w <= 0) break;
78  }
79}
80
81void fl_frame2(const char* s, int x, int y, int w, int h) {
82  uchar *g = fl_gray_ramp();
83  if (h > 0 && w > 0) for (;*s;) {
84    // draw bottom line:
85    fl_color(g[*s++]);
86    fl_xyline(x, y+h-1, x+w-1);
87    if (--h <= 0) break;
88    // draw right line:
89    fl_color(g[*s++]);
90    fl_yxline(x+w-1, y+h-1, y);
91    if (--w <= 0) break;
92    // draw top line:
93    fl_color(g[*s++]);
94    fl_xyline(x, y, x+w-1);
95    y++; if (--h <= 0) break;
96    // draw left line:
97    fl_color(g[*s++]);
98    fl_yxline(x, y+h-1, y);
99    x++; if (--w <= 0) break;
100  }
101}
102
103void fl_no_box(int, int, int, int, Fl_Color) {}
104
105void fl_thin_down_frame(int x, int y, int w, int h, Fl_Color) {
106  fl_frame2("WWHH",x,y,w,h);
107}
108
109void fl_thin_down_box(int x, int y, int w, int h, Fl_Color c) {
110  fl_thin_down_frame(x,y,w,h,c);
111  fl_color(draw_it_active ? c : fl_inactive(c));
112  fl_rectf(x+1, y+1, w-2, h-2);
113}
114
115void fl_thin_up_frame(int x, int y, int w, int h, Fl_Color) {
116  fl_frame2("HHWW",x,y,w,h);
117}
118
119void fl_thin_up_box(int x, int y, int w, int h, Fl_Color c) {
120  fl_thin_up_frame(x,y,w,h,c);
121  fl_color(draw_it_active ? c : fl_inactive(c));
122  fl_rectf(x+1, y+1, w-2, h-2);
123}
124
125void fl_up_frame(int x, int y, int w, int h, Fl_Color) {
126#if BORDER_WIDTH == 1
127  fl_frame2("HHWW",x,y,w,h);
128#else
129#if BORDER_WIDTH == 2
130  fl_frame2("AAWWMMTT",x,y,w,h);
131#else
132  fl_frame("AAAAWWJJUTNN",x,y,w,h);
133#endif
134#endif
135}
136
137#define D1 BORDER_WIDTH
138#define D2 (BORDER_WIDTH+BORDER_WIDTH)
139
140void fl_up_box(int x, int y, int w, int h, Fl_Color c) {
141  fl_up_frame(x,y,w,h,c);
142  fl_color(draw_it_active ? c : fl_inactive(c));
143  fl_rectf(x+D1, y+D1, w-D2, h-D2);
144}
145
146void fl_down_frame(int x, int y, int w, int h, Fl_Color) {
147#if BORDER_WIDTH == 1
148  fl_frame2("WWHH",x,y,w,h);
149#else
150#if BORDER_WIDTH == 2
151  fl_frame2("WWMMPPAA",x,y,w,h);
152#else
153  fl_frame("NNTUJJWWAAAA",x,y,w,h);
154#endif
155#endif
156}
157
158void fl_down_box(int x, int y, int w, int h, Fl_Color c) {
159  fl_down_frame(x,y,w,h,c);
160  fl_color(c); fl_rectf(x+D1, y+D1, w-D2, h-D2);
161}
162
163void fl_engraved_frame(int x, int y, int w, int h, Fl_Color) {
164  fl_frame("HHWWWWHH",x,y,w,h);
165}
166
167void fl_engraved_box(int x, int y, int w, int h, Fl_Color c) {
168  fl_engraved_frame(x,y,w,h,c);
169  fl_color(draw_it_active ? c : fl_inactive(c));
170  fl_rectf(x+2, y+2, w-4, h-4);
171}
172
173void fl_embossed_frame(int x, int y, int w, int h, Fl_Color) {
174  fl_frame("WWHHHHWW",x,y,w,h);
175}
176
177void fl_embossed_box(int x, int y, int w, int h, Fl_Color c) {
178  fl_embossed_frame(x,y,w,h,c);
179  fl_color(draw_it_active ? c : fl_inactive(c));
180  fl_rectf(x+2, y+2, w-4, h-4);
181}
182
183void fl_rectbound(int x, int y, int w, int h, Fl_Color bgcolor) {
184  fl_color(draw_it_active ? FL_BLACK : fl_inactive(FL_BLACK));
185  fl_rect(x, y, w, h);
186  fl_color(draw_it_active ? bgcolor : fl_inactive(bgcolor));
187  fl_rectf(x+1, y+1, w-2, h-2);
188}
189#define fl_border_box fl_rectbound
190
191void fl_border_frame(int x, int y, int w, int h, Fl_Color c) {
192  fl_color(draw_it_active ? c : fl_inactive(c));
193  fl_rect(x, y, w, h);
194}
195
196////////////////////////////////////////////////////////////////
197
198static struct {
199  Fl_Box_Draw_F *f;
200  uchar dx, dy, dw, dh;
201  int set;
202} fl_box_table[256] = {
203// must match list in Enumerations.H!!!
204  {fl_no_box,           0,0,0,0,1},             
205  {fl_rectf,            0,0,0,0,1}, // FL_FLAT_BOX
206  {fl_up_box,           D1,D1,D2,D2,1},
207  {fl_down_box,         D1,D1,D2,D2,1},
208  {fl_up_frame,         D1,D1,D2,D2,1},
209  {fl_down_frame,       D1,D1,D2,D2,1},
210  {fl_thin_up_box,      1,1,2,2,1},
211  {fl_thin_down_box,    1,1,2,2,1},
212  {fl_thin_up_frame,    1,1,2,2,1},
213  {fl_thin_down_frame,  1,1,2,2,1},
214  {fl_engraved_box,     2,2,4,4,1},
215  {fl_embossed_box,     2,2,4,4,1},
216  {fl_engraved_frame,   2,2,4,4,1},
217  {fl_embossed_frame,   2,2,4,4,1},
218  {fl_border_box,       1,1,2,2,1},
219  {fl_border_box,       1,1,5,5,0}, // _FL_SHADOW_BOX,
220  {fl_border_frame,     1,1,2,2,1},
221  {fl_border_frame,     1,1,5,5,0}, // _FL_SHADOW_FRAME,
222  {fl_border_box,       1,1,2,2,0}, // _FL_ROUNDED_BOX,
223  {fl_border_box,       1,1,2,2,0}, // _FL_RSHADOW_BOX,
224  {fl_border_frame,     1,1,2,2,0}, // _FL_ROUNDED_FRAME
225  {fl_rectf,            0,0,0,0,0}, // _FL_RFLAT_BOX,
226  {fl_up_box,           3,3,6,6,0}, // _FL_ROUND_UP_BOX
227  {fl_down_box,         3,3,6,6,0}, // _FL_ROUND_DOWN_BOX,
228  {fl_up_box,           0,0,0,0,0}, // _FL_DIAMOND_UP_BOX
229  {fl_down_box,         0,0,0,0,0}, // _FL_DIAMOND_DOWN_BOX
230  {fl_border_box,       1,1,2,2,0}, // _FL_OVAL_BOX,
231  {fl_border_box,       1,1,2,2,0}, // _FL_OVAL_SHADOW_BOX,
232  {fl_border_frame,     1,1,2,2,0}, // _FL_OVAL_FRAME
233  {fl_rectf,            0,0,0,0,0}, // _FL_OVAL_FLAT_BOX,
234  {fl_up_box,           4,4,8,8,0}, // _FL_PLASTIC_UP_BOX,
235  {fl_down_box,         2,2,4,4,0}, // _FL_PLASTIC_DOWN_BOX,
236  {fl_up_frame,         2,2,4,4,0}, // _FL_PLASTIC_UP_FRAME,
237  {fl_down_frame,       2,2,4,4,0}, // _FL_PLASTIC_DOWN_FRAME,
238  {fl_up_box,           2,2,4,4,0}, // _FL_PLASTIC_THIN_UP_BOX,
239  {fl_down_box,         2,2,4,4,0}, // _FL_PLASTIC_THIN_DOWN_BOX,
240  {fl_up_box,           2,2,4,4,0}, // _FL_PLASTIC_ROUND_UP_BOX,
241  {fl_down_box,         2,2,4,4,0}, // _FL_PLASTIC_ROUND_DOWN_BOX,
242  {fl_up_box,           2,2,4,4,0}, // _FL_GTK_UP_BOX,
243  {fl_down_box,         2,2,4,4,0}, // _FL_GTK_DOWN_BOX,
244  {fl_up_frame,         2,2,4,4,0}, // _FL_GTK_UP_FRAME,
245  {fl_down_frame,       2,2,4,4,0}, // _FL_GTK_DOWN_FRAME,
246  {fl_up_frame,         1,1,2,2,0}, // _FL_GTK_THIN_UP_FRAME,
247  {fl_down_frame,       1,1,2,2,0}, // _FL_GTK_THIN_DOWN_FRAME,
248  {fl_up_box,           1,1,2,2,0}, // _FL_GTK_THIN_ROUND_UP_BOX,
249  {fl_down_box,         1,1,2,2,0}, // _FL_GTK_THIN_ROUND_DOWN_BOX,
250  {fl_up_box,           2,2,4,4,0}, // _FL_GTK_ROUND_UP_BOX,
251  {fl_down_box,         2,2,4,4,0}, // _FL_GTK_ROUND_DOWN_BOX,
252  {fl_up_box,           3,3,6,6,0}, // FL_FREE_BOX+0
253  {fl_down_box,         3,3,6,6,0}, // FL_FREE_BOX+1
254  {fl_up_box,           3,3,6,6,0}, // FL_FREE_BOX+2
255  {fl_down_box,         3,3,6,6,0}, // FL_FREE_BOX+3
256  {fl_up_box,           3,3,6,6,0}, // FL_FREE_BOX+4
257  {fl_down_box,         3,3,6,6,0}, // FL_FREE_BOX+5
258  {fl_up_box,           3,3,6,6,0}, // FL_FREE_BOX+6
259  {fl_down_box,         3,3,6,6,0}, // FL_FREE_BOX+7
260};
261
262int Fl::box_dx(Fl_Boxtype t) {return fl_box_table[t].dx;}
263int Fl::box_dy(Fl_Boxtype t) {return fl_box_table[t].dy;}
264int Fl::box_dw(Fl_Boxtype t) {return fl_box_table[t].dw;}
265int Fl::box_dh(Fl_Boxtype t) {return fl_box_table[t].dh;}
266
267void fl_internal_boxtype(Fl_Boxtype t, Fl_Box_Draw_F* f) {
268  if (!fl_box_table[t].set) {
269    fl_box_table[t].f   = f;
270    fl_box_table[t].set = 1;
271  }
272}
273
274Fl_Box_Draw_F *Fl::get_boxtype(Fl_Boxtype t) {
275  return fl_box_table[t].f;
276}
277
278void Fl::set_boxtype(Fl_Boxtype t, Fl_Box_Draw_F* f,
279                      uchar a, uchar b, uchar c, uchar d) {
280  fl_box_table[t].f   = f;
281  fl_box_table[t].set = 1;
282  fl_box_table[t].dx  = a;
283  fl_box_table[t].dy  = b;
284  fl_box_table[t].dw  = c;
285  fl_box_table[t].dh  = d;
286}
287
288void Fl::set_boxtype(Fl_Boxtype t, Fl_Boxtype f) {
289  fl_box_table[t] = fl_box_table[f];
290}
291
292void fl_draw_box(Fl_Boxtype t, int x, int y, int w, int h, Fl_Color c) {
293  if (t && fl_box_table[t].f) fl_box_table[t].f(x,y,w,h,c);
294}
295
296//extern Fl_Widget *fl_boxcheat; // hack set by Fl_Window.cxx
297
298void Fl_Widget::draw_box() const {
299  int t = box_;
300  if (!t) return;
301//   if (this == fl_boxcheat) {
302//     fl_boxcheat = 0;
303//     if (t == FL_FLAT_BOX) return;
304//     t += 2; // convert box to frame
305//   }
306  draw_box((Fl_Boxtype)t, x_, y_, w_, h_, (Fl_Color)color_);
307}
308
309void Fl_Widget::draw_box(Fl_Boxtype b, Fl_Color c) const {
310  draw_box(b, x_, y_, w_, h_, c);
311}
312
313void Fl_Widget::draw_box(Fl_Boxtype b, int X, int Y, int W, int H, Fl_Color c)
314const {
315  draw_it_active = active_r();
316  fl_box_table[b].f(X, Y, W, H, c);
317  draw_it_active = 1;
318}
319
320//
321// End of "$Id$".
322//
Note: See TracBrowser for help on using the repository browser.