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", background_color.r, background_color.g, background_color.b));
40 if(border_color.defined)
41 st.add_line(format("SetBorderColor %d %d %d", border_color.r, border_color.g, border_color.b));
43 if(text_color.defined)
44 st.add_line(format("SetTextColor %d %d %d", text_color.r, text_color.g, text_color.b));
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_named);
58 add("border_color", &Loader::border_color);
59 add("border_color", &Loader::border_color_named);
60 add("font_size", &Loader::font_size);
61 add("text_color", &Loader::text_color);
62 add("text_color", &Loader::text_color_named);
65 void Appearance::Loader::background_color(unsigned r, unsigned g, unsigned b)
67 obj.background_color = Color(r, g, b);
70 void Appearance::Loader::background_color_named(const string &name)
73 throw logic_error("No theme");
74 obj.background_color = theme->get_color(name);
77 void Appearance::Loader::border_color(unsigned r, unsigned g, unsigned b)
79 obj.border_color = Color(r, g, b);
82 void Appearance::Loader::border_color_named(const string &name)
85 throw logic_error("No theme");
86 obj.border_color = theme->get_color(name);
89 void Appearance::Loader::font_size(float s)
91 float base_size = (theme ? theme->get_base_font_size() : 32);
92 obj.font_size = base_size*s+0.5f;
95 void Appearance::Loader::text_color(unsigned r, unsigned g, unsigned b)
97 obj.text_color = Color(r, g, b);
100 void Appearance::Loader::text_color_named(const string &name)
103 throw logic_error("No theme");
104 obj.text_color = theme->get_color(name);