-#include <msp/core/except.h>
+#include <msp/fs/utils.h>
#include "resources.h"
using namespace std;
namespace GLtk {
Resources::Resources():
- path("."),
default_font(0)
{
- add_keyword<GL::Font>("font");
- add_keyword<Graphic>("graphic");
- add_keyword<Style>("style");
-
- add_creator(&Resources::create_font);
- add_creator(&Resources::create_texture);
-}
-
-void Resources::set_path(const Path &p)
-{
- path=p;
+ add_type<Graphic>().keyword("graphic");
+ add_type<GL::Texture2D>().keyword("texture").creator(&Resources::create_texture);
+ add_type<GL::Font>().keyword("font");
+ add_type<Style>().keyword("style");
}
const GL::Font &Resources::get_default_font() const
{
if(!default_font)
- throw InvalidState("No default font");
+ throw logic_error("!default_font");
return *default_font;
}
-GL::Font *Resources::create_font(const string &name)
-{
- RefPtr<GL::Font> fnt=new GL::Font;
- DataFile::load<GL::Font, Resources &>(*fnt, (path/(name+".font")).str(), *this);
- if(!default_font)
- default_font=fnt.get();
- return fnt.release();
-}
-
GL::Texture2D *Resources::create_texture(const string &name)
{
- RefPtr<GL::Texture2D> tex=new GL::Texture2D;
- tex->image((path/(name+".png")).str());
- tex->set_min_filter(GL::LINEAR);
- return tex.release();
+ string ext = FS::extpart(name);
+ if(ext==".png" || ext==".jpg")
+ {
+ IO::Seekable *io = open_from_sources(name);
+ Graphics::Image image;
+ image.load_io(*io);
+ GL::Texture2D *tex = new GL::Texture2D;
+ tex->set_min_filter(GL::LINEAR);
+ tex->image(image);
+ return tex;
+ }
+ else
+ return 0;
}
void Resources::Loader::default_font(const string &name)
{
- res.default_font=&res.get<GL::Font>(name);
+ res.default_font = &res.get<GL::Font>(name);
}
void Resources::Loader::font(const string &name)
{
- RefPtr<GL::Font> fnt=new GL::Font;
- load_sub(*fnt);
+ RefPtr<GL::Font> fnt = new GL::Font;
+ load_sub(*fnt, res);
res.add(name, fnt.get());
if(!res.default_font)
- res.default_font=fnt.get();
+ res.default_font = fnt.get();
fnt.release();
}