More theme tweaks.
[ntk.git] / src / Cairo_Theme.cxx
blob8f7c5a48b1a8d5a202ae2a6ed1049ff05418140f
2 /*******************************************************************************/
3 /* Copyright (C) 2012 Jonathan Moore Liles */
4 /* Copyright (C) 2001-2005 by Colin Jones */
5 /* */
6 /* This program is free software; you can redistribute it and/or modify it */
7 /* under the terms of the GNU General Public License as published by the */
8 /* Free Software Foundation; either version 2 of the License, or (at your */
9 /* option) any later version. */
10 /* */
11 /* This program is distributed in the hope that it will be useful, but WITHOUT */
12 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
13 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for */
14 /* more details. */
15 /* */
16 /* You should have received a copy of the GNU General Public License along */
17 /* with This program; see the file COPYING. If not,write to the Free Software */
18 /* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
19 /*******************************************************************************/
21 #include <cairo/cairo.h>
23 #include <FL/Fl.H>
24 #include <FL/Fl_Cairo.H>
25 #include <FL/x.H>
26 #include <FL/fl_draw.H>
28 #include "FL/Fl_Theme.H"
29 #include <math.h>
31 float fl_box_saturation = 0.8f;
32 bool fl_boxes_use_gradients = true;
33 bool fl_debug_boxes = false;
35 static const int DX = 1;
37 #define BSCALE 0.00392156862f
39 static void cairo_color(Fl_Color c)
41 cairo_t *cr = Fl::cairo_cc();
43 uchar r,g,b;
45 c = fl_color_average( c, FL_GRAY, fl_box_saturation );
47 Fl_Color bc = Fl::draw_box_active() ? c : fl_inactive( c );
49 fl_color( bc );
51 Fl::get_color( bc, r, g, b );
53 cairo_set_source_rgb( cr, r * BSCALE, g * BSCALE, b * BSCALE );
56 static void rect_path ( int x, int y, int w, int h, double radius )
58 cairo_t *cr = Fl::cairo_cc();
60 double degrees = M_PI / 180.0;
62 x += DX; y += DX; w -= DX*2; h -= DX*2;
64 cairo_new_sub_path (cr);
65 cairo_arc (cr, x + w - radius, y + radius, radius, -90 * degrees, 0 * degrees);
66 cairo_arc (cr, x + w - radius, y + h - radius, radius, 0 * degrees, 90 * degrees);
67 cairo_arc (cr, x + radius, y + h - radius, radius, 90 * degrees, 180 * degrees);
68 cairo_arc (cr, x + radius, y + radius, radius, 180 * degrees, 270 * degrees);
69 cairo_close_path (cr);
72 static void draw_rect(int x, int y, int w, int h, Fl_Color bc, double radius = 1.5 )
74 cairo_t *cr = Fl::cairo_cc();
76 rect_path( x, y, w, h, radius );
78 cairo_color( bc );
80 cairo_set_line_width (cr, DX);
81 cairo_stroke (cr);
82 cairo_set_line_width (cr, 1);
85 static void draw_rectf(int x, int y, int w, int h, Fl_Color bc, double radius = 1.5 )
87 /* // Draw the outline around the perimeter of the box */
88 /* fl_color(fl_color_average(FL_BLACK, FL_BACKGROUND_COLOR, .1)); */
90 cairo_t *cr = Fl::cairo_cc();
92 rect_path( x, y, w, h, radius );
94 uchar r,g,b;
96 cairo_color( bc );
98 Fl::get_color( fl_color(), r, g, b );
100 float rf = r * BSCALE;
101 float gf = g * BSCALE;
102 float bf = b * BSCALE;
104 cairo_pattern_t *grad = 0;
106 if ( fl_boxes_use_gradients )
109 grad = cairo_pattern_create_linear( x, y, x, y + h );//, 350.0, 350.0);
111 cairo_pattern_add_color_stop_rgb( grad, 0.0, rf, gf, bf );
112 cairo_pattern_add_color_stop_rgb( grad, 0.4, rf, gf, bf );
113 cairo_pattern_add_color_stop_rgb( grad, 0.8, rf + 0.1, gf + 0.1, bf + 0.1 );
115 cairo_set_source( cr, grad );
117 else
119 cairo_set_source_rgb (cr, rf, gf, bf );
122 cairo_fill_preserve (cr);
123 cairo_set_line_width (cr, DX);
125 Fl::get_color( fl_color_average( FL_FOREGROUND_COLOR, FL_BACKGROUND_COLOR, 0.1f),
126 r,g,b);
128 cairo_set_source_rgba(cr, r*BSCALE,g*BSCALE,b*BSCALE,1);
130 /* cairo_set_source_rgba (cr, 0, 0, 0, 0.6 ); */
131 cairo_stroke (cr);
133 if ( grad )
134 cairo_pattern_destroy( grad );
136 cairo_set_line_width (cr, 1);
139 static void shade_rect_up(int x, int y, int w, int h, Fl_Color bc)
141 draw_rectf( x, y, w, h, bc );
144 static void frame_rect_up(int x, int y, int w, int h, Fl_Color bc)
146 draw_rect( x,y,w,h, bc );
149 static void frame_rect_down(int x, int y, int w, int h, Fl_Color bc)
151 draw_rect( x,y,w,h, bc );
154 static void shade_rect_down(int x, int y, int w, int h, Fl_Color bc)
156 draw_rectf( x, y, w, h, bc );
159 static void up_frame(int x, int y, int w, int h, Fl_Color c)
161 frame_rect_up(x, y, w, h, c);
164 static void thin_up_box(int x, int y, int w, int h, Fl_Color c)
166 shade_rect_up(x, y, w, h, c);
169 static void up_box(int x, int y, int w, int h, Fl_Color c)
171 shade_rect_up(x, y, w, h, c);
174 static void down_frame(int x, int y, int w, int h, Fl_Color c)
176 frame_rect_down(x, y, w, h, fl_darker(c));
179 static void down_box(int x, int y, int w, int h, Fl_Color c)
181 shade_rect_down(x, y, w, h, c == FL_BACKGROUND_COLOR || c == FL_BACKGROUND2_COLOR ? fl_darker(c) : c );
184 static void thin_down_box(int x, int y, int w, int h, Fl_Color c)
186 down_box(x, y, w, h,
187 FL_BACKGROUND_COLOR == c || FL_BACKGROUND2_COLOR == c
188 ? fl_darker(c)
189 : c );
192 static void border_box(int x, int y, int w, int h, Fl_Color c)
194 cairo_color(c);
196 fl_rectf( x,y,w,h );
198 cairo_color(fl_darker(c));
200 fl_rect(x,y,w,h);
203 static void
204 init_theme ( void )
206 Fl::set_boxtype( FL_UP_BOX, up_box, DX,DX,DX*2,DX*2 );
207 Fl::set_boxtype( FL_DOWN_BOX, down_box, DX,DX,DX*2,DX*2 );
208 Fl::set_boxtype( FL_THIN_UP_BOX, thin_up_box, DX,DX,DX*2,DX*2 );
209 Fl::set_boxtype( FL_THIN_DOWN_BOX, thin_down_box, DX,DX,DX*2,DX*2 );
210 Fl::set_boxtype( FL_UP_FRAME, up_frame, DX,DX,DX*2,DX*2 );
211 Fl::set_boxtype( FL_DOWN_FRAME, down_frame, DX,DX,DX*2,DX*2 );
212 /* Fl::set_boxtype( FL_THIN_UP_BOX, thin_up_box, 1,1,1,1 ); */
213 /* Fl::set_boxtype( FL_THIN_DOWN_BOX, thin_down_box, 1,1,1,1 ); */
214 Fl::set_boxtype( FL_ROUND_UP_BOX, up_box, DX,DX,DX*2,DX*2 );
215 Fl::set_boxtype( FL_ROUND_DOWN_BOX, down_box, DX,DX,DX*2,DX*2 );
216 Fl::set_boxtype( FL_BORDER_BOX, border_box, 1,1,2,2 );
219 void
220 init_cairo_theme ( void )
222 Fl_Theme *t = new Fl_Theme( "Cairo", "Pure Cairo Theme", "Jonathan Moore Liles", init_theme );
224 Fl_Theme::add( t );