first workable version on Os X
[blender.git] / intern / ghost / intern / GHOST_NDOFManager.cpp
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
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. 
8  *
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.
13  *
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.
17  *
18  * Contributor(s): none yet.
19  *
20  * ***** END GPL LICENSE BLOCK *****
21  */
22
23
24 #include "GHOST_NDOFManager.h"
25 //#include "GHOST_WindowWin32.h"
26
27
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};
30
31 namespace
32 {
33     GHOST_NDOFLibraryInit_fp ndofLibraryInit = 0;
34     GHOST_NDOFLibraryShutdown_fp ndofLibraryShutdown = 0;
35     GHOST_NDOFDeviceOpen_fp ndofDeviceOpen = 0;
36 //    GHOST_NDOFEventHandler_fp ndofEventHandler = 0;
37     
38     
39 }
40
41
42 //typedef enum SpwRetVal (WINAPI *PFNSI_INIT) (void);
43
44 GHOST_NDOFManager::GHOST_NDOFManager()
45 {
46     m_DeviceHandle = 0;
47
48     // discover the API from the plugin
49     ndofLibraryInit = 0;
50     ndofLibraryShutdown = 0;
51     ndofDeviceOpen = 0;
52  //   ndofEventHandler = 0;
53 }
54
55 GHOST_NDOFManager::~GHOST_NDOFManager()
56 {
57     if (ndofLibraryShutdown)
58         ndofLibraryShutdown(m_DeviceHandle);
59
60     m_DeviceHandle = 0;
61 }
62
63
64 void
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)
70 {
71     ndofLibraryInit = setNdofLibraryInit;
72     ndofLibraryShutdown = setNdofLibraryShutdown;
73     ndofDeviceOpen = setNdofDeviceOpen;
74 //       original patch    
75 //    ndofEventHandler = setNdofEventHandler;
76
77     if (ndofLibraryInit  && ndofDeviceOpen)
78     {
79        printf("%i client \n", ndofLibraryInit());
80                 m_DeviceHandle = ndofDeviceOpen((void *)&currentNdofValues);    
81         }
82     
83     
84 /*
85     if (ndofDeviceOpen)
86     {
87         GHOST_WindowWin32* win32 = (GHOST_WindowWin32*) window; // GHOST_IWindow doesn't have RTTI...
88         if (win32 != 0)
89         {
90             m_DeviceHandle = ndofDeviceOpen(win32->getHWND());
91         }
92     }
93     */
94 }
95
96
97 /** original patch only */
98 /*  
99 GHOST_TEventNDOFData*
100 GHOST_NDOFManager::handle(unsigned int message, unsigned int* wParam, unsigned long* lParam)
101 {
102     static GHOST_TEventNDOFData sbdata;
103     int handled = 0;
104     if (ndofEventHandler && m_DeviceHandle != 0)
105     {
106         handled = ndofEventHandler(&sbdata.tx, m_DeviceHandle, message, wParam, lParam);
107     }
108     printf("handled %i\n", handled);
109     return handled ? &sbdata : 0;
110 }
111 */
112
113 bool 
114 GHOST_NDOFManager::available() 
115
116     return m_DeviceHandle != 0; 
117 }
118
119 bool 
120 GHOST_NDOFManager::event_present() 
121
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);
127         return true;
128         }else
129         return false;
130
131 }
132
133 void        GHOST_NDOFManager::GHOST_NDOFGetDatas(GHOST_TEventNDOFData &datas)
134 {
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;
146
147 }
148
149 /*
150 //#ifdef
151 OSStatus GHOST_SystemCarbon::blendEventHandlerProc(EventHandlerCallRef handler, EventRef event, void* userData)
152 {
153 }
154
155 */