[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [31395] branches/soc-2010-merwin: pencils down! additional Windows Wacom wackiness.

Mike Erwin significant.bit at gmail.com
Mon Aug 16 20:59:36 CEST 2010


Revision: 31395
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=31395
Author:   merwin
Date:     2010-08-16 20:59:36 +0200 (Mon, 16 Aug 2010)

Log Message:
-----------
pencils down! additional Windows Wacom wackiness.

Modified Paths:
--------------
    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
    branches/soc-2010-merwin/notes/week 12 notes.txt

Modified: branches/soc-2010-merwin/intern/ghost/intern/GHOST_SystemWin32.cpp
===================================================================
--- branches/soc-2010-merwin/intern/ghost/intern/GHOST_SystemWin32.cpp	2010-08-16 18:50:59 UTC (rev 31394)
+++ branches/soc-2010-merwin/intern/ghost/intern/GHOST_SystemWin32.cpp	2010-08-16 18:59:36 UTC (rev 31395)
@@ -841,7 +841,7 @@
 bool GHOST_SystemWin32::handleEvent(GHOST_WindowWin32* window, UINT msg, WPARAM wParam, LPARAM lParam)
 	{
 	GHOST_Event* event = NULL;
-	bool eventSent = false;
+	bool eventHandled = false;
 
 	static int mousePosX = 0, mousePosY = 0; // track mouse position between calls
 
@@ -1014,10 +1014,19 @@
 
 		case WM_MOUSEMOVE:
 			{
-			if (!eventIsFromTablet() && !m_tabletManager->anyButtonsDown())
+			if (!eventIsFromTablet())
+				{
 				// Even with careful checking, a stray cursor event sneaks through just before each
 				// tablet mouse/pen button up event. Keep clean separation between tablet and mouse!
-				{
+				if (m_tabletManager->anyButtonsDown())
+					{
+					// tablet manager handles all its own cursor moves.
+					// ignore 'regular' mouse while a tablet tool is being used.
+					DefWindowProc(window->getHWND(), WM_MOUSEMOVE, wParam, lParam);
+					eventHandled = true;
+					break;
+					}
+
 				int xPrev = mousePosX;
 				int yPrev = mousePosY;
 				// window coordinates are passed in via lParam
@@ -1056,10 +1065,10 @@
          UINT rawSize = sizeof(RAWINPUT);
 
          GetRawInputData((HRAWINPUT)lParam, RID_INPUT, raw_ptr, &rawSize, sizeof(RAWINPUTHEADER));
-         eventSent |= processRawInput(raw, window);
+         eventHandled |= processRawInput(raw, window);
 
 			if (processRawInput(raw, window))
-				eventSent = true;
+				eventHandled = true;
 //			else
 //				DefRawInputProc(&raw_ptr, 1, sizeof(RAWINPUTHEADER));
 
@@ -1089,7 +1098,7 @@
 					for (int i = 0; i < n; ++i)
 						{
 						RAWINPUT const& raw = rawBuffer[i];
-						eventSent |= processRawInput(raw, window);
+						eventHandled |= processRawInput(raw, window);
 						}
 
 					// clear processed events from the queue
@@ -1290,13 +1299,13 @@
 #endif // illustrative code
 	}
 
-	if (!eventSent)
+	if (!eventHandled)
 		if (event) {
 			pushEvent(event);
-			eventSent = true;
+			eventHandled = true;
 		}
 
-	return eventSent;
+	return eventHandled;
 }
 
 GHOST_TUns8* GHOST_SystemWin32::getClipboard(bool selection) const

Modified: branches/soc-2010-merwin/intern/ghost/intern/GHOST_TabletManagerWin32.cpp
===================================================================
--- branches/soc-2010-merwin/intern/ghost/intern/GHOST_TabletManagerWin32.cpp	2010-08-16 18:50:59 UTC (rev 31394)
+++ branches/soc-2010-merwin/intern/ghost/intern/GHOST_TabletManagerWin32.cpp	2010-08-16 18:59:36 UTC (rev 31395)
@@ -171,27 +171,6 @@
 	printf("WinTab version %d.%d (%d.%d)\n",
 		HIBYTE(specV), LOBYTE(specV), HIBYTE(implV), LOBYTE(implV));
 
-	UINT ndevices, ncursors;
-      func_Info(WTI_INTERFACE, IFC_NDEVICES, &ndevices);
-      func_Info(WTI_INTERFACE, IFC_NCURSORS, &ncursors);
-
-	printf("%d tablets, %d tools\n", ndevices, ncursors);
-	if (ndevices > 1)
-		; // support this?
-
-	// query for overall capabilities and ranges
-	char tabletName[LC_NAMELEN];
-	if (func_Info(WTI_DEVICES, DVC_NAME, tabletName))
-		puts(tabletName);
-
-	puts("\nactive tablet area");
-	AXIS xRange, yRange;
-	func_Info(WTI_DEVICES, DVC_X, &xRange);
-	func_Info(WTI_DEVICES, DVC_Y, &yRange);
-	print(xRange,"x"); print(yRange,"y");
-
-	putchar('\n');
-
 	UINT extensionCount;
 	func_Info(WTI_INTERFACE, IFC_NEXTENSIONS, &extensionCount);
 	for (UINT i = 0; i < extensionCount; ++i)
@@ -201,9 +180,85 @@
 		printf("extension %d: %s\n", i, name);
 		}
 
-//	for (int i = cursorBase; i < cursorBase + cursorCount; ++i)
-	for (UINT i = 0; i < ncursors; ++i)
+	UINT deviceCount, cursorCount;
+	func_Info(WTI_INTERFACE, IFC_NDEVICES, &deviceCount);
+	func_Info(WTI_INTERFACE, IFC_NCURSORS, &cursorCount);
+
+	printf("%d tablets, %d tools\n", deviceCount, cursorCount);
+	if (deviceCount > 1)
+		; // support this?
+
+	for (UINT i = 0; i < deviceCount; ++i)
 		{
+		Tablet tablet;
+
+		// query for overall capabilities and ranges
+		char tabletName[LC_NAMELEN];
+		if (func_Info(WTI_DEVICES, DVC_NAME, tabletName))
+			printf("tablet %d: %s\n", i, tabletName);
+	
+		puts("\nactive tablet area");
+		AXIS xRange, yRange;
+		func_Info(WTI_DEVICES + i, DVC_X, &xRange);
+		func_Info(WTI_DEVICES + i, DVC_Y, &yRange);
+		tablet.size_x = xRange.axMax;
+		tablet.size_y = yRange.axMax;
+		print(xRange,"x"); print(yRange,"y");
+
+		func_Info(WTI_DEVICES + i, DVC_NCSRTYPES, &cursorCount);
+		func_Info(WTI_DEVICES + i, DVC_FIRSTCSR, &cursorBase);
+		tablet.cursorBase = cursorBase;
+		tablet.cursorCount = cursorCount;
+		printf("owns tools %d to %d\n", cursorBase, cursorBase + cursorCount - 1);
+
+		func_Info(WTI_DEVICES + i, DVC_PKTDATA, &allTools);
+		puts("\nall tools have"); print(allTools);
+		func_Info(WTI_DEVICES + i, DVC_CSRDATA, &someTools);
+		puts("some tools also have"); print(someTools);
+
+		puts("\npressure sensitivity");
+		AXIS pressureRange;
+		hasPressure = (allTools|someTools) & PK_NORMAL_PRESSURE
+			&& func_Info(WTI_DEVICES + i, DVC_NPRESSURE, &pressureRange);
+
+		if (hasPressure)
+			{
+			print(pressureRange);
+			pressureScale = 1.f / pressureRange.axMax;
+			}
+		else
+			pressureScale = 0.f;
+
+		puts("\ntilt sensitivity");
+		AXIS tiltRange[3];
+		hasTilt = (allTools|someTools) & PK_ORIENTATION
+			&& func_Info(WTI_DEVICES + i, DVC_ORIENTATION, &tiltRange);
+
+		if (hasTilt)
+			{
+			// leave this code in place to help support tablets I haven't tested
+			const char* axisName[] = {"azimuth","altitude","twist"};
+			for (int i = 0; i < 3; ++i)
+				print(tiltRange[i], axisName[i]);
+
+			// cheat by using available data from Intuos4. test on other tablets!!!
+			// azimuthScale = 1.f / HIWORD(tiltRange[1].axResolution);
+			// altitudeScale = 1.f / tiltRange[1].axMax;
+
+			azimuthScale = 1.f / tiltRange[0].axMax;
+			altitudeScale = 1.f / tiltRange[1].axMax;
+			}
+		else
+			{
+			puts("none");
+			azimuthScale = altitudeScale = 0.f;
+			}
+		
+		tablets.push_back(tablet);
+		}
+
+	for (UINT i = 0; i < cursorCount; ++i)
+		{
 		// what can each cursor do?
 
 		UINT physID;
@@ -415,6 +470,13 @@
 			int y = packet.pkY;
 	
 			if (activeTool.type == TABLET_MOUSE)
+				{
+				// until scaling is working better, use system cursor position instead
+				POINT systemPos;
+				GetCursorPos(&systemPos);
+				x = systemPos.x;
+				y = systemPos.y;
+
 				if (x == prevMouseX && y == prevMouseY && packet.pkButtons == prevButtons)
 					// don't send any "mouse hasn't moved" events
 					continue;
@@ -422,6 +484,7 @@
 					prevMouseX = x;
 					prevMouseY = y;
 					}
+				}
 
 			anyProcessed = true;
 
@@ -601,6 +664,7 @@
 				activeTool.type = TABLET_NONE;
 			}
 
+//#if 0
 		// now try another way
 		func_Info(WTI_CURSORS + packet.pkCursor, CSR_TYPE, &cursorType);
 		switch (cursorType & 0xf06)
@@ -623,6 +687,7 @@
 			default:
 				puts("???");
 			}
