]> git.tdb.fi Git - libs/gltk.git/blob - source/style.cpp
Font size loading fixes
[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",       &Loader::font);
42         add("font_color", &Loader::font_color);
43         add("font_size",  &Style::font_size);
44         add("part",       static_cast<void (Loader::*)()>(&Loader::part));
45         add("part",       static_cast<void (Loader::*)(const std::string &)>(&Loader::part));
46         // Deprecated alias
47         add("special",    static_cast<void (Loader::*)(const std::string &)>(&Loader::part));
48 }
49
50 void Style::Loader::font(const string &n)
51 {
52         style.font = &res.get<GL::Font>(n);
53         style.font_size = style.font->get_native_size();
54 }
55
56 void Style::Loader::font_color(float r, float g, float b)
57 {
58         style.font_color = GL::Color(r, g, b);
59 }
60
61 void Style::Loader::part()
62 {
63         part(string());
64 }
65
66 void Style::Loader::part(const string &n)
67 {
68         Part p(n);
69         load_sub(p, res);
70         style.parts.push_back(p);
71 }
72
73 } // namespace GLtk
74 } // namespace Msp