[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [31274] branches/soc-2010-merwin: Updated Win32 tablet code.

Mike Erwin significant.bit at gmail.com
Thu Aug 12 06:03:42 CEST 2010


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

Log Message:
-----------
Updated Win32 tablet code.

Modified Paths:
--------------
    branches/soc-2010-merwin/experimental/WinTablet/Tablet.cpp
    branches/soc-2010-merwin/experimental/WinTablet/Tablet.h
    branches/soc-2010-merwin/intern/ghost/intern/GHOST_System.cpp
    branches/soc-2010-merwin/intern/ghost/intern/GHOST_SystemWin32.cpp
    branches/soc-2010-merwin/intern/ghost/intern/GHOST_SystemWin32.h
    branches/soc-2010-merwin/intern/ghost/intern/GHOST_WindowCocoa.mm
    branches/soc-2010-merwin/intern/ghost/intern/GHOST_WindowWin32.cpp
    branches/soc-2010-merwin/intern/ghost/intern/GHOST_WindowWin32.h

Added Paths:
-----------
    branches/soc-2010-merwin/intern/ghost/intern/GHOST_TabletManagerWin32.cpp
    branches/soc-2010-merwin/intern/ghost/intern/GHOST_TabletManagerWin32.h

Removed Paths:
-------------
    branches/soc-2010-merwin/intern/ghost/intern/Utils.c
    branches/soc-2010-merwin/intern/ghost/intern/Utils.h

Modified: branches/soc-2010-merwin/experimental/WinTablet/Tablet.cpp
===================================================================
--- branches/soc-2010-merwin/experimental/WinTablet/Tablet.cpp	2010-08-12 03:37:45 UTC (rev 31273)
+++ branches/soc-2010-merwin/experimental/WinTablet/Tablet.cpp	2010-08-12 04:03:40 UTC (rev 31274)
@@ -20,6 +20,7 @@
 			{
 			// connect function pointers
 			func_Open = (WTOPENA) GetProcAddress(lib_Wintab,"WTOpenA");
+			func_Close = (WTCLOSE) GetProcAddress(lib_Wintab,"WTClose");
 			func_Info = (WTINFOA) GetProcAddress(lib_Wintab,"WTInfoA");
 			func_QueueSizeSet = (WTQUEUESIZESET) GetProcAddress(lib_Wintab,"WTQueueSizeSet");
 			func_PacketsGet = (WTPACKETSGET) GetProcAddress(lib_Wintab,"WTPacketsGet");
@@ -29,7 +30,6 @@
 			func_Info(WTI_INTERFACE, IFC_IMPLVERSION, &implV);
 			printf("Wintab version %d.%d (%d.%d)\n",
 				HIBYTE(specV), LOBYTE(specV), HIBYTE(implV), LOBYTE(implV));
-//				specV >> 8, specV & 0xff, implV >> 8, implV & 0xff);
 
 			// query for overall capabilities and ranges
 			char tabletName[40];
@@ -64,10 +64,21 @@
 			&& func_Info(0,0,NULL); // tablet plugged in
 		}
 
-	HCTX Tablet::openForWindow(HWND window)
-		// instead of returning the context, could remember the window/context mapping.
-		// this class should handle all tablet internals, not push work onto the window.
+	HCTX Tablet::contextForWindow(HWND window)
 		{
+		std::map<HWND,HCTX>::iterator i = contexts.find(window);
+		if (i == contexts.end())
+			return 0; // not found
+		else
+			return i->second;
+		}
+
+	void Tablet::openForWindow(HWND window)
+		{
+		if (contextForWindow(window) != 0)
+			// this window already has a tablet context
+			return;
+
 		// set up context
 		LOGCONTEXT archetype;
 		func_Info(WTI_DEFCONTEXT, 0, &archetype);
@@ -86,19 +97,36 @@
 			--tabletQueueSize;
 		printf("tablet queue size: %d\n", tabletQueueSize);
 
-		return context;
+		contexts[window] = context;
 		}
 
-	void Tablet::processPackets(HCTX context)
+	void Tablet::closeForWindow(HWND window)
 		{
-		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)
+		HCTX context = contextForWindow(window);
+
+		if (context)
 			{
-			PACKET const& packet = packets[i];
-			int x = packet.pkX;
-			int y = packet.pkY;
-			int pressure = packet.pkNormalPressure;
+			func_Close(context);
+			// also remove it from our books:
+			contexts.erase(contexts.find(window));
 			}
 		}
