Maelstrom: Added support for press/release sounds

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

From ecba5aa262362eb4198c6a62d2eef314c0fc1d1f Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Sun, 27 Jan 2013 08:36:21 -0800
Subject: [PATCH] Added support for press/release sounds

---
 screenlib/UIArea.cpp          |  6 +++++-
 screenlib/UIElementButton.cpp | 21 +++++++++++++++++++++
 screenlib/UIElementButton.h   |  2 ++
 3 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/screenlib/UIArea.cpp b/screenlib/UIArea.cpp
index d7fe3f62..a72609fa 100644
--- a/screenlib/UIArea.cpp
+++ b/screenlib/UIArea.cpp
@@ -249,7 +249,11 @@ UIArea::LoadString(rapidxml::xml_node<> *node, const char *name, char *&value)
 		if (value) {
 			SDL_free(value);
 		}
-		value = SDL_strdup(attr->value());
+		if (*attr->value()) {
+			value = SDL_strdup(attr->value());
+		} else {
+			value = NULL;
+		}
 		return true;
 	}
 	return false;
diff --git a/screenlib/UIElementButton.cpp b/screenlib/UIElementButton.cpp
index 8022db1b..7d4e7b68 100644
--- a/screenlib/UIElementButton.cpp
+++ b/screenlib/UIElementButton.cpp
@@ -34,6 +34,8 @@ UIElementButton::UIElementButton(UIBaseElement *parent, const char *name, UIDraw
 
 	m_hotkey = SDLK_UNKNOWN;
 	m_hotkeyMod = KMOD_NONE;
+	m_pressSound = NULL;
+	m_releaseSound = NULL;
 	m_clickSound = NULL;
 	m_clickPanel = NULL;
 	m_buttonState = NUM_BUTTON_STATES;
@@ -42,6 +44,12 @@ UIElementButton::UIElementButton(UIBaseElement *parent, const char *name, UIDraw
 
 UIElementButton::~UIElementButton()
 {
+	if (m_pressSound) {
+		SDL_free(m_pressSound);
+	}
+	if (m_releaseSound) {
+		SDL_free(m_releaseSound);
+	}
 	if (m_clickSound) {
 		SDL_free(m_clickSound);
 	}
@@ -126,6 +134,8 @@ UIElementButton::Load(rapidxml::xml_node<> *node, const UITemplates *templates)
 	}
 	SetButtonState(BUTTON_STATE_NORMAL);
 
+	LoadString(node, "pressSound", m_pressSound);
+	LoadString(node, "releaseSound", m_releaseSound);
 	LoadString(node, "clickSound", m_clickSound);
 	LoadString(node, "clickPanel", m_clickPanel);
 
@@ -231,6 +241,17 @@ UIElementButton::SetButtonState(BUTTON_STATE state)
 		SetImage(m_stateImages[state]);
 	}
 
+	if (m_buttonState == BUTTON_STATE_NORMAL && state == BUTTON_STATE_PRESSED) {
+		if (m_pressSound) {
+			GetUI()->PlaySound(m_pressSound);
+		}
+	}
+	if (m_buttonState == BUTTON_STATE_PRESSED && state == BUTTON_STATE_NORMAL) {
+		if (m_releaseSound) {
+			GetUI()->PlaySound(m_releaseSound);
+		}
+	}
+
 	m_buttonState = state;
 }
 
diff --git a/screenlib/UIElementButton.h b/screenlib/UIElementButton.h
index 6408dee2..678432e8 100644
--- a/screenlib/UIElementButton.h
+++ b/screenlib/UIElementButton.h
@@ -61,6 +61,8 @@ DECLARE_TYPESAFE_CLASS(UIElement)
 protected:
 	SDL_Keycode m_hotkey;
 	int m_hotkeyMod;
+	char *m_pressSound;
+	char *m_releaseSound;
 	char *m_clickSound;
 	char *m_clickPanel;
 	BUTTON_STATE m_buttonState;