]> git.tdb.fi Git - libs/gltk.git/blob - source/style.cpp
Change Style so it doesn't need a special loading function
[libs/gltk.git] / source / style.cpp
1 #include "resources.h"
2 #include "style.h"
3
4 using namespace std;
5
6 namespace Msp {
7 namespace GLtk {
8
9 Style::Style():
10         font(0),
11         font_size(0)
12 { }
13
14 const GL::Font &Style::get_font() const
15 {
16         if(!font)
17                 throw logic_error("!font");
18         return *font;
19 }
20
21 const Part *Style::get_part(const string &name) const
22 {
23         for(PartSeq::const_iterator i=parts.begin(); i!=parts.end(); ++i)
24                 if(i->get_name()==name)
25                         return &*i;
26
27         return 0;
28 }
29
30
31 Style::Loader::Loader(Style &s, Resources &r):
32         style(s),
33         res(r)
34 {
35         if(!style.font)
36         {
37                 style.font = &r.get_default_font();
38                 style.font_size = style.font->get_native_size();
39         }
40
41         add("font",       &Style::font);
42         add("font_color", &Loader::font_color);
43         add("part",       static_cast<void (Loader::*)()>(&Loader::part));
44         add("part",       static_cast<void (Loader::*)(const std::string &)>(&Loader::part));
45         // Deprecated alias
46         add("special",    static_cast<void (Loader::*)(const std::string &)>(&Loader::part));
47 }
48
49 void Style::Loader::font_color(float r, float g, float b)
50 {
51         style.font_color = GL::Color(r, g, b);
52 }
53
54 void Style::Loader::part()
55 {
56         part(string());
57 }
58
59 void Style::Loader::part(const string &n)
60 {
61         Part p(n);
62         load_sub(p, res);
63         style.parts.push_back(p);
64 }
65
66 } // namespace GLtk
67 } // namespace Msp