]> git.tdb.fi Git - libs/gltk.git/blob - source/resources.cpp
Font size loading fixes
[libs/gltk.git] / source / resources.cpp
1 #include <msp/fs/utils.h>
2 #include "resources.h"
3
4 using namespace std;
5
6 namespace Msp {
7 namespace GLtk {
8
9 Resources::Resources():
10         default_font(0)
11 {
12         add_type<Graphic>().keyword("graphic");
13         add_type<GL::Texture2D>().keyword("texture");
14         add_type<GL::Font>().keyword("font");
15         add_type<Style>().keyword("style");
16 }
17
18 const GL::Font &Resources::get_default_font() const
19 {
20         if(!default_font)
21                 throw logic_error("!default_font");
22
23         return *default_font;
24 }
25
26
27 Resources::Loader::Loader(Resources &r):
28         Collection::Loader(r),
29         res(r)
30 {
31         add("default_font", &Loader::default_font);
32         add("font", &Loader::font);
33 }
34
35 void Resources::Loader::default_font(const string &name)
36 {
37         res.default_font = &res.get<GL::Font>(name);
38 }
39
40 void Resources::Loader::font(const string &name)
41 {
42         RefPtr<GL::Font> fnt = new GL::Font;
43         load_sub(*fnt, res);
44         res.add(name, fnt.get());
45         if(!res.default_font)
46                 res.default_font = fnt.get();
47         fnt.release();
48 }
49
50 } // namespace GLtk
51 } // namespace Msp