Tweak themes for more color consistency.
[ntk.git] / src / Vector_Theme.cxx
blob503c408cf1d479d4334b07b0095e15e1b33da154
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 static const int DX = 2;
33 static void cairo_color(Fl_Color c)
35 cairo_t *cr = Fl::cairo_cc();
37 uchar r,g,b;
39 Fl_Color bc = Fl::draw_box_active() ? c : fl_inactive( c );
41 fl_color( bc );
43 Fl::get_color( bc, r, g, b );
45 cairo_set_source_rgb( cr, r / 255.0, g / 255.0, b / 255.0 );
48 static Fl_Color border_color ( Fl_Color c )
50 return fl_color_average( FL_FOREGROUND_COLOR, c, 0.20f );
51 /* return fl_color_average( FL_FOREGROUND_COLOR, c, 0.33f ); */
52 /* return fl_color_average( FL_FOREGROUND_COLOR, c, 0.50f ); */
55 static Fl_Color interior_color ( Fl_Color c )
57 return fl_color_average( FL_BACKGROUND_COLOR, c, 0.33f );
60 static Fl_Color outer_border_color ( Fl_Color c )
62 /* return fl_darker( interior_color( c ) ); */
63 return fl_color_average( c, FL_BACKGROUND_COLOR, 0.50f );
66 static void rect_path ( float x, float y, float w, float h, double radius )
68 x+= 0.5f;
69 y+= 0.5f;
70 w-=1;
71 h-=1;
73 cairo_t *cr = Fl::cairo_cc();
75 double degrees = M_PI / 180.0;
77 cairo_new_sub_path (cr);
78 cairo_arc (cr, x + w - radius, y + radius, radius, -90 * degrees, 0 * degrees);
79 cairo_arc (cr, x + w - radius, y + h - radius, radius, 0 * degrees, 90 * degrees);
80 cairo_arc (cr, x + radius, y + h - radius, radius, 90 * degrees, 180 * degrees);
81 cairo_arc (cr, x + radius, y + radius, radius, 180 * degrees, 270 * degrees);
82 cairo_close_path (cr);
85 static void draw_rect(int x, int y, int w, int h, Fl_Color bc, double radius = 3 )
87 cairo_t *cr = Fl::cairo_cc();
89 rect_path( x, y, w, h, radius );
90 cairo_color( bc );
91 cairo_stroke (cr);
94 static void draw_rectf(int x, int y, int w, int h, Fl_Color bc, double radius = 3 )
96 cairo_t *cr = Fl::cairo_cc();
98 rect_path( x, y, w, h, radius );
100 cairo_color( bc );
101 cairo_fill (cr);
104 static void up_box(int x, int y, int w, int h, Fl_Color bc)
106 draw_rectf( x, y, w, h, interior_color( bc ) );
107 /* draw_rect( x, y, w, h, border_color( bc ) ); */
108 draw_rect( x+1, y+1, w-2, h-2, border_color( bc ) );
109 draw_rect( x, y, w, h, outer_border_color( bc ) );
112 static void up_frame(int x, int y, int w, int h, Fl_Color bc)
114 /* draw_rect( x, y, w, h, border_color( bc ) ); */
115 draw_rect( x+1,y+1,w-2,h-2, border_color(bc) );
116 draw_rect( x, y, w, h, outer_border_color( bc ) );
119 static void down_frame(int x, int y, int w, int h, Fl_Color bc)
121 /* draw_rect( x, y, w, h, bc ); */
122 draw_rect( x+1,y+1,w-2,h-2, bc );
123 draw_rect( x, y, w, h, outer_border_color( bc ) );
126 static void down_box(int x, int y, int w, int h, Fl_Color bc)
128 draw_rectf( x, y, w, h,
129 FL_BACKGROUND_COLOR == bc || FL_BACKGROUND2_COLOR == bc
130 ? fl_darker(interior_color(bc))
131 : interior_color( bc ) );
132 /* draw_rect( x, y, w, h, bc ); */
133 draw_rect( x+1, y+1, w-2, h-2, bc );
134 draw_rect( x, y, w, h, outer_border_color( bc ) );
137 static void border_box(int x, int y, int w, int h, Fl_Color bc)
139 cairo_color( interior_color( bc ) );
140 fl_rectf( x, y, w, h );
141 cairo_color( border_color( bc ) );
142 /* fl_rect( x, y, w, h, bc ); */
143 fl_rect( x+1, y+1, w-2, h-2, bc );
144 cairo_color( outer_border_color( bc ) );
145 fl_rect( x, y, w, h, bc );
148 static void
149 init_theme ( void )
151 Fl::set_boxtype( FL_UP_BOX, up_box, DX,DX,DX*2,DX*2 );
152 Fl::set_boxtype( FL_DOWN_BOX, down_box, DX,DX,DX*2,DX*2 );
153 Fl::set_boxtype( FL_THIN_UP_BOX, up_box, DX,DX,DX*2,DX*2 );
154 Fl::set_boxtype( FL_THIN_DOWN_BOX, down_box, DX,DX,DX*2,DX*2 );
155 Fl::set_boxtype( FL_UP_FRAME, up_frame, DX,DX,DX*2,DX*2 );
156 Fl::set_boxtype( FL_DOWN_FRAME, down_frame, DX,DX,DX*2,DX*2 );
157 Fl::set_boxtype( FL_ROUND_UP_BOX, up_box, DX,DX,DX*2,DX*2 );
158 Fl::set_boxtype( FL_ROUND_DOWN_BOX, down_box, DX,DX,DX*2,DX*2 );
159 Fl::set_boxtype( FL_BORDER_BOX, border_box, 1,1,2,2 );
162 void
163 init_vector_theme ( void )
165 Fl_Theme *t = new Fl_Theme( "Vector", "Simple vector theme based on Cairo", "Jonathan Moore Liles", init_theme );
167 Fl_Theme::add( t );