3 This file is part of libmspgltk
4 Copyright © 2007 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
8 #include <msp/core/except.h>
9 #include <msp/fs/utils.h>
10 #include "resources.h"
17 Resources::Resources():
24 Resources::Resources(const FS::Path &fn):
25 path(FS::dirname(fn)),
30 DataFile::load(*this, fn.str());
33 void Resources::init()
35 add_keyword<Graphic>("graphic");
36 add_keyword<GL::Texture2D>("texture");
38 add_creator(&Resources::create_font);
39 add_creator(&Resources::create_texture);
42 void Resources::set_path(const FS::Path &p)
44 /* XXX bad, should change Collection API to allow creators to form paths
45 relative to the datafile location */
49 const GL::Font &Resources::get_default_font() const
52 throw InvalidState("No default font");
57 GL::Font *Resources::create_font(const string &name)
59 RefPtr<GL::Font> fnt = new GL::Font;
60 DataFile::load(*fnt, (path/name).str(), *this);
62 default_font = fnt.get();
66 GL::Texture2D *Resources::create_texture(const string &name)
68 RefPtr<GL::Texture2D> tex = new GL::Texture2D;
69 tex->load_image((path/name).str());
70 tex->set_min_filter(GL::LINEAR);
75 Resources::Loader::Loader(Resources &r):
76 Collection::Loader(r),
79 add("default_font", &Loader::default_font);
80 add("font", &Loader::font);
81 add("style", &Loader::style);
84 void Resources::Loader::default_font(const string &name)
86 res.default_font = res.get<GL::Font>(name);
89 void Resources::Loader::font(const string &name)
91 RefPtr<GL::Font> fnt = new GL::Font;
93 res.add(name, fnt.get());
95 res.default_font = fnt.get();
99 void Resources::Loader::style(const string &name)
101 RefPtr<Style> stl = new Style(res);
103 res.add(name, stl.get());