+
+	void Tablet::processPackets(HWND window)
+		{
+		HCTX context = contextForWindow(window);
+
+		if (context)
+			{
+			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];
+				int x = packet.pkX;
+				int y = packet.pkY;
+				int pressure = packet.pkNormalPressure;
+				}
+			}
+		}

Modified: branches/soc-2010-merwin/experimental/WinTablet/Tablet.h
===================================================================
--- branches/soc-2010-merwin/experimental/WinTablet/Tablet.h	2010-08-12 03:37:45 UTC (rev 31273)
+++ branches/soc-2010-merwin/experimental/WinTablet/Tablet.h	2010-08-12 04:03:40 UTC (rev 31274)
@@ -8,21 +8,24 @@
 #define WIN32_LEAN_AND_MEAN
 #include	<windows.h>
 #include "wintab.h"
+#include <map>
 
 // from Wacom's Utils.h
 typedef UINT ( API * WTINFOA ) ( UINT, UINT, LPVOID );
-typedef HCTX ( API * WTOPENA )( HWND, LPLOGCONTEXTA, BOOL );
+typedef HCTX ( API * WTOPENA ) ( HWND, LPLOGCONTEXTA, BOOL );
+typedef BOOL ( API * WTCLOSE ) ( HCTX );
 typedef BOOL ( API * WTQUEUESIZESET ) ( HCTX, int );
-typedef int  ( API * WTPACKETSGET ) (HCTX, int, LPVOID);
+typedef int  ( API * WTPACKETSGET ) ( HCTX, int, LPVOID );
 
 class Tablet
 	{
 	// the Wintab library
-	HINSTANCE lib_Wintab;
-//	HMODULE
+	HMODULE lib_Wintab;
+//	HINSTANCE?
 
 	// WinTab function pointers
 	WTOPENA func_Open;
+	WTCLOSE func_Close;
 	WTINFOA func_Info;
 	WTQUEUESIZESET func_QueueSizeSet;
 	WTPACKETSGET func_PacketsGet;
@@ -32,12 +35,17 @@
 	float tilt_x_scale, tilt_y_scale;
 	// others?
 
+	// book-keeping
+	std::map<HWND,HCTX> contexts;
+	HCTX contextForWindow(HWND);
+
 public:
 	Tablet();
 	~Tablet();
 	bool available();
-	HCTX openForWindow(HWND window);
-	void processPackets(HCTX context);
+	void openForWindow(HWND window);
+	void closeForWindow(HWND window);
+	void processPackets(HWND window);
 	};
 
 #endif

Modified: branches/soc-2010-merwin/intern/ghost/intern/GHOST_System.cpp
===================================================================
--- branches/soc-2010-merwin/intern/ghost/intern/GHOST_System.cpp	2010-08-12 03:37:45 UTC (rev 31273)
+++ branches/soc-2010-merwin/intern/ghost/intern/GHOST_System.cpp	2010-08-12 04:03:40 UTC (rev 31274)
@@ -291,29 +291,15 @@
 
 GHOST_TSuccess GHOST_System::exit()
 {
-	if (getFullScreen()) {
+	if (getFullScreen())
 		endFullScreen();
-	}
-	if (m_displayManager) {
-		delete m_displayManager;
-		m_displayManager = 0;
-	}
-	if (m_windowManager) {
-		delete m_windowManager;
-		m_windowManager = 0;
-	}
-	if (m_timerManager) {
-		delete m_timerManager;
-		m_timerManager = 0;
-	}
-	if (m_eventManager) {
-		delete m_eventManager;
-		m_eventManager = 0;
-	}
-    if (m_ndofManager) {
-        delete m_ndofManager;
-        m_ndofManager = 0;
-    }
+
+	delete m_displayManager;
+	delete m_windowManager;
+	delete m_timerManager;
+	delete m_eventManager;
+	delete m_ndofManager;
+
 	return GHOST_kSuccess;
 }
 

