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
diff --git a/gui/pages.cpp b/gui/pages.cpp
index 18ddf9c..cd5e340 100644
--- a/gui/pages.cpp
+++ b/gui/pages.cpp
@@ -208,8 +208,7 @@
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 @@
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 @@
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 @@
PageSet::PageSet(char* xmlFile)
{
- mResources = NULL;
+ mResources = new ResourceManager;
mCurrentPage = NULL;
mOverlayPage = NULL;
@@ -742,7 +739,7 @@
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 @@
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 @@
}
}
-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)