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