1 #include <msp/strings/format.h>
2 #include "appearance.h"
9 Appearance::Appearance():
15 void Appearance::merge_from(const Appearance &other)
18 font_size = other.font_size;
19 if(other.border_color.defined)
20 border_color = other.border_color;
21 if(other.background_color.defined)
22 background_color = other.background_color;
23 if(other.text_color.defined)
24 text_color = other.text_color;
27 sound_type = other.sound_type;
28 sound_volume = other.sound_volume;
32 void Appearance::add_lines(FilterStatement &st) const
35 st.add_line(format("SetFontSize %d", font_size));
37 if(background_color.defined)
38 st.add_line(format("SetBackgroundColor %d %d %d %d", background_color.r, background_color.g, background_color.b, background_color.a));
40 if(border_color.defined)
41 st.add_line(format("SetBorderColor %d %d %d %d", border_color.r, border_color.g, border_color.b, border_color.a));
43 if(text_color.defined)
44 st.add_line(format("SetTextColor %d %d %d %d", text_color.r, text_color.g, text_color.b, text_color.a));
47 st.add_line(format("PlayAlertSound %d %d", sound_type, sound_volume));
51 Appearance::Loader::Loader(Appearance &a, const Theme *t):
52 DataFile::ObjectLoader<Appearance>(a),
55 add("alert_sound", &Appearance::sound_type, &Appearance::sound_volume);
56 add("background_color", &Loader::background_color);
57 add("background_color", &Loader::background_color_alpha);
58 add("background_color", &Loader::background_color_named);
59 add("border_color", &Loader::border_color);
60 add("border_color", &Loader::border_color_alpha);
61 add("border_color", &Loader::border_color_named);
62 add("font_size", &Loader::font_size);
63 add("inherit", &Loader::inherit);
64 add("text_color", &Loader::text_color);
65 add("text_color", &Loader::text_color_alpha);
66 add("text_color", &Loader::text_color_named);
69 void Appearance::Loader::background_color(unsigned r, unsigned g, unsigned b)
71 obj.background_color = Color(r, g, b);
74 void Appearance::Loader::background_color_alpha(unsigned r, unsigned g, unsigned b, unsigned a)
76 obj.background_color = Color(r, g, b, a);
79 void Appearance::Loader::background_color_named(const string &name)
82 throw logic_error("No theme");
83 obj.background_color = theme->get_color(name);
86 void Appearance::Loader::border_color(unsigned r, unsigned g, unsigned b)
88 obj.border_color = Color(r, g, b);
91 void Appearance::Loader::border_color_alpha(unsigned r, unsigned g, unsigned b, unsigned a)
93 obj.border_color = Color(r, g, b, a);
96 void Appearance::Loader::border_color_named(const string &name)
99 throw logic_error("No theme");
100 obj.border_color = theme->get_color(name);
103 void Appearance::Loader::font_size(float s)
105 float base_size = (theme ? theme->get_base_font_size() : 32);
106 obj.font_size = base_size*s+0.5f;
109 void Appearance::Loader::inherit(const string &name)
112 throw logic_error("No theme");
113 obj = theme->get_appearance(name);
116 void Appearance::Loader::text_color(unsigned r, unsigned g, unsigned b)
118 obj.text_color = Color(r, g, b);
121 void Appearance::Loader::text_color_alpha(unsigned r, unsigned g, unsigned b, unsigned a)
123 obj.text_color = Color(r, g, b, a);
126 void Appearance::Loader::text_color_named(const string &name)
129 throw logic_error("No theme");
130 obj.text_color = theme->get_color(name);