Modified: branches/soc-2010-merwin/intern/ghost/intern/GHOST_SystemWin32.cpp
===================================================================
--- branches/soc-2010-merwin/intern/ghost/intern/GHOST_SystemWin32.cpp	2010-08-12 03:37:45 UTC (rev 31273)
+++ branches/soc-2010-merwin/intern/ghost/intern/GHOST_SystemWin32.cpp	2010-08-12 04:03:40 UTC (rev 31274)
@@ -44,11 +44,11 @@
 
 // win64 doesn't define GWL_USERDATA
 #ifdef WIN32
-#ifndef GWL_USERDATA
-#define GWL_USERDATA GWLP_USERDATA
-#define GWL_WNDPROC GWLP_WNDPROC
+  #ifndef GWL_USERDATA
+    #define GWL_USERDATA GWLP_USERDATA
+    #define GWL_WNDPROC GWLP_WNDPROC
+  #endif
 #endif
-#endif
 
 #include "GHOST_Debug.h"
 #include "GHOST_DisplayManagerWin32.h"
@@ -61,44 +61,45 @@
 #include "GHOST_WindowManager.h"
 #include "GHOST_WindowWin32.h"
 #include "GHOST_NDOFManagerWin32.h"
+#include "GHOST_TabletManagerWin32.h"
 
 // Key code values not found in winuser.h
 #ifndef VK_MINUS
-#define VK_MINUS 0xBD
-#endif // VK_MINUS
+  #define VK_MINUS 0xBD
+#endif
 #ifndef VK_SEMICOLON
-#define VK_SEMICOLON 0xBA
-#endif // VK_SEMICOLON
+  #define VK_SEMICOLON 0xBA
+#endif
 #ifndef VK_PERIOD
-#define VK_PERIOD 0xBE
-#endif // VK_PERIOD
+  #define VK_PERIOD 0xBE
+#endif
 #ifndef VK_COMMA
-#define VK_COMMA 0xBC
-#endif // VK_COMMA
+  #define VK_COMMA 0xBC
+#endif
 #ifndef VK_QUOTE
-#define VK_QUOTE 0xDE
-#endif // VK_QUOTE
+  #define VK_QUOTE 0xDE
+#endif
 #ifndef VK_BACK_QUOTE
-#define VK_BACK_QUOTE 0xC0
-#endif // VK_BACK_QUOTE
+  #define VK_BACK_QUOTE 0xC0
+#endif
 #ifndef VK_SLASH
-#define VK_SLASH 0xBF
-#endif // VK_SLASH
+  #define VK_SLASH 0xBF
+#endif
 #ifndef VK_BACK_SLASH
-#define VK_BACK_SLASH 0xDC
-#endif // VK_BACK_SLASH
+  #define VK_BACK_SLASH 0xDC
+#endif
 #ifndef VK_EQUALS
-#define VK_EQUALS 0xBB
-#endif // VK_EQUALS
+  #define VK_EQUALS 0xBB
+#endif
 #ifndef VK_OPEN_BRACKET
-#define VK_OPEN_BRACKET 0xDB
-#endif // VK_OPEN_BRACKET
+  #define VK_OPEN_BRACKET 0xDB
+#endif
 #ifndef VK_CLOSE_BRACKET
-#define VK_CLOSE_BRACKET 0xDD
-#endif // VK_CLOSE_BRACKET
+  #define VK_CLOSE_BRACKET 0xDD
+#endif
 #ifndef VK_GR_LESS
