2 /*******************************************************************************/
3 /* Copyright (C) 2012 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 /*******************************************************************************/
20 #include "FL/Fl_Theme.H"
22 #include <FL/Fl_Window.H>
23 #include <FL/Fl_Preferences.H>
25 Fl_Theme
*Fl_Theme::first
;
26 Fl_Theme
*Fl_Theme::_current
;
27 Fl_Color_Scheme
*Fl_Color_Scheme::first
;
28 Fl_Color_Scheme
*Fl_Color_Scheme::_current
;
31 int Fl_Color_Scheme::total
;
34 Fl_Theme::add ( Fl_Theme
*t
)
42 Fl_Theme::get ( void )
44 Fl_Theme
**r
= (Fl_Theme
**) malloc( sizeof( Fl_Theme
* ) * ( total
+ 1 ) );
47 for ( Fl_Theme
*t
= first
; t
; t
= t
->next
, i
++ )
57 Fl_Preferences
*prefs ( void )
61 snprintf( path
, sizeof(path
), "%s/.config/ntk/", getenv("HOME" ) );
63 Fl_Preferences
*p
= new Fl_Preferences( path
, "ntk", "theme" );
68 static void conf_set ( const char *key
, const char *value
)
70 Fl_Preferences
*p
= prefs();
77 static void conf_set ( const char *key
, Fl_Color value
)
79 Fl_Preferences
*p
= prefs();
81 p
->set( key
, (int)value
);
86 static const char *conf_get ( const char *key
, const char *def
)
90 Fl_Preferences
*p
= prefs();
92 p
->get( key
, buf
, def
, sizeof( buf
) );
101 conf_get_color ( const char *key
, Fl_Color def
)
103 Fl_Preferences
*p
= prefs();
107 p
->get( key
, c
, def
);
114 /* sets the configured default */
116 Fl_Theme::load_default ( void )
118 const char *name
= conf_get( "theme", "cairo" );
120 int rv
= set( name
);
122 Fl_Color_Scheme::set( "Dark" );
126 Fl::get_color( conf_get_color( "background", FL_BACKGROUND_COLOR
), r
, g
, b
);
127 Fl::background( r
, g
, b
);
128 Fl::get_color( conf_get_color( "background2", FL_BACKGROUND2_COLOR
), r
, g
, b
);
129 Fl::background2( r
, g
, b
);
130 Fl::get_color( conf_get_color( "foreground", FL_FOREGROUND_COLOR
), r
, g
, b
);
131 Fl::foreground( r
, g
, b
);
137 Fl_Theme::save ( void )
139 conf_set( "theme", Fl_Theme::_current
->name() );
143 Fl_Theme::set ( const char *name
)
145 for ( Fl_Theme
*t
= first
; t
; t
= t
->next
)
146 if ( !strcasecmp( t
->name(), name
) )
152 Fl_Theme::_current
= t
;
163 Fl_Theme::refresh ( void )
165 for ( Fl_Window
*w
= Fl::first_window(); w
; w
= Fl::next_window( w
) )
170 Fl_Color_Scheme::add ( Fl_Color_Scheme
*t
)
178 Fl_Color_Scheme::get ( void )
180 Fl_Color_Scheme
**r
= (Fl_Color_Scheme
**) malloc( sizeof( Fl_Color_Scheme
* ) * ( total
+ 1 ) );
183 for ( Fl_Color_Scheme
*t
= first
; t
; t
= t
->next
, i
++ )
192 Fl_Color_Scheme::save ( void )
194 conf_set( "color_scheme", Fl_Color_Scheme::_current
->name() );
195 conf_set( "background", Fl::get_color( FL_BACKGROUND_COLOR
) );
196 conf_set( "foreground", Fl::get_color( FL_FOREGROUND_COLOR
) );
197 conf_set( "background2", Fl::get_color( FL_BACKGROUND2_COLOR
) );
201 Fl_Color_Scheme::refresh ( void )
203 for ( Fl_Window
*w
= Fl::first_window(); w
; w
= Fl::next_window( w
) )
208 Fl_Color_Scheme::set ( const char *name
)
210 for ( Fl_Color_Scheme
*t
= first
; t
; t
= t
->next
)
211 if ( !strcasecmp( t
->name(), name
) )
215 Fl::get_color( t
->_bg
, r
, g
, b
);
216 Fl::background( r
, g
, b
);
217 Fl::get_color( t
->_bg2
, r
, g
, b
);
218 Fl::background2( r
, g
, b
);
219 Fl::get_color( t
->_fg
, r
, g
, b
);
220 Fl::foreground( r
, g
, b
);
221 /* Fl::get_color( t->_sel, r, g, b ); */
222 /* Fl::selection( r, g, b ); */
224 Fl_Color_Scheme::_current
= t
;