commiting fixes from Ettore for building on linux & win 32
[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
26
27 // the variable is outside the class because it must be accessed from plugin
28 static volatile GHOST_TEventNDOFData currentNdofValues = {0,0,0,0,0,0,0,0,0,0,0};
29
30 #if !defined(_WIN32) && !defined(__APPLE__)
31 #include "GHOST_SystemX11.h"
32 #endif
33
34 namespace
35 {
36     GHOST_NDOFLibraryInit_fp ndofLibraryInit = 0;
37     GHOST_NDOFLibraryShutdown_fp ndofLibraryShutdown = 0;
38     GHOST_NDOFDeviceOpen_fp ndofDeviceOpen = 0;
39 }
40
41 GHOST_NDOFManager::GHOST_NDOFManager()
42 {
43     m_DeviceHandle = 0;
44
45     // discover the API from the plugin
46     ndofLibraryInit = 0;
47     ndofLibraryShutdown = 0;
48     ndofDeviceOpen = 0;
49 }
50
51 GHOST_NDOFManager::~GHOST_NDOFManager()
52 {
53     if (ndofLibraryShutdown)
54         ndofLibraryShutdown(m_DeviceHandle);
55
56     m_DeviceHandle = 0;
57 }
58
59
60 void
61 GHOST_NDOFManager::deviceOpen(GHOST_IWindow* window,
62         GHOST_NDOFLibraryInit_fp setNdofLibraryInit, 
63         GHOST_NDOFLibraryShutdown_fp setNdofLibraryShutdown,
64         GHOST_NDOFDeviceOpen_fp setNdofDeviceOpen)
65 {
66     ndofLibraryInit = setNdofLibraryInit;
67     ndofLibraryShutdown = setNdofLibraryShutdown;
68     ndofDeviceOpen = setNdofDeviceOpen;
69
70     if (ndofLibraryInit  && ndofDeviceOpen)
71     {
72        printf("%i client \n", ndofLibraryInit());
73                 #if defined(_WIN32) || defined(__APPLE__)
74                         m_DeviceHandle = ndofDeviceOpen((void *)&currentNdofValues);    
75                 #else
76                         GHOST_SystemX11 *sys;
77                         sys = static_cast<GHOST_SystemX11*>(GHOST_ISystem::getSystem());
78                         void *ndofInfo = sys->prepareNdofInfo(&currentNdofValues);
79                         m_DeviceHandle = ndofDeviceOpen(ndofInfo);
80                 #endif
81         }
82 }
83
84
85 /** original patch only */
86 /*  
87 GHOST_TEventNDOFData*
88 GHOST_NDOFManager::handle(unsigned int message, unsigned int* wParam, unsigned long* lParam)
89 {
90     static GHOST_TEventNDOFData sbdata;
91     int handled = 0;
92     if (ndofEventHandler && m_DeviceHandle != 0)
93     {
94         handled = ndofEventHandler(&sbdata.tx, m_DeviceHandle, message, wParam, lParam);
95     }
96     printf("handled %i\n", handled);
97     return handled ? &sbdata : 0;
98 }
99 */
100
101 bool 
102 GHOST_NDOFManager::available() const
103
104     return m_DeviceHandle != 0; 
105 }
106
107 bool 
108 GHOST_NDOFManager::event_present() const
109
110     if( currentNdofValues.changed >0) {
111                 printf("time %llu but%u x%i y%i z%i rx%i ry%i rz%i \n"  ,                       
112                                 currentNdofValues.time,         currentNdofValues.buttons,
113                                 currentNdofValues.tx,currentNdofValues.ty,currentNdofValues.tz,
114                                 currentNdofValues.rx,currentNdofValues.ry,currentNdofValues.rz);
115         return true;
116         }else
117         return false;
118
119 }
120
121 void        GHOST_NDOFManager::GHOST_NDOFGetDatas(GHOST_TEventNDOFData &datas) const
122 {
123         datas.tx = currentNdofValues.tx;
124         datas.ty = currentNdofValues.ty;
125         datas.tz = currentNdofValues.tz;
126         datas.rx = currentNdofValues.rx;
127         datas.ry = currentNdofValues.ry;
128         datas.rz = currentNdofValues.rz;
129         datas.buttons = currentNdofValues.buttons;
130         datas.client = currentNdofValues.client;
131         datas.address = currentNdofValues.address;
132         datas.time = currentNdofValues.time;
133         datas.delta = currentNdofValues.delta;
134 }