Maelstrom: If an element overrides a template size, make sure the image area changes as well.

https://github.com/libsdl-org/Maelstrom/commit/a2fa49b0959d64ff3276d304d49bcf5c469903f8

From a2fa49b0959d64ff3276d304d49bcf5c469903f8 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Sun, 11 Nov 2012 02:26:07 -0800
Subject: [PATCH] If an element overrides a template size, make sure the image
 area changes as well.

---
 screenlib/UIArea.cpp       | 9 +++++----
 screenlib/UIDrawEngine.cpp | 5 ++++-
 screenlib/UIElement.h      | 6 ++++++
 3 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/screenlib/UIArea.cpp b/screenlib/UIArea.cpp
index 99593f48..d7fe3f62 100644
--- a/screenlib/UIArea.cpp
+++ b/screenlib/UIArea.cpp
@@ -57,11 +57,12 @@ UIArea::Load(rapidxml::xml_node<> *node)
 
 	child = node->first_node("size", 0, false);
 	if (child) {
-		if (LoadNumber(child, "w", m_rect.w)) {
-			m_autosizeWidth = false;
+		int w, h;
+		if (LoadNumber(child, "w", w)) {
+			SetWidth(w);
 		}
-		if (LoadNumber(child, "h", m_rect.h)) {
-			m_autosizeHeight = false;
+		if (LoadNumber(child, "h", h)) {
+			SetHeight(h);
 		}
 	}
 
diff --git a/screenlib/UIDrawEngine.cpp b/screenlib/UIDrawEngine.cpp
index 4b9432b2..ebd5c3dc 100644
--- a/screenlib/UIDrawEngine.cpp
+++ b/screenlib/UIDrawEngine.cpp
@@ -205,17 +205,20 @@ UIDrawEngine::OnImageChanged()
 
 	if (image) {
 		int w, h;
+		bool parent = false;
 		if (m_element->IsAutoSizingWidth()) {
 			w = image->Width();
 		} else {
 			w = m_element->Width();
+			parent = true;
 		}
 		if (m_element->IsAutoSizingHeight()) {
 			h = image->Height();
 		} else {
 			h = m_element->Height();
+			parent = true;
 		}
-		m_element->GetImageArea()->AutoSize(w, h);
+		m_element->GetImageArea()->AutoSize(w, h, parent);
 		m_element->AutoSize(w, h);
 	}
 }
diff --git a/screenlib/UIElement.h b/screenlib/UIElement.h
index ab0125d4..1092a77e 100644
--- a/screenlib/UIElement.h
+++ b/screenlib/UIElement.h
@@ -92,6 +92,12 @@ DECLARE_TYPESAFE_CLASS(UIBaseElement)
 	override void LoadData(Prefs *prefs);
 	override void SaveData(Prefs *prefs);
 
+	override void OnRectChanged() {
+		UIBaseElement::OnRectChanged();
+
+		m_imageArea.AutoSize(Width(), Height(), true);
+	}
+
 	// Set the draw engine for this element
 	// This should be called before Load() so the draw engine can load too.
 	// Once set, the element owns the draw engine and will free it.