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