]> git.tdb.fi Git - poefilter.git/blob - source/appearance.cpp
Associate categories and appearances at filter level
[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", background_color.r, background_color.g, background_color.b));
39
40         if(border_color.defined)
41                 st.add_line(format("SetBorderColor %d %d %d", border_color.r, border_color.g, border_color.b));
42
43         if(text_color.defined)
44                 st.add_line(format("SetTextColor %d %d %d", text_color.r, text_color.g, text_color.b));
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_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);
63 }
64
65 void Appearance::Loader::background_color(unsigned r, unsigned g, unsigned b)
66 {
67         obj.background_color = Color(r, g, b);
68 }
69
70 void Appearance::Loader::background_color_named(const string &name)
71 {
72         if(!theme)
73                 throw logic_error("No theme");
74         obj.background_color = theme->get_color(name);
75 }
76
77 void Appearance::Loader::border_color(unsigned r, unsigned g, unsigned b)
78 {
79         obj.border_color = Color(r, g, b);
80 }
81
82 void Appearance::Loader::border_color_named(const string &name)
83 {
84         if(!theme)
85                 throw logic_error("No theme");
86         obj.border_color = theme->get_color(name);
87 }
88
89 void Appearance::Loader::font_size(float s)
90 {
91         float base_size = (theme ? theme->get_base_font_size() : 32);
92         obj.font_size = base_size*s+0.5f;
93 }
94
95 void Appearance::Loader::text_color(unsigned r, unsigned g, unsigned b)
96 {
97         obj.text_color = Color(r, g, b);
98 }
99
100 void Appearance::Loader::text_color_named(const string &name)
101 {
102         if(!theme)
103                 throw logic_error("No theme");
104         obj.text_color = theme->get_color(name);
105 }