X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fresources.cpp;h=11fc1fabe8a0a467ba82019337cc2d2851674e42;hb=2b70e8801c43875ed3f4135bdd0141265cff0312;hp=2cfe022c1a1d74d5035aa855922dcc7ba9e5f0c8;hpb=ed9873ba7ee862ad76937f579fe371c1a27d5715;p=libs%2Fgltk.git diff --git a/source/resources.cpp b/source/resources.cpp index 2cfe022..11fc1fa 100644 --- a/source/resources.cpp +++ b/source/resources.cpp @@ -1,11 +1,5 @@ -/* $Id$ - -This file is part of libmspgltk -Copyright © 2007 Mikko Rasa, Mikkosoft Productions -Distributed under the LGPL -*/ - #include +#include #include "resources.h" using namespace std; @@ -16,16 +10,33 @@ 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"); + add_keyword("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; + /* XXX bad, should change Collection API to allow creators to form paths + relative to the datafile location */ + path = p; } const GL::Font &Resources::get_default_font() const @@ -38,16 +49,16 @@ const GL::Font &Resources::get_default_font() const GL::Font *Resources::create_font(const string &name) { - RefPtr fnt=new GL::Font; - DataFile::load(*fnt, (path/name).str(), *this); + RefPtr fnt = new GL::Font; + DataFile::load(*fnt, (path/name).str(), *this); if(!default_font) - default_font=fnt.get(); + default_font = fnt.get(); return fnt.release(); } GL::Texture2D *Resources::create_texture(const string &name) { - RefPtr tex=new GL::Texture2D; + RefPtr tex = new GL::Texture2D; tex->load_image((path/name).str()); tex->set_min_filter(GL::LINEAR); return tex.release(); @@ -65,22 +76,22 @@ Resources::Loader::Loader(Resources &r): void Resources::Loader::default_font(const string &name) { - res.default_font=res.get(name); + res.default_font = res.get(name); } void Resources::Loader::font(const string &name) { - RefPtr fnt=new GL::Font; - load_sub(*fnt); + RefPtr 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(); } void Resources::Loader::style(const string &name) { - RefPtr