1 #include <msp/fs/utils.h>
9 Resources::Resources():
16 Resources::Resources(const FS::Path &fn):
17 path(FS::dirname(fn)),
22 DataFile::load(*this, fn.str());
25 void Resources::init()
27 add_keyword<Graphic>("graphic");
28 add_keyword<GL::Texture2D>("texture");
30 add_creator(&Resources::create_font);
31 add_creator(&Resources::create_texture);
34 void Resources::set_path(const FS::Path &p)
36 /* XXX bad, should change Collection API to allow creators to form paths
37 relative to the datafile location */
41 const GL::Font &Resources::get_default_font() const
44 throw logic_error("!default_font");
49 GL::Font *Resources::create_font(const string &name)
51 RefPtr<GL::Font> fnt = new GL::Font;
52 DataFile::load(*fnt, (path/name).str(), *this);
54 default_font = fnt.get();
58 GL::Texture2D *Resources::create_texture(const string &name)
60 RefPtr<GL::Texture2D> tex = new GL::Texture2D;
61 tex->load_image((path/name).str());
62 tex->set_min_filter(GL::LINEAR);
67 Resources::Loader::Loader(Resources &r):
68 Collection::Loader(r),
71 add("default_font", &Loader::default_font);
72 add("font", &Loader::font);
73 add("style", &Loader::style);
76 void Resources::Loader::default_font(const string &name)
78 res.default_font = res.get<GL::Font>(name);
81 void Resources::Loader::font(const string &name)
83 RefPtr<GL::Font> fnt = new GL::Font;
85 res.add(name, fnt.get());
87 res.default_font = fnt.get();
91 void Resources::Loader::style(const string &name)
93 RefPtr<Style> stl = new Style(res);
95 res.add(name, stl.get());