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/pages.cpp | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) (limited to 'gui/pages.cpp') diff --git a/gui/pages.cpp b/gui/pages.cpp index 18ddf9c33..cd5e340d6 100644 --- a/gui/pages.cpp +++ b/gui/pages.cpp @@ -208,8 +208,7 @@ FontResource* LoadAttrFont(xml_node<>* element, const char* attrname) if (name.empty()) return NULL; else - return (FontResource*) PageManager::FindResource(name); - // TODO: make resource lookup type-safe + return PageManager::GetResources()->FindFont(name); } ImageResource* LoadAttrImage(xml_node<>* element, const char* attrname) @@ -218,8 +217,7 @@ ImageResource* LoadAttrImage(xml_node<>* element, const char* attrname) if (name.empty()) return NULL; else - return (ImageResource*) PageManager::FindResource(name); - // TODO: make resource lookup type-safe + return PageManager::GetResources()->FindImage(name); } AnimationResource* LoadAttrAnimation(xml_node<>* element, const char* attrname) @@ -228,8 +226,7 @@ AnimationResource* LoadAttrAnimation(xml_node<>* element, const char* attrname) if (name.empty()) return NULL; else - return (AnimationResource*) PageManager::FindResource(name); - // TODO: make resource lookup type-safe + return PageManager::GetResources()->FindAnimation(name); } bool LoadPlacement(xml_node<>* node, int* x, int* y, int* w /* = NULL */, int* h /* = NULL */, RenderObject::Placement* placement /* = NULL */) @@ -649,7 +646,7 @@ int Page::NotifyVarChange(std::string varName, std::string value) PageSet::PageSet(char* xmlFile) { - mResources = NULL; + mResources = new ResourceManager; mCurrentPage = NULL; mOverlayPage = NULL; @@ -742,7 +739,7 @@ int PageSet::Load(ZipArchive* package) LOGINFO("Loading resources...\n"); child = parent->first_node("resources"); if (child) - mResources = new ResourceManager(child, package); + mResources->LoadResources(child, package); LOGINFO("Loading variables...\n"); child = parent->first_node("variables"); @@ -937,9 +934,9 @@ int PageSet::SetOverlay(Page* page) return 0; } -Resource* PageSet::FindResource(std::string name) +const ResourceManager* PageSet::GetResources() { - return mResources ? mResources->FindResource(name) : NULL; + return mResources; } Page* PageSet::FindPage(std::string name) @@ -1307,17 +1304,9 @@ int PageManager::ChangeOverlay(std::string name) } } -Resource* PageManager::FindResource(std::string name) +const ResourceManager* PageManager::GetResources() { - return (mCurrentSet ? mCurrentSet->FindResource(name) : NULL); -} - -Resource* PageManager::FindResource(std::string package, std::string name) -{ - PageSet* tmp; - - tmp = FindPackage(name); - return (tmp ? tmp->FindResource(name) : NULL); + return (mCurrentSet ? mCurrentSet->GetResources() : NULL); } int PageManager::SwitchToConsole(void) -- cgit v1.2.3