]> git.tdb.fi Git - libs/gltk.git/blob - source/style.cpp
Add method to get a Part by name
[libs/gltk.git] / source / style.cpp
1 /* $Id$
2
3 This file is part of libmspgltk
4 Copyright © 2007  Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
6 */
7
8 #include "resources.h"
9 #include "style.h"
10
11 using namespace std;
12
13 namespace Msp {
14 namespace GLtk {
15
16 Style::Style(Resources &r):
17         font(&r.get_default_font())
18 { }
19
20 const Part *Style::get_part(const string &name) const
21 {
22         for(PartSeq::const_iterator i=parts.begin(); i!=parts.end(); ++i)
23                 if(i->get_name()==name)
24                         return &*i;
25
26         return 0;
27 }
28
29
30 Style::Loader::Loader(Style &s, Resources &r):
31         style(s),
32         res(r)
33 {
34         add("font",       &Style::font);
35         add("font_color", &Loader::font_color);
36         add("part",       static_cast<void (Loader::*)()>(&Loader::part));
37         add("part",       static_cast<void (Loader::*)(const std::string &)>(&Loader::part));
38         // Deprecated alias
39         add("special",    static_cast<void (Loader::*)(const std::string &)>(&Loader::part));
40 }
41
42 void Style::Loader::font_color(float r, float g, float b)
43 {
44         style.font_color = GL::Color(r, g, b);
45 }
46
47 void Style::Loader::part()
48 {
49         part(string());
50 }
51
52 void Style::Loader::part(const string &n)
53 {
54         Part p(n);
55         load_sub(p, res);
56         style.parts.push_back(p);
57 }
58
59 } // namespace GLtk
60 } // namespace Msp