[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [31303] branches/soc-2010-merwin/intern/ ghost/intern: still working on tablet for Windows...

Mike Erwin significant.bit at gmail.com
Fri Aug 13 02:34:57 CEST 2010


Revision: 31303
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=31303
Author:   merwin
Date:     2010-08-13 02:34:57 +0200 (Fri, 13 Aug 2010)

Log Message:
-----------
still working on tablet for Windows...

Modified Paths:
--------------
    branches/soc-2010-merwin/intern/ghost/intern/GHOST_Buttons.cpp
    branches/soc-2010-merwin/intern/ghost/intern/GHOST_Buttons.h
    branches/soc-2010-merwin/intern/ghost/intern/GHOST_SystemWin32.cpp
    branches/soc-2010-merwin/intern/ghost/intern/GHOST_TabletManagerWin32.cpp
    branches/soc-2010-merwin/intern/ghost/intern/GHOST_TabletManagerWin32.h

Modified: branches/soc-2010-merwin/intern/ghost/intern/GHOST_Buttons.cpp
===================================================================
--- branches/soc-2010-merwin/intern/ghost/intern/GHOST_Buttons.cpp	2010-08-12 20:42:06 UTC (rev 31302)
+++ branches/soc-2010-merwin/intern/ghost/intern/GHOST_Buttons.cpp	2010-08-13 00:34:57 UTC (rev 31303)
@@ -71,4 +71,9 @@
     m_ButtonRight = false;
 }
 
+bool GHOST_Buttons::anyDown() const
+{
+	return m_ButtonLeft || m_ButtonMiddle || m_ButtonRight;	
+}
+
 GHOST_Buttons::~GHOST_Buttons() {}

Modified: branches/soc-2010-merwin/intern/ghost/intern/GHOST_Buttons.h
===================================================================
--- branches/soc-2010-merwin/intern/ghost/intern/GHOST_Buttons.h	2010-08-12 20:42:06 UTC (rev 31302)
+++ branches/soc-2010-merwin/intern/ghost/intern/GHOST_Buttons.h	2010-08-13 00:34:57 UTC (rev 31303)
@@ -67,8 +67,13 @@
     /**
      * Sets the state of all buttons to up.
      */
-    virtual void clear(); 
-    
+    virtual void clear();
+
+    /**
+     * Are any buttons currently pressed?
+     */
+    bool anyDown() const;
+
     GHOST_TUns8 m_ButtonLeft		: 1;
     GHOST_TUns8 m_ButtonMiddle		: 1;
     GHOST_TUns8 m_ButtonRight		: 1;

Modified: branches/soc-2010-merwin/intern/ghost/intern/GHOST_SystemWin32.cpp
===================================================================
--- branches/soc-2010-merwin/intern/ghost/intern/GHOST_SystemWin32.cpp	2010-08-12 20:42:06 UTC (rev 31302)
+++ branches/soc-2010-merwin/intern/ghost/intern/GHOST_SystemWin32.cpp	2010-08-13 00:34:57 UTC (rev 31303)
@@ -506,8 +506,9 @@
 
 GHOST_EventButton* GHOST_SystemWin32::processButtonEvent(GHOST_TEventType type, GHOST_IWindow *window, GHOST_TButtonMask mask)
 {
-	if (eventIsFromTablet())
-		return NULL;
+	puts("ghost button event");
+//	if (eventIsFromTablet())
+//		return NULL;
 
 	return new GHOST_EventButton (getSystem()->getMilliSeconds(), type, window, mask);
 }
@@ -932,7 +933,7 @@
 		// Tablet events, processed
 		////////////////////////////////////////////////////////////////////////
 		case WT_PACKET:
-			m_tabletManager->processPackets((HCTX)lParam);
+			m_tabletManager->processPackets(window);
 			break;
 		case WT_CSRCHANGE:
 			m_tabletManager->changeTool((HCTX)lParam, wParam);
