https://github.com/libsdl-org/Maelstrom/commit/944427a6bd204925392f2e9d37384f67efd326e6
From 944427a6bd204925392f2e9d37384f67efd326e6 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Sun, 16 Dec 2012 21:11:22 -0800
Subject: [PATCH] Take draw level into account when dispatching events.
---
screenlib/UIBaseElement.cpp | 19 +++++++++++++++----
screenlib/UIBaseElement.h | 1 +
screenlib/UIManager.cpp | 6 ++++--
3 files changed, 20 insertions(+), 6 deletions(-)
diff --git a/screenlib/UIBaseElement.cpp b/screenlib/UIBaseElement.cpp
index 167bed93..2bf3f3cb 100644
--- a/screenlib/UIBaseElement.cpp
+++ b/screenlib/UIBaseElement.cpp
@@ -200,19 +200,30 @@ UIBaseElement::Draw(DRAWLEVEL drawLevel)
}
bool
-UIBaseElement::HandleEvent(const SDL_Event &event)
+UIBaseElement::DispatchEvent(const SDL_Event &event, DRAWLEVEL drawLevel)
{
for (int i = m_elements.length(); i--; ) {
- if (!m_elements[i]->IsShown()) {
+ UIBaseElement *element = m_elements[i];
+
+ if (!element->IsShown()) {
continue;
}
- if (m_elements[i]->IsDisabled()) {
+ if (element->IsDisabled()) {
continue;
}
- if (m_elements[i]->HandleEvent(event)) {
+ if (element->DispatchEvent(event, drawLevel)) {
return true;
}
}
+ if (drawLevel == GetDrawLevel()) {
+ return HandleEvent(event);
+ }
+ return false;
+}
+
+bool
+UIBaseElement::HandleEvent(const SDL_Event &event)
+{
return false;
}
diff --git a/screenlib/UIBaseElement.h b/screenlib/UIBaseElement.h
index 685f09b4..9c61c3ee 100644
--- a/screenlib/UIBaseElement.h
+++ b/screenlib/UIBaseElement.h
@@ -206,6 +206,7 @@ class UIBaseElement : public UIArea
DRAWLEVEL GetDrawLevel() const { return m_drawLevel; }
virtual void Draw(DRAWLEVEL drawLevel);
+ bool DispatchEvent(const SDL_Event &event, DRAWLEVEL drawLevel);
virtual bool HandleEvent(const SDL_Event &event);
virtual void Action(UIBaseElement *sender, const char *action);
diff --git a/screenlib/UIManager.cpp b/screenlib/UIManager.cpp
index 4c7f72a2..3b1319cf 100644
--- a/screenlib/UIManager.cpp
+++ b/screenlib/UIManager.cpp
@@ -416,8 +416,10 @@ UIManager::HandleEvent(const SDL_Event &event)
for (unsigned i = m_visible.length(); i--; ) {
UIPanel *panel = m_visible[i];
- if (panel->HandleEvent(event)) {
- return true;
+ for (int drawLevel = NUM_DRAWLEVELS; drawLevel--; ) {
+ if (panel->DispatchEvent(event, (DRAWLEVEL)drawLevel)) {
+ return true;
+ }
}
if (panel->IsFullscreen()) {
break;