From: Mikko Rasa Date: Tue, 16 Oct 2007 13:57:32 +0000 (+0000) Subject: Derive Resources from DataFile::Collection X-Git-Tag: 0.9~31 X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=d7ae291415a21cc886fe318070b41ac8d3e57a30;p=libs%2Fgltk.git Derive Resources from DataFile::Collection Make fonts embeddable in datafiles Make fonts and textures automatically loadable Use GL::Color instead of a private Color class Use GL::Immediate for rendering Graphics Use a single hyphen-separated string as style name Remove the obsolete instantiation of DataFile::TypeResolver --- diff --git a/source/color.h b/source/color.h deleted file mode 100644 index 1d6b456..0000000 --- a/source/color.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef MSP_GLTK_COLOR_H_ -#define MSP_GLTK_COLOR_H_ - -namespace Msp { -namespace GLtk { - -struct Color -{ - float r, g, b; - - Color(): r(1), g(1), b(1) { } - Color(float r_, float g_, float b_): r(r_), g(g_), b(b_) { } -}; - -} // namespace GLtk -} // namespace Msp - -#endif diff --git a/source/graphic.cpp b/source/graphic.cpp index d05123a..3579610 100644 --- a/source/graphic.cpp +++ b/source/graphic.cpp @@ -1,16 +1,13 @@ +#include #include "graphic.h" #include "resources.h" using namespace std; -#include - namespace Msp { namespace GLtk { -Graphic::Graphic(const Resources &r, const string &n): - res(r), - name(n), +Graphic::Graphic(): texture(0) { } @@ -49,23 +46,25 @@ void Graphic::render(unsigned wd, unsigned ht) const unsigned ymin=border.bottom ? 0 : 1; unsigned ymax=border.top ? 3 : 2; + GL::Immediate imm((GL::TEXCOORD2,GL::VERTEX2)); for(unsigned i=ymin; i(n); graph.slice=Geometry(0, 0, graph.texture->get_width(), graph.texture->get_height()); } diff --git a/source/graphic.h b/source/graphic.h index 912786c..a9722ad 100644 --- a/source/graphic.h +++ b/source/graphic.h @@ -15,18 +15,22 @@ class Graphic public: class Loader: public DataFile::Loader { - public: - Loader(Graphic &); private: Graphic &graph; + Resources &res; + + public: + typedef Resources Collection; + Loader(Graphic &, Resources &); + private: void texture(const std::string &); void slice(unsigned, unsigned, unsigned, unsigned); void border(); void shadow(); }; - Graphic(const Resources &, const std::string &); + Graphic(); const Sides &get_border() const { return border; } const Sides &get_shadow() const { return shadow; } const GL::Texture2D *get_texture() const { return texture; } @@ -34,8 +38,6 @@ public: unsigned get_height() const { return slice.h; } void render(unsigned, unsigned) const; private: - const Resources &res; - std::string name; Sides border; Sides shadow; const GL::Texture2D *texture; diff --git a/source/part.cpp b/source/part.cpp index 4544993..1d96538 100644 --- a/source/part.cpp +++ b/source/part.cpp @@ -7,8 +7,7 @@ using namespace std; namespace Msp { namespace GLtk { -Part::Part(const Resources &r, const string &n): - res(r), +Part::Part(const string &n): name(n), width(1), height(1), @@ -36,8 +35,9 @@ void Part::render(const Geometry &geom, State state) const } -Part::Loader::Loader(Part &p): - part(p) +Part::Loader::Loader(Part &p, Resources &r): + part(p), + res(r) { add("graphic", &Loader::graphic); add("align", &Loader::align); @@ -61,7 +61,7 @@ Part::Loader::~Loader() void Part::Loader::graphic(State s, const string &n) { - part.graphic[s]=&part.res.get_graphic(n); + part.graphic[s]=&res.get(n); } void Part::Loader::align(int x, int y) diff --git a/source/part.h b/source/part.h index 29085c2..58386ca 100644 --- a/source/part.h +++ b/source/part.h @@ -18,18 +18,20 @@ class Part public: class Loader: public DataFile::Loader { - public: - Loader(Part &); - ~Loader(); private: Part ∂ + Resources &res; + public: + Loader(Part &, Resources &); + ~Loader(); + private: void graphic(State, const std::string &); void align(int, int); void fill(bool, bool); }; - Part(const Resources &, const std::string &); + Part(const std::string &); const std::string &get_name() const { return name; } const Graphic *get_graphic(State) const; unsigned get_width() const { return width; } @@ -39,7 +41,6 @@ public: bool get_fill_y() const { return fill_y; } void render(const Geometry &, State) const; private: - const Resources &res; std::string name; const Graphic *graphic[N_STATES_]; unsigned width; diff --git a/source/resources.cpp b/source/resources.cpp index aad671c..650140b 100644 --- a/source/resources.cpp +++ b/source/resources.cpp @@ -1,4 +1,4 @@ -#include +#include #include "resources.h" using namespace std; @@ -7,24 +7,20 @@ namespace Msp { namespace GLtk { Resources::Resources(): + path("."), default_font(0) -{ } - -Resources::~Resources() { - for(FontMap::iterator i=fonts.begin(); i!=fonts.end(); ++i) - delete i->second; - for(TextureMap::iterator i=textures.begin(); i!=textures.end(); ++i) - delete i->second; + add_keyword("font"); + add_keyword("graphic"); + add_keyword