added filtered event dispatch for lo-fi mouse/pen input

This commit is contained in:
Mike Erwin 2010-07-08 01:53:36 +00:00
parent 6365cb3fa8
commit 12d7b10c10
4 changed files with 82 additions and 8 deletions

@ -38,6 +38,10 @@
#include <algorithm>
#include "GHOST_Debug.h"
// for testing lo-fi
#include "GHOST_EventPrinter.h"
#include <iostream>
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;

@ -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.

@ -198,6 +198,9 @@ bool GHOST_System::dispatchEvents()
{
bool handled;
if (m_eventManager) {
if (m_input_fidelity_hint == LO_FI)
handled = m_eventManager->dispatchEvents_lo_fi();
else
handled = m_eventManager->dispatchEvents();
}
else {
@ -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();

@ -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