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_gtk.cxx
Go to the documentation of this file.
1 //
2 // "$Id$"
3 //
4 // "GTK" drawing routines for the Fast Light Tool Kit (FLTK).
5 //
6 // These box types provide a GTK+ look, based on Red Hat's Bluecurve
7 // theme...
8 //
9 // Copyright 2006-2010 by Michael Sweet.
10 //
11 // This library is free software. Distribution and use rights are outlined in
12 // the file "COPYING" which should have been included with this file. If this
13 // file is missing or damaged, see the license at:
14 //
15 // http://www.fltk.org/COPYING.php
16 //
17 // Please report all bugs and problems on the following page:
18 //
19 // http://www.fltk.org/str.php
20 //
21 
22 // Box drawing code for an obscure box type.
23 // These box types are in separate files so they are not linked
24 // in if not used.
25 
26 #include <FL/Fl.H>
27 #include <FL/fl_draw.H>
28 
30 
31 
32 static void gtk_color(Fl_Color c) {
34 }
35 
36 static void gtk_up_frame(int x, int y, int w, int h, Fl_Color c) {
38  fl_xyline(x + 2, y + 1, x + w - 3);
39  fl_yxline(x + 1, y + 2, y + h - 3);
40 
42  fl_begin_loop();
43  fl_vertex(x, y + 2);
44  fl_vertex(x + 2, y);
45  fl_vertex(x + w - 3, y);
46  fl_vertex(x + w - 1, y + 2);
47  fl_vertex(x + w - 1, y + h - 3);
48  fl_vertex(x + w - 3, y + h - 1);
49  fl_vertex(x + 2, y + h - 1);
50  fl_vertex(x, y + h - 3);
51  fl_end_loop();
52 }
53 
54 
55 static void gtk_up_box(int x, int y, int w, int h, Fl_Color c) {
56  gtk_up_frame(x, y, w, h, c);
57 
59  fl_xyline(x + 2, y + 2, x + w - 3);
61  fl_xyline(x + 2, y + 3, x + w - 3);
63  fl_xyline(x + 2, y + 4, x + w - 3);
64  gtk_color(c);
65  fl_rectf(x + 2, y + 5, w - 4, h - 7);
67  fl_xyline(x + 2, y + h - 4, x + w - 3);
69  fl_xyline(x + 2, y + h - 3, x + w - 3);
71  fl_xyline(x + 2, y + h - 2, x + w - 3);
72  fl_yxline(x + w - 2, y + 2, y + h - 3);
73 }
74 
75 
76 static void gtk_down_frame(int x, int y, int w, int h, Fl_Color c) {
78  fl_begin_loop();
79  fl_vertex(x, y + 2);
80  fl_vertex(x + 2, y);
81  fl_vertex(x + w - 3, y);
82  fl_vertex(x + w - 1, y + 2);
83  fl_vertex(x + w - 1, y + h - 3);
84  fl_vertex(x + w - 3, y + h - 1);
85  fl_vertex(x + 2, y + h - 1);
86  fl_vertex(x, y + h - 3);
87  fl_end_loop();
88 
90  fl_xyline(x + 2, y + 1, x + w - 3);
91  fl_yxline(x + 1, y + 2, y + h - 3);
92 
94  fl_yxline(x + 2, y + h - 2, y + 2, x + w - 2);
95 }
96 
97 
98 static void gtk_down_box(int x, int y, int w, int h, Fl_Color c) {
99  gtk_down_frame(x, y, w, h, c);
100 
101  gtk_color(c);
102  fl_rectf(x + 3, y + 3, w - 5, h - 4);
103  fl_yxline(x + w - 2, y + 3, y + h - 3);
104 }
105 
106 
107 static void gtk_thin_up_frame(int x, int y, int w, int h, Fl_Color c) {
109  fl_xyline(x + 1, y, x + w - 2);
110  fl_yxline(x, y + 1, y + h - 2);
111 
113  fl_xyline(x + 1, y + h - 1, x + w - 2);
114  fl_yxline(x + w - 1, y + 1, y + h - 2);
115 }
116 
117 
118 static void gtk_thin_up_box(int x, int y, int w, int h, Fl_Color c) {
119  gtk_thin_up_frame(x, y, w, h, c);
120 
122  fl_xyline(x + 1, y + 1, x + w - 2);
124  fl_xyline(x + 1, y + 2, x + w - 2);
126  fl_xyline(x + 1, y + 3, x + w - 2);
127  gtk_color(c);
128  fl_rectf(x + 1, y + 4, w - 2, h - 8);
130  fl_xyline(x + 1, y + h - 4, x + w - 2);
132  fl_xyline(x + 1, y + h - 3, x + w - 2);
134  fl_xyline(x + 1, y + h - 2, x + w - 2);
135 }
136 
137 
138 static void gtk_thin_down_frame(int x, int y, int w, int h, Fl_Color c) {
140  fl_xyline(x + 1, y, x + w - 2);
141  fl_yxline(x, y + 1, y + h - 2);
142 
144  fl_xyline(x + 1, y + h - 1, x + w - 2);
145  fl_yxline(x + w - 1, y + 1, y + h - 2);
146 }
147 
148 
149 static void gtk_thin_down_box(int x, int y, int w, int h, Fl_Color c) {
150  gtk_thin_down_frame(x, y, w, h, c);
151 
152  gtk_color(c);
153  fl_rectf(x + 1, y + 1, w - 2, h - 2);
154 }
155 
156 //------------------------
157 // new GTK+ style for round buttons
158 #if 1
159 
160 static void fl_arc_i(int x,int y,int w,int h,double a1,double a2) {
161  fl_arc(x,y,w,h,a1,a2);
162 }
163 
165 
166 static void draw(int which, int x,int y,int w,int h, int inset)
167 {
168  if (inset*2 >= w) inset = (w-1)/2;
169  if (inset*2 >= h) inset = (h-1)/2;
170  x += inset;
171  y += inset;
172  w -= 2*inset;
173  h -= 2*inset;
174  int d = w <= h ? w : h;
175  if (d <= 1) return;
176  void (*f)(int,int,int,int,double,double);
177  f = (which==FILL) ? fl_pie : fl_arc_i;
178  if (which >= CLOSED) {
179  f(x+w-d, y, d, d, w<=h ? 0 : -90, w<=h ? 180 : 90);
180  f(x, y+h-d, d, d, w<=h ? 180 : 90, w<=h ? 360 : 270);
181  } else if (which == UPPER_LEFT) {
182  f(x+w-d, y, d, d, 45, w<=h ? 180 : 90);
183  f(x, y+h-d, d, d, w<=h ? 180 : 90, 225);
184  } else { // LOWER_RIGHT
185  f(x, y+h-d, d, d, 225, w<=h ? 360 : 270);
186  f(x+w-d, y, d, d, w<=h ? 360 : 270, 360+45);
187  }
188  if (which == FILL) {
189  if (w < h)
190  fl_rectf(x, y+d/2, w, h-(d&-2));
191  else if (w > h)
192  fl_rectf(x+d/2, y, w-(d&-2), h);
193  } else {
194  if (w < h) {
195  if (which != UPPER_LEFT) fl_yxline(x+w-1, y+d/2-1, y+h-d/2+1);
196  if (which != LOWER_RIGHT) fl_yxline(x, y+d/2-1, y+h-d/2+1);
197  } else if (w > h) {
198  if (which != UPPER_LEFT) fl_xyline(x+d/2-1, y+h-1, x+w-d/2+1);
199  if (which != LOWER_RIGHT) fl_xyline(x+d/2-1, y, x+w-d/2+1);
200  }
201  }
202 }
203 
204 static void gtk_round_up_box(int x, int y, int w, int h, Fl_Color c) {
205  gtk_color(c);
206  draw(FILL, x, y, w, h, 2);
207 
209  draw(LOWER_RIGHT, x+1, y, w-2, h, 2);
210  draw(LOWER_RIGHT, x, y, w, h, 3);
212  draw(LOWER_RIGHT, x+1, y, w-2, h, 1);
213  draw(LOWER_RIGHT, x, y, w, h, 2);
215  draw(LOWER_RIGHT, x+1, y, w-2, h, 0);
216  draw(LOWER_RIGHT, x, y, w, h, 1);
217 
219  draw(UPPER_LEFT, x, y, w, h, 4);
220  draw(UPPER_LEFT, x+1, y, w-2, h, 3);
222  draw(UPPER_LEFT, x, y, w, h, 3);
223  draw(UPPER_LEFT, x+1, y, w-2, h, 2);
225  draw(UPPER_LEFT, x, y, w, h, 2);
226  draw(UPPER_LEFT, x+1, y, w-2, h, 1);
228  draw(UPPER_LEFT, x, y, w, h, 1);
229  draw(UPPER_LEFT, x+1, y, w-2, h, 0);
230 
232  draw(CLOSED, x, y, w, h, 0);
233 }
234 
235 static void gtk_round_down_box(int x, int y, int w, int h, Fl_Color c) {
236  gtk_color(c);
237  draw(FILL, x, y, w, h, 2);
238 
240  draw(UPPER_LEFT, x, y, w, h, 2);
241  draw(UPPER_LEFT, x+1, y, w-2, h, 1);
243  draw(UPPER_LEFT, x, y, w, h, 1);
244  draw(UPPER_LEFT, x+1, y, w-2, h, 0);
245 
247  draw(CLOSED, x, y, w, h, 0);
248 }
249 
250 #else
251 
252 static void gtk_round_up_box(int x, int y, int w, int h, Fl_Color c) {
253  gtk_color(c);
254  fl_pie(x, y, w, h, 0.0, 360.0);
256  fl_arc(x, y, w, h, 45.0, 180.0);
258  fl_arc(x, y, w, h, 180.0, 405.0);
260  fl_arc(x, y, w, h, 225.0, 360.0);
261 }
262 
263 
264 static void gtk_round_down_box(int x, int y, int w, int h, Fl_Color c) {
265  gtk_color(c);
266  fl_pie(x, y, w, h, 0.0, 360.0);
268  fl_arc(x + 1, y, w, h, 90.0, 210.0);
270  fl_arc(x, y, w, h, 0.0, 360.0);
271 }
272 
273 #endif
274 
286 
287  return _FL_GTK_UP_BOX;
288 }
289 
290 
291 //
292 // End of "$Id$".
293 //
gtk_round_up_box
static void gtk_round_up_box(int x, int y, int w, int h, Fl_Color c)
Definition: fl_gtk.cxx:204
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_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
_FL_GTK_THIN_UP_FRAME
gtk+ version of FL_THIN_UP_FRAME
Definition: Enumerations.H:649
Fl_Boxtype
Fl_Boxtype
Definition: Enumerations.H:603
FL_WHITE
const Fl_Color FL_WHITE
Definition: Enumerations.H:971
UPPER_LEFT
Definition: fl_gtk.cxx:164
gtk_down_frame
static void gtk_down_frame(int x, int y, int w, int h, Fl_Color c)
Definition: fl_gtk.cxx:76
_FL_GTK_ROUND_DOWN_BOX
gtk+ version of FL_ROUND_DOWN_BOX
Definition: Enumerations.H:652
gtk_thin_down_frame
static void gtk_thin_down_frame(int x, int y, int w, int h, Fl_Color c)
Definition: fl_gtk.cxx:138
fl_begin_loop
void fl_begin_loop()
Definition: fl_draw.H:370
FILL
Definition: fl_gtk.cxx:164
FL_BLACK
const Fl_Color FL_BLACK
Definition: Enumerations.H:956
gtk_up_frame
static void gtk_up_frame(int x, int y, int w, int h, Fl_Color c)
Definition: fl_gtk.cxx:36
_FL_GTK_UP_FRAME
gtk+ version of FL_UP_FRAME
Definition: Enumerations.H:645
Fl::set_box_color
static void set_box_color(Fl_Color)
Definition: fl_boxtype.cxx:93
_FL_GTK_DOWN_BOX
gtk+ version of FL_DOWN_BOX
Definition: Enumerations.H:644
fl_end_loop
void fl_end_loop()
Definition: fl_draw.H:436
fl_xyline
void fl_xyline(int x, int y, int x1)
Definition: fl_draw.H:255
CLOSED
Definition: fl_gtk.cxx:164
gtk_thin_up_frame
static void gtk_thin_up_frame(int x, int y, int w, int h, Fl_Color c)
Definition: fl_gtk.cxx:107
draw
static void draw(int which, int x, int y, int w, int h, int inset)
Definition: fl_gtk.cxx:166
fl_draw.H
utility header to pull drawing functions together
LOWER_RIGHT
Definition: fl_gtk.cxx:164
fl_arc
void fl_arc(int x, int y, int w, int h, double a1, double a2)
Definition: fl_draw.H:304
gtk_thin_up_box
static void gtk_thin_up_box(int x, int y, int w, int h, Fl_Color c)
Definition: fl_gtk.cxx:118
fl_internal_boxtype
void fl_internal_boxtype(Fl_Boxtype, Fl_Box_Draw_F *)
Definition: fl_boxtype.cxx:404
_FL_GTK_ROUND_UP_BOX
gtk+ version of FL_ROUND_UP_BOX
Definition: Enumerations.H:651
fl_pie
void fl_pie(int x, int y, int w, int h, double a1, double a2)
Definition: fl_draw.H:317
fl_yxline
void fl_yxline(int x, int y, int y1)
Definition: fl_draw.H:270
fl_define_FL_GTK_UP_BOX
Fl_Boxtype fl_define_FL_GTK_UP_BOX()
Definition: fl_gtk.cxx:275
_FL_GTK_THIN_DOWN_FRAME
gtk+ version of FL_THIN_DOWN_FRAME
Definition: Enumerations.H:650
gtk_up_box
static void gtk_up_box(int x, int y, int w, int h, Fl_Color c)
Definition: fl_gtk.cxx:55
x
int x
Definition: test.c:73
gtk_thin_down_box
static void gtk_thin_down_box(int x, int y, int w, int h, Fl_Color c)
Definition: fl_gtk.cxx:149
_FL_GTK_UP_BOX
gtk+ version of FL_UP_BOX
Definition: Enumerations.H:643
_FL_GTK_DOWN_FRAME
gtk+ version of FL_DOWN_FRAME
Definition: Enumerations.H:646
gtk_round_down_box
static void gtk_round_down_box(int x, int y, int w, int h, Fl_Color c)
Definition: fl_gtk.cxx:235
y
int y
Definition: test.c:74
_FL_GTK_THIN_UP_BOX
gtk+ version of FL_THIN_UP_BOX
Definition: Enumerations.H:647
gtk_color
static void gtk_color(Fl_Color c)
Definition: fl_gtk.cxx:32
f
Fl_Box_Draw_F * f
Definition: fl_boxtype.cxx:285
fl_arc_i
static void fl_arc_i(int x, int y, int w, int h, double a1, double a2)
Definition: fl_gtk.cxx:160
fl_vertex
void fl_vertex(double x, double y)
Definition: fl_draw.H:379
fl_color_average
Fl_Color fl_color_average(Fl_Color c1, Fl_Color c2, float weight)
Definition: fl_color.cxx:402
_FL_GTK_THIN_DOWN_BOX
gtk+ version of FL_THIN_DOWN_BOX
Definition: Enumerations.H:648
gtk_down_box
static void gtk_down_box(int x, int y, int w, int h, Fl_Color c)
Definition: fl_gtk.cxx:98