[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [31286] branches/soc-2010-merwin/intern/ ghost/intern: Better Intuos4 support on Windows.

Mike Erwin significant.bit at gmail.com
Thu Aug 12 15:04:12 CEST 2010


Revision: 31286
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=31286
Author:   merwin
Date:     2010-08-12 15:04:00 +0200 (Thu, 12 Aug 2010)

Log Message:
-----------
Better Intuos4 support on Windows.

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

Modified: branches/soc-2010-merwin/intern/ghost/intern/GHOST_SystemWin32.cpp
===================================================================
--- branches/soc-2010-merwin/intern/ghost/intern/GHOST_SystemWin32.cpp	2010-08-12 12:17:47 UTC (rev 31285)
+++ branches/soc-2010-merwin/intern/ghost/intern/GHOST_SystemWin32.cpp	2010-08-12 13:04:00 UTC (rev 31286)
@@ -140,7 +140,9 @@
 
 GHOST_TUns64 GHOST_SystemWin32::getMilliSeconds() const
 {
-	// Hardware does not support high resolution timers. We will use GetTickCount instead then.
+	// If hardware does not support high resolution timers,
+	// we will use GetTickCount instead.
+
 	if (!m_hasPerformanceCounter) {
 		return ::GetTickCount();
 	}
@@ -153,7 +155,7 @@
 	__int64 delta = 1000*(count-m_start);
 
 	GHOST_TUns64 t = (GHOST_TUns64)(delta/m_freq);
-	return t; 
+	return t;
 }
 
 
@@ -174,7 +176,7 @@
 
 
 GHOST_IWindow* GHOST_SystemWin32::createWindow(
-	const STR_String& title, 
+	const STR_String& title,
 	GHOST_TInt32 left, GHOST_TInt32 top, GHOST_TUns32 width, GHOST_TUns32 height,
 	GHOST_TWindowState state, GHOST_TDrawingContextType type,
 	bool stereoVisual, const GHOST_TUns16 numOfAASamples, const GHOST_TEmbedderWindowID parentWindow )
@@ -195,7 +197,7 @@
 
 			delete window;
 			window = 0;
-			
+
 			// If another window is found, let the wm know about that one, but not the old one
 			if (other_window)
 			{
@@ -222,7 +224,7 @@
 #else
 			GHOST_TUns64 next = timerMgr->nextFireTime();
 			GHOST_TInt64 maxSleep = next - getMilliSeconds();
-			
+
 			if (next == GHOST_kFireTimeNever) {
 				::WaitMessage();
 			} else if(maxSleep >= 0.0) {
@@ -565,7 +567,7 @@
 {
 	// short fwKeys = LOWORD(wParam);			// key flags
 	int zDelta = (short) HIWORD(wParam);	// wheel rotation
-	
+
 	// zDelta /= WHEEL_DELTA;
 	// temporary fix below: microsoft now has added more precision, making the above division not work
 	if (zDelta <= 0 ) zDelta= -1; else zDelta= 1;	
@@ -930,14 +932,22 @@
 		// Tablet events, processed
 		////////////////////////////////////////////////////////////////////////
 		case WT_PACKET:
-			puts("WT_PACKET");
+			// puts("WT_PACKET");
 			// window->processWin32TabletEvent(wParam, lParam);
-			m_tabletManager->processPackets(window);
+			m_tabletManager->processPackets((HCTX)lParam);
 			break;
 		case WT_CSRCHANGE:
+			m_tabletManager->changeTool((HCTX)lParam, wParam);
+			break;
 		case WT_PROXIMITY:
+			// description was weird.. give me numbers!
+			// printf("prox: %d %d\n", LOWORD(lParam), HIWORD(lParam));
+			if (LOWORD(lParam) == 0)
+				{
+				puts("-- dropping tool --");
+				m_tabletManager->dropTool();
+				}
 			// window->processWin32TabletInitEvent();
-			m_tabletManager->changeTool(window);
 			break;
 
 		////////////////////////////////////////////////////////////////////////
@@ -997,9 +1007,15 @@
 
 				if (m_input_fidelity_hint == HI_FI)
 					{
-					// int n =
-					getMoreMousePoints(mousePosX, mousePosY, xPrev, yPrev, window);
-					// printf("%d more mouse points found\n", n);
+					int buttons;
+					getButtons(buttons);
+					// don't bother grabbing extra mouse motion unless we're in a stroke
+					if (buttons)
+						{
+						// int n =
+						getMoreMousePoints(mousePosX, mousePosY, xPrev, yPrev, window);
+						// printf("%d more mouse points found\n", n);
+						}
 					}
 
 				// uncomment here and in getMoreMousePoints to show effectiveness of hi-fi input

Modified: branches/soc-2010-merwin/intern/ghost/intern/GHOST_TabletManagerWin32.cpp
===================================================================
--- branches/soc-2010-merwin/intern/ghost/intern/GHOST_TabletManagerWin32.cpp	2010-08-12 12:17:47 UTC (rev 31285)
+++ branches/soc-2010-merwin/intern/ghost/intern/GHOST_TabletManagerWin32.cpp	2010-08-12 13:04:00 UTC (rev 31286)
@@ -2,18 +2,19 @@
 #include "GHOST_WindowWin32.h"
 #include <stdio.h>
 #include <stdlib.h>
+#include <math.h>
 
-#define PACKETDATA	PK_CURSOR | PK_X | PK_Y | PK_BUTTONS | PK_NORMAL_PRESSURE
-#define PACKETTILT 	PKEXT_ABSOLUTE
-#define PACKETMODE	PK_BUTTONS
+#define PACKETDATA PK_CURSOR | PK_X | PK_Y | PK_BUTTONS | PK_NORMAL_PRESSURE | PK_ORIENTATION
+#define PACKETMODE PK_BUTTONS
+// #define PACKETTILT PKEXT_ABSOLUTE
 
 #include "pktdef.h"
 
-#define MAX_QUEUE_SIZE 128
+#define MAX_QUEUE_SIZE 100
 
 GHOST_TabletManagerWin32::GHOST_TabletManagerWin32()
 	{
-	resetActiveTool();
+	dropTool();
 
 	// open WinTab
 	lib_Wintab = LoadLibrary("wintab32.dll");
@@ -26,11 +27,12 @@
 		func_Info = (WTINFOA) GetProcAddress(lib_Wintab,"WTInfoA");
 		func_QueueSizeSet = (WTQUEUESIZESET) GetProcAddress(lib_Wintab,"WTQueueSizeSet");
 		func_PacketsGet = (WTPACKETSGET) GetProcAddress(lib_Wintab,"WTPacketsGet");
+		func_Packet = (WTPACKET) GetProcAddress(lib_Wintab,"WTPacket");
 
 		WORD specV, implV;
 		func_Info(WTI_INTERFACE, IFC_SPECVERSION, &specV);
 		func_Info(WTI_INTERFACE, IFC_IMPLVERSION, &implV);
-		printf("Wintab version %d.%d (%d.%d)\n",
+		printf("WinTab version %d.%d (%d.%d)\n",
 			HIBYTE(specV), LOBYTE(specV), HIBYTE(implV), LOBYTE(implV));
 
 		// query for overall capabilities and ranges
@@ -44,8 +46,11 @@
 
 		printf("active area: %dx%d\n", xRange.axMax, yRange.axMax);
 
+		func_Info(WTI_DEVICES, DVC_NCSRTYPES, &cursorCount);
+		func_Info(WTI_DEVICES, DVC_FIRSTCSR, &cursorBase);
+
 		AXIS pressureRange;
-		hasPressure = func_Info(WTI_DEVICES, DVC_NPRESSURE, &pressureRange) && pressureRange.axMax != 0;
+		hasPressure = func_Info(WTI_DEVICES, DVC_NPRESSURE, &pressureRange);// && pressureRange.axMax != 0;
 
 		printf("pressure sensitivity: ");
 		if (hasPressure)
@@ -59,20 +64,71 @@
 			pressureScale = 0.f;
 			}
 
-		AXIS tiltRange;
-		hasTilt = func_Info(WTI_DEVICES, DVC_ORIENTATION, &tiltRange) && tiltRange.axMax != 0;
+		printf("tilt sensitivity:\n");
+		AXIS tiltRange[3];
+		hasTilt = func_Info(WTI_DEVICES, DVC_ORIENTATION, tiltRange);
 
-		printf("tilt sensitivity: ");
 		if (hasTilt)
 			{
-			printf("%d to %d\n", tiltRange.axMin, tiltRange.axMax);
-			tiltScale = 1.f / tiltRange.axMax;
+			// cheat by using available data from Intuos4. test on other tablets!!!
+			azimuthScale = 1.f / HIWORD(tiltRange[1].axResolution);
+			altitudeScale = 1.f / tiltRange[1].axMax;
+			printf("azi scale %f\n", azimuthScale);
+			printf("alt scale %f\n", altitudeScale);
+
+			// leave this code in place to help support tablets I haven't tested
+			const char* axisName[] = {"azimuth","altitude","twist"};
+			const char* unitName[] = {NULL,"inch","cm","circle"};
+			for (int i = 0; i < 3; ++i)
+				{
+				AXIS const& t = tiltRange[i];
+				if (t.axResolution)
+					printf("%s: %d to %d values per %d.%d %s\n",
+						axisName[i], t.axMin, t.axMax,
+						HIWORD(t.axResolution), LOWORD(t.axResolution),
+						unitName[t.axUnits]);
+				}
 			}
 		else
 			{
 			printf("none\n");
-			tiltScale = 0.f;
 			}
+
+#if 0 // WTX_TILT -- cartesian tilt extension, no conversion needed
+		// this isn't working for [mce], so let it rest for now
+		printf("raw tilt sensitivity:\n");
+		hasTilt = false;
+		UINT tag = 0;
+		UINT extensionCount;
+		func_Info(WTI_INTERFACE, IFC_NEXTENSIONS, &extensionCount);
+//		for (UINT i = 0; func_Info(WTI_EXTENSIONS + i, EXT_TAG, &tag); ++i)
+		for (UINT i = 0; i < extensionCount; ++i)
+			{
+			printf("trying extension %d\n", i);
+			func_Info(WTI_EXTENSIONS + i, EXT_TAG, &tag);
+			if (tag == WTX_TILT)
+				{
+				hasTilt = true;
+				break;
+				}
+			}
+
+		if (hasTilt)
+			{
+			func_Info(WTI_EXTENSIONS + tag, EXT_MASK, &tiltMask);
+			AXIS tiltRange[2];
+			func_Info(WTI_EXTENSIONS + tag, EXT_AXES, tiltRange);
+			printf("%d to %d along x\n", tiltRange[0].axMin, tiltRange[0].axMax);
+			printf("%d to %d along y\n", tiltRange[1].axMin, tiltRange[1].axMax);
+			tiltScaleX = 1.f / tiltRange[0].axMax;
+			tiltScaleY = 1.f / tiltRange[1].axMax;
+			}
+		else
+			{
+			printf("none\n");
+			tiltScaleX = tiltScaleY = 0.f;
+			}
+#endif // WTX_TILT
 		}
 	}
 
@@ -88,13 +144,6 @@
 		&& func_Info(0,0,NULL); // tablet plugged in
 	}
 
-void GHOST_TabletManagerWin32::resetActiveTool()
-	{
-	activeTool.type = TABLET_NONE;
-	activeTool.hasPressure = false;
-	activeTool.hasTilt = false;
-	}
-
 HCTX GHOST_TabletManagerWin32::contextForWindow(GHOST_WindowWin32* window)
 	{
 	std::map<GHOST_WindowWin32*,HCTX>::iterator i = contexts.find(window);
@@ -112,20 +161,20 @@
 
 	// set up context
 	LOGCONTEXT archetype;
-	func_Info(WTI_DEFCONTEXT, 0, &archetype);
+	func_Info(WTI_DEFSYSCTX, 0, &archetype);
 
-	strcpy(archetype.lcName, "merwin special");
+	strcpy(archetype.lcName, "blender special");
 	archetype.lcPktData = PACKETDATA;
 	archetype.lcPktMode = PACKETMODE;
-	archetype.lcOptions |= CXO_SYSTEM | CXO_MESSAGES;
+	archetype.lcOptions |= CXO_MESSAGES | CXO_CSRMESSAGES;
 
-// BEGIN from Wacom's TILTTEST.c
-	/* 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);
@@ -151,150 +200,160 @@
 		}
 	}
 
-void GHOST_TabletManagerWin32::processPackets(GHOST_WindowWin32* window)
+void GHOST_TabletManagerWin32::convertTilt(ORIENTATION const& ort, TabletToolData& data)
 	{
-	HCTX context = contextForWindow(window);
+	// this code used to live in GHOST_WindowWin32
+	// now it lives here
 
-	if (context)
+	float vecLen;
+	float altRad, azmRad;	/* in radians */
+
+	/*
+	from the wintab spec:
+	orAzimuth	Specifies the clockwise rotation of the
+	cursor about the z axis through a full circular range.
+
+	orAltitude	Specifies the angle with the x-y plane
+	through a signed, semicircular range.  Positive values
+	specify an angle upward toward the positive z axis;
+	negative values specify an angle downward toward the negative z axis.
+
+	wintab.h defines .orAltitude as a UINT but documents .orAltitude
+	as positive for upward angles and negative for downward angles.
+	WACOM uses negative altitude values to show that the pen is inverted;
+	therefore we cast .orAltitude as an (int) and then use the absolute value.
+	*/
+
+	/* convert raw fixed point data to radians */
+	altRad = fabs(ort.orAltitude) * altitudeScale * M_PI/2.0;
+	azmRad = ort.orAzimuth * azimuthScale * M_PI*2.0;
+
+	/* find length of the stylus' projected vector on the XY plane */
+	vecLen = cos(altRad);
+

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list