2 Copyright (C) 2000-2007 Paul Davis
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.
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.
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.
20 #ifndef __ardour_ui_configuration_h__
21 #define __ardour_ui_configuration_h__
27 #include "pbd/stateful.h"
28 #include "pbd/xml++.h"
29 #include "ardour/configuration_variable.h"
31 #include "canvas/colors.h"
35 /* This is very similar to ARDOUR::ConfigVariable but expects numeric values to
36 * be in hexadecimal. This is because it is intended for use with color
37 * specifications which are easier to scan for issues in "rrggbbaa" format than
41 class ColorVariable : public ARDOUR::ConfigVariableBase
44 ColorVariable (std::string str) : ARDOUR::ConfigVariableBase (str) {}
45 ColorVariable (std::string str, T val) : ARDOUR::ConfigVariableBase (str), value (val) {}
59 std::string get_as_string () const {
68 void set_from_string (std::string const & s) {
76 T get_for_save() { return value; }
80 class UIConfiguration : public PBD::Stateful
86 static UIConfiguration* instance() { return _instance; }
88 std::map<std::string,ColorVariable<ArdourCanvas::Color> *> configurable_colors;
97 int set_state (const XMLNode&, int version);
98 XMLNode& get_state (void);
99 XMLNode& get_variables (std::string);
100 void set_variables (const XMLNode&);
101 void pack_canvasvars ();
102 void reset_derived_colors ();
104 ArdourCanvas::Color base_color_by_name (const std::string&) const;
105 ArdourCanvas::Color color (const std::string&) const;
106 ArdourCanvas::HSV color_hsv (const std::string&) const;
108 sigc::signal<void,std::string> ParameterChanged;
109 void map_parameters (boost::function<void (std::string)>&);
111 #undef UI_CONFIG_VARIABLE
112 #define UI_CONFIG_VARIABLE(Type,var,name,value) \
113 Type get_##var () const { return var.get(); } \
114 bool set_##var (Type val) { bool ret = var.set (val); if (ret) { ParameterChanged (name); } return ret; }
115 #include "ui_config_vars.h"
116 #undef UI_CONFIG_VARIABLE
117 #undef CANVAS_STRING_VARIABLE
118 #define CANVAS_STRING_VARIABLE(var,name) \
119 std::string get_##var () const { return var.get(); } \
120 bool set_##var (const std::string& val) { bool ret = var.set (val); if (ret) { ParameterChanged (name); } return ret; }
121 #define CANVAS_FONT_VARIABLE(var,name) \
122 Pango::FontDescription get_##var () const { return ARDOUR_UI_UTILS::sanitized_font (var.get()); } \
123 bool set_##var (const std::string& val) { bool ret = var.set (val); if (ret) { ParameterChanged (name); } return ret; }
124 #include "canvas_vars.h"
125 #undef CANVAS_STRING_VARIABLE
126 #undef CANVAS_FONT_VARIABLE
128 #undef CANVAS_BASE_COLOR
129 #define CANVAS_BASE_COLOR(var,name,val) \
130 ArdourCanvas::Color get_##var() const { return var.get(); } \
131 bool set_##var (ArdourCanvas::Color v) { bool ret = var.set (v); if (ret) { ParameterChanged (#var); } return ret; } \
132 bool set_##var(const ArdourCanvas::HSV& v) const { return set_##var (v.color()); }
133 #include "base_colors.h"
134 #undef CANVAS_BASE_COLOR
137 #define CANVAS_COLOR(var,name,base,modifier) ArdourCanvas::Color get_##var() const { return var.get().color(); }
144 RelativeHSV (const std::string& b, const ArdourCanvas::HSV& mod)
147 , quantized_hue (-1.0) {}
148 std::string base_color;
149 ArdourCanvas::HSV modifier;
150 double quantized_hue;
152 ArdourCanvas::HSV get() const;
155 /* these are loaded from serialized state (e.g. XML) */
156 std::map<std::string,RelativeHSV> relative_colors;
157 /* these are computed during color_compute()*/
158 std::map<std::string,ArdourCanvas::HSV> actual_colors;
159 /* these map from the name/key of relative colors to the color/value of actual colors */
160 std::map<std::string,std::string> color_aliases;
162 /* declare variables */
164 #undef UI_CONFIG_VARIABLE
165 #define UI_CONFIG_VARIABLE(Type,var,name,value) ARDOUR::ConfigVariable<Type> var;
166 #include "ui_config_vars.h"
167 #undef UI_CONFIG_VARIABLE
169 #define CANVAS_STRING_VARIABLE(var,name) ARDOUR::ConfigVariable<std::string> var;
170 #define CANVAS_FONT_VARIABLE(var,name) ARDOUR::ConfigVariable<std::string> var;
171 #include "canvas_vars.h"
172 #undef CANVAS_STRING_VARIABLE
173 #undef CANVAS_FONT_VARIABLE
175 /* declare base color variables (these are modifiable by the user) */
177 #undef CANVAS_BASE_COLOR
178 #define CANVAS_BASE_COLOR(var,name,val) ColorVariable<ArdourCanvas::Color> var;
179 #include "base_colors.h"
180 #undef CANVAS_BASE_COLOR
182 /* declare relative color variables (not directly modifiable) */
185 #define CANVAS_COLOR(var,name,base,modifier) RelativeHSV var;
191 static UIConfiguration* _instance;
193 void color_compute ();
194 void print_relative_def (std::string camelcase, std::string name, ArdourCanvas::Color c);
195 void color_theme_changed ();
196 void regenerate_relative_definitions ();
197 ArdourCanvas::Color quantized (ArdourCanvas::Color);
200 #endif /* __ardour_ui_configuration_h__ */