]> git.saurik.com Git - wxWidgets.git/blob - src/msw/joystick.cpp
Symantec makefile fixes (for OLE files)
[wxWidgets.git] / src / msw / joystick.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: joystick.cpp
3 // Purpose: wxJoystick class
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 04/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "joystick.h"
14 #endif
15
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
18
19 #ifdef __BORLANDC__
20 #pragma hdrstop
21 #endif
22
23 #include "wx/string.h"
24 #include "wx/window.h"
25 #include "wx/msw/private.h"
26
27 #if !defined( __GNUWIN32__ ) || defined(wxUSE_NORLANDER_HEADERS)
28 #include <mmsystem.h>
29 #endif
30
31 #if !defined(__WIN32__) && !defined(_MMRESULT_)
32 typedef UINT MMRESULT;
33 #endif
34
35 #ifndef __TWIN32__
36 #ifdef __GNUWIN32__
37 #ifndef wxUSE_NORLANDER_HEADERS
38 #include <wx/msw/gnuwin32/extra.h>
39 #endif
40 #endif
41 #endif
42
43 // Why doesn't BC++ have joyGetPosEx?
44 #if !defined(__WIN32__) || defined(__BORLANDC__) || defined(__TWIN32__)
45 #define NO_JOYGETPOSEX
46 #endif
47
48 #include <wx/window.h>
49 #include <wx/msw/joystick.h>
50
51 IMPLEMENT_DYNAMIC_CLASS(wxJoystick, wxObject)
52
53 // Attributes
54 ////////////////////////////////////////////////////////////////////////////
55
56 wxPoint wxJoystick::GetPosition(void) const
57 {
58 JOYINFO joyInfo;
59 MMRESULT res = joyGetPos(m_joystick, & joyInfo);
60 if (res == JOYERR_NOERROR )
61 return wxPoint(joyInfo.wXpos, joyInfo.wYpos);
62 else
63 return wxPoint(0, 0);
64 }
65
66 int wxJoystick::GetZPosition(void) const
67 {
68 JOYINFO joyInfo;
69 MMRESULT res = joyGetPos(m_joystick, & joyInfo);
70 if (res == JOYERR_NOERROR )
71 return joyInfo.wZpos;
72 else
73 return 0;
74 }
75
76 int wxJoystick::GetButtonState(void) const
77 {
78 JOYINFO joyInfo;
79 MMRESULT res = joyGetPos(m_joystick, & joyInfo);
80 if (res == JOYERR_NOERROR )
81 {
82 int buttons = 0;
83
84 if (joyInfo.wButtons & JOY_BUTTON1)
85 buttons |= wxJOY_BUTTON1;
86 if (joyInfo.wButtons & JOY_BUTTON2)
87 buttons |= wxJOY_BUTTON2;
88 if (joyInfo.wButtons & JOY_BUTTON3)
89 buttons |= wxJOY_BUTTON3;
90 if (joyInfo.wButtons & JOY_BUTTON4)
91 buttons |= wxJOY_BUTTON4;
92 return buttons;
93 }
94 else
95 return 0;
96 }
97
98 int wxJoystick::GetPOVPosition(void) const
99 {
100 #ifndef NO_JOYGETPOSEX
101 JOYINFOEX joyInfo;
102 joyInfo.dwFlags = JOY_RETURNPOV;
103 MMRESULT res = joyGetPosEx(m_joystick, & joyInfo);
104 if (res == JOYERR_NOERROR )
105 {
106 return joyInfo.dwPOV;
107 }
108 else
109 return 0;
110 #else
111 return 0;
112 #endif
113 }
114
115 int wxJoystick::GetPOVCTSPosition(void) const
116 {
117 #ifndef NO_JOYGETPOSEX
118 JOYINFOEX joyInfo;
119 joyInfo.dwFlags = JOY_RETURNPOVCTS;
120 MMRESULT res = joyGetPosEx(m_joystick, & joyInfo);
121 if (res == JOYERR_NOERROR )
122 {
123 return joyInfo.dwPOV;
124 }
125 else
126 return 0;
127 #else
128 return 0;
129 #endif
130 }
131
132 int wxJoystick::GetRudderPosition(void) const
133 {
134 #ifndef NO_JOYGETPOSEX
135 JOYINFOEX joyInfo;
136 joyInfo.dwFlags = JOY_RETURNR;
137 MMRESULT res = joyGetPosEx(m_joystick, & joyInfo);
138 if (res == JOYERR_NOERROR )
139 {
140 return joyInfo.dwRpos;
141 }
142 else
143 return 0;
144 #else
145 return 0;
146 #endif
147 }
148
149 int wxJoystick::GetUPosition(void) const
150 {
151 #ifndef NO_JOYGETPOSEX
152 JOYINFOEX joyInfo;
153 joyInfo.dwFlags = JOY_RETURNU;
154 MMRESULT res = joyGetPosEx(m_joystick, & joyInfo);
155 if (res == JOYERR_NOERROR )
156 {
157 return joyInfo.dwUpos;
158 }
159 else
160 return 0;
161 #else
162 return 0;
163 #endif
164 }
165
166 int wxJoystick::GetVPosition(void) const
167 {
168 #ifndef NO_JOYGETPOSEX
169 JOYINFOEX joyInfo;
170 joyInfo.dwFlags = JOY_RETURNV;
171 MMRESULT res = joyGetPosEx(m_joystick, & joyInfo);
172 if (res == JOYERR_NOERROR )
173 {
174 return joyInfo.dwVpos;
175 }
176 else
177 return 0;
178 #else
179 return 0;
180 #endif
181 }
182
183 int wxJoystick::GetMovementThreshold(void) const
184 {
185 UINT thresh = 0;
186 MMRESULT res = joyGetThreshold(m_joystick, & thresh);
187 if (res == JOYERR_NOERROR )
188 {
189 return thresh;
190 }
191 else
192 return 0;
193 }
194
195 void wxJoystick::SetMovementThreshold(int threshold)
196 {
197 UINT thresh = threshold;
198 joySetThreshold(m_joystick, thresh);
199 }
200
201 // Capabilities
202 ////////////////////////////////////////////////////////////////////////////
203
204 bool wxJoystick::IsOk(void) const
205 {
206 JOYINFO joyInfo;
207 MMRESULT res = joyGetPos(m_joystick, & joyInfo);
208 return ((joyGetNumDevs() > 0) || (res == JOYERR_NOERROR));
209 }
210
211 int wxJoystick::GetNumberJoysticks(void) const
212 {
213 return joyGetNumDevs();
214 }
215
216 int wxJoystick::GetManufacturerId(void) const
217 {
218 JOYCAPS joyCaps;
219 if (joyGetDevCaps(m_joystick, & joyCaps, sizeof(JOYCAPS)) != JOYERR_NOERROR)
220 return 0;
221 else
222 return joyCaps.wMid;
223 }
224
225 int wxJoystick::GetProductId(void) const
226 {
227 JOYCAPS joyCaps;
228 if (joyGetDevCaps(m_joystick, & joyCaps, sizeof(JOYCAPS)) != JOYERR_NOERROR)
229 return 0;
230 else
231 return joyCaps.wPid;
232 }
233
234 wxString wxJoystick::GetProductName(void) const
235 {
236 JOYCAPS joyCaps;
237 if (joyGetDevCaps(m_joystick, & joyCaps, sizeof(JOYCAPS)) != JOYERR_NOERROR)
238 return wxString("");
239 else
240 return wxString(joyCaps.szPname);
241 }
242
243 int wxJoystick::GetXMin(void) const
244 {
245 JOYCAPS joyCaps;
246 if (joyGetDevCaps(m_joystick, & joyCaps, sizeof(JOYCAPS)) != JOYERR_NOERROR)
247 return 0;
248 else
249 return joyCaps.wXmin;
250 }
251
252 int wxJoystick::GetYMin(void) const
253 {
254 JOYCAPS joyCaps;
255 if (joyGetDevCaps(m_joystick, & joyCaps, sizeof(JOYCAPS)) != JOYERR_NOERROR)
256 return 0;
257 else
258 return joyCaps.wYmin;
259 }
260
261 int wxJoystick::GetZMin(void) const
262 {
263 JOYCAPS joyCaps;
264 if (joyGetDevCaps(m_joystick, & joyCaps, sizeof(JOYCAPS)) != JOYERR_NOERROR)
265 return 0;
266 else
267 return joyCaps.wZmin;
268 }
269
270 int wxJoystick::GetXMax(void) const
271 {
272 JOYCAPS joyCaps;
273 if (joyGetDevCaps(m_joystick, & joyCaps, sizeof(JOYCAPS)) != JOYERR_NOERROR)
274 return 0;
275 else
276 return joyCaps.wXmax;
277 }
278
279 int wxJoystick::GetYMax(void) const
280 {
281 JOYCAPS joyCaps;
282 if (joyGetDevCaps(m_joystick, & joyCaps, sizeof(JOYCAPS)) != JOYERR_NOERROR)
283 return 0;
284 else
285 return joyCaps.wYmax;
286 }
287
288 int wxJoystick::GetZMax(void) const
289 {
290 JOYCAPS joyCaps;
291 if (joyGetDevCaps(m_joystick, & joyCaps, sizeof(JOYCAPS)) != JOYERR_NOERROR)
292 return 0;
293 else
294 return joyCaps.wZmax;
295 }
296
297 int wxJoystick::GetNumberButtons(void) const
298 {
299 JOYCAPS joyCaps;
300 if (joyGetDevCaps(m_joystick, & joyCaps, sizeof(JOYCAPS)) != JOYERR_NOERROR)
301 return 0;
302 else
303 return joyCaps.wNumButtons;
304 }
305
306 int wxJoystick::GetNumberAxes(void) const
307 {
308 #if defined(__WIN32__) && !defined(__TWIN32__)
309 JOYCAPS joyCaps;
310 if (joyGetDevCaps(m_joystick, & joyCaps, sizeof(JOYCAPS)) != JOYERR_NOERROR)
311 return 0;
312 else
313 return joyCaps.wNumAxes;
314 #else
315 return 0;
316 #endif
317 }
318
319 int wxJoystick::GetMaxButtons(void) const
320 {
321 #if defined(__WIN32__) && !defined(__TWIN32__)
322 JOYCAPS joyCaps;
323 if (joyGetDevCaps(m_joystick, & joyCaps, sizeof(JOYCAPS)) != JOYERR_NOERROR)
324 return 0;
325 else
326 return joyCaps.wMaxButtons;
327 #else
328 return 0;
329 #endif
330 }
331
332 int wxJoystick::GetMaxAxes(void) const
333 {
334 #if defined(__WIN32__) && !defined(__TWIN32__)
335 JOYCAPS joyCaps;
336 if (joyGetDevCaps(m_joystick, & joyCaps, sizeof(JOYCAPS)) != JOYERR_NOERROR)
337 return 0;
338 else
339 return joyCaps.wMaxAxes;
340 #else
341 return 0;
342 #endif
343 }
344
345 int wxJoystick::GetPollingMin(void) const
346 {
347 JOYCAPS joyCaps;
348 if (joyGetDevCaps(m_joystick, & joyCaps, sizeof(JOYCAPS)) != JOYERR_NOERROR)
349 return 0;
350 else
351 return joyCaps.wPeriodMin;
352 }
353
354 int wxJoystick::GetPollingMax(void) const
355 {
356 JOYCAPS joyCaps;
357 if (joyGetDevCaps(m_joystick, & joyCaps, sizeof(JOYCAPS)) != JOYERR_NOERROR)
358 return 0;
359 else
360 return joyCaps.wPeriodMax;
361 }
362
363 int wxJoystick::GetRudderMin(void) const
364 {
365 #if defined(__WIN32__) && !defined(__TWIN32__)
366 JOYCAPS joyCaps;
367 if (joyGetDevCaps(m_joystick, & joyCaps, sizeof(JOYCAPS)) != JOYERR_NOERROR)
368 return 0;
369 else
370 return joyCaps.wRmin;
371 #else
372 return 0;
373 #endif
374 }
375
376 int wxJoystick::GetRudderMax(void) const
377 {
378 #if defined(__WIN32__) && !defined(__TWIN32__)
379 JOYCAPS joyCaps;
380 if (joyGetDevCaps(m_joystick, & joyCaps, sizeof(JOYCAPS)) != JOYERR_NOERROR)
381 return 0;
382 else
383 return joyCaps.wRmax;
384 #else
385 return 0;
386 #endif
387 }
388
389 int wxJoystick::GetUMin(void) const
390 {
391 #if defined(__WIN32__) && !defined(__TWIN32__)
392 JOYCAPS joyCaps;
393 if (joyGetDevCaps(m_joystick, & joyCaps, sizeof(JOYCAPS)) != JOYERR_NOERROR)
394 return 0;
395 else
396 return joyCaps.wUmin;
397 #else
398 return 0;
399 #endif
400 }
401
402 int wxJoystick::GetUMax(void) const
403 {
404 #if defined(__WIN32__) && !defined(__TWIN32__)
405 JOYCAPS joyCaps;
406 if (joyGetDevCaps(m_joystick, & joyCaps, sizeof(JOYCAPS)) != JOYERR_NOERROR)
407 return 0;
408 else
409 return joyCaps.wUmax;
410 #else
411 return 0;
412 #endif
413 }
414
415 int wxJoystick::GetVMin(void) const
416 {
417 #if defined(__WIN32__) && !defined(__TWIN32__)
418 JOYCAPS joyCaps;
419 if (joyGetDevCaps(m_joystick, & joyCaps, sizeof(JOYCAPS)) != JOYERR_NOERROR)
420 return 0;
421 else
422 return joyCaps.wVmin;
423 #else
424 return 0;
425 #endif
426 }
427
428 int wxJoystick::GetVMax(void) const
429 {
430 #if defined(__WIN32__) && !defined(__TWIN32__)
431 JOYCAPS joyCaps;
432 if (joyGetDevCaps(m_joystick, & joyCaps, sizeof(JOYCAPS)) != JOYERR_NOERROR)
433 return 0;
434 else
435 return joyCaps.wVmax;
436 #else
437 return 0;
438 #endif
439 }
440
441
442 bool wxJoystick::HasRudder(void) const
443 {
444 #if defined(__WIN32__) && !defined(__TWIN32__)
445 JOYCAPS joyCaps;
446 if (joyGetDevCaps(m_joystick, & joyCaps, sizeof(JOYCAPS)) != JOYERR_NOERROR)
447 return FALSE;
448 else
449 return ((joyCaps.wCaps & JOYCAPS_HASR) == JOYCAPS_HASR);
450 #else
451 return FALSE;
452 #endif
453 }
454
455 bool wxJoystick::HasZ(void) const
456 {
457 #if defined(__WIN32__) && !defined(__TWIN32__)
458 JOYCAPS joyCaps;
459 if (joyGetDevCaps(m_joystick, & joyCaps, sizeof(JOYCAPS)) != JOYERR_NOERROR)
460 return FALSE;
461 else
462 return ((joyCaps.wCaps & JOYCAPS_HASZ) == JOYCAPS_HASZ);
463 #else
464 return FALSE;
465 #endif
466 }
467
468 bool wxJoystick::HasU(void) const
469 {
470 #if defined(__WIN32__) && !defined(__TWIN32__)
471 JOYCAPS joyCaps;
472 if (joyGetDevCaps(m_joystick, & joyCaps, sizeof(JOYCAPS)) != JOYERR_NOERROR)
473 return FALSE;
474 else
475 return ((joyCaps.wCaps & JOYCAPS_HASU) == JOYCAPS_HASU);
476 #else
477 return FALSE;
478 #endif
479 }
480
481 bool wxJoystick::HasV(void) const
482 {
483 #if defined(__WIN32__) && !defined(__TWIN32__)
484 JOYCAPS joyCaps;
485 if (joyGetDevCaps(m_joystick, & joyCaps, sizeof(JOYCAPS)) != JOYERR_NOERROR)
486 return FALSE;
487 else
488 return ((joyCaps.wCaps & JOYCAPS_HASV) == JOYCAPS_HASV);
489 #else
490 return FALSE;
491 #endif
492 }
493
494 bool wxJoystick::HasPOV(void) const
495 {
496 #if defined(__WIN32__) && !defined(__TWIN32__)
497 JOYCAPS joyCaps;
498 if (joyGetDevCaps(m_joystick, & joyCaps, sizeof(JOYCAPS)) != JOYERR_NOERROR)
499 return FALSE;
500 else
501 return ((joyCaps.wCaps & JOYCAPS_HASPOV) == JOYCAPS_HASPOV);
502 #else
503 return FALSE;
504 #endif
505 }
506
507 bool wxJoystick::HasPOV4Dir(void) const
508 {
509 #if defined(__WIN32__) && !defined(__TWIN32__)
510 JOYCAPS joyCaps;
511 if (joyGetDevCaps(m_joystick, & joyCaps, sizeof(JOYCAPS)) != JOYERR_NOERROR)
512 return FALSE;
513 else
514 return ((joyCaps.wCaps & JOYCAPS_POV4DIR) == JOYCAPS_POV4DIR);
515 #else
516 return FALSE;
517 #endif
518 }
519
520 bool wxJoystick::HasPOVCTS(void) const
521 {
522 #if defined(__WIN32__) && !defined(__TWIN32__)
523 JOYCAPS joyCaps;
524 if (joyGetDevCaps(m_joystick, & joyCaps, sizeof(JOYCAPS)) != JOYERR_NOERROR)
525 return FALSE;
526 else
527 return ((joyCaps.wCaps & JOYCAPS_POVCTS) == JOYCAPS_POVCTS);
528 #else
529 return FALSE;
530 #endif
531 }
532
533 // Operations
534 ////////////////////////////////////////////////////////////////////////////
535
536 bool wxJoystick::SetCapture(wxWindow* win, int pollingFreq)
537 {
538 BOOL changed = (pollingFreq == 0);
539 MMRESULT res = joySetCapture((HWND) win->GetHWND(), m_joystick, pollingFreq, changed);
540 return (res == JOYERR_NOERROR);
541 }
542
543 bool wxJoystick::ReleaseCapture(void)
544 {
545 MMRESULT res = joyReleaseCapture(m_joystick);
546 return (res == JOYERR_NOERROR);
547 }
548