+//#endif
 
 		WTPKT toolData;
 		func_Info(WTI_CURSORS + packet.pkCursor, CSR_PKTDATA, &toolData);

Modified: branches/soc-2010-merwin/intern/ghost/intern/GHOST_TabletManagerWin32.h
===================================================================
--- branches/soc-2010-merwin/intern/ghost/intern/GHOST_TabletManagerWin32.h	2010-08-16 18:50:59 UTC (rev 31394)
+++ branches/soc-2010-merwin/intern/ghost/intern/GHOST_TabletManagerWin32.h	2010-08-16 18:59:36 UTC (rev 31395)
@@ -9,6 +9,7 @@
 #include	<windows.h>
 #include "wintab.h"
 #include <map>
+#include <vector>
 
 #include "GHOST_Types.h"
 class GHOST_WindowWin32;
@@ -22,6 +23,10 @@
 typedef BOOL ( API * WTPACKET ) ( HCTX, UINT, LPVOID );
 // END
 
+// TabletToolData (and its components) are meant to replace GHOST_TabletData
+// and its customdata analogue in the window manager. For now it's confined to the
+// TabletManager.
+
 typedef enum { TABLET_NONE, TABLET_PEN, TABLET_ERASER, TABLET_MOUSE } TabletToolType;
 
 typedef struct
