]> git.tdb.fi Git - poefilter.git/blob - source/theme.cpp
Correctly merge icon and light beam appearances
[poefilter.git] / source / theme.cpp
1 #include <msp/core/maputils.h>
2 #include "theme.h"
3
4 using namespace std;
5 using namespace Msp;
6
7 Theme::Theme():
8         base_font_size(32)
9 { }
10
11 void Theme::set_color(const string &name, const Color &color)
12 {
13         colors[name] = color;
14 }
15
16 const Color &Theme::get_color(const string &name) const
17 {
18         return get_item(colors, name);
19 }
20
21 void Theme::set_base_font_size(unsigned size)
22 {
23         base_font_size = size;
24 }
25
26 void Theme::set_appearance(const string &name, const Appearance &app)
27 {
28         appearances[name] = app;
29 }
30
31 const Appearance &Theme::get_appearance(const string &name) const
32 {
33         return get_item(appearances, name);
34 }
35
36 const Appearance *Theme::find_appearance(const string &name) const
37 {
38         AppearanceMap::const_iterator i = appearances.find(name);
39         return (i!=appearances.end() ? &i->second : 0);
40 }
41
42
43 Theme::Loader::Loader(Theme &t):
44         DataFile::ObjectLoader<Theme>(t)
45 {
46         add("appearance", &Loader::appearance);
47         add("base_font_size", &Theme::base_font_size);
48         add("color", &Loader::color);
49         add("color", &Loader::color_alpha);
50 }
51
52 void Theme::Loader::appearance(const string &name)
53 {
54         Appearance app;
55         Appearance::Loader ldr(app, &obj);
56         load_sub_with(ldr);
57         obj.set_appearance(name, app);
58 }
59
60 void Theme::Loader::color(const string &name, unsigned r, unsigned g, unsigned b)
61 {
62         obj.set_color(name, Color(r, g, b));
63 }
64
65 void Theme::Loader::color_alpha(const string &name, unsigned r, unsigned g, unsigned b, unsigned a)
66 {
67         obj.set_color(name, Color(r, g, b, a));
68 }