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_type<Graphic>().keyword("graphic");
28 add_type<GL::Texture2D>().keyword("texture").creator(&Resources::create_texture);
29 add_type<GL::Font>().creator(&Resources::create_font);
32 void Resources::set_path(const FS::Path &p)
34 /* XXX bad, should change Collection API to allow creators to form paths
35 relative to the datafile location */
39 const GL::Font &Resources::get_default_font() const
42 throw logic_error("!default_font");
47 GL::Font *Resources::create_font(const string &name)
49 RefPtr<GL::Font> fnt = new GL::Font;
50 DataFile::load(*fnt, (path/name).str(), *this);
52 default_font = fnt.get();
56 GL::Texture2D *Resources::create_texture(const string &name)
58 RefPtr<GL::Texture2D> tex = new GL::Texture2D;
59 tex->load_image((path/name).str());
60 tex->set_min_filter(GL::LINEAR);
65 Resources::Loader::Loader(Resources &r):
66 Collection::Loader(r),
69 add("default_font", &Loader::default_font);
70 add("font", &Loader::font);
71 add("style", &Loader::style);
74 void Resources::Loader::default_font(const string &name)
76 res.default_font = &res.get<GL::Font>(name);
79 void Resources::Loader::font(const string &name)
81 RefPtr<GL::Font> fnt = new GL::Font;
83 res.add(name, fnt.get());
85 res.default_font = fnt.get();
89 void Resources::Loader::style(const string &name)
91 RefPtr<Style> stl = new Style(res);
93 res.add(name, stl.get());