]> git.tdb.fi Git - poefilter.git/blob - source/appearance.cpp
cb132fd135a96c0effdaee80d274b331006e0a70
[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         show_icon(false),
14         icon_shape(CIRCLE),
15         icon_color(WHITE),
16         icon_size(1),
17         show_beam(false),
18         beam_color(WHITE)
19 { }
20
21 void Appearance::merge_from(const Appearance &other)
22 {
23         if(other.font_size)
24                 font_size = other.font_size;
25         if(other.border_color.defined)
26                 border_color = other.border_color;
27         if(other.background_color.defined)
28                 background_color = other.background_color;
29         if(other.text_color.defined)
30                 text_color = other.text_color;
31         if(other.sound_type)
32         {
33                 sound_type = other.sound_type;
34                 sound_volume = other.sound_volume;
35         }
36 }
37
38 void Appearance::add_lines(FilterStatement &st) const
39 {
40         if(font_size)
41                 st.add_line(format("SetFontSize %d", font_size));
42
43         if(background_color.defined)
44                 st.add_line(format("SetBackgroundColor %d %d %d %d", background_color.r, background_color.g, background_color.b, background_color.a));
45
46         if(border_color.defined)
47                 st.add_line(format("SetBorderColor %d %d %d %d", border_color.r, border_color.g, border_color.b, border_color.a));
48
49         if(text_color.defined)
50                 st.add_line(format("SetTextColor %d %d %d %d", text_color.r, text_color.g, text_color.b, text_color.a));
51
52         if(show_icon)
53                 st.add_line(format("MinimapIcon %d %s %s", icon_size, icon_color, icon_shape));
54
55         if(sound_type)
56         {
57                 st.add_line(format("PlayAlertSound %d %d", sound_type, sound_volume));
58                 st.add_line("DisableDropSound");
59         }
60
61         if(show_beam)
62                 st.add_line(format("PlayEffect %s", beam_color));
63 }
64
65
66 Appearance::Loader::Loader(Appearance &a, const Theme *t):
67         DataFile::ObjectLoader<Appearance>(a),
68         theme(t)
69 {
70         add("alert_sound", &Appearance::sound_type, &Appearance::sound_volume);
71         add("background_color", &Loader::background_color);
72         add("background_color", &Loader::background_color_alpha);
73         add("background_color", &Loader::background_color_named);
74         add("border_color", &Loader::border_color);
75         add("border_color", &Loader::border_color_alpha);
76         add("border_color", &Loader::border_color_named);
77         add("font_size", &Loader::font_size);
78         add("inherit", &Loader::inherit);
79         add("light_beam", &Loader::light_beam);
80         add("minimap_icon", &Loader::minimap_icon);
81         add("minimap_icon", &Loader::minimap_icon_size);
82         add("text_color", &Loader::text_color);
83         add("text_color", &Loader::text_color_alpha);
84         add("text_color", &Loader::text_color_named);
85 }
86
87 void Appearance::Loader::background_color(unsigned r, unsigned g, unsigned b)
88 {
89         obj.background_color = Color(r, g, b);
90 }
91
92 void Appearance::Loader::background_color_alpha(unsigned r, unsigned g, unsigned b, unsigned a)
93 {
94         obj.background_color = Color(r, g, b, a);
95 }
96
97 void Appearance::Loader::background_color_named(const string &name)
98 {
99         if(!theme)
100                 throw logic_error("No theme");
101         obj.background_color = theme->get_color(name);
102 }
103
104 void Appearance::Loader::border_color(unsigned r, unsigned g, unsigned b)
105 {
106         obj.border_color = Color(r, g, b);
107 }
108
109 void Appearance::Loader::border_color_alpha(unsigned r, unsigned g, unsigned b, unsigned a)
110 {
111         obj.border_color = Color(r, g, b, a);
112 }
113
114 void Appearance::Loader::border_color_named(const string &name)
115 {
116         if(!theme)
117                 throw logic_error("No theme");
118         obj.border_color = theme->get_color(name);
119 }
120
121 void Appearance::Loader::font_size(float s)
122 {
123         float base_size = (theme ? theme->get_base_font_size() : 32);
124         obj.font_size = base_size*s+0.5f;
125 }
126
127 void Appearance::Loader::inherit(const string &name)
128 {
129         if(!theme)
130                 throw logic_error("No theme");
131         obj = theme->get_appearance(name);
132 }
133
134 void Appearance::Loader::light_beam(EffectColor color)
135 {
136         obj.show_beam = true;
137         obj.beam_color = color;
138 }
139
140 void Appearance::Loader::minimap_icon(EffectColor color, IconShape shape)
141 {
142         minimap_icon_size(color, shape, 1);
143 }
144
145 void Appearance::Loader::minimap_icon_size(EffectColor color, IconShape shape, unsigned size)
146 {
147         obj.show_icon = true;
148         obj.icon_shape = shape;
149         obj.icon_color = color;
150         obj.icon_size = size;
151 }
152
153 void Appearance::Loader::text_color(unsigned r, unsigned g, unsigned b)
154 {
155         obj.text_color = Color(r, g, b);
156 }
157
158 void Appearance::Loader::text_color_alpha(unsigned r, unsigned g, unsigned b, unsigned a)
159 {
160         obj.text_color = Color(r, g, b, a);
161 }
162
163 void Appearance::Loader::text_color_named(const string &name)
164 {
165         if(!theme)
166                 throw logic_error("No theme");
167         obj.text_color = theme->get_color(name);
168 }