]> git.tdb.fi Git - libs/gltk.git/blobdiff - source/resources.cpp
Add icon support to Button
[libs/gltk.git] / source / resources.cpp
index 650140ba4552f59b066f00cc5677b5d34dfd9734..b1b129b757fd6a65139a9cfb00c6a8663e75af17 100644 (file)
@@ -1,3 +1,10 @@
+/* $Id$
+
+This file is part of libmspgltk
+Copyright © 2007  Mikko Rasa, Mikkosoft Productions
+Distributed under the LGPL
+*/
+
 #include <msp/core/except.h>
 #include "resources.h"
 
@@ -10,15 +17,14 @@ Resources::Resources():
        path("."),
        default_font(0)
 {
-       add_keyword<GL::Font>("font");
        add_keyword<Graphic>("graphic");
-       add_keyword<Style>("style");
+       add_keyword<GL::Texture2D>("texture");
 
        add_creator(&Resources::create_font);
        add_creator(&Resources::create_texture);
 }
 
-void Resources::set_path(const Path &p)
+void Resources::set_path(const FS::Path &p)
 {
        path=p;
 }
@@ -34,14 +40,16 @@ const GL::Font &Resources::get_default_font() const
 GL::Font *Resources::create_font(const string &name)
 {
        RefPtr<GL::Font> fnt=new GL::Font;
-       DataFile::load(*fnt, (path/(name+".font")).str());
+       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->image((path/(name+".png")).str());
+       tex->load_image((path/name).str());
        tex->set_min_filter(GL::LINEAR);
        return tex.release();
 }
@@ -51,18 +59,33 @@ Resources::Loader::Loader(Resources &r):
        Collection::Loader(r),
        res(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);
 }
 
 void Resources::Loader::font(const string &name)
 {
        RefPtr<GL::Font> fnt=new GL::Font;
-       load_sub(*fnt);
+       load_sub(*fnt, res);
        res.add(name, fnt.get());
        if(!res.default_font)
                res.default_font=fnt.get();
        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