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 <boost/function.hpp>
28 #include <boost/bind.hpp>
30 #include "pbd/stateful.h"
31 #include "pbd/xml++.h"
32 #include "ardour/configuration_variable.h"
34 #include "canvas/colors.h"
38 /* This is very similar to ARDOUR::ConfigVariable but expects numeric values to
39 * be in hexadecimal. This is because it is intended for use with color
40 * specifications which are easier to scan for issues in "rrggbbaa" format than
44 class ColorVariable : public ARDOUR::ConfigVariableBase
47 ColorVariable (std::string str) : ARDOUR::ConfigVariableBase (str) {}
48 ColorVariable (std::string str, T val) : ARDOUR::ConfigVariableBase (str), value (val) {}
62 std::string get_as_string () const {
71 void set_from_string (std::string const & s) {
79 T get_for_save() { return value; }
83 class UIConfiguration : public PBD::Stateful
87 RelativeHSV (const std::string& b, const ArdourCanvas::HSV& mod)
90 , quantized_hue (-1.0) {}
91 std::string base_color;
92 ArdourCanvas::HSV modifier;
95 ArdourCanvas::HSV get() const;
101 static UIConfiguration* instance() { return _instance; }
103 std::map<std::string,ColorVariable<ArdourCanvas::Color> *> configurable_colors;
110 int load_defaults ();
112 void color_theme_changed ();
114 static void load_rc_file (std::string const &, bool themechange);
116 int set_state (const XMLNode&, int version);
117 XMLNode& get_state (void);
118 XMLNode& get_variables (std::string);
119 void set_variables (const XMLNode&);
121 typedef std::map<std::string,RelativeHSV> RelativeColors;
122 typedef std::map<std::string,std::string> ColorAliases;
124 RelativeColors relative_colors;
125 ColorAliases color_aliases;
127 void set_alias (std::string const & name, std::string const & alias);
129 void reset_relative (const std::string& name, const RelativeHSV& new_value);
131 RelativeHSV color_as_relative_hsv (ArdourCanvas::Color c);
132 ArdourCanvas::Color quantized (ArdourCanvas::Color) const;
134 ArdourCanvas::Color base_color_by_name (const std::string&) const;
135 ArdourCanvas::Color color (const std::string&) const;
136 ArdourCanvas::HSV color_hsv (const std::string&) const;
138 sigc::signal<void,std::string> ParameterChanged;
139 void map_parameters (boost::function<void (std::string)>&);
141 void parameter_changed (std::string);
143 #undef UI_CONFIG_VARIABLE
144 #define UI_CONFIG_VARIABLE(Type,var,name,value) \
145 Type get_##var () const { return var.get(); } \
146 bool set_##var (Type val) { bool ret = var.set (val); if (ret) { ParameterChanged (name); } return ret; }
147 #include "ui_config_vars.h"
148 #undef UI_CONFIG_VARIABLE
149 #define CANVAS_FONT_VARIABLE(var,name) \
150 Pango::FontDescription get_##var () const { return ARDOUR_UI_UTILS::sanitized_font (var.get()); } \
151 bool set_##var (const std::string& val) { bool ret = var.set (val); if (ret) { ParameterChanged (name); } return ret; }
152 #include "canvas_vars.h"
153 #undef CANVAS_FONT_VARIABLE
155 #undef CANVAS_BASE_COLOR
156 #define CANVAS_BASE_COLOR(var,name,val) \
157 ArdourCanvas::Color get_##var() const { return var.get(); } \
158 bool set_##var (ArdourCanvas::Color v) { bool ret = var.set (v); if (ret) { ParameterChanged (#var); } return ret; } \
159 bool set_##var(const ArdourCanvas::HSV& v) const { return set_##var (v.color()); }
160 #include "base_colors.h"
161 #undef CANVAS_BASE_COLOR
164 #define COLOR_ALIAS(var,name,alias) ArdourCanvas::Color get_##var() const { return color (name); }
165 #include "color_aliases.h"
169 /* declare variables */
171 #undef UI_CONFIG_VARIABLE
172 #define UI_CONFIG_VARIABLE(Type,var,name,value) ARDOUR::ConfigVariable<Type> var;
173 #include "ui_config_vars.h"
174 #undef UI_CONFIG_VARIABLE
176 #define CANVAS_FONT_VARIABLE(var,name) ARDOUR::ConfigVariable<std::string> var;
177 #include "canvas_vars.h"
178 #undef CANVAS_FONT_VARIABLE
180 /* declare base color variables (these are modifiable by the user) */
182 #undef CANVAS_BASE_COLOR
183 #define CANVAS_BASE_COLOR(var,name,val) ColorVariable<ArdourCanvas::Color> var;
184 #include "base_colors.h"
185 #undef CANVAS_BASE_COLOR
189 bool aliases_modified;
190 bool derived_modified;
192 static UIConfiguration* _instance;
194 void load_color_aliases (XMLNode const &);
195 void reset_gtk_theme ();
197 XMLNode _saved_state_node;
198 int _saved_state_version;
201 #endif /* __ardour_ui_configuration_h__ */