From 5267a21667ab6117cdbb26d054c774b33ab3bb1f Mon Sep 17 00:00:00 2001 From: that Date: Wed, 6 May 2015 23:45:57 +0200 Subject: gui: move retainaspect handling to the resource ctors LoadResources should only decide on the resource type, everything else is handled by the resources themselves. Change-Id: I30f68293960c23560979f650efc4393992cf5824 --- gui/resources.cpp | 20 ++++++++------------ gui/resources.hpp | 4 ++-- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/gui/resources.cpp b/gui/resources.cpp index dcd4ca8b0..41655c376 100644 --- a/gui/resources.cpp +++ b/gui/resources.cpp @@ -179,7 +179,7 @@ FontResource::~FontResource() } } -ImageResource::ImageResource(xml_node<>* node, ZipArchive* pZip, int retain_aspect) +ImageResource::ImageResource(xml_node<>* node, ZipArchive* pZip) : Resource(node, pZip) { std::string file; @@ -198,6 +198,8 @@ ImageResource::ImageResource(xml_node<>* node, ZipArchive* pZip, int retain_aspe return; } + bool retain_aspect = (node->first_attribute("retainaspect") != NULL); + // the value does not matter, if retainaspect is present, we assume that we want to retain it LoadImage(pZip, file, &temp_surface); CheckAndScaleImage(temp_surface, &mSurface, retain_aspect); } @@ -208,7 +210,7 @@ ImageResource::~ImageResource() res_free_surface(mSurface); } -AnimationResource::AnimationResource(xml_node<>* node, ZipArchive* pZip, int retain_aspect) +AnimationResource::AnimationResource(xml_node<>* node, ZipArchive* pZip) : Resource(node, pZip) { std::string file; @@ -224,6 +226,8 @@ AnimationResource::AnimationResource(xml_node<>* node, ZipArchive* pZip, int ret return; } + bool retain_aspect = (node->first_attribute("retainaspect") != NULL); + // the value does not matter, if retainaspect is present, we assume that we want to retain it for (;;) { std::ostringstream fileName; @@ -313,11 +317,7 @@ void ResourceManager::LoadResources(xml_node<>* resList, ZipArchive* pZip) } else if (type == "image") { - int retain = 0; - xml_attribute<>* retain_aspect_ratio = child->first_attribute("retainaspect"); - if (retain_aspect_ratio) - retain = 1; // the value does not matter, if retainaspect is present, we assume that we want to retain it - ImageResource* res = new ImageResource(child, pZip, retain); + ImageResource* res = new ImageResource(child, pZip); if (res->GetResource()) mImages.push_back(res); else { @@ -327,11 +327,7 @@ void ResourceManager::LoadResources(xml_node<>* resList, ZipArchive* pZip) } else if (type == "animation") { - int retain = 0; - xml_attribute<>* retain_aspect_ratio = child->first_attribute("retainaspect"); - if (retain_aspect_ratio) - retain = 1; // the value does not matter, if retainaspect is present, we assume that we want to retain it - AnimationResource* res = new AnimationResource(child, pZip, retain); + AnimationResource* res = new AnimationResource(child, pZip); if (res->GetResourceCount()) mAnimations.push_back(res); else { diff --git a/gui/resources.hpp b/gui/resources.hpp index 0ce968427..0eb32674d 100644 --- a/gui/resources.hpp +++ b/gui/resources.hpp @@ -58,7 +58,7 @@ protected: class ImageResource : public Resource { public: - ImageResource(xml_node<>* node, ZipArchive* pZip, int retain_aspect); + ImageResource(xml_node<>* node, ZipArchive* pZip); virtual ~ImageResource(); public: @@ -73,7 +73,7 @@ protected: class AnimationResource : public Resource { public: - AnimationResource(xml_node<>* node, ZipArchive* pZip, int retain_aspect); + AnimationResource(xml_node<>* node, ZipArchive* pZip); virtual ~AnimationResource(); public: -- cgit v1.2.3