]> git.tdb.fi Git - libs/gltk.git/commitdiff
Reintroduce the Resources constructor that immediately loads a file
authorMikko Rasa <tdb@tdb.fi>
Wed, 16 Jan 2013 16:58:51 +0000 (18:58 +0200)
committerMikko Rasa <tdb@tdb.fi>
Wed, 16 Jan 2013 17:01:41 +0000 (19:01 +0200)
This covers many simple use cases and avoids the need of creating a
sub-class to add sources or load data before a Root is created.

source/resources.cpp
source/resources.h

index 045096e52dea7c31a55c872211cd781e276d3449..36be79e7914272d76a30c4c5af904c8fa5dc6cee 100644 (file)
@@ -6,15 +6,37 @@ using namespace std;
 namespace Msp {
 namespace GLtk {
 
-Resources::Resources():
-       default_font(0)
+Resources::Resources()
 {
+       init();
+}
+
+Resources::Resources(const FS::Path &fn)
+{
+       init();
+
+       dir_src = new DataFile::DirectorySource;
+       dir_src->add_directory(FS::dirname(fn));
+       add_source(*dir_src);
+
+       DataFile::load(*this, fn.str());
+}
+
+void Resources::init()
+{
+       default_font = 0;
+       dir_src = 0;
        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");
 }
 
+Resources::~Resources()
+{
+       delete dir_src;
+}
+
 const GL::Font &Resources::get_default_font() const
 {
        if(!default_font)
index 77987e88c29ad8a023c8adc7f6b6f9c98410aae6..d83c2087543e75c1e6371f0c74cd6a7cdc6d0e2b 100644 (file)
@@ -4,6 +4,7 @@
 #include <msp/gl/font.h>
 #include <msp/gl/texture.h>
 #include <msp/datafile/collection.h>
+#include <msp/datafile/directorysource.h>
 #include <msp/fs/path.h>
 #include "graphic.h"
 #include "style.h"
@@ -20,6 +21,7 @@ class Resources: public DataFile::Collection
 private:
        FS::Path path;
        GL::Font *default_font;
+       DataFile::DirectorySource *dir_src;
 
 public:
        class Loader: public Collection::Loader
@@ -36,6 +38,11 @@ public:
 
 public:
        Resources();
+       Resources(const FS::Path &);
+private:
+       void init();
+public:
+       ~Resources();
 
        const GL::Font &get_default_font() const;