]> git.tdb.fi Git - poefilter.git/blob - source/appearance.cpp
ccd847666b388900534464f1ae196b0d09737e53
[poefilter.git] / source / appearance.cpp
1 #include <msp/strings/format.h>
2 #include "appearance.h"
3 #include "filter.h"
4 #include "theme.h"
5
6 using namespace std;
7 using namespace Msp;
8
9 Appearance::Appearance():
10         font_size(0),
11         sound_type(0),
12         sound_volume(100)
13 { }
14
15 void Appearance::merge_from(const Appearance &other)
16 {
17         if(other.font_size)
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;
25         if(other.sound_type)
26         {
27                 sound_type = other.sound_type;
28                 sound_volume = other.sound_volume;
29         }
30 }
31
32 void Appearance::add_lines(FilterStatement &st) const
33 {
34         if(font_size)
35                 st.add_line(format("SetFontSize %d", font_size));
36
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));
39
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));
42
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));
45
46         if(sound_type)
47                 st.add_line(format("PlayAlertSound %d %d", sound_type, sound_volume));
48 }
49
50
51 Appearance::Loader::Loader(Appearance &a, const Theme *t):
52         DataFile::ObjectLoader<Appearance>(a),
53         theme(t)
54 {
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("text_color", &Loader::text_color);
64         add("text_color", &Loader::text_color_alpha);
65         add("text_color", &Loader::text_color_named);
66 }
67
68 void Appearance::Loader::background_color(unsigned r, unsigned g, unsigned b)
69 {
70         obj.background_color = Color(r, g, b);
71 }
72
73 void Appearance::Loader::background_color_alpha(unsigned r, unsigned g, unsigned b, unsigned a)
74 {
75         obj.background_color = Color(r, g, b, a);
76 }
77
78 void Appearance::Loader::background_color_named(const string &name)
79 {
80         if(!theme)
81                 throw logic_error("No theme");
82         obj.background_color = theme->get_color(name);
83 }
84
85 void Appearance::Loader::border_color(unsigned r, unsigned g, unsigned b)
86 {
87         obj.border_color = Color(r, g, b);
88 }
89
90 void Appearance::Loader::border_color_alpha(unsigned r, unsigned g, unsigned b, unsigned a)
91 {
92         obj.border_color = Color(r, g, b, a);
93 }
94
95 void Appearance::Loader::border_color_named(const string &name)
96 {
97         if(!theme)
98                 throw logic_error("No theme");
99         obj.border_color = theme->get_color(name);
100 }
101
102 void Appearance::Loader::font_size(float s)
103 {
104         float base_size = (theme ? theme->get_base_font_size() : 32);
105         obj.font_size = base_size*s+0.5f;
106 }
107
108 void Appearance::Loader::text_color(unsigned r, unsigned g, unsigned b)
109 {
110         obj.text_color = Color(r, g, b);
111 }
112
113 void Appearance::Loader::text_color_alpha(unsigned r, unsigned g, unsigned b, unsigned a)
114 {
115         obj.text_color = Color(r, g, b, a);
116 }
117
118 void Appearance::Loader::text_color_named(const string &name)
119 {
120         if(!theme)
121                 throw logic_error("No theme");
122         obj.text_color = theme->get_color(name);
123 }