From 74ac6060ccb68e6ae80dbcb44d11f07a17e26034 Mon Sep 17 00:00:00 2001 From: that Date: Wed, 4 Mar 2015 22:39:34 +0100 Subject: gui: type safe resources part 2 - separate collections for fonts, images, animations - no more ugly casts - fix crash if main ui.xml did not define any resources but include did - don't stop loading resources if one "type" attribute is missing Change-Id: I70c1c9ca66ca65d9fba1ba3eded34f3d8a07488e --- gui/resources.hpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'gui/resources.hpp') diff --git a/gui/resources.hpp b/gui/resources.hpp index 69d24279f..83fc7a537 100644 --- a/gui/resources.hpp +++ b/gui/resources.hpp @@ -18,7 +18,6 @@ public: public: std::string GetName() { return mName; } - virtual bool loadedOK() = 0; private: std::string mName; @@ -47,8 +46,6 @@ public: void* GetResource() { return this ? mFont : NULL; } int GetHeight() { return gr_getMaxFontHeight(this ? mFont : NULL); } - virtual bool loadedOK() { return mFont != NULL; } - protected: void* mFont; Type m_type; @@ -65,8 +62,6 @@ public: int GetWidth() { return gr_get_width(this ? mSurface : NULL); } int GetHeight() { return gr_get_height(this ? mSurface : NULL); } - virtual bool loadedOK() { return mSurface != NULL; } - protected: gr_surface mSurface; }; @@ -83,7 +78,6 @@ public: int GetWidth() { return gr_get_width(this ? GetResource() : NULL); } int GetHeight() { return gr_get_height(this ? GetResource() : NULL); } int GetResourceCount() { return mSurfaces.size(); } - virtual bool loadedOK() { return !mSurfaces.empty(); } protected: std::vector mSurfaces; @@ -92,15 +86,19 @@ protected: class ResourceManager { public: - ResourceManager(xml_node<>* resList, ZipArchive* pZip); + ResourceManager(); virtual ~ResourceManager(); void LoadResources(xml_node<>* resList, ZipArchive* pZip); public: - Resource* FindResource(std::string name); + FontResource* FindFont(const std::string& name) const; + ImageResource* FindImage(const std::string& name) const; + AnimationResource* FindAnimation(const std::string& name) const; private: - std::vector mResources; + std::vector mFonts; + std::vector mImages; + std::vector mAnimations; }; #endif // _RESOURCE_HEADER -- cgit v1.2.3