Maelstrom: Added a flag for fast iteration of UI layouts

https://github.com/libsdl-org/Maelstrom/commit/1c58142b5f7a2a311b6e3e9ee5944828c799a23e

From 1c58142b5f7a2a311b6e3e9ee5944828c799a23e Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Mon, 31 Oct 2011 17:57:08 -0400
Subject: [PATCH] Added a flag for fast iteration of UI layouts

---
 MacDialog.cpp              |  4 ++++
 screenlib/SDL_FrameBuf.cpp |  4 ++++
 screenlib/SDL_FrameBuf.h   |  3 +++
 screenlib/UIManager.cpp    | 10 +++++++++-
 screenlib/UIManager.h      |  2 +-
 5 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/MacDialog.cpp b/MacDialog.cpp
index c165a6ba..411c907f 100644
--- a/MacDialog.cpp
+++ b/MacDialog.cpp
@@ -38,7 +38,11 @@ MacDialog::MacDialog(UIManager *ui, const char *name) :
 	m_colors[COLOR_MEDIUM] = m_screen->MapRGB(0xBB, 0xBB, 0xBB);
 	m_colors[COLOR_LIGHT] = m_screen->MapRGB(0xCC, 0xCC, 0xFF);
 	m_colors[COLOR_WHITE] = m_screen->MapRGB(0xFF, 0xFF, 0xFF);
+#ifdef FAST_ITERATION
+	m_expand = false;
+#else
 	m_expand = true;
+#endif
 	m_step = 0;
 }
 
diff --git a/screenlib/SDL_FrameBuf.cpp b/screenlib/SDL_FrameBuf.cpp
index 33ace8fb..e02ee068 100644
--- a/screenlib/SDL_FrameBuf.cpp
+++ b/screenlib/SDL_FrameBuf.cpp
@@ -129,6 +129,9 @@ FrameBuf:: QueueBlit(int dstx, int dsty, SDL_Texture *src,
 void
 FrameBuf:: Fade(void)
 {
+#ifdef FAST_ITERATION
+	return;
+#else
 	const int max = 32;
 	Uint16 ramp[256];   
 
@@ -148,6 +151,7 @@ FrameBuf:: Fade(void)
 		}
 		SDL_SetWindowGammaRamp(window, ramp, ramp, ramp);
 	}
+#endif
 } 
 
 int
diff --git a/screenlib/SDL_FrameBuf.h b/screenlib/SDL_FrameBuf.h
index 0dcc2bbc..482a252e 100644
--- a/screenlib/SDL_FrameBuf.h
+++ b/screenlib/SDL_FrameBuf.h
@@ -28,6 +28,9 @@
    and it supports loading 8 bits-per-pixel masked images.
 */
 
+// Define this if you're rapidly iterating on UI screens
+#define FAST_ITERATION
+
 #include <stdio.h>
 
 #include "SDL.h"
diff --git a/screenlib/UIManager.cpp b/screenlib/UIManager.cpp
index ebee156d..69c44da2 100644
--- a/screenlib/UIManager.cpp
+++ b/screenlib/UIManager.cpp
@@ -224,13 +224,21 @@ UIManager::HidePanel(UIPanel *panel)
 		if (!panel->IsCursorVisible()) {
 			m_screen->ShowCursor();
 		}
+
+#ifdef FAST_ITERATION
+		// This is useful for iteration, panels are reloaded 
+		// each time they are shown.
+		DeletePanel(panel);
+#endif
 	}
 }
 
 void
 UIManager::DeletePanel(UIPanel *panel)
 {
-	if (panel) {
+	if (panel && m_panels.find(panel)) {
+		// Remove us so we don't recurse in HidePanel() or callbacks
+		m_panels.remove(panel);
 		HidePanel(panel);
 		delete panel;
 	}
diff --git a/screenlib/UIManager.h b/screenlib/UIManager.h
index ae2579a4..eb9efa91 100644
--- a/screenlib/UIManager.h
+++ b/screenlib/UIManager.h
@@ -82,7 +82,7 @@ class UIManager : public UIArea, public UIFontInterface, public UISoundInterface
 	}
 	void DeletePanel(UIPanel *panel);
 	void DeletePanel(const char *name) {
-		DeletePanel(GetPanel(name));
+		DeletePanel(GetPanel(name, false));
 	}
 
 	void Draw(bool fullUpdate = true);