https://github.com/libsdl-org/Maelstrom/commit/6a71cea3c51967892fa1d9fc757b25f5061b5560
From 6a71cea3c51967892fa1d9fc757b25f5061b5560 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Wed, 2 Nov 2011 00:34:59 -0400
Subject: [PATCH] Fixed bug anchoring text at a specific location in the main
menu buttons
---
screenlib/UIArea.cpp | 13 +++++++++++++
screenlib/UIArea.h | 4 +---
screenlib/UIElement.cpp | 10 ++++++++--
3 files changed, 22 insertions(+), 5 deletions(-)
diff --git a/screenlib/UIArea.cpp b/screenlib/UIArea.cpp
index dbfa40ea..d9e71cd7 100644
--- a/screenlib/UIArea.cpp
+++ b/screenlib/UIArea.cpp
@@ -89,6 +89,19 @@ UIArea::Load(rapidxml::xml_node<> *node)
return true;
}
+UIArea *
+UIArea::GetAnchorElement(const char *name)
+{
+ if (m_anchor.element) {
+ if (name) {
+ return m_anchor.element->GetAnchorElement(name);
+ } else {
+ return m_anchor.element;
+ }
+ }
+ return NULL;
+}
+
void
UIArea::SetPosition(int x, int y) {
/* Setting the position breaks the anchoring */
diff --git a/screenlib/UIArea.h b/screenlib/UIArea.h
index 1bfe59ee..04bc3ffa 100644
--- a/screenlib/UIArea.h
+++ b/screenlib/UIArea.h
@@ -58,9 +58,7 @@ class UIArea : public ErrorBase
bool Load(rapidxml::xml_node<> *node);
// This function returns anchor areas by name
- virtual UIArea *GetAnchorElement(const char *name) {
- return NULL;
- }
+ virtual UIArea *GetAnchorElement(const char *name);
void SetPosition(int x, int y);
void SetSize(int w, int h, bool autosize = false);
diff --git a/screenlib/UIElement.cpp b/screenlib/UIElement.cpp
index 1f76ef09..ccd0d2a0 100644
--- a/screenlib/UIElement.cpp
+++ b/screenlib/UIElement.cpp
@@ -134,7 +134,10 @@ UIElement::Load(rapidxml::xml_node<> *node, const UITemplates *templates)
child = node->first_node("TextArea", 0, false);
if (child) {
- m_textArea.Load(child);
+ if (!m_textArea.Load(child)) {
+ fprintf(stderr, "Warning: Couldn't load TextArea\n");
+ return false;
+ }
}
child = node->first_node("TextShadow", 0, false);
@@ -168,7 +171,10 @@ UIElement::Load(rapidxml::xml_node<> *node, const UITemplates *templates)
child = node->first_node("ImageArea", 0, false);
if (child) {
- m_imageArea.Load(child);
+ if (!m_textArea.Load(child)) {
+ fprintf(stderr, "Warning: Couldn't load ImageArea\n");
+ return false;
+ }
}
if (m_drawEngine) {