2 /*******************************************************************************/
3 /* Copyright (C) 2008 Jonathan Moore Liles */
5 /* This program is free software; you can redistribute it and/or modify it */
6 /* under the terms of the GNU General Public License as published by the */
7 /* Free Software Foundation; either version 2 of the License, or (at your */
8 /* option) any later version. */
10 /* This program is distributed in the hope that it will be useful, but WITHOUT */
11 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
12 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for */
15 /* You should have received a copy of the GNU General Public License along */
16 /* with This program; see the file COPYING. If not,write to the Free Software */
17 /* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
18 /*******************************************************************************/
21 #pragma GCC diagnostic ignored "-Wchar-subscripts"
23 #include <FL/fl_draw.H>
26 #include "FL/Fl_Theme.H"
28 /* Crystal boxes, base (obviously) on the FLTK1 'plastic' boxes, but
29 * without the rude color blending and with a slightly enhanced
32 extern uchar
*fl_gray_ramp();
35 shade_color ( uchar gc
, Fl_Color bc
)
37 return fl_color_average( ( Fl_Color
) gc
, bc
, 0.25f
);
42 frame_rect ( int x
, int y
, int w
, int h
, const char *c
, Fl_Color bc
)
44 uchar
*g
= fl_gray_ramp();
45 int b
= strlen( c
) / 4 + 1;
47 for ( x
+= b
, y
+= b
, w
-= 2 * b
, h
-= 2 * b
; b
> 1; b
-- )
49 // Draw lines around the perimeter of the button, 4 colors per
51 fl_color( shade_color( g
[*c
++], bc
) );
52 fl_line( x
, y
+ h
+ b
, x
+ w
- 1, y
+ h
+ b
, x
+ w
+ b
- 1, y
+ h
);
53 fl_color( shade_color( g
[*c
++], bc
) );
54 fl_line( x
+ w
+ b
- 1, y
+ h
, x
+ w
+ b
- 1, y
, x
+ w
- 1, y
- b
);
55 fl_color( shade_color( g
[*c
++], bc
) );
56 fl_line( x
+ w
- 1, y
- b
, x
, y
- b
, x
- b
, y
);
57 fl_color( shade_color( g
[*c
++], bc
) );
58 fl_line( x
- b
, y
, x
- b
, y
+ h
, x
, y
+ h
+ b
);
64 frame_round ( int x
, int y
, int w
, int h
, const char *c
, Fl_Color bc
)
66 uchar
*g
= fl_gray_ramp();
67 int b
= strlen( c
) / 4 + 1;
69 if ( ! Fl::draw_box_active() )
70 bc
= fl_inactive( bc
);
74 for ( ; b
> 1; b
--, x
++, y
++, w
-= 2, h
-= 2 )
76 fl_color( shade_color( g
[*c
++], bc
) );
77 fl_arc( x
, y
, w
, h
, 45.0, 135.0 );
78 fl_color( shade_color( g
[*c
++], bc
) );
79 fl_arc( x
, y
, w
, h
, 315.0, 405.0 );
80 fl_color( shade_color( g
[*c
++], bc
) );
81 fl_arc( x
, y
, w
, h
, 225.0, 315.0 );
82 fl_color( shade_color( g
[*c
++], bc
) );
83 fl_arc( x
, y
, w
, h
, 135.0, 225.0 );
89 for ( ; b
> 1; d
--, b
--, x
++, y
++, w
-= 2, h
-= 2 )
91 fl_color( shade_color( g
[*c
++], bc
) );
92 fl_arc( x
, y
, h
, h
, 90.0, 135.0 );
93 fl_xyline( x
+ d
, y
, x
+ w
- d
);
94 fl_arc( x
+ w
- h
, y
, h
, h
, 45.0, 90.0 );
95 fl_color( shade_color( g
[*c
++], bc
) );
96 fl_arc( x
+ w
- h
, y
, h
, h
, 315.0, 405.0 );
97 fl_color( shade_color( g
[*c
++], bc
) );
98 fl_arc( x
+ w
- h
, y
, h
, h
, 270.0, 315.0 );
99 fl_xyline( x
+ d
, y
+ h
- 1, x
+ w
- d
);
100 fl_arc( x
, y
, h
, h
, 225.0, 270.0 );
101 fl_color( shade_color( g
[*c
++], bc
) );
102 fl_arc( x
, y
, h
, h
, 135.0, 225.0 );
108 for ( ; b
> 1; d
--, b
--, x
++, y
++, w
-= 2, h
-= 2 )
110 fl_color( shade_color( g
[*c
++], bc
) );
111 fl_arc( x
, y
, w
, w
, 45.0, 135.0 );
112 fl_color( shade_color( g
[*c
++], bc
) );
113 fl_arc( x
, y
, w
, w
, 0.0, 45.0 );
114 fl_yxline( x
+ w
- 1, y
+ d
, y
+ h
- d
);
115 fl_arc( x
, y
+ h
- w
, w
, w
, 315.0, 360.0 );
116 fl_color( shade_color( g
[*c
++], bc
) );
117 fl_arc( x
, y
+ h
- w
, w
, w
, 225.0, 315.0 );
118 fl_color( shade_color( g
[*c
++], bc
) );
119 fl_arc( x
, y
+ h
- w
, w
, w
, 180.0, 225.0 );
120 fl_yxline( x
, y
+ d
, y
+ h
- d
);
121 fl_arc( x
, y
, w
, w
, 135.0, 180.0 );
128 shade_rect ( int x
, int y
, int w
, int h
, const char *c
, Fl_Color bc
)
130 uchar
*g
= fl_gray_ramp();
132 int clen
= strlen( c
) - 1;
133 int chalf
= clen
/ 2;
136 if ( ! Fl::draw_box_active() )
137 bc
= fl_inactive( bc
);
141 // Horizontal shading...
145 for ( i
= 0, j
= 0; j
< chalf
; i
++, j
+= cstep
)
147 // Draw the top line and points...
148 fl_color( shade_color( g
[c
[i
]], bc
) );
149 fl_xyline( x
+ 1, y
+ i
, x
+ w
- 2 );
151 fl_color( shade_color( g
[c
[i
] - 2], bc
) );
152 fl_point( x
, y
+ i
+ 1 );
153 fl_point( x
+ w
- 1, y
+ i
+ 1 );
155 // Draw the bottom line and points...
156 fl_color( shade_color( g
[c
[clen
- i
]], bc
) );
157 fl_xyline( x
+ 1, y
+ h
- i
, x
+ w
- 2 );
159 fl_color( shade_color( g
[c
[clen
- i
] - 2], bc
) );
160 fl_point( x
, y
+ h
- i
);
161 fl_point( x
+ w
- 1, y
+ h
- i
);
164 // Draw the interior and sides...
167 // fl_color( shade_color( g[c[chalf]], bc ) );
169 fl_rectf( x
+ 1, y
+ i
, w
- 2, h
- 2 * i
+ 1 );
171 fl_color( shade_color( g
[c
[chalf
] - 2], bc
) );
172 fl_yxline( x
, y
+ i
, y
+ h
- i
);
173 fl_yxline( x
+ w
- 1, y
+ i
, y
+ h
- i
);
177 // Vertical shading...
181 for ( i
= 0, j
= 0; j
< chalf
; i
++, j
+= cstep
)
183 // Draw the left line and points...
184 fl_color( shade_color( g
[c
[i
]], bc
) );
185 fl_yxline( x
+ i
, y
+ 1, y
+ h
- 1 );
187 fl_color( shade_color( g
[c
[i
] - 2], bc
) );
188 fl_point( x
+ i
+ 1, y
);
189 fl_point( x
+ i
+ 1, y
+ h
);
191 // Draw the right line and points...
192 fl_color( shade_color( g
[c
[clen
- i
]], bc
) );
193 fl_yxline( x
+ w
- 1 - i
, y
+ 1, y
+ h
- 1 );
195 fl_color( shade_color( g
[c
[clen
- i
] - 2], bc
) );
196 fl_point( x
+ w
- 2 - i
, y
);
197 fl_point( x
+ w
- 2 - i
, y
+ h
);
200 // Draw the interior, top, and bottom...
203 fl_color( shade_color( g
[c
[chalf
]], bc
) );
204 fl_rectf( x
+ i
, y
+ 1, w
- 2 * i
, h
- 1 );
206 fl_color( shade_color( g
[c
[chalf
] - 2], bc
) );
207 fl_xyline( x
+ i
, y
, x
+ w
- i
);
208 fl_xyline( x
+ i
, y
+ h
, x
+ w
- i
);
213 shade_round ( int x
, int y
, int w
, int h
, const char *c
, Fl_Color bc
)
215 uchar
*g
= fl_gray_ramp();
217 int clen
= strlen( c
) - 1;
218 int chalf
= clen
/ 2;
224 for ( i
= 0; i
< chalf
; i
++, d
--, x
++, y
++, w
-= 2, h
-= 2 )
226 fl_color( shade_color( g
[c
[i
]], bc
) );
227 fl_pie( x
, y
, h
, h
, 90.0, 135.0 + i
* na
);
228 fl_xyline( x
+ d
, y
, x
+ w
- d
);
229 fl_pie( x
+ w
- h
, y
, h
, h
, 45.0 + i
* na
, 90.0 );
230 fl_color( shade_color( g
[c
[i
] - 2], bc
) );
231 fl_pie( x
+ w
- h
, y
, h
, h
, 315.0 + i
* na
, 405.0 + i
* na
);
232 fl_color( shade_color( g
[c
[clen
- i
]], bc
) );
233 fl_pie( x
+ w
- h
, y
, h
, h
, 270.0, 315.0 + i
* na
);
234 fl_xyline( x
+ d
, y
+ h
- 1, x
+ w
- d
);
235 fl_pie( x
, y
, h
, h
, 225.0 + i
* na
, 270.0 );
236 fl_color( shade_color( g
[c
[clen
- i
] - 2], bc
) );
237 fl_pie( x
, y
, h
, h
, 135.0 + i
* na
, 225.0 + i
* na
);
241 // fl_color( shade_color( g[c[chalf]], bc ) );
243 fl_rectf( x
+ d
, y
, w
- h
+ 1, h
+ 1 );
244 fl_pie( x
, y
, h
, h
, 90.0, 270.0 );
245 fl_pie( x
+ w
- h
, y
, h
, h
, 270.0, 90.0 );
251 for ( i
= 0; i
< chalf
; i
++, d
--, x
++, y
++, w
-= 2, h
-= 2 )
253 fl_color( shade_color( g
[c
[i
]], bc
) );
254 fl_pie( x
, y
, w
, w
, 45.0 + i
* na
, 135.0 + i
* na
);
255 fl_color( shade_color( g
[c
[i
] - 2], bc
) );
256 fl_pie( x
, y
, w
, w
, 0.0, 45.0 + i
* na
);
257 fl_yxline( x
+ w
- 1, y
+ d
, y
+ h
- d
);
258 fl_pie( x
, y
+ h
- w
, w
, w
, 315.0 + i
* na
, 360.0 );
259 fl_color( shade_color( g
[c
[clen
- i
]], bc
) );
260 fl_pie( x
, y
+ h
- w
, w
, w
, 225.0 + i
* na
, 315.0 + i
* na
);
261 fl_color( shade_color( g
[c
[clen
- i
] - 2], bc
) );
262 fl_pie( x
, y
+ h
- w
, w
, w
, 180.0, 225.0 + i
* na
);
263 fl_yxline( x
, y
+ d
, y
+ h
- d
);
264 fl_pie( x
, y
, w
, w
, 135.0 + i
* na
, 180.0 );
266 // fl_color( shade_color( g[c[chalf]], bc ) );
268 fl_rectf( x
, y
+ d
, w
+ 1, h
- w
+ 1 );
269 fl_pie( x
, y
, w
, w
, 0.0, 180.0 );
270 fl_pie( x
, y
+ h
- w
, w
, w
, 180.0, 360.0 );
276 up_frame ( int x
, int y
, int w
, int h
, Fl_Color c
)
278 frame_rect( x
, y
, w
, h
- 1, "KLDIIJLM", c
);
283 narrow_thin_box ( int x
, int y
, int w
, int h
, Fl_Color c
)
285 if ( h
<= 0 || w
<= 0 )
287 uchar
*g
= fl_gray_ramp();
288 fl_color( shade_color( g
['R'], c
) );
289 fl_rectf( x
+ 1, y
+ 1, w
- 2, h
- 2 );
290 fl_color( shade_color( g
['I'], c
) );
293 fl_xyline( x
+ 1, y
, x
+ w
- 2 );
294 fl_xyline( x
+ 1, y
+ h
- 1, x
+ w
- 2 );
298 fl_yxline( x
, y
+ 1, y
+ h
- 2 );
299 fl_yxline( x
+ w
- 1, y
+ 1, y
+ h
- 2 );
305 thin_up_box ( int x
, int y
, int w
, int h
, Fl_Color c
)
307 if ( w
> 4 && h
> 4 )
309 shade_rect( x
+ 1, y
+ 1, w
- 2, h
- 3, "RQOQSUWQ", c
);
310 frame_rect( x
, y
, w
, h
- 1, "IJLM", c
);
313 narrow_thin_box( x
, y
, w
, h
, c
);
318 up_box ( int x
, int y
, int w
, int h
, Fl_Color c
)
320 if ( w
> 8 && h
> 8 )
322 shade_rect( x
+ 1, y
+ 1, w
- 2, h
- 3, "RVQNOPQRSTUVWVQ", c
);
323 // shade_rect( x + 1, y + 1, w - 2, h - 3, "STUVWVQRWXVUVVQ", c );
324 // shade_rect( x + 1, y + 1, w - 2, h - 3, "FISPPQQRSSTTUPJ", c );
326 frame_rect( x
, y
, w
, h
- 1, "IJLM", c
);
330 thin_up_box( x
, y
, w
, h
, c
);
335 up_round ( int x
, int y
, int w
, int h
, Fl_Color c
)
337 shade_round( x
, y
, w
, h
, "RVQNOPQRSTUVWVQ", c
);
338 frame_round( x
, y
, w
, h
, "IJLM", c
);
343 down_frame ( int x
, int y
, int w
, int h
, Fl_Color c
)
345 frame_rect( x
, y
, w
, h
- 1, "LLLLTTRR", c
);
350 down_box ( int x
, int y
, int w
, int h
, Fl_Color c
)
352 if ( w
> 6 && h
> 6 )
354 // shade_rect( x + 2, y + 2, w - 4, h - 5, "STUVWWWVT", c );
355 fl_rectf( x
+ 2, y
+ 2, w
- 4, h
- 5 ,
356 FL_BACKGROUND_COLOR
== c
|| FL_BACKGROUND2_COLOR
== c
359 down_frame( x
, y
, w
, h
, c
);
363 narrow_thin_box( x
, y
, w
, h
, c
);
369 down_round ( int x
, int y
, int w
, int h
, Fl_Color c
)
371 shade_round( x
, y
, w
, h
, "STUVWWWVT", c
);
372 frame_round( x
, y
, w
, h
, "IJLM", c
);
376 border_box ( int x
, int y
, int w
, int h
, Fl_Color c
)
380 fl_color(fl_darker(c
));
388 printf( "Initializing crystal boxtypes" );
390 /* replace the plastic boxes... (is there a better way?) */
391 Fl::set_boxtype( FL_UP_BOX
, up_box
, 4,4,8,8 );
392 Fl::set_boxtype( FL_DOWN_BOX
, down_box
, 2,2,4,4 );
393 Fl::set_boxtype( FL_UP_FRAME
, up_frame
, 2,2,4,4 );
394 Fl::set_boxtype( FL_DOWN_FRAME
, down_frame
, 2,2,4,4 );
395 Fl::set_boxtype( FL_THIN_UP_BOX
, thin_up_box
, 1,1,2,2 );
396 Fl::set_boxtype( FL_THIN_DOWN_BOX
, down_box
, 1,1,2,2 );
397 Fl::set_boxtype( FL_ROUND_UP_BOX
, up_round
, 1,1,2,2 );
398 Fl::set_boxtype( FL_ROUND_DOWN_BOX
, down_round
, 1,1,2,2 );
399 Fl::set_boxtype( FL_BORDER_BOX
, border_box
, 1,1,2,2 );
403 init_crystal_theme ( void )
405 Fl_Theme
*t
= new Fl_Theme( "Crystal", "", "", init_theme
);