Maelstrom: Added element visibility

From f9a346577cf2785aa9de12b57b432b8665318cf0 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Sat, 22 Oct 2011 17:25:29 -0400
Subject: [PATCH] Added element visibility

---
 screenlib/UIArea.cpp    | 11 +++++++++++
 screenlib/UIArea.h      | 11 +++++++++++
 screenlib/UIManager.cpp |  4 +++-
 screenlib/UIPanel.cpp   |  4 +++-
 4 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/screenlib/UIArea.cpp b/screenlib/UIArea.cpp
index bae27d11..2bc188f3 100644
--- a/screenlib/UIArea.cpp
+++ b/screenlib/UIArea.cpp
@@ -56,6 +56,7 @@ UIArea::UIArea() : ErrorBase()
 	m_rect.y = 0;
 	m_rect.w = 0;
 	m_rect.h = 0;
+	m_shown = true;
 }
 
 bool
@@ -64,6 +65,16 @@ UIArea::Load(rapidxml::xml_node<> *node)
 	rapidxml::xml_node<> *child;
 	rapidxml::xml_attribute<> *attr;
 
+	attr = node->first_attribute("shown", 0, false);
+	if (attr) {
+		const char *value = attr->value();
+		if (*value == '0' || *value == 'f' || *value == 'F') {
+			m_shown = false;
+		} else {
+			m_shown = true;
+		}
+	}
+
 	child = node->first_node("size", 0, false);
 	if (child) {
 		attr = child->first_attribute("w", 0, false);
diff --git a/screenlib/UIArea.h b/screenlib/UIArea.h
index 93a55d8c..da98bbff 100644
--- a/screenlib/UIArea.h
+++ b/screenlib/UIArea.h
@@ -88,8 +88,19 @@ class UIArea : public ErrorBase
 	}
 	void GetAnchorLocation(AnchorLocation spot, int *x, int *y) const;
 
+	void Show() {
+		m_shown = true;
+	}
+	void Hide() {
+		m_shown = false;
+	}
+	bool IsShown() const {
+		return m_shown;
+	}
+
 protected:
 	SDL_Rect m_rect;
+	bool m_shown;
 };
 
 #endif // _UIArea_h
diff --git a/screenlib/UIManager.cpp b/screenlib/UIManager.cpp
index ab6068f6..57a38256 100644
--- a/screenlib/UIManager.cpp
+++ b/screenlib/UIManager.cpp
@@ -39,7 +39,9 @@ void
 UIManager::Draw()
 {
 	for (unsigned i = 0; i < m_panels.length(); ++i) {
-		m_panels[i]->Draw();
+		if (m_panels[i]->IsShown()) {
+			m_panels[i]->Draw();
+		}
 	}
 }
 
diff --git a/screenlib/UIPanel.cpp b/screenlib/UIPanel.cpp
index 395a6a6b..930ab3d1 100644
--- a/screenlib/UIPanel.cpp
+++ b/screenlib/UIPanel.cpp
@@ -158,7 +158,9 @@ void
 UIPanel::Draw()
 {
 	for (unsigned i = 0; i < m_elements.length(); ++i) {
-		m_elements[i]->Draw(m_screen);
+		if (m_elements[i]->IsShown()) {
+			m_elements[i]->Draw(m_screen);
+		}
 	}
 }