X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fresources.cpp;h=b7586e886ee41df0eb711230c1ebe4bfcba8402c;hb=b51fd94242badcd3807a39c339979f4f358120cd;hp=b1b129b757fd6a65139a9cfb00c6a8663e75af17;hpb=94ac63c6f41227ce57790d9903039ec18a6ef3fd;p=libs%2Fgltk.git diff --git a/source/resources.cpp b/source/resources.cpp index b1b129b..b7586e8 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; @@ -14,46 +7,21 @@ namespace Msp { namespace GLtk { Resources::Resources(): - path("."), default_font(0) { - add_keyword("graphic"); - add_keyword("texture"); - - add_creator(&Resources::create_font); - add_creator(&Resources::create_texture); -} - -void Resources::set_path(const FS::Path &p) -{ - path=p; + add_type().keyword("graphic"); + add_type().keyword("texture"); + add_type().keyword("font"); } const GL::Font &Resources::get_default_font() const { if(!default_font) - throw InvalidState("No default font"); + throw logic_error("!default_font"); return *default_font; } -GL::Font *Resources::create_font(const string &name) -{ - RefPtr fnt=new GL::Font; - 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 tex=new GL::Texture2D; - tex->load_image((path/name).str()); - tex->set_min_filter(GL::LINEAR); - return tex.release(); -} - Resources::Loader::Loader(Resources &r): Collection::Loader(r), @@ -66,22 +34,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; + 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