From 5e8285302c1d04b631682a82d56c5afc46d20ad5 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sat, 8 Dec 2012 12:24:27 +0200 Subject: [PATCH] Update loaders to use ObjectLoader as base class --- source/graphic.cpp | 13 ++++++------- source/graphic.h | 12 +++--------- source/logic.cpp | 4 ++-- source/logic.h | 5 ++--- source/style.cpp | 19 +++++++++---------- source/style.h | 13 +++---------- 6 files changed, 25 insertions(+), 41 deletions(-) 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); -- 2.43.0