2007-06-29 13:33:35 -04:00
|
|
|
/*
|
2009-10-14 12:10:01 -04:00
|
|
|
Copyright (C) 2000-2007 Paul Davis
|
2007-06-29 13:33:35 -04:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __ardour_ui_configuration_h__
|
|
|
|
#define __ardour_ui_configuration_h__
|
|
|
|
|
|
|
|
#include <sstream>
|
|
|
|
#include <ostream>
|
|
|
|
#include <iostream>
|
|
|
|
|
2014-12-05 09:01:49 -05:00
|
|
|
#include <boost/function.hpp>
|
|
|
|
#include <boost/bind.hpp>
|
|
|
|
|
2009-10-14 12:10:01 -04:00
|
|
|
#include "pbd/stateful.h"
|
2009-02-25 13:26:51 -05:00
|
|
|
#include "pbd/xml++.h"
|
2009-05-13 20:13:27 -04:00
|
|
|
#include "ardour/configuration_variable.h"
|
2007-06-29 13:33:35 -04:00
|
|
|
|
2014-11-19 13:14:26 -05:00
|
|
|
#include "canvas/colors.h"
|
|
|
|
|
2014-06-19 11:18:37 -04:00
|
|
|
#include "utils.h"
|
|
|
|
|
2014-06-13 10:54:12 -04:00
|
|
|
/* This is very similar to ARDOUR::ConfigVariable but expects numeric values to
|
|
|
|
* be in hexadecimal. This is because it is intended for use with color
|
|
|
|
* specifications which are easier to scan for issues in "rrggbbaa" format than
|
|
|
|
* as decimals.
|
|
|
|
*/
|
2007-06-29 13:33:35 -04:00
|
|
|
template<class T>
|
2014-06-13 10:54:12 -04:00
|
|
|
class ColorVariable : public ARDOUR::ConfigVariableBase
|
2007-06-29 13:33:35 -04:00
|
|
|
{
|
2014-12-05 09:01:49 -05:00
|
|
|
public:
|
2014-06-13 10:54:12 -04:00
|
|
|
ColorVariable (std::string str) : ARDOUR::ConfigVariableBase (str) {}
|
|
|
|
ColorVariable (std::string str, T val) : ARDOUR::ConfigVariableBase (str), value (val) {}
|
2007-06-29 13:33:35 -04:00
|
|
|
|
|
|
|
bool set (T val) {
|
|
|
|
if (val == value) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
value = val;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
T get() const {
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2009-05-13 20:13:27 -04:00
|
|
|
std::string get_as_string () const {
|
2007-06-29 13:33:35 -04:00
|
|
|
std::stringstream ss;
|
|
|
|
ss << std::hex;
|
|
|
|
ss.fill('0');
|
|
|
|
ss.width(8);
|
|
|
|
ss << value;
|
2009-05-13 20:13:27 -04:00
|
|
|
return ss.str ();
|
2007-06-29 13:33:35 -04:00
|
|
|
}
|
2009-05-13 20:13:27 -04:00
|
|
|
|
|
|
|
void set_from_string (std::string const & s) {
|
|
|
|
std::stringstream ss;
|
|
|
|
ss << std::hex;
|
|
|
|
ss << s;
|
|
|
|
ss >> value;
|
2007-06-29 13:33:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
T get_for_save() { return value; }
|
2007-06-29 16:29:39 -04:00
|
|
|
T value;
|
2007-06-29 13:33:35 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
class UIConfiguration : public PBD::Stateful
|
|
|
|
{
|
2014-12-05 09:01:49 -05:00
|
|
|
public:
|
|
|
|
struct RelativeHSV {
|
|
|
|
RelativeHSV (const std::string& b, const ArdourCanvas::HSV& mod)
|
|
|
|
: base_color (b)
|
|
|
|
, modifier (mod)
|
|
|
|
, quantized_hue (-1.0) {}
|
|
|
|
std::string base_color;
|
|
|
|
ArdourCanvas::HSV modifier;
|
|
|
|
double quantized_hue;
|
|
|
|
|
|
|
|
ArdourCanvas::HSV get() const;
|
|
|
|
};
|
|
|
|
|
2007-06-29 13:33:35 -04:00
|
|
|
UIConfiguration();
|
|
|
|
~UIConfiguration();
|
|
|
|
|
2014-11-19 13:14:26 -05:00
|
|
|
static UIConfiguration* instance() { return _instance; }
|
|
|
|
|
2014-11-20 14:01:12 -05:00
|
|
|
std::map<std::string,ColorVariable<ArdourCanvas::Color> *> configurable_colors;
|
2011-10-26 17:01:14 -04:00
|
|
|
|
|
|
|
bool dirty () const;
|
|
|
|
void set_dirty ();
|
2007-06-29 13:33:35 -04:00
|
|
|
|
|
|
|
int load_state ();
|
|
|
|
int save_state ();
|
2008-02-01 22:57:35 -05:00
|
|
|
int load_defaults ();
|
2007-06-29 13:33:35 -04:00
|
|
|
|
2009-10-15 14:56:11 -04:00
|
|
|
int set_state (const XMLNode&, int version);
|
2007-06-29 13:33:35 -04:00
|
|
|
XMLNode& get_state (void);
|
|
|
|
XMLNode& get_variables (std::string);
|
|
|
|
void set_variables (const XMLNode&);
|
2014-12-05 09:01:49 -05:00
|
|
|
|
|
|
|
typedef std::map<std::string,RelativeHSV> RelativeColors;
|
|
|
|
typedef std::map<std::string,std::string> ColorAliases;
|
|
|
|
|
|
|
|
RelativeColors relative_colors;
|
|
|
|
ColorAliases color_aliases;
|
|
|
|
|
|
|
|
void set_alias (std::string const & name, std::string const & alias);
|
|
|
|
|
|
|
|
void reset_relative (const std::string& name, const RelativeHSV& new_value);
|
|
|
|
|
|
|
|
RelativeHSV color_as_relative_hsv (ArdourCanvas::Color c);
|
|
|
|
ArdourCanvas::Color quantized (ArdourCanvas::Color) const;
|
2007-06-29 13:33:35 -04:00
|
|
|
|
2014-11-19 13:14:26 -05:00
|
|
|
ArdourCanvas::Color base_color_by_name (const std::string&) const;
|
|
|
|
ArdourCanvas::Color color (const std::string&) const;
|
|
|
|
ArdourCanvas::HSV color_hsv (const std::string&) const;
|
2011-10-26 17:01:14 -04:00
|
|
|
|
2013-06-21 17:15:56 -04:00
|
|
|
sigc::signal<void,std::string> ParameterChanged;
|
|
|
|
void map_parameters (boost::function<void (std::string)>&);
|
2007-06-29 13:33:35 -04:00
|
|
|
|
2013-04-16 23:46:22 -04:00
|
|
|
#undef UI_CONFIG_VARIABLE
|
|
|
|
#define UI_CONFIG_VARIABLE(Type,var,name,value) \
|
|
|
|
Type get_##var () const { return var.get(); } \
|
|
|
|
bool set_##var (Type val) { bool ret = var.set (val); if (ret) { ParameterChanged (name); } return ret; }
|
|
|
|
#include "ui_config_vars.h"
|
2007-06-29 13:33:35 -04:00
|
|
|
#undef UI_CONFIG_VARIABLE
|
2014-06-19 11:18:37 -04:00
|
|
|
#define CANVAS_FONT_VARIABLE(var,name) \
|
2014-06-25 15:27:37 -04:00
|
|
|
Pango::FontDescription get_##var () const { return ARDOUR_UI_UTILS::sanitized_font (var.get()); } \
|
2014-06-19 11:18:37 -04:00
|
|
|
bool set_##var (const std::string& val) { bool ret = var.set (val); if (ret) { ParameterChanged (name); } return ret; }
|
2013-04-16 23:46:22 -04:00
|
|
|
#include "canvas_vars.h"
|
2014-06-19 11:18:37 -04:00
|
|
|
#undef CANVAS_FONT_VARIABLE
|
2013-04-16 23:46:22 -04:00
|
|
|
|
2014-11-19 13:14:26 -05:00
|
|
|
#undef CANVAS_BASE_COLOR
|
|
|
|
#define CANVAS_BASE_COLOR(var,name,val) \
|
|
|
|
ArdourCanvas::Color get_##var() const { return var.get(); } \
|
|
|
|
bool set_##var (ArdourCanvas::Color v) { bool ret = var.set (v); if (ret) { ParameterChanged (#var); } return ret; } \
|
|
|
|
bool set_##var(const ArdourCanvas::HSV& v) const { return set_##var (v.color()); }
|
|
|
|
#include "base_colors.h"
|
|
|
|
#undef CANVAS_BASE_COLOR
|
|
|
|
|
2014-12-01 09:16:30 -05:00
|
|
|
#undef COLOR_ALIAS
|
2014-12-02 07:05:14 -05:00
|
|
|
#define COLOR_ALIAS(var,name,alias) ArdourCanvas::Color get_##var() const { return color (name); }
|
2014-12-01 09:16:30 -05:00
|
|
|
#include "color_aliases.h"
|
|
|
|
#undef COLOR_ALIAS
|
|
|
|
|
2013-04-16 23:46:22 -04:00
|
|
|
private:
|
|
|
|
/* declare variables */
|
|
|
|
|
|
|
|
#undef UI_CONFIG_VARIABLE
|
2014-06-13 10:54:12 -04:00
|
|
|
#define UI_CONFIG_VARIABLE(Type,var,name,value) ARDOUR::ConfigVariable<Type> var;
|
2007-06-29 13:33:35 -04:00
|
|
|
#include "ui_config_vars.h"
|
2013-04-16 23:46:22 -04:00
|
|
|
#undef UI_CONFIG_VARIABLE
|
|
|
|
|
2014-06-19 11:18:37 -04:00
|
|
|
#define CANVAS_FONT_VARIABLE(var,name) ARDOUR::ConfigVariable<std::string> var;
|
2007-06-29 13:33:35 -04:00
|
|
|
#include "canvas_vars.h"
|
2014-06-19 11:18:37 -04:00
|
|
|
#undef CANVAS_FONT_VARIABLE
|
2007-06-29 13:33:35 -04:00
|
|
|
|
2014-11-19 13:14:26 -05:00
|
|
|
/* declare base color variables (these are modifiable by the user) */
|
|
|
|
|
|
|
|
#undef CANVAS_BASE_COLOR
|
2014-11-20 14:01:12 -05:00
|
|
|
#define CANVAS_BASE_COLOR(var,name,val) ColorVariable<ArdourCanvas::Color> var;
|
2014-11-19 13:14:26 -05:00
|
|
|
#include "base_colors.h"
|
|
|
|
#undef CANVAS_BASE_COLOR
|
|
|
|
|
2007-06-29 13:33:35 -04:00
|
|
|
XMLNode& state ();
|
2011-10-26 17:01:14 -04:00
|
|
|
bool _dirty;
|
2014-12-05 11:17:56 -05:00
|
|
|
bool aliases_modified;
|
|
|
|
bool derived_modified;
|
|
|
|
|
2014-11-19 13:14:26 -05:00
|
|
|
static UIConfiguration* _instance;
|
|
|
|
|
|
|
|
void color_theme_changed ();
|
2014-12-05 11:17:56 -05:00
|
|
|
|
|
|
|
void load_color_aliases (XMLNode const &);
|
2007-06-29 13:33:35 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* __ardour_ui_configuration_h__ */
|
|
|
|
|