Mixer: Fix receiving of direct OSC messages.
[nondaw.git] / FL / Fl_Theme.C
blob8f2937ab78baa73642d6beaf66aa3c92ef1081e2
2 /*******************************************************************************/
3 /* Copyright (C) 2012 Jonathan Moore Liles                                     */
4 /*                                                                             */
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.                                                  */
9 /*                                                                             */
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   */
13 /* more details.                                                               */
14 /*                                                                             */
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"
21 #include <FL/Fl.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;
29 int Fl_Theme::total;
30 int Fl_Color_Scheme::total;
32 void
33 Fl_Theme::add ( Fl_Theme *t )
35     t->next = first;
36     first = t;
37     total++;
40 Fl_Theme **
41 Fl_Theme::get ( void )
43     Fl_Theme **r = (Fl_Theme**) malloc( sizeof( Fl_Theme* ) * ( total + 1 ) );
45     int i = 0;
46     for ( Fl_Theme *t = first; t; t = t->next, i++ )
47         r[i] = t;
49     r[i] = 0;
51     return r;
55 static 
56 Fl_Preferences *prefs ( void )
58     char *path;
60     asprintf( &path, "%s/.config/ntk/", getenv("HOME" )  );
61     
62     Fl_Preferences *p = new Fl_Preferences( path, "ntk", "theme" );
64     free( path );
66     return p;
69 static void conf_set ( const char *key, const char *value )
71     Fl_Preferences *p = prefs();
73     p->set( key, value );
75     delete p;
78 static void conf_set ( const char *key, Fl_Color value )
80     Fl_Preferences *p = prefs();
82     p->set( key, (int)value );
84     delete p;
87 static const char *conf_get ( const char *key, const char *def )
89     static char buf[256];
91     Fl_Preferences *p = prefs();
93     p->get( key, buf, def, sizeof( buf ) );
95     delete p;
97     return buf;
100 static 
101 Fl_Color
102 conf_get_color ( const char *key, Fl_Color def )
104     Fl_Preferences *p = prefs();
106     int c;
108     p->get( key, c, def );
110     delete p;
112     return (Fl_Color)c;
115 static bool dont_save = false;
117 /* sets the configured default */
119 Fl_Theme::set ( void )
121     const char *name = conf_get( "theme", "clean" );
123     int rv = set( name );
125     dont_save = true;
127     Fl_Color_Scheme::set( "System" );
129     dont_save = false;
131     uchar r, g, b;
132     
133     Fl::get_color( conf_get_color( "background", FL_BACKGROUND_COLOR ), r, g, b );
134     Fl::background( r, g, b );
135     Fl::get_color( conf_get_color( "background2", FL_BACKGROUND2_COLOR ), r, g, b );            
136     Fl::background2( r, g, b );
137     Fl::get_color( conf_get_color( "foreground", FL_FOREGROUND_COLOR ), r, g, b );            
138     Fl::foreground( r, g, b );
139     
140     return rv;
144 Fl_Theme::set ( const char *name )
146     for ( Fl_Theme *t = first; t; t = t->next )
147         if ( !strcasecmp( t->name(), name ) )
148         {
149             /* reset boxtypes */
150             Fl::reload_scheme();
152             printf( "Theme set to %s\n", t->name() );
153             t->_init_func();
154             Fl_Theme::_current = t;
156             conf_set( "theme", t->name() );
158             for ( Fl_Window *w = Fl::first_window(); w; w = Fl::next_window( w ) )
159                 w->redraw();
161             return 1;
162         }
164     return 0;
167 void
168 Fl_Color_Scheme::add ( Fl_Color_Scheme *t )
170     t->next = first;
171     first = t;
172     total++;
175 Fl_Color_Scheme **
176 Fl_Color_Scheme::get ( void )
178     Fl_Color_Scheme **r = (Fl_Color_Scheme**) malloc( sizeof( Fl_Color_Scheme* ) * ( total + 1 ) );
180     int i = 0;
181     for ( Fl_Color_Scheme *t = first; t; t = t->next, i++ )
182         r[i] = t;
184     r[i] = 0;
186     return r;
189 void
190 Fl_Color_Scheme::save ( void )
192     if ( ! dont_save )
193     {
194         conf_set( "background", Fl::get_color( FL_BACKGROUND_COLOR ) );
195         conf_set( "foreground", Fl::get_color( FL_FOREGROUND_COLOR ) );
196         conf_set( "background2", Fl::get_color( FL_BACKGROUND2_COLOR ) );
197     }
199     for ( Fl_Window *w = Fl::first_window(); w; w = Fl::next_window( w ) )
200         w->redraw();
204 Fl_Color_Scheme::set ( const char *name )
206     for ( Fl_Color_Scheme *t = first; t; t = t->next )
207         if ( !strcasecmp( t->name(), name ) )
208         {
209             uchar r, g, b;
211             Fl::get_color( t->_bg, r, g, b );            
212             Fl::background( r, g, b );
213             Fl::get_color( t->_bg2, r, g, b );            
214             Fl::background2( r, g, b );
215             Fl::get_color( t->_fg, r, g, b );            
216             Fl::foreground( r, g, b );
217             /* Fl::get_color( t->_sel, r, g, b );             */
218             /* Fl::selection( r, g, b ); */
220             conf_set( "color_scheme", t->name() );
222             save();
224             return 1;
225         }
227     return 0;