@@ -1002,10 +1003,10 @@
 
 				if (m_input_fidelity_hint == HI_FI)
 					{
-					int buttons;
+					GHOST_Buttons buttons;
 					getButtons(buttons);
 					// don't bother grabbing extra mouse motion unless we're in a stroke
-					if (buttons)
+					if (buttons.anyDown())
 						{
 						// int n =
 						getMoreMousePoints(mousePosX, mousePosY, xPrev, yPrev, window);

Modified: branches/soc-2010-merwin/intern/ghost/intern/GHOST_TabletManagerWin32.cpp
===================================================================
--- branches/soc-2010-merwin/intern/ghost/intern/GHOST_TabletManagerWin32.cpp	2010-08-12 20:42:06 UTC (rev 31302)
+++ branches/soc-2010-merwin/intern/ghost/intern/GHOST_TabletManagerWin32.cpp	2010-08-13 00:34:57 UTC (rev 31303)
@@ -3,6 +3,9 @@
 
 #include "GHOST_TabletManagerWin32.h"
 #include "GHOST_WindowWin32.h"
+#include "GHOST_System.h"
+#include "GHOST_EventCursor.h"
+#include "GHOST_EventButton.h"
 #include <stdio.h>
 #include <stdlib.h>
 #include <math.h>
@@ -162,20 +165,39 @@
 
 	// set up context
 	LOGCONTEXT archetype;
-	func_Info(WTI_DEFSYSCTX, 0, &archetype);
+//	func_Info(WTI_DEFSYSCTX, 0, &archetype);
+	func_Info(WTI_DEFCONTEXT, 0, &archetype);
 
 	strcpy(archetype.lcName, "blender special");
 	archetype.lcPktData = PACKETDATA;
 	archetype.lcPktMode = PACKETMODE;
-	archetype.lcOptions |= CXO_MESSAGES | CXO_CSRMESSAGES;
+//	archetype.lcOptions |= CXO_MESSAGES | CXO_CSRMESSAGES;
+	archetype.lcOptions |= CXO_SYSTEM | CXO_MESSAGES | CXO_CSRMESSAGES;
 
-/*
-	if (hasTilt)
+	// we want first 5 buttons
+	archetype.lcBtnDnMask = 0x1f;
+	archetype.lcBtnUpMask = 0x1f;
+
+// BEGIN derived from Wacom's TILTTEST.C:
+	AXIS TabletX, TabletY;
+	func_Info(WTI_DEVICES,DVC_X,&TabletX);
+	func_Info(WTI_DEVICES,DVC_Y,&TabletY);
+	archetype.lcInOrgX = 0;
+	archetype.lcInOrgY = 0;
+	archetype.lcInExtX = TabletX.axMax;
+	archetype.lcInExtY = TabletY.axMax;
+    /* output the data in screen coords */
+	archetype.lcOutOrgX = archetype.lcOutOrgY = 0;
+	archetype.lcOutExtX = GetSystemMetrics(SM_CXSCREEN);
+    /* move origin to upper left */
+	archetype.lcOutExtY = -GetSystemMetrics(SM_CYSCREEN);
+// END
+
+/*	if (hasTilt)
 		{
 		archetype.lcPktData |= tiltMask;
 		archetype.lcMoveMask |= tiltMask;
-		}
-*/
+		} */
 
 	// open the context
 	HCTX context = func_Open(window->getHWND(), &archetype, TRUE);
@@ -237,71 +259,117 @@
 	data.tilt_y = sin(M_PI/2.0 - azmRad) * vecLen;
 	}
 
