1 #include <msp/core/except.h>
2 #include <msp/fs/utils.h>
10 Resources::Resources():
17 Resources::Resources(const FS::Path &fn):
18 path(FS::dirname(fn)),
23 DataFile::load(*this, fn.str());
26 void Resources::init()
28 add_keyword<Graphic>("graphic");
29 add_keyword<GL::Texture2D>("texture");
31 add_creator(&Resources::create_font);
32 add_creator(&Resources::create_texture);
35 void Resources::set_path(const FS::Path &p)
37 /* XXX bad, should change Collection API to allow creators to form paths
38 relative to the datafile location */
42 const GL::Font &Resources::get_default_font() const
45 throw InvalidState("No default font");
50 GL::Font *Resources::create_font(const string &name)
52 RefPtr<GL::Font> fnt = new GL::Font;
53 DataFile::load(*fnt, (path/name).str(), *this);
55 default_font = fnt.get();
59 GL::Texture2D *Resources::create_texture(const string &name)
61 RefPtr<GL::Texture2D> tex = new GL::Texture2D;
62 tex->load_image((path/name).str());
63 tex->set_min_filter(GL::LINEAR);
68 Resources::Loader::Loader(Resources &r):
69 Collection::Loader(r),
72 add("default_font", &Loader::default_font);
73 add("font", &Loader::font);
74 add("style", &Loader::style);
77 void Resources::Loader::default_font(const string &name)
79 res.default_font = res.get<GL::Font>(name);
82 void Resources::Loader::font(const string &name)
84 RefPtr<GL::Font> fnt = new GL::Font;
86 res.add(name, fnt.get());
88 res.default_font = fnt.get();
92 void Resources::Loader::style(const string &name)
94 RefPtr<Style> stl = new Style(res);
96 res.add(name, stl.get());