-#define VK_GR_LESS 0xE2
-#endif // VK_GR_LESS
+  #define VK_GR_LESS 0xE2
+#endif
 
 
 GHOST_SystemWin32::GHOST_SystemWin32()
@@ -106,14 +107,14 @@
   m_separateLeftRight(false),
   m_separateLeftRightInitialized(false)
 {
-	m_displayManager = new GHOST_DisplayManagerWin32 ();
+	m_displayManager = new GHOST_DisplayManagerWin32;
 	GHOST_ASSERT(m_displayManager, "GHOST_SystemWin32::GHOST_SystemWin32(): m_displayManager==0\n");
 	m_displayManager->initialize();
 
 	// Require COM for GHOST_DropTargetWin32 created in GHOST_WindowWin32.
 	OleInitialize(0);
 
-	m_input_fidelity_hint = LO_FI; // just for testing...
+	m_input_fidelity_hint = HI_FI; // just for testing...
 
 	// register for RawInput devices
 	RAWINPUTDEVICE devices[1];
@@ -132,6 +133,8 @@
 {
 	// Shutdown COM
 	OleUninitialize();
+
+	delete m_tabletManager;
 }
 
 
@@ -176,16 +179,19 @@
 	GHOST_TWindowState state, GHOST_TDrawingContextType type,
 	bool stereoVisual, const GHOST_TUns16 numOfAASamples, const GHOST_TEmbedderWindowID parentWindow )
 {
-	GHOST_Window* window = 0;
-	window = new GHOST_WindowWin32 (this, title, left, top, width, height, state, type, stereoVisual, numOfAASamples);
+	GHOST_WindowWin32* window =
+		new GHOST_WindowWin32 (this, title, left, top, width, height, state, type, stereoVisual, numOfAASamples);
+
 	if (window) {
 		if (window->getValid()) {
 			m_windowManager->addWindow(window);
 			m_windowManager->setActiveWindow(window);
+			if (m_tabletManager->available())
+				window->becomeTabletAware(m_tabletManager);
 		}
 		else {
 			// An invalid window could be one that was used to test for AA
-			GHOST_Window *other_window = ((GHOST_WindowWin32*)window)->getNextWindow();
+			GHOST_WindowWin32* other_window = (GHOST_WindowWin32*) window->getNextWindow();
 
 			delete window;
 			window = 0;
@@ -329,6 +335,7 @@
 	GHOST_TSuccess success = GHOST_System::init();
 
 	m_ndofManager = new GHOST_NDOFManagerWin32(*this);
+	m_tabletManager = new GHOST_TabletManagerWin32;
 
 	/* Disable scaling on high DPI displays on Vista */
 	HMODULE user32 = ::LoadLibraryA("user32.dll");
@@ -374,14 +381,6 @@
 	return success;
 }
 
-
-GHOST_TSuccess GHOST_SystemWin32::exit()
-{
-	// [mce] since this duplicates its super, why bother?
-	return GHOST_System::exit();
-}
-
-
 GHOST_TKey GHOST_SystemWin32::convertKey(WPARAM wParam, LPARAM lParam) const
 {
 	GHOST_TKey key;
@@ -497,9 +496,17 @@
 	((GHOST_SystemWin32*)getSystem())->storeModifierKeys(newModifiers);
 }
 
+bool eventIsFromTablet()
+	{
+	// bool IsFromPen = ((GetMessageExtraInfo() & 0xFF515700) == 0xFF515700); // this only works on TabletPCs
+	return GetMessageExtraInfo() & 0x7f; // true for tablet mouse, not just pen
+	}
 
 GHOST_EventButton* GHOST_SystemWin32::processButtonEvent(GHOST_TEventType type, GHOST_IWindow *window, GHOST_TButtonMask mask)
 {
+	if (eventIsFromTablet())
+		return NULL;
+

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list