more tweaking of color management.
[ardour.git] / gtk2_ardour / ui_config.h
1 /*
2     Copyright (C) 2000-2007 Paul Davis
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #ifndef __ardour_ui_configuration_h__
21 #define __ardour_ui_configuration_h__
22
23 #include <sstream>
24 #include <ostream>
25 #include <iostream>
26
27 #include <boost/function.hpp>
28 #include <boost/bind.hpp>
29
30 #include "pbd/stateful.h"
31 #include "pbd/xml++.h"
32 #include "ardour/configuration_variable.h"
33
34 #include "canvas/colors.h"
35
36 #include "utils.h"
37
38 class UIConfiguration : public PBD::Stateful
39 {
40     public:
41         struct RelativeHSV {
42                 RelativeHSV (const std::string& b, const ArdourCanvas::HSV& mod) 
43                         : base_color (b)
44                         , modifier (mod)
45                         , quantized_hue (-1.0) {}
46                 std::string base_color;
47                 ArdourCanvas::HSV modifier;
48                 double quantized_hue;
49
50                 ArdourCanvas::HSV get() const;
51         };
52
53         UIConfiguration();
54         ~UIConfiguration();
55
56         static UIConfiguration* instance() { return _instance; }
57
58         void load_rc_file (bool themechange, bool allow_own = true);
59
60         int load_state ();
61         int save_state ();
62         int load_defaults ();
63
64         int set_state (const XMLNode&, int version);
65         XMLNode& get_state (void);
66         XMLNode& get_variables (std::string);
67         void set_variables (const XMLNode&);
68
69         typedef std::map<std::string,RelativeHSV> RelativeColors;
70         typedef std::map<std::string,std::string> ColorAliases;
71         typedef std::map<std::string,ArdourCanvas::Color> BaseColors;
72
73         BaseColors     base_colors;
74         RelativeColors relative_colors;
75         ColorAliases   color_aliases;
76
77         void set_alias (std::string const & name, std::string const & alias);
78         void set_relative (const std::string& name, const RelativeHSV& new_value);
79         void set_base (const std::string& name, ArdourCanvas::Color);
80         
81         RelativeHSV color_as_relative_hsv (ArdourCanvas::Color c);
82         std::string color_as_alias (ArdourCanvas::Color c);
83         ArdourCanvas::Color quantized (ArdourCanvas::Color) const;
84
85         ArdourCanvas::Color base_color_by_name (const std::string&) const;
86         ArdourCanvas::Color color (const std::string&) const;
87         ArdourCanvas::HSV  color_hsv (const std::string&) const;
88
89         sigc::signal<void,std::string> ParameterChanged;
90         void map_parameters (boost::function<void (std::string)>&);
91
92         void parameter_changed (std::string);
93         
94 #undef UI_CONFIG_VARIABLE
95 #define UI_CONFIG_VARIABLE(Type,var,name,value) \
96         Type get_##var () const { return var.get(); } \
97         bool set_##var (Type val) { bool ret = var.set (val); if (ret) { ParameterChanged (name); } return ret;  }
98 #include "ui_config_vars.h"
99 #undef  UI_CONFIG_VARIABLE
100 #define CANVAS_FONT_VARIABLE(var,name) \
101         Pango::FontDescription get_##var () const { return ARDOUR_UI_UTILS::sanitized_font (var.get()); } \
102         bool set_##var (const std::string& val) { bool ret = var.set (val); if (ret) { ParameterChanged (name); } return ret;  }
103 #include "canvas_vars.h"
104 #undef CANVAS_FONT_VARIABLE
105
106 #undef CANVAS_BASE_COLOR
107 #define CANVAS_BASE_COLOR(var,name,val) \
108         ArdourCanvas::Color get_##var() const { return base_color_by_name (name); }
109 #include "base_colors.h"
110 #undef CANVAS_BASE_COLOR
111
112 #undef COLOR_ALIAS
113 #define COLOR_ALIAS(var,name,alias) ArdourCanvas::Color get_##var() const { return color (name); }
114 #include "color_aliases.h"
115 #undef COLOR_ALIAS
116
117   private:
118         /* declare variables */
119
120 #undef  UI_CONFIG_VARIABLE
121 #define UI_CONFIG_VARIABLE(Type,var,name,value) ARDOUR::ConfigVariable<Type> var;
122 #include "ui_config_vars.h"
123 #undef UI_CONFIG_VARIABLE
124
125 #define CANVAS_FONT_VARIABLE(var,name) ARDOUR::ConfigVariable<std::string> var;
126 #include "canvas_vars.h"
127 #undef CANVAS_FONT_VARIABLE
128
129         XMLNode& state ();
130         bool _dirty;
131         bool base_modified;
132         bool aliases_modified;
133         bool derived_modified;
134         
135         static UIConfiguration* _instance;
136
137         int store_color_theme ();
138         void load_base_colors (XMLNode const &);
139         void load_color_aliases (XMLNode const &);
140         void load_relative_colors (XMLNode const &);
141         void reset_gtk_theme ();
142         void colors_changed ();
143         int load_color_theme (bool allow_own=true);
144
145         uint32_t block_save;
146 };
147
148 std::ostream& operator<< (std::ostream& o, const UIConfiguration::RelativeHSV& rhsv);
149
150 #endif /* __ardour_ui_configuration_h__ */
151