]> git.tdb.fi Git - libs/gltk.git/blob - source/style.cpp
Update loaders to use ObjectLoader as base class
[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         DataFile::CollectionObjectLoader<Style, Resources>(s, &r)
33 {
34         if(!obj.font)
35         {
36                 obj.font = &get_collection().get_default_font();
37                 obj.font_size = obj.font->get_native_size();
38         }
39
40         add("font",       &Loader::font);
41         add("font_color", &Loader::font_color);
42         add("font_size",  &Style::font_size);
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(const string &n)
50 {
51         obj.font = &get_collection().get<GL::Font>(n);
52         obj.font_size = obj.font->get_native_size();
53 }
54
55 void Style::Loader::font_color(float r, float g, float b)
56 {
57         obj.font_color = GL::Color(r, g, b);
58 }
59
60 void Style::Loader::part()
61 {
62         part(string());
63 }
64
65 void Style::Loader::part(const string &n)
66 {
67         Part p(n);
68         load_sub(p, get_collection());
69         obj.parts.push_back(p);
70 }
71
72 } // namespace GLtk
73 } // namespace Msp