]> git.tdb.fi Git - libs/gltk.git/blob - source/style.cpp
Add getter for Panel::layout
[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",       &Loader::part);
44         add("part",       &Loader::unnamed_part);
45 }
46
47 void Style::Loader::font(const string &n)
48 {
49         obj.font = &get_collection().get<GL::Font>(n);
50         obj.font_size = obj.font->get_native_size();
51 }
52
53 void Style::Loader::font_color(float r, float g, float b)
54 {
55         obj.font_color = GL::Color(r, g, b);
56 }
57
58 void Style::Loader::part(const string &n)
59 {
60         Part p(n);
61         load_sub(p, get_collection());
62         obj.parts.push_back(p);
63 }
64
65 void Style::Loader::unnamed_part()
66 {
67         part(string());
68 }
69
70 } // namespace GLtk
71 } // namespace Msp