X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fresources.cpp;h=e83c1bb178e5adea2acc6525acfdc01c0b8b87f1;hb=2accd84fb2f8cc96efea8b3f27e381c2d2749160;hp=7415beb5473312e57fcabb29d6691114aa733fc1;hpb=0af3c2393bd00f39db3bfaf5b78a7a44f0fd5ff1;p=libs%2Fgltk.git diff --git a/source/resources.cpp b/source/resources.cpp index 7415beb..e83c1bb 100644 --- a/source/resources.cpp +++ b/source/resources.cpp @@ -1,11 +1,4 @@ -/* $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; @@ -17,22 +10,36 @@ Resources::Resources(): path("."), default_font(0) { - add_keyword("graphic"); - add_keyword("texture"); + init(); +} - add_creator(&Resources::create_font); - add_creator(&Resources::create_texture); +Resources::Resources(const FS::Path &fn): + path(FS::dirname(fn)), + default_font(0) +{ + init(); + + DataFile::load(*this, fn.str()); +} + +void Resources::init() +{ + add_type().keyword("graphic"); + add_type().keyword("texture").creator(&Resources::create_texture); + add_type().creator(&Resources::create_font); } 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; } const GL::Font &Resources::get_default_font() const { if(!default_font) - throw InvalidState("No default font"); + throw logic_error("!default_font"); return *default_font; } @@ -66,7 +73,7 @@ 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)