1 #include <msp/core/error.h>
9 Resources::Resources():
13 Resources::~Resources()
15 for(FontMap::iterator i=fonts.begin(); i!=fonts.end(); ++i)
17 for(TextureMap::iterator i=textures.begin(); i!=textures.end(); ++i)
21 const GL::Font &Resources::get_font(const string &name) const
23 FontMap::const_iterator i=fonts.find(name);
25 throw KeyError("Unknown font "+name);
30 const GL::Font &Resources::get_default_font() const
33 throw InvalidState("No default font");
38 const GL::Texture2D &Resources::get_texture(const string &name) const
40 TextureMap::const_iterator i=textures.find(name);
42 throw KeyError("Unknown texture "+name);
47 const Graphic &Resources::get_graphic(const string &name) const
49 GraphicMap::const_iterator i=graphics.find(name);
51 throw KeyError("Unknown graphic "+name);
56 const Style &Resources::get_style(const string &wdg, const string &name) const
58 StyleMap::const_iterator i=styles.find(StyleId(wdg, name));
60 throw KeyError("Unknown style "+name+" for widget "+wdg);
66 Resources::Loader::Loader(Resources &r):
69 add("font", &Loader::font);
70 add("texture", &Loader::texture);
71 add("graphic", &Loader::graphic);
72 add("style", &Loader::style);
75 void Resources::Loader::font(const string &fn)
77 RefPtr<GL::Font> fnt=new GL::Font;
78 Parser::load(*fnt, fn);
80 res.fonts.insert(FontMap::value_type(fn.substr(0, fn.rfind('.')), fnt.get()));
82 res.default_font=fnt.get();
86 void Resources::Loader::texture(const string &fn)
88 RefPtr<GL::Texture2D> tex=new GL::Texture2D;
90 tex->set_min_filter(GL::LINEAR);
92 res.textures.insert(TextureMap::value_type(fn.substr(0, fn.rfind('.')), tex.release()));
95 void Resources::Loader::graphic(const std::string &n)
97 Graphic graph(res, n);
99 if(!graph.get_texture())
100 throw Exception("Graphic without texture");
102 res.graphics.insert(GraphicMap::value_type(n, graph));
105 void Resources::Loader::style(const string &w, const string &n)
107 Style stl(res, w, n);
110 res.styles.insert(StyleMap::value_type(StyleId(w, n), stl));
114 bool Resources::StyleId::operator<(const StyleId &other) const
116 if(widget<other.widget)
118 return widget==other.widget && name<other.name;