From: Mikko Rasa Date: Sat, 8 Dec 2012 10:24:27 +0000 (+0200) Subject: Update loaders to use ObjectLoader as base class X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=5e8285302c1d04b631682a82d56c5afc46d20ad5;p=libs%2Fgltk.git Update loaders to use ObjectLoader as base class --- diff --git a/source/graphic.cpp b/source/graphic.cpp index 0b0ba0e..5fc27ef 100644 --- a/source/graphic.cpp +++ b/source/graphic.cpp @@ -73,8 +73,7 @@ void Graphic::create_texcoords(float low, float high, float brd1, float brd2, fl Graphic::Loader::Loader(Graphic &g, Resources &r): - graph(g), - res(r) + DataFile::CollectionObjectLoader(g, &r) { add("texture", &Loader::texture); add("slice", &Loader::slice); @@ -85,23 +84,23 @@ Graphic::Loader::Loader(Graphic &g, Resources &r): void Graphic::Loader::texture(const string &n) { - graph.texture = &res.get(n); - graph.slice = Geometry(0, 0, graph.texture->get_width(), graph.texture->get_height()); + obj.texture = &get_collection().get(n); + obj.slice = Geometry(0, 0, obj.texture->get_width(), obj.texture->get_height()); } void Graphic::Loader::slice(unsigned x, unsigned y, unsigned w, unsigned h) { - graph.slice = Geometry(x, y, w, h); + obj.slice = Geometry(x, y, w, h); } void Graphic::Loader::border() { - load_sub(graph.border); + load_sub(obj.border); } void Graphic::Loader::shadow() { - load_sub(graph.shadow); + load_sub(obj.shadow); } } // namespace GLtk diff --git a/source/graphic.h b/source/graphic.h index f457d36..1ae0d5e 100644 --- a/source/graphic.h +++ b/source/graphic.h @@ -3,7 +3,7 @@ #include #include -#include +#include #include "geometry.h" namespace Msp { @@ -17,17 +17,11 @@ Stores a single graphical element. Graphics are used as parts of widgets. class Graphic { public: - class Loader: public DataFile::Loader + class Loader: public DataFile::CollectionObjectLoader { - private: - Graphic &graph; - Resources &res; - public: - typedef Resources Collection; - Loader(Graphic &, Resources &); - Graphic &get_object() const { return graph; } + private: void texture(const std::string &); void slice(unsigned, unsigned, unsigned, unsigned); diff --git a/source/logic.cpp b/source/logic.cpp index db382fe..e9542a6 100644 --- a/source/logic.cpp +++ b/source/logic.cpp @@ -7,7 +7,7 @@ namespace Msp { namespace GLtk { Logic::Loader::Loader(Logic &l, const map &w): - logic(l), + DataFile::ObjectLoader(l), widgets(w) { add("bind", &Loader::bind); @@ -22,7 +22,7 @@ void Logic::Loader::bind(const string &wdg, const string &data) act.type = data.substr(0, colon); if(colon!=string::npos) act.data = data.substr(colon+1); - logic.bindings.push_back(act); + obj.bindings.push_back(act); } } // namespace GLtk diff --git a/source/logic.h b/source/logic.h index cd10578..1d25c6e 100644 --- a/source/logic.h +++ b/source/logic.h @@ -5,7 +5,7 @@ #include #include #include -#include +#include namespace Msp { namespace GLtk { @@ -21,10 +21,9 @@ See also class Connector. class Logic { public: - class Loader: public DataFile::Loader + class Loader: public DataFile::ObjectLoader { private: - Logic &logic; const std::map &widgets; public: diff --git a/source/style.cpp b/source/style.cpp index 44ad414..da772dc 100644 --- a/source/style.cpp +++ b/source/style.cpp @@ -29,13 +29,12 @@ const Part *Style::get_part(const string &name) const Style::Loader::Loader(Style &s, Resources &r): - style(s), - res(r) + DataFile::CollectionObjectLoader(s, &r) { - if(!style.font) + if(!obj.font) { - style.font = &r.get_default_font(); - style.font_size = style.font->get_native_size(); + obj.font = &get_collection().get_default_font(); + obj.font_size = obj.font->get_native_size(); } add("font", &Loader::font); @@ -49,13 +48,13 @@ Style::Loader::Loader(Style &s, Resources &r): void Style::Loader::font(const string &n) { - style.font = &res.get(n); - style.font_size = style.font->get_native_size(); + obj.font = &get_collection().get(n); + obj.font_size = obj.font->get_native_size(); } void Style::Loader::font_color(float r, float g, float b) { - style.font_color = GL::Color(r, g, b); + obj.font_color = GL::Color(r, g, b); } void Style::Loader::part() @@ -66,8 +65,8 @@ void Style::Loader::part() void Style::Loader::part(const string &n) { Part p(n); - load_sub(p, res); - style.parts.push_back(p); + load_sub(p, get_collection()); + obj.parts.push_back(p); } } // namespace GLtk diff --git a/source/style.h b/source/style.h index 620aa21..08e274c 100644 --- a/source/style.h +++ b/source/style.h @@ -3,7 +3,7 @@ #include #include -#include +#include #include "part.h" namespace Msp { @@ -18,18 +18,11 @@ generic properties. class Style { public: - class Loader: public DataFile::Loader + class Loader: public DataFile::CollectionObjectLoader { - private: - Style &style; - Resources &res; - public: - typedef Resources Collection; - Loader(Style &, Resources &); - Style &get_object() const { return style; } - Resources &get_collection() const { return res; } + private: void font(const std::string &); void font_color(float, float, float);