From 8fcbfafa633ea772f1571a5b54b16bf8c218c753 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Sun, 23 Oct 2011 03:32:37 -0400
Subject: [PATCH] Added a load path so we can load different layouts on
different platforms
---
splash.xml => UI/splash.xml | 0
init.cpp | 1 +
screenlib/UIManager.cpp | 12 +++++++++++-
screenlib/UIManager.h | 2 ++
4 files changed, 14 insertions(+), 1 deletion(-)
rename splash.xml => UI/splash.xml (100%)
diff --git a/splash.xml b/UI/splash.xml
similarity index 100%
rename from splash.xml
rename to UI/splash.xml
diff --git a/init.cpp b/init.cpp
index 781006fc..89dfeb9a 100644
--- a/init.cpp
+++ b/init.cpp
@@ -802,6 +802,7 @@ int DoInitializations(Uint32 window_flags, Uint32 render_flags)
/* Create the UI manager */
ui = new UIManager(screen, CreateMaelstromUIElement);
+ ui->SetLoadPath("UI");
/* Load the Sound Server and initialize sound */
sound = new Sound("Maelstrom Sounds", gSoundLevel);
diff --git a/screenlib/UIManager.cpp b/screenlib/UIManager.cpp
index b5f0238b..8387d9b8 100644
--- a/screenlib/UIManager.cpp
+++ b/screenlib/UIManager.cpp
@@ -28,6 +28,8 @@
UIManager::UIManager(FrameBuf *screen, UIElementFactory factory) : UIArea(screen)
{
m_elementFactory = factory;
+ m_loadPath = new char[2];
+ strcpy(m_loadPath, ".");
}
UIManager::~UIManager()
@@ -38,13 +40,21 @@ UIManager::~UIManager()
}
}
+void
+UIManager::SetLoadPath(const char *path)
+{
+ delete[] m_loadPath;
+ m_loadPath = new char[strlen(path)+1];
+ strcpy(m_loadPath, path);
+}
+
UIPanel *
UIManager::LoadPanel(const char *name)
{
UIPanel *panel;
char file[1024];
- sprintf(file, "%s.xml", name);
+ sprintf(file, "%s/%s.xml", m_loadPath, name);
panel = new UIPanel(this, name);
if (!panel->Load(file)) {
SetError("%s", panel->Error());
diff --git a/screenlib/UIManager.h b/screenlib/UIManager.h
index 28500940..1f1b8d63 100644
--- a/screenlib/UIManager.h
+++ b/screenlib/UIManager.h
@@ -46,6 +46,7 @@ class UIManager : public UIArea
return m_elementFactory;
}
+ void SetLoadPath(const char *path);
UIPanel *LoadPanel(const char *name);
UIPanel *GetPanel(const char *name);
@@ -78,6 +79,7 @@ class UIManager : public UIArea
protected:
UIElementFactory m_elementFactory;
+ char *m_loadPath;
array<UIPanel *> m_panels;
array<UIPanel *> m_visible;
};