]> git.tdb.fi Git - libs/gltk.git/commitdiff
Add a constructor to Resources that loads a datafile
authorMikko Rasa <tdb@tdb.fi>
Thu, 4 Nov 2010 07:12:01 +0000 (07:12 +0000)
committerMikko Rasa <tdb@tdb.fi>
Thu, 4 Nov 2010 07:12:01 +0000 (07:12 +0000)
source/resources.cpp
source/resources.h

index 7415beb5473312e57fcabb29d6691114aa733fc1..825fc2517875771874c564989ea9da04c27e144f 100644 (file)
@@ -6,6 +6,7 @@ Distributed under the LGPL
 */
 
 #include <msp/core/except.h>
+#include <msp/fs/utils.h>
 #include "resources.h"
 
 using namespace std;
@@ -16,6 +17,20 @@ 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");
@@ -26,6 +41,8 @@ Resources::Resources():
 
 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;
 }
 
index c61d38abdffac50070c6019add97cbcdbbcf5617..e4d7f731cf10aff1f634e97810a81d9c85cc479d 100644 (file)
@@ -43,7 +43,11 @@ public:
        };
 
        Resources();
+       Resources(const FS::Path &);
+private:
+       void init();
 
+public:
        void set_path(const FS::Path &);
        const GL::Font &get_default_font() const;
 private: