forked from bartvdbraak/blender
added filtered event dispatch for lo-fi mouse/pen input
This commit is contained in:
parent
6365cb3fa8
commit
12d7b10c10
@ -38,6 +38,10 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include "GHOST_Debug.h"
|
#include "GHOST_Debug.h"
|
||||||
|
|
||||||
|
// for testing lo-fi
|
||||||
|
#include "GHOST_EventPrinter.h"
|
||||||
|
#include <iostream>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
GHOST_EventManager::GHOST_EventManager()
|
GHOST_EventManager::GHOST_EventManager()
|
||||||
{
|
{
|
||||||
@ -81,7 +85,7 @@ GHOST_TUns32 GHOST_EventManager::getNumEvents(GHOST_TEventType type)
|
|||||||
GHOST_IEvent* GHOST_EventManager::peekEvent()
|
GHOST_IEvent* GHOST_EventManager::peekEvent()
|
||||||
{
|
{
|
||||||
GHOST_IEvent* event = 0;
|
GHOST_IEvent* event = 0;
|
||||||
if (m_events.size() > 0) {
|
if (!m_events.empty()) {
|
||||||
event = m_events.back();
|
event = m_events.back();
|
||||||
}
|
}
|
||||||
return event;
|
return event;
|
||||||
@ -104,6 +108,24 @@ GHOST_TSuccess GHOST_EventManager::pushEvent(GHOST_IEvent* event)
|
|||||||
|
|
||||||
|
|
||||||
bool GHOST_EventManager::dispatchEvent(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;
|
bool handled;
|
||||||
if (event) {
|
if (event) {
|
||||||
@ -120,7 +142,7 @@ bool GHOST_EventManager::dispatchEvent(GHOST_IEvent* event)
|
|||||||
}
|
}
|
||||||
return handled;
|
return handled;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
bool GHOST_EventManager::dispatchEvent()
|
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 GHOST_EventManager::addConsumer(GHOST_IEventConsumer* consumer)
|
||||||
{
|
{
|
||||||
GHOST_TSuccess success;
|
GHOST_TSuccess success;
|
||||||
|
@ -108,6 +108,14 @@ public:
|
|||||||
*/
|
*/
|
||||||
virtual bool dispatchEvents();
|
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.
|
* Adds a consumer to the list of event consumers.
|
||||||
* @param consumer The consumer added to the list.
|
* @param consumer The consumer added to the list.
|
||||||
|
@ -198,7 +198,10 @@ bool GHOST_System::dispatchEvents()
|
|||||||
{
|
{
|
||||||
bool handled;
|
bool handled;
|
||||||
if (m_eventManager) {
|
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 {
|
else {
|
||||||
handled = false;
|
handled = false;
|
||||||
@ -283,11 +286,6 @@ GHOST_TSuccess GHOST_System::init()
|
|||||||
m_eventManager = new GHOST_EventManager ();
|
m_eventManager = new GHOST_EventManager ();
|
||||||
m_ndofManager = new GHOST_NDOFManager();
|
m_ndofManager = new GHOST_NDOFManager();
|
||||||
|
|
||||||
#if 0
|
|
||||||
if(m_ndofManager)
|
|
||||||
printf("ndof manager \n");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef GHOST_DEBUG
|
#ifdef GHOST_DEBUG
|
||||||
if (m_eventManager) {
|
if (m_eventManager) {
|
||||||
m_eventPrinter = new GHOST_EventPrinter();
|
m_eventPrinter = new GHOST_EventPrinter();
|
||||||
|
@ -39,6 +39,7 @@
|
|||||||
#include "GHOST_Buttons.h"
|
#include "GHOST_Buttons.h"
|
||||||
#include "GHOST_ModifierKeys.h"
|
#include "GHOST_ModifierKeys.h"
|
||||||
#include "GHOST_EventManager.h"
|
#include "GHOST_EventManager.h"
|
||||||
|
|
||||||
#ifdef GHOST_DEBUG
|
#ifdef GHOST_DEBUG
|
||||||
#include "GHOST_EventPrinter.h"
|
#include "GHOST_EventPrinter.h"
|
||||||
#endif // GHOST_DEBUG
|
#endif // GHOST_DEBUG
|
||||||
|
Loading…
Reference in New Issue
Block a user