2 * ***** BEGIN GPL LICENSE BLOCK *****
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 * Contributor(s): none yet.
20 * ***** END GPL LICENSE BLOCK *****
24 #include "GHOST_NDOFManager.h"
25 //#include "GHOST_WindowWin32.h"
28 // the variable is outside the class because it must be accessed from plugin
29 static volatile GHOST_TEventNDOFData currentNdofValues = {0,0,0,0,0,0,0,0,0,0,0};
33 GHOST_NDOFLibraryInit_fp ndofLibraryInit = 0;
34 GHOST_NDOFLibraryShutdown_fp ndofLibraryShutdown = 0;
35 GHOST_NDOFDeviceOpen_fp ndofDeviceOpen = 0;
36 // GHOST_NDOFEventHandler_fp ndofEventHandler = 0;
42 //typedef enum SpwRetVal (WINAPI *PFNSI_INIT) (void);
44 GHOST_NDOFManager::GHOST_NDOFManager()
48 // discover the API from the plugin
50 ndofLibraryShutdown = 0;
52 // ndofEventHandler = 0;
55 GHOST_NDOFManager::~GHOST_NDOFManager()
57 if (ndofLibraryShutdown)
58 ndofLibraryShutdown(m_DeviceHandle);
65 GHOST_NDOFManager::deviceOpen(GHOST_IWindow* window,
66 GHOST_NDOFLibraryInit_fp setNdofLibraryInit,
67 GHOST_NDOFLibraryShutdown_fp setNdofLibraryShutdown,
68 GHOST_NDOFDeviceOpen_fp setNdofDeviceOpen)
69 // GHOST_NDOFEventHandler_fp setNdofEventHandler)
71 ndofLibraryInit = setNdofLibraryInit;
72 ndofLibraryShutdown = setNdofLibraryShutdown;
73 ndofDeviceOpen = setNdofDeviceOpen;
75 // ndofEventHandler = setNdofEventHandler;
77 if (ndofLibraryInit && ndofDeviceOpen)
79 printf("%i client \n", ndofLibraryInit());
80 m_DeviceHandle = ndofDeviceOpen((void *)¤tNdofValues);
87 GHOST_WindowWin32* win32 = (GHOST_WindowWin32*) window; // GHOST_IWindow doesn't have RTTI...
90 m_DeviceHandle = ndofDeviceOpen(win32->getHWND());
97 /** original patch only */
100 GHOST_NDOFManager::handle(unsigned int message, unsigned int* wParam, unsigned long* lParam)
102 static GHOST_TEventNDOFData sbdata;
104 if (ndofEventHandler && m_DeviceHandle != 0)
106 handled = ndofEventHandler(&sbdata.tx, m_DeviceHandle, message, wParam, lParam);
108 printf("handled %i\n", handled);
109 return handled ? &sbdata : 0;
114 GHOST_NDOFManager::available()
116 return m_DeviceHandle != 0;
120 GHOST_NDOFManager::event_present()
122 if( currentNdofValues.changed >0) {
123 printf("time %llu but%u x%i y%i z%i rx%i ry%i rz%i \n" ,
124 currentNdofValues.time, currentNdofValues.buttons,
125 currentNdofValues.tx,currentNdofValues.ty,currentNdofValues.tz,
126 currentNdofValues.rx,currentNdofValues.ry,currentNdofValues.rz);
133 void GHOST_NDOFManager::GHOST_NDOFGetDatas(GHOST_TEventNDOFData &datas)
135 datas.tx = currentNdofValues.tx;
136 datas.ty = currentNdofValues.ty;
137 datas.tz = currentNdofValues.tz;
138 datas.rx = currentNdofValues.rx;
139 datas.ry = currentNdofValues.ry;
140 datas.rz = currentNdofValues.rz;
141 datas.buttons = currentNdofValues.buttons;
142 datas.client = currentNdofValues.client;
143 datas.address = currentNdofValues.address;
144 datas.time = currentNdofValues.time;
145 datas.delta = currentNdofValues.delta;
151 OSStatus GHOST_SystemCarbon::blendEventHandlerProc(EventHandlerCallRef handler, EventRef event, void* userData)