From 0a6749fd16f08f454aecb747a8d5f2cf798e7340 Mon Sep 17 00:00:00 2001 From: Jonathan Moore Liles Date: Sat, 23 Jan 2010 20:45:53 -0600 Subject: [PATCH] Mixer: Add stuff to Options/ menu. Save and load options. --- Mixer/Mixer.C | 89 ++++++++++++++++++++++++++++++++++++++++++++++++--- Mixer/Mixer.H | 8 +++++ Mixer/main.C | 23 ++++++++++++- 3 files changed, 115 insertions(+), 5 deletions(-) diff --git a/Mixer/Mixer.C b/Mixer/Mixer.C index f150eab..746cb83 100644 --- a/Mixer/Mixer.C +++ b/Mixer/Mixer.C @@ -26,17 +26,19 @@ #include #include #include +#include #include #include "New_Project_Dialog.H" #include "Engine/Engine.H" #include "FL/Fl_Flowpack.H" #include "Project.H" - +#include "FL/Fl_Menu_Settings.H" #include #include "debug.h" const double STATUS_UPDATE_FREQ = 0.2f; +extern char *user_config_dir; #include "util/debug.h" @@ -133,6 +135,50 @@ void Mixer::cb_menu(Fl_Widget* o) { { rows( 3 ); } + else if (! strcmp( picked, "&Options/&Display/&Style/&Default") ) + { + Fl::scheme( "plastic" ); + } + else if (! strcmp( picked, "&Options/&Display/&Style/&Flat") ) + { + Fl::scheme( "gtk+" ); + } + else if (! strcmp( picked, "&Options/&Display/&Colors/&System") ) + { + //Fl::get_system_colors(); + + unsigned char r, g, b; + + Fl::get_color( system_colors[ 0 ], r, g, b ); + + Fl::background( r, g, b ); + + Fl::get_color( system_colors[ 1 ], r, g, b ); + + Fl::foreground( r, g, b ); + + Fl::get_color( system_colors[ 2 ], r, g, b ); + + Fl::background2( r, g, b ); + + Fl::scheme( Fl::scheme() ); + } + else if (! strcmp( picked, "&Options/&Display/&Colors/&Dark") ) + { + Fl::background2( 100, 100, 100 ); + Fl::background( 50, 50, 50 ); + Fl::foreground( 255, 255, 255 ); + + Fl::scheme( Fl::scheme() ); + } + else if (! strcmp( picked, "&Options/&Display/&Colors/&Light") ) + { + Fl::background2( 192, 192, 192 ); + Fl::background( 220, 220, 220 ); + Fl::foreground( 0, 0, 0 ); + + Fl::scheme( Fl::scheme() ); + } } @@ -143,10 +189,18 @@ void Mixer::cb_menu(Fl_Widget* o, void* v) { Mixer::Mixer ( int X, int Y, int W, int H, const char *L ) : Fl_Group( X, Y, W, H, L ) { + + Fl::get_system_colors(); + Fl::scheme( "plastic" ); + + system_colors[ 0 ] = (Fl_Color)Fl::get_color( FL_BACKGROUND_COLOR ); + system_colors[ 1 ] = (Fl_Color)Fl::get_color( FL_FOREGROUND_COLOR ); + system_colors[ 2 ] = (Fl_Color)Fl::get_color( FL_BACKGROUND2_COLOR ); + _rows = 1; box( FL_NO_BOX ); labelsize( 96 ); - { Fl_Menu_Bar *o = new Fl_Menu_Bar( X, Y, W, 24 ); + { Fl_Menu_Bar *o = menubar = new Fl_Menu_Bar( X, Y, W, 24 ); o->add( "&Project/&New" ); o->add( "&Project/&Open" ); o->add( "&Project/&Save", FL_CTRL + 's', 0, 0 ); @@ -156,7 +210,11 @@ Mixer::Mixer ( int X, int Y, int W, int H, const char *L ) : o->add( "&Mixer/&Rows/One", '1', 0, 0 ); o->add( "&Mixer/&Rows/Two", '2', 0, 0 ); o->add( "&Mixer/&Rows/Three", '3', 0, 0 ); - o->add( "_&Options" ); + o->add( "_&Options/&Display/&Style/&Default", 0, 0, 0, FL_MENU_RADIO | FL_MENU_VALUE ); + o->add( "_&Options/&Display/&Style/&Flat", 0, 0, 0, FL_MENU_RADIO ); + o->add( "_&Options/&Display/&Colors/&System", 0, 0, 0, FL_MENU_RADIO | FL_MENU_VALUE ); + o->add( "_&Options/&Display/&Colors/&Dark", 0, 0, 0, FL_MENU_RADIO ); + o->add( "_&Options/&Display/&Colors/&Light", 0, 0, 0, FL_MENU_RADIO ); o->add( "&Help/&Manual" ); o->add( "&Help/&About" ); o->callback( cb_menu, this ); @@ -184,14 +242,16 @@ Mixer::Mixer ( int X, int Y, int W, int H, const char *L ) : // Fl::add_timeout( STATUS_UPDATE_FREQ, update_cb, this ); - MESSAGE( "Scanning for plugins..." ); + load_options(); } Mixer::~Mixer ( ) { DMESSAGE( "Destroying mixer" ); + save_options(); + /* FIXME: teardown */ mixer_strips->clear(); } @@ -374,6 +434,27 @@ Mixer::save ( void ) return true; } +static const char options_filename[] = "options"; + +void +Mixer::load_options ( void ) +{ +// save options + + char *path; + asprintf( &path, "%s/options", user_config_dir ); + ((Fl_Menu_Settings*)menubar)->load( menubar->find_item( "&Options" ), path ); + free( path ); +} + +void +Mixer::save_options ( void ) +{ + char *path; + asprintf( &path, "%s/%s", user_config_dir, options_filename ); + ((Fl_Menu_Settings*)menubar)->dump( menubar->find_item( "&Options" ), path ); + free( path ); +} int Mixer::handle ( int m ) diff --git a/Mixer/Mixer.H b/Mixer/Mixer.H index a7a8cb9..bc64451 100644 --- a/Mixer/Mixer.H +++ b/Mixer/Mixer.H @@ -27,6 +27,7 @@ #include "Mixer_Strip.H" class Fl_Flowpack; +class Fl_Menu_Bar; class Mixer : public Fl_Group { @@ -35,6 +36,8 @@ private: int _rows; + Fl_Color system_colors[3]; + Mixer_Strip* track_by_name ( const char *name ); char * get_unique_track_name ( const char *name ); @@ -44,17 +47,22 @@ private: void cb_menu(Fl_Widget*); static void cb_menu(Fl_Widget*, void*); + Fl_Menu_Bar *menubar; Fl_Scroll *scroll; Fl_Pack *pack; Fl_Flowpack *mixer_strips; + void load_options ( void ); + void save_options ( void ); + protected: virtual int handle ( int m ); public: + void rows ( int n ); virtual void resize ( int X, int Y, int W, int H ); diff --git a/Mixer/main.C b/Mixer/main.C index ffe9dad..52f7a48 100644 --- a/Mixer/main.C +++ b/Mixer/main.C @@ -52,6 +52,25 @@ Mixer *mixer; #include "Mono_Pan_Module.H" #include "Chain.H" +#include +#include + +/* TODO: put these in a header */ +#define USER_CONFIG_DIR ".non-mixer/" + +char *user_config_dir; + +#include + +static int +ensure_dirs ( void ) +{ + asprintf( &user_config_dir, "%s/%s", getenv( "HOME" ), USER_CONFIG_DIR ); + + int r = mkdir( user_config_dir, 0777 ); + + return r == 0 || errno == EEXIST; +} #include @@ -67,6 +86,8 @@ main ( int argc, char **argv ) Thread thread( "UI" ); thread.set(); + ensure_dirs(); + Fl_Tooltip::color( FL_BLACK ); Fl_Tooltip::textcolor( FL_YELLOW ); Fl_Tooltip::size( 14 ); @@ -100,7 +121,7 @@ main ( int argc, char **argv ) Fl_Double_Window *main_window; { - Fl_Double_Window *o = main_window = new Fl_Double_Window( 1024, 768, "Mixer" ); + Fl_Double_Window *o = main_window = new Fl_Double_Window( 800, 600, "Mixer" ); { Fl_Widget *o = mixer = new Mixer( 0, 0, main_window->w(), main_window->h(), NULL ); Fl_Group::current()->resizable(o);