Revision: 30098
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=30098
Author:   merwin
Date:     2010-07-08 03:53:36 +0200 (Thu, 08 Jul 2010)

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

Modified Paths:
--------------
    branches/soc-2010-merwin/intern/ghost/intern/GHOST_EventManager.cpp
    branches/soc-2010-merwin/intern/ghost/intern/GHOST_EventManager.h
    branches/soc-2010-merwin/intern/ghost/intern/GHOST_System.cpp
    branches/soc-2010-merwin/intern/ghost/intern/GHOST_System.h

Modified: branches/soc-2010-merwin/intern/ghost/intern/GHOST_EventManager.cpp
===================================================================
--- branches/soc-2010-merwin/intern/ghost/intern/GHOST_EventManager.cpp 
2010-07-08 00:01:16 UTC (rev 30097)
+++ branches/soc-2010-merwin/intern/ghost/intern/GHOST_EventManager.cpp 
2010-07-08 01:53:36 UTC (rev 30098)
@@ -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_IEvent* GHOST_EventManager::peekEvent()
 {
        GHOST_IEvent* event = 0;
-       if (m_events.size() > 0) {
+       if (!m_events.empty()) {
                event = m_events.back();
        }
        return event;
@@ -105,6 +109,24 @@
 
 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) {
                handled = true;
@@ -120,8 +142,8 @@
        }
        return handled;
 }
+#endif
 
-
 bool GHOST_EventManager::dispatchEvent()
 {
        GHOST_IEvent* event = popEvent(); 
@@ -152,6 +174,51 @@
 }
 
 
+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;

Modified: branches/soc-2010-merwin/intern/ghost/intern/GHOST_EventManager.h
===================================================================
--- branches/soc-2010-merwin/intern/ghost/intern/GHOST_EventManager.h   
2010-07-08 00:01:16 UTC (rev 30097)
+++ branches/soc-2010-merwin/intern/ghost/intern/GHOST_EventManager.h   
2010-07-08 01:53:36 UTC (rev 30098)
@@ -109,6 +109,14 @@
        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.
         * @return Indication as to whether addition has succeeded.

Modified: branches/soc-2010-merwin/intern/ghost/intern/GHOST_System.cpp
===================================================================
--- branches/soc-2010-merwin/intern/ghost/intern/GHOST_System.cpp       
2010-07-08 00:01:16 UTC (rev 30097)
+++ branches/soc-2010-merwin/intern/ghost/intern/GHOST_System.cpp       
2010-07-08 01:53:36 UTC (rev 30098)
@@ -198,7 +198,10 @@
 {
        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 @@
        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();

Modified: branches/soc-2010-merwin/intern/ghost/intern/GHOST_System.h
===================================================================
--- branches/soc-2010-merwin/intern/ghost/intern/GHOST_System.h 2010-07-08 
00:01:16 UTC (rev 30097)
+++ branches/soc-2010-merwin/intern/ghost/intern/GHOST_System.h 2010-07-08 
01:53:36 UTC (rev 30098)
@@ -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


_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to