@@ -31,7 +36,7 @@
 	// capabilities
 	bool hasPressure : 1;
 	bool hasTilt : 1;
-	
+
 	} TabletTool;
 
 
@@ -45,6 +50,30 @@
 	} TabletToolData;
 
 
+// "Tablet" structure is not active by pencils down
+// but will be soon.
+
+struct Tablet
+	{
+	bool hasPressure;
+	float pressureScale;
+
+	bool hasTilt;
+	float azimuthScale;
+	float altitudeScale;
+
+	UINT size_x, size_y;
+
+	UINT cursorCount;
+	UINT cursorBase;
+
+	WTPKT allTools; // standard info available from any tool (mouse/pen/etc.)
+	WTPKT someTools; // extra info available from only some tools
+
+	bool ownsCursor(UINT x)
+		{ return (x - cursorBase) < cursorCount; }
+	};
+
 class GHOST_TabletManagerWin32
 	{
 	// the Wintab library
@@ -78,6 +107,8 @@
 	std::map<GHOST_WindowWin32*,HCTX> contexts;
 	HCTX contextForWindow(GHOST_WindowWin32*);
 
+	std::vector<Tablet> tablets;
+
 	GHOST_WindowWin32* activeWindow;
 	TabletTool activeTool;
 	BYTE sysButtonMap[32]; // user's custom button assignments for active tool

Modified: branches/soc-2010-merwin/notes/week 12 notes.txt
===================================================================
--- branches/soc-2010-merwin/notes/week 12 notes.txt	2010-08-16 18:50:59 UTC (rev 31394)
+++ branches/soc-2010-merwin/notes/week 12 notes.txt	2010-08-16 18:59:36 UTC (rev 31395)
@@ -326,4 +326,28 @@
 
 Ok, fixed. I prefer gpencil without smoothing. Capture what I draw, not what I could've drawn! Smoothing off by default?
 
-Good night!
\ No newline at end of file
+Good night!
+
+
+16 Aug --
+
+Tie up a few loose ends before 2pm! Using both tablets today, making sure yesterday's code still works with Graphire.
+
+With both plugged in blender reports "2 tablets, 12 tools". Only some of those 12 cursors are valid/available. PhysID says which ones, but I don't know if they can be matched to their proper tablet. Tilt detection is still hit-or-miss.
+
+Here we go! From the spec:
+
+DVC_NCSRTYPES
+UINT Returns the number of supported cursor types.
+
+DVC_FIRSTCSR
+UINT Returns the first cursor type number for the device.
+
+I really should keep track of info per tablet. Hack up a Tablet struct for this purpose. It can claim cursors as they come in, and also scale incoming tablet coordinates to the screen. It's hard to choose proper scaling during context setup, so instead ask for device coordinates.
+

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list