Maelstrom: Stretched textures shouldn't affect the size of their elements.

https://github.com/libsdl-org/Maelstrom/commit/2fb773dd6a5edae3048935053521b37b21a4c2eb

From 2fb773dd6a5edae3048935053521b37b21a4c2eb Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Wed, 24 Apr 2013 22:10:27 -0700
Subject: [PATCH] Stretched textures shouldn't affect the size of their
 elements. If you specify only width or only height for an element, it will
 still autosize to the parent in the other dimension.

---
 screenlib/UIArea.cpp       | 30 ++++++++++++++++++++++--------
 screenlib/UIArea.h         |  3 ++-
 screenlib/UIDrawEngine.cpp |  8 +++++---
 screenlib/UITexture.h      |  1 +
 4 files changed, 30 insertions(+), 12 deletions(-)

diff --git a/screenlib/UIArea.cpp b/screenlib/UIArea.cpp
index a72609fa..f44c0deb 100644
--- a/screenlib/UIArea.cpp
+++ b/screenlib/UIArea.cpp
@@ -25,7 +25,8 @@
 
 UIArea::UIArea(UIArea *anchor, int w, int h) : ErrorBase()
 {
-	m_autosizeParent = true;
+	m_autosizeParentWidth = true;
+	m_autosizeParentHeight = true;
 	m_autosizeWidth = true;
 	m_autosizeHeight = true;
 	m_rect.x = 0;
@@ -131,7 +132,8 @@ UIArea::SetSize(int w, int h, bool autosize, bool parent)
 		m_autosizeHeight = false;
 	}
 	if (!parent) {
-		m_autosizeParent = false;
+		m_autosizeParentWidth = false;
+		m_autosizeParentHeight = false;
 	}
 }
 
@@ -147,7 +149,7 @@ UIArea::SetWidth(int w, bool autosize, bool parent)
 		m_autosizeWidth = false;
 	}
 	if (!parent) {
-		m_autosizeParent = false;
+		m_autosizeParentWidth = false;
 	}
 }
 
@@ -163,21 +165,33 @@ UIArea::SetHeight(int h, bool autosize, bool parent)
 		m_autosizeHeight = false;
 	}
 	if (!parent) {
-		m_autosizeParent = false;
+		m_autosizeParentHeight = false;
 	}
 }
 
 void
 UIArea::AutoSize(int w, int h, bool parent)
 {
-	if (parent && !m_autosizeParent) {
-		return;
-	}
 	if (m_autosizeWidth && m_autosizeHeight) {
-		SetSize(w, h, true, parent);
+		if (parent && !m_autosizeParentWidth && !m_autosizeParentHeight) {
+			return;
+		}
+		if (parent && !m_autosizeParentWidth) {
+			SetHeight(h, true, parent);
+		} else if (parent && !m_autosizeParentHeight) {
+			SetWidth(w, true, parent);
+		} else {
+			SetSize(w, h, true, parent);
+		}
 	} else if (m_autosizeWidth) {
+		if (parent && !m_autosizeParentWidth) {
+			return;
+		}
 		SetWidth(w, true, parent);
 	} else if (m_autosizeHeight)  {
+		if (parent && !m_autosizeParentHeight) {
+			return;
+		}
 		SetHeight(h, true, parent);
 	}
 }
diff --git a/screenlib/UIArea.h b/screenlib/UIArea.h
index f6a5b816..a1c2152d 100644
--- a/screenlib/UIArea.h
+++ b/screenlib/UIArea.h
@@ -141,7 +141,8 @@ class UIArea : public ErrorBase
 
 private:
 	/* This is private so updates can trigger OnRectChanged() */
-	bool m_autosizeParent;
+	bool m_autosizeParentWidth;
+	bool m_autosizeParentHeight;
 	bool m_autosizeWidth;
 	bool m_autosizeHeight;
 	SDL_Rect m_rect;
diff --git a/screenlib/UIDrawEngine.cpp b/screenlib/UIDrawEngine.cpp
index fe567d77..d9965574 100644
--- a/screenlib/UIDrawEngine.cpp
+++ b/screenlib/UIDrawEngine.cpp
@@ -211,20 +211,22 @@ UIDrawEngine::OnImageChanged()
 	if (image) {
 		int w, h;
 		bool parent = false;
-		if (m_element->IsAutoSizingWidth()) {
+		if (!image->IsStretching() && m_element->IsAutoSizingWidth()) {
 			w = image->Width();
 		} else {
 			w = m_element->Width();
 			parent = true;
 		}
-		if (m_element->IsAutoSizingHeight()) {
+		if (!image->IsStretching() && m_element->IsAutoSizingHeight()) {
 			h = image->Height();
 		} else {
 			h = m_element->Height();
 			parent = true;
 		}
 		m_element->GetImageArea()->AutoSize(w, h, parent);
-		m_element->AutoSize(w, h);
+		if (!image->IsStretching()) {
+			m_element->AutoSize(w, h);
+		}
 	}
 }
 
diff --git a/screenlib/UITexture.h b/screenlib/UITexture.h
index 0a38378e..fb358981 100644
--- a/screenlib/UITexture.h
+++ b/screenlib/UITexture.h
@@ -58,6 +58,7 @@ class UITexture
 		m_angle = angle;
 	}
 	void SetStretchGrid(int cornerSize);
+	bool IsStretching() const { return m_stretch; }
 
 	void Draw(FrameBuf *screen, int x, int y, int w, int h);