]> git.tdb.fi Git - libs/gltk.git/blobdiff - source/resources.cpp
Update loaders to use ObjectLoader as base class
[libs/gltk.git] / source / resources.cpp
index 11fc1fabe8a0a467ba82019337cc2d2851674e42..3e0f851d701e3b961a38b564a1280507861f0d77 100644 (file)
@@ -1,4 +1,3 @@
-#include <msp/core/except.h>
 #include <msp/fs/utils.h>
 #include "resources.h"
 
@@ -8,62 +7,22 @@ namespace Msp {
 namespace GLtk {
 
 Resources::Resources():
-       path("."),
        default_font(0)
 {
-       init();
-}
-
-Resources::Resources(const FS::Path &fn):
-       path(FS::dirname(fn)),
-       default_font(0)
-{
-       init();
-
-       DataFile::load(*this, fn.str());
-}
-
-void Resources::init()
-{
-       add_keyword<Graphic>("graphic");
-       add_keyword<GL::Texture2D>("texture");
-
-       add_creator(&Resources::create_font);
-       add_creator(&Resources::create_texture);
-}
-
-void Resources::set_path(const FS::Path &p)
-{
-       /* XXX bad, should change Collection API to allow creators to form paths
-       relative to the datafile location */
-       path = p;
+       add_type<Graphic>().keyword("graphic");
+       add_type<GL::Texture2D>().keyword("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(*fnt, (path/name).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->load_image((path/name).str());
-       tex->set_min_filter(GL::LINEAR);
-       return tex.release();
-}
-
 
 Resources::Loader::Loader(Resources &r):
        Collection::Loader(r),
@@ -71,12 +30,11 @@ Resources::Loader::Loader(Resources &r):
 {
        add("default_font", &Loader::default_font);
        add("font", &Loader::font);
-       add("style", &Loader::style);
 }
 
 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)
@@ -89,13 +47,5 @@ void Resources::Loader::font(const string &name)
        fnt.release();
 }
 
-void Resources::Loader::style(const string &name)
-{
-       RefPtr<Style> stl = new Style(res);
-       load_sub(*stl, res);
-       res.add(name, stl.get());
-       stl.release();
-}
-
 } // namespace GLtk
 } // namespace Msp