From 12d7b10c10fd3636a7cb61909f12e4e10e8fe73d Mon Sep 17 00:00:00 2001 From: Mike Erwin Date: Thu, 8 Jul 2010 01:53:36 +0000 Subject: [PATCH] added filtered event dispatch for lo-fi mouse/pen input --- intern/ghost/intern/GHOST_EventManager.cpp | 71 +++++++++++++++++++++- intern/ghost/intern/GHOST_EventManager.h | 8 +++ intern/ghost/intern/GHOST_System.cpp | 10 ++- intern/ghost/intern/GHOST_System.h | 1 + 4 files changed, 82 insertions(+), 8 deletions(-) diff --git a/intern/ghost/intern/GHOST_EventManager.cpp b/intern/ghost/intern/GHOST_EventManager.cpp index 0eeb2245cd0..8f5b5e74339 100644 --- a/intern/ghost/intern/GHOST_EventManager.cpp +++ b/intern/ghost/intern/GHOST_EventManager.cpp @@ -38,6 +38,10 @@ #include #include "GHOST_Debug.h" +// for testing lo-fi +#include "GHOST_EventPrinter.h" +#include +using namespace std; GHOST_EventManager::GHOST_EventManager() { @@ -81,7 +85,7 @@ GHOST_TUns32 GHOST_EventManager::getNumEvents(GHOST_TEventType type) GHOST_IEvent* GHOST_EventManager::peekEvent() { GHOST_IEvent* event = 0; - if (m_events.size() > 0) { + if (!m_events.empty()) { event = m_events.back(); } return event; @@ -104,6 +108,24 @@ GHOST_TSuccess GHOST_EventManager::pushEvent(GHOST_IEvent* event) bool GHOST_EventManager::dispatchEvent(GHOST_IEvent* event) +{ + // [mce] this variant switches the "handled" flag to work as described in the header + // it also stops after the first consumer has handled the event + bool handled = false; + if (event) { + TConsumerVector::iterator iter; + for (iter = m_consumers.begin(); iter != m_consumers.end(); iter++) { + if ((*iter)->processEvent(event)) { + handled = true; + // break; + } + } + } + return handled; +} + +#if 0 // disable to test a variant +bool GHOST_EventManager::dispatchEvent_original(GHOST_IEvent* event) { bool handled; if (event) { @@ -120,7 +142,7 @@ bool GHOST_EventManager::dispatchEvent(GHOST_IEvent* event) } return handled; } - +#endif bool GHOST_EventManager::dispatchEvent() { @@ -152,6 +174,51 @@ bool GHOST_EventManager::dispatchEvents() } +bool GHOST_EventManager::dispatchEvents_lo_fi() +{ + if (m_events.empty()) + return false; + + bool allHandled = true; + GHOST_IEvent* cursorMove = NULL; + GHOST_IEvent* event = NULL; + + GHOST_EventPrinter printer; + + // when Pen gets its own event type, track it alongside mouse moves + // they probably won't both be active, but you never know + + cout << "\n--- lo-fi dispatch ---"; + cout << "\ndiscard:"; + while ((event = popEvent()) != NULL) { + if (event->getType() == GHOST_kEventCursorMove) { + // just a simple (x,y) pair, nothing much to adjust + // discard the older event and keep the latest + if (cursorMove) { + printer.processEvent(cursorMove); + delete cursorMove; + } + cursorMove = event; + } + else // not a cursor move event + if (!dispatchEvent(event)) + allHandled = false; + } + + // finally dispatch the single cursor update + if (cursorMove) { + cout << "\nsend:"; + printer.processEvent(cursorMove); + if (!dispatchEvent(cursorMove)) + allHandled = false; + } + + cout << endl; + + return allHandled; +} + + GHOST_TSuccess GHOST_EventManager::addConsumer(GHOST_IEventConsumer* consumer) { GHOST_TSuccess success; diff --git a/intern/ghost/intern/GHOST_EventManager.h b/intern/ghost/intern/GHOST_EventManager.h index 40ba133e8fd..5071adb1bd4 100644 --- a/intern/ghost/intern/GHOST_EventManager.h +++ b/intern/ghost/intern/GHOST_EventManager.h @@ -108,6 +108,14 @@ public: */ virtual bool dispatchEvents(); + /** + * Dispatches most events on the stack, consolidating cursor moves into a single move. + * The event stack will be empty afterwards. + * @return Indicates whether all events were handled by some consumer. + */ + bool dispatchEvents_lo_fi(); + + /** * Adds a consumer to the list of event consumers. * @param consumer The consumer added to the list. diff --git a/intern/ghost/intern/GHOST_System.cpp b/intern/ghost/intern/GHOST_System.cpp index 3cd3528eeb6..25b55345d46 100644 --- a/intern/ghost/intern/GHOST_System.cpp +++ b/intern/ghost/intern/GHOST_System.cpp @@ -198,7 +198,10 @@ bool GHOST_System::dispatchEvents() { bool handled; if (m_eventManager) { - handled = m_eventManager->dispatchEvents(); + if (m_input_fidelity_hint == LO_FI) + handled = m_eventManager->dispatchEvents_lo_fi(); + else + handled = m_eventManager->dispatchEvents(); } else { handled = false; @@ -283,11 +286,6 @@ GHOST_TSuccess GHOST_System::init() m_eventManager = new GHOST_EventManager (); m_ndofManager = new GHOST_NDOFManager(); -#if 0 - if(m_ndofManager) - printf("ndof manager \n"); -#endif - #ifdef GHOST_DEBUG if (m_eventManager) { m_eventPrinter = new GHOST_EventPrinter(); diff --git a/intern/ghost/intern/GHOST_System.h b/intern/ghost/intern/GHOST_System.h index 6f570b33079..1aeb8597573 100644 --- a/intern/ghost/intern/GHOST_System.h +++ b/intern/ghost/intern/GHOST_System.h @@ -39,6 +39,7 @@ #include "GHOST_Buttons.h" #include "GHOST_ModifierKeys.h" #include "GHOST_EventManager.h" + #ifdef GHOST_DEBUG #include "GHOST_EventPrinter.h" #endif // GHOST_DEBUG