-void GHOST_TabletManagerWin32::processPackets(HCTX context)
+void GHOST_TabletManagerWin32::processPackets(GHOST_WindowWin32* window)
 	{
-	PACKET packets[MAX_QUEUE_SIZE];
-	int n = func_PacketsGet(context, MAX_QUEUE_SIZE, packets);
-//	printf("processing %d packets\n", n);
+	HCTX context = contextForWindow(window);
 
-	for (int i = 0; i < n; ++i)
+	if (context)
 		{
-		PACKET const& packet = packets[i];
-		TabletToolData data = {activeTool};
-		int x = packet.pkX;
-		int y = packet.pkY;
-
-		if (activeTool.type == TABLET_MOUSE)
-			if (x == prevMouseX && y == prevMouseY)
-				// don't send any "mouse hasn't moved" events
-				continue;
-			else {
-				prevMouseX = x;
-				prevMouseY = y;
+		PACKET packets[MAX_QUEUE_SIZE];
+		int n = func_PacketsGet(context, MAX_QUEUE_SIZE, packets);
+	//	printf("processing %d packets\n", n);
+	
+		for (int i = 0; i < n; ++i)
+			{
+			PACKET const& packet = packets[i];
+			TabletToolData data = {activeTool};
+			int x = packet.pkX;
+			int y = packet.pkY;
+	
+			if (activeTool.type == TABLET_MOUSE)
+				if (x == prevMouseX && y == prevMouseY)
+					// don't send any "mouse hasn't moved" events
+					continue;
+				else {
+					prevMouseX = x;
+					prevMouseY = y;
+					}
+	
+			// every packet from a WT_PACKET message comes from the same tool
+			switch (activeTool.type)
+				{
+				case TABLET_MOUSE:
+					printf("mouse");
+					break;
+				case TABLET_PEN:
+					printf("pen");
+					break;
+				case TABLET_ERASER:
+					printf("eraser");
+					break;
+				default:
+					printf("???");
 				}
+	
+			printf(" (%d,%d)", x, y);
+	
+			if (activeTool.hasPressure)
+				{
+				if (packet.pkNormalPressure)
+					{
+					data.pressure = pressureScale * packet.pkNormalPressure;
+					printf(" %d%%", (int)(100 * data.pressure));
+					}
+				else
+					data.tool.hasPressure = false;
+				}
+	
+			if (activeTool.hasTilt)
+				{
+				// ORIENTATION const& tilt = packet.pkOrientation;
+				// printf(" /%d,%d/", tilt.orAzimuth, tilt.orAltitude);
+				convertTilt(packet.pkOrientation, data);
+	
+				// data.tilt_x = tiltScaleX * packet.pkTilt.tiltX;
+				// data.tilt_y = tiltScaleY * packet.pkTilt.tiltY;
+				printf(" /%.2f,%.2f/", data.tilt_x, data.tilt_y);
+				}
+	
+			putchar('\n');
 
-		// every packet from a WT_PACKET message comes from the same tool
-		switch (activeTool.type)
-			{
-			case TABLET_MOUSE:
-				printf("mouse");
-				break;
-			case TABLET_PEN:
-				printf("pen");
-				break;
-			case TABLET_ERASER:
-				printf("eraser");
-				break;
-			default:
-				printf("???");
-			}
+			// at this point, construct a GHOST event and push it into the queue!
+			// (having trouble with Wacom mouse scaling, so ignore it for now)
 
-		printf(" (%d,%d)", x, y);
-
-		if (activeTool.hasPressure)
-			{
-			if (packet.pkNormalPressure)
+//			if (activeTool.type == TABLET_PEN || activeTool.type == TABLET_ERASER)
 				{
-				data.pressure = pressureScale * packet.pkNormalPressure;
-				printf(" %d%%", (int)(100 * data.pressure));
-				}
-			else
-				data.tool.hasPressure = false;
-			}
+				GHOST_System* system = (GHOST_System*) GHOST_ISystem::getSystem();
 
-		if (activeTool.hasTilt)
-			{
-			// ORIENTATION const& tilt = packet.pkOrientation;
-			// printf(" /%d,%d/", tilt.orAzimuth, tilt.orAltitude);
-			convertTilt(packet.pkOrientation, data);
+				if (packet.pkButtons)
+					{
+					// which button?
+					GHOST_TButtonMask e_button;
+					int buttonNumber = LOWORD(packet.pkButtons);
+					e_button = (GHOST_TButtonMask) buttonNumber;
 
-			// data.tilt_x = tiltScaleX * packet.pkTilt.tiltX;
-			// data.tilt_y = tiltScaleY * packet.pkTilt.tiltY;
-			printf(" /%.2f,%.2f/", data.tilt_x, data.tilt_y);
-			}
+					// pressed or released?
+					GHOST_TEventType e_action;
+					int buttonAction = HIWORD(packet.pkButtons);
+					if (buttonAction == TBN_DOWN)
+						e_action = GHOST_kEventButtonDown;
+					else
+						e_action = GHOST_kEventButtonUp;
 
-		putchar('\n');
+					printf("button %d %s\n", buttonNumber, buttonAction == TBN_DOWN ? "down" : "up");
 
-		// at this point, construct a GHOST event and push it into the queue!
+					GHOST_EventButton* e = new GHOST_EventButton(system->getMilliSeconds(), e_action, window, e_button);
+					
+//					system->pushEvent(e);
+					}
+				else
+					{
+					GHOST_EventCursor* e = new GHOST_EventCursor(system->getMilliSeconds(), GHOST_kEventCursorMove, window, x, y);
+
+					// use older TabletData struct for testing until mine is in place
+					GHOST_TabletData& e_data = ((GHOST_TEventCursorData*) e->getData())->tablet;
+					e_data.Active = (GHOST_TTabletMode) data.tool.type;
+					e_data.Pressure = data.pressure;
+					e_data.Xtilt = data.tilt_x;
+					e_data.Ytilt = data.tilt_y;
+
+//					system->pushEvent(e);
+					}
+				}
+			}
 		}
 	}
 

Modified: branches/soc-2010-merwin/intern/ghost/intern/GHOST_TabletManagerWin32.h
===================================================================
--- branches/soc-2010-merwin/intern/ghost/intern/GHOST_TabletManagerWin32.h	2010-08-12 20:42:06 UTC (rev 31302)
+++ branches/soc-2010-merwin/intern/ghost/intern/GHOST_TabletManagerWin32.h	2010-08-13 00:34:57 UTC (rev 31303)
@@ -90,7 +90,7 @@
 	void openForWindow(GHOST_WindowWin32*);
 	void closeForWindow(GHOST_WindowWin32*);
 
-	void processPackets(HCTX);
+	void processPackets(GHOST_WindowWin32*);
 
 	void changeTool(HCTX, UINT serialNumber);
 	void dropTool();





More information about the Bf-blender-cvs mailing list