1 #include <msp/fs/utils.h>
14 Resources::Resources(const FS::Path &fn)
18 dir_src = new DataFile::DirectorySource;
19 dir_src->add_directory(FS::dirname(fn));
22 DataFile::load(*this, fn.str());
25 void Resources::init()
29 add_type<Graphic>().keyword("graphic");
30 add_type<GL::Texture2D>().keyword("texture").creator(&Resources::create_texture);
31 add_type<GL::Font>().keyword("font");
32 add_type<Style>().keyword("style");
35 Resources::~Resources()
40 const GL::Font &Resources::get_default_font() const
43 throw logic_error("!default_font");
48 GL::Texture2D *Resources::create_texture(const string &name)
50 string ext = FS::extpart(name);
51 if(ext==".png" || ext==".jpg")
53 IO::Seekable *io = open_from_sources(name);
54 Graphics::Image image;
56 GL::Texture2D *tex = new GL::Texture2D;
57 tex->set_min_filter(GL::LINEAR);
66 Resources::Loader::Loader(Resources &r):
67 Collection::Loader(r),
70 add("default_font", &Loader::default_font);
71 add("font", &Loader::font);
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();