From f6ed8fc1f51e368bb76905d9f1d2d3735e70a644 Mon Sep 17 00:00:00 2001 From: that Date: Sat, 14 Feb 2015 20:23:16 +0100 Subject: gui: make resources type safe - add string, int, color and resource loading helpers - use typed resource classes, and some cleanup in loading code - remove abstract GetResource() to enforce type safe access - add height and width query methods to resources and use them - minor cleanup - simplify LoadPlacement Change-Id: I9b81785109a80b3806ad6b50cba4d893b87b0db1 --- gui/resources.hpp | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'gui/resources.hpp') diff --git a/gui/resources.hpp b/gui/resources.hpp index cc5e7b6ff..69d24279f 100644 --- a/gui/resources.hpp +++ b/gui/resources.hpp @@ -17,8 +17,8 @@ public: virtual ~Resource() {} public: - virtual void* GetResource(void) = 0; - std::string GetName(void) { return mName; } + std::string GetName() { return mName; } + virtual bool loadedOK() = 0; private: std::string mName; @@ -44,7 +44,10 @@ public: virtual ~FontResource(); public: - virtual void* GetResource(void) { return mFont; } + void* GetResource() { return this ? mFont : NULL; } + int GetHeight() { return gr_getMaxFontHeight(this ? mFont : NULL); } + + virtual bool loadedOK() { return mFont != NULL; } protected: void* mFont; @@ -58,7 +61,11 @@ public: virtual ~ImageResource(); public: - virtual void* GetResource(void) { return mSurface; } + gr_surface GetResource() { return this ? mSurface : NULL; } + 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; @@ -71,9 +78,12 @@ public: virtual ~AnimationResource(); public: - virtual void* GetResource(void) { return mSurfaces.empty() ? NULL : mSurfaces.at(0); } - virtual void* GetResource(int entry) { return mSurfaces.empty() ? NULL : mSurfaces.at(entry); } - virtual int GetResourceCount(void) { return mSurfaces.size(); } + gr_surface GetResource() { return (!this || mSurfaces.empty()) ? NULL : mSurfaces.at(0); } + gr_surface GetResource(int entry) { return (!this || mSurfaces.empty()) ? NULL : mSurfaces.at(entry); } + 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; -- cgit v1.2.3