]>
Commit | Line | Data |
---|---|---|
2bda0e17 KB |
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$ | |
6c9a19aa | 8 | // Copyright: (c) Julian Smart |
65571936 | 9 | // Licence: wxWindows licence |
2bda0e17 KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
2bda0e17 KB |
12 | // For compilers that support precompilation, includes "wx.h". |
13 | #include "wx/wxprec.h" | |
14 | ||
a3b46648 | 15 | #ifdef __BORLANDC__ |
2bda0e17 KB |
16 | #pragma hdrstop |
17 | #endif | |
18 | ||
0c589ad0 BM |
19 | #include "wx/string.h" |
20 | #include "wx/window.h" | |
21 | #include "wx/msw/private.h" | |
2bda0e17 | 22 | |
ae090fdb | 23 | #if !defined(__GNUWIN32_OLD__) || defined(__CYGWIN10__) |
c42404a5 | 24 | #include <mmsystem.h> |
2bda0e17 KB |
25 | #endif |
26 | ||
2bda0e17 | 27 | // Why doesn't BC++ have joyGetPosEx? |
b39dbf34 | 28 | #if !defined(__WIN32__) || defined(__BORLANDC__) |
2bda0e17 KB |
29 | #define NO_JOYGETPOSEX |
30 | #endif | |
31 | ||
3096bd2f | 32 | #include "wx/window.h" |
c9ee46c3 | 33 | #include "wx/msw/registry.h" |
3096bd2f | 34 | #include "wx/msw/joystick.h" |
2bda0e17 | 35 | |
c9ee46c3 VZ |
36 | #include <regstr.h> |
37 | ||
2bda0e17 KB |
38 | IMPLEMENT_DYNAMIC_CLASS(wxJoystick, wxObject) |
39 | ||
40 | // Attributes | |
41 | //////////////////////////////////////////////////////////////////////////// | |
42 | ||
131f9d9b | 43 | /** |
598ddd96 WS |
44 | johan@linkdata.se 2002-08-20: |
45 | Now returns only valid, functioning | |
46 | joysticks, counting from the first | |
47 | available and upwards. | |
131f9d9b | 48 | */ |
c892a77e | 49 | wxJoystick::wxJoystick(int joystick) |
131f9d9b JS |
50 | { |
51 | JOYINFO joyInfo; | |
598ddd96 WS |
52 | int i, maxsticks; |
53 | ||
54 | maxsticks = joyGetNumDevs(); | |
55 | for( i=0; i<maxsticks; i++ ) | |
56 | { | |
57 | if( joyGetPos(i, & joyInfo) == JOYERR_NOERROR ) | |
58 | { | |
59 | if( !joystick ) | |
60 | { | |
61 | /* Found the one we want, store actual OS id and return */ | |
62 | m_joystick = i; | |
63 | return; | |
64 | } | |
65 | joystick --; | |
66 | } | |
67 | } | |
68 | ||
69 | /* No such joystick, return ID 0 */ | |
70 | m_joystick = 0; | |
71 | return; | |
ae199d6e | 72 | } |
131f9d9b | 73 | |
c42404a5 | 74 | wxPoint wxJoystick::GetPosition() const |
2bda0e17 KB |
75 | { |
76 | JOYINFO joyInfo; | |
77 | MMRESULT res = joyGetPos(m_joystick, & joyInfo); | |
78 | if (res == JOYERR_NOERROR ) | |
79 | return wxPoint(joyInfo.wXpos, joyInfo.wYpos); | |
80 | else | |
c47addef | 81 | return wxPoint(0,0); |
2bda0e17 KB |
82 | } |
83 | ||
c42404a5 | 84 | int wxJoystick::GetZPosition() const |
2bda0e17 KB |
85 | { |
86 | JOYINFO joyInfo; | |
87 | MMRESULT res = joyGetPos(m_joystick, & joyInfo); | |
88 | if (res == JOYERR_NOERROR ) | |
89 | return joyInfo.wZpos; | |
90 | else | |
91 | return 0; | |
92 | } | |
93 | ||
131f9d9b | 94 | /** |
598ddd96 WS |
95 | johan@linkdata.se 2002-08-20: |
96 | Return a bitmap with all button states in it, | |
97 | like the GTK version does and Win32 does. | |
131f9d9b | 98 | */ |
c42404a5 | 99 | int wxJoystick::GetButtonState() const |
2bda0e17 KB |
100 | { |
101 | JOYINFO joyInfo; | |
102 | MMRESULT res = joyGetPos(m_joystick, & joyInfo); | |
103 | if (res == JOYERR_NOERROR ) | |
104 | { | |
598ddd96 | 105 | return joyInfo.wButtons; |
131f9d9b | 106 | #if 0 |
2bda0e17 KB |
107 | int buttons = 0; |
108 | ||
109 | if (joyInfo.wButtons & JOY_BUTTON1) | |
110 | buttons |= wxJOY_BUTTON1; | |
111 | if (joyInfo.wButtons & JOY_BUTTON2) | |
112 | buttons |= wxJOY_BUTTON2; | |
113 | if (joyInfo.wButtons & JOY_BUTTON3) | |
114 | buttons |= wxJOY_BUTTON3; | |
115 | if (joyInfo.wButtons & JOY_BUTTON4) | |
116 | buttons |= wxJOY_BUTTON4; | |
131f9d9b | 117 | |
2bda0e17 | 118 | return buttons; |
131f9d9b | 119 | #endif |
2bda0e17 KB |
120 | } |
121 | else | |
122 | return 0; | |
123 | } | |
124 | ||
131f9d9b | 125 | /** |
598ddd96 WS |
126 | JLI 2002-08-20: |
127 | Returns -1 to signify error. | |
131f9d9b | 128 | */ |
c42404a5 | 129 | int wxJoystick::GetPOVPosition() const |
2bda0e17 KB |
130 | { |
131 | #ifndef NO_JOYGETPOSEX | |
132 | JOYINFOEX joyInfo; | |
133 | joyInfo.dwFlags = JOY_RETURNPOV; | |
b9f933ab | 134 | joyInfo.dwSize = sizeof(joyInfo); |
2bda0e17 KB |
135 | MMRESULT res = joyGetPosEx(m_joystick, & joyInfo); |
136 | if (res == JOYERR_NOERROR ) | |
137 | { | |
138 | return joyInfo.dwPOV; | |
139 | } | |
140 | else | |
131f9d9b | 141 | return -1; |
2bda0e17 | 142 | #else |
131f9d9b | 143 | return -1; |
2bda0e17 KB |
144 | #endif |
145 | } | |
146 | ||
131f9d9b | 147 | /** |
598ddd96 WS |
148 | johan@linkdata.se 2002-08-20: |
149 | Returns -1 to signify error. | |
131f9d9b | 150 | */ |
c42404a5 | 151 | int wxJoystick::GetPOVCTSPosition() const |
2bda0e17 KB |
152 | { |
153 | #ifndef NO_JOYGETPOSEX | |
154 | JOYINFOEX joyInfo; | |
155 | joyInfo.dwFlags = JOY_RETURNPOVCTS; | |
b9f933ab | 156 | joyInfo.dwSize = sizeof(joyInfo); |
2bda0e17 KB |
157 | MMRESULT res = joyGetPosEx(m_joystick, & joyInfo); |
158 | if (res == JOYERR_NOERROR ) | |
159 | { | |
160 | return joyInfo.dwPOV; | |
161 | } | |
162 | else | |
131f9d9b | 163 | return -1; |
2bda0e17 | 164 | #else |
131f9d9b | 165 | return -1; |
2bda0e17 KB |
166 | #endif |
167 | } | |
168 | ||
c42404a5 | 169 | int wxJoystick::GetRudderPosition() const |
2bda0e17 KB |
170 | { |
171 | #ifndef NO_JOYGETPOSEX | |
172 | JOYINFOEX joyInfo; | |
173 | joyInfo.dwFlags = JOY_RETURNR; | |
b9f933ab | 174 | joyInfo.dwSize = sizeof(joyInfo); |
2bda0e17 KB |
175 | MMRESULT res = joyGetPosEx(m_joystick, & joyInfo); |
176 | if (res == JOYERR_NOERROR ) | |
177 | { | |
178 | return joyInfo.dwRpos; | |
179 | } | |
180 | else | |
181 | return 0; | |
182 | #else | |
183 | return 0; | |
184 | #endif | |
185 | } | |
186 | ||
c42404a5 | 187 | int wxJoystick::GetUPosition() const |
2bda0e17 KB |
188 | { |
189 | #ifndef NO_JOYGETPOSEX | |
190 | JOYINFOEX joyInfo; | |
191 | joyInfo.dwFlags = JOY_RETURNU; | |
b9f933ab | 192 | joyInfo.dwSize = sizeof(joyInfo); |
2bda0e17 KB |
193 | MMRESULT res = joyGetPosEx(m_joystick, & joyInfo); |
194 | if (res == JOYERR_NOERROR ) | |
195 | { | |
196 | return joyInfo.dwUpos; | |
197 | } | |
198 | else | |
199 | return 0; | |
200 | #else | |
201 | return 0; | |
202 | #endif | |
203 | } | |
204 | ||
c42404a5 | 205 | int wxJoystick::GetVPosition() const |
2bda0e17 KB |
206 | { |
207 | #ifndef NO_JOYGETPOSEX | |
208 | JOYINFOEX joyInfo; | |
209 | joyInfo.dwFlags = JOY_RETURNV; | |
b9f933ab | 210 | joyInfo.dwSize = sizeof(joyInfo); |
2bda0e17 KB |
211 | MMRESULT res = joyGetPosEx(m_joystick, & joyInfo); |
212 | if (res == JOYERR_NOERROR ) | |
213 | { | |
214 | return joyInfo.dwVpos; | |
215 | } | |
216 | else | |
217 | return 0; | |
218 | #else | |
219 | return 0; | |
220 | #endif | |
221 | } | |
222 | ||
c42404a5 | 223 | int wxJoystick::GetMovementThreshold() const |
2bda0e17 KB |
224 | { |
225 | UINT thresh = 0; | |
226 | MMRESULT res = joyGetThreshold(m_joystick, & thresh); | |
227 | if (res == JOYERR_NOERROR ) | |
228 | { | |
229 | return thresh; | |
230 | } | |
231 | else | |
232 | return 0; | |
233 | } | |
234 | ||
235 | void wxJoystick::SetMovementThreshold(int threshold) | |
236 | { | |
237 | UINT thresh = threshold; | |
238 | joySetThreshold(m_joystick, thresh); | |
239 | } | |
240 | ||
241 | // Capabilities | |
242 | //////////////////////////////////////////////////////////////////////////// | |
243 | ||
131f9d9b | 244 | /** |
598ddd96 WS |
245 | johan@linkdata.se 2002-08-20: |
246 | Now returns the number of connected, functioning | |
247 | joysticks, as intended. | |
131f9d9b JS |
248 | */ |
249 | int wxJoystick::GetNumberJoysticks() | |
2bda0e17 KB |
250 | { |
251 | JOYINFO joyInfo; | |
598ddd96 WS |
252 | int i, maxsticks, actualsticks; |
253 | maxsticks = joyGetNumDevs(); | |
254 | actualsticks = 0; | |
255 | for( i=0; i<maxsticks; i++ ) | |
256 | { | |
257 | if( joyGetPos( i, & joyInfo ) == JOYERR_NOERROR ) | |
258 | { | |
259 | actualsticks ++; | |
260 | } | |
261 | } | |
131f9d9b | 262 | return actualsticks; |
2bda0e17 KB |
263 | } |
264 | ||
131f9d9b | 265 | /** |
598ddd96 WS |
266 | johan@linkdata.se 2002-08-20: |
267 | The old code returned true if there were any | |
268 | joystick capable drivers loaded (=always). | |
131f9d9b JS |
269 | */ |
270 | bool wxJoystick::IsOk() const | |
2bda0e17 | 271 | { |
131f9d9b JS |
272 | JOYINFO joyInfo; |
273 | return (joyGetPos(m_joystick, & joyInfo) == JOYERR_NOERROR); | |
2bda0e17 KB |
274 | } |
275 | ||
c42404a5 | 276 | int wxJoystick::GetManufacturerId() const |
2bda0e17 KB |
277 | { |
278 | JOYCAPS joyCaps; | |
279 | if (joyGetDevCaps(m_joystick, & joyCaps, sizeof(JOYCAPS)) != JOYERR_NOERROR) | |
280 | return 0; | |
281 | else | |
282 | return joyCaps.wMid; | |
283 | } | |
284 | ||
c42404a5 | 285 | int wxJoystick::GetProductId() const |
2bda0e17 KB |
286 | { |
287 | JOYCAPS joyCaps; | |
288 | if (joyGetDevCaps(m_joystick, & joyCaps, sizeof(JOYCAPS)) != JOYERR_NOERROR) | |
289 | return 0; | |
290 | else | |
291 | return joyCaps.wPid; | |
292 | } | |
293 | ||
c42404a5 | 294 | wxString wxJoystick::GetProductName() const |
2bda0e17 | 295 | { |
4708068c JS |
296 | wxString str; |
297 | #ifndef __WINE__ | |
2bda0e17 | 298 | JOYCAPS joyCaps; |
c9ee46c3 | 299 | if (joyGetDevCaps(m_joystick, &joyCaps, sizeof(joyCaps)) != JOYERR_NOERROR) |
2b5f62a0 | 300 | return wxEmptyString; |
c9ee46c3 VZ |
301 | |
302 | wxRegKey key1(wxString::Format(wxT("HKEY_LOCAL_MACHINE\\%s\\%s\\%s"), | |
303 | REGSTR_PATH_JOYCONFIG, joyCaps.szRegKey, REGSTR_KEY_JOYCURR)); | |
304 | ||
c9ee46c3 VZ |
305 | key1.QueryValue(wxString::Format(wxT("Joystick%d%s"), |
306 | m_joystick + 1, REGSTR_VAL_JOYOEMNAME), | |
307 | str); | |
308 | ||
309 | wxRegKey key2(wxString::Format(wxT("HKEY_LOCAL_MACHINE\\%s\\%s"), | |
310 | REGSTR_PATH_JOYOEM, str.c_str())); | |
311 | key2.QueryValue(REGSTR_VAL_JOYOEMNAME, str); | |
4708068c | 312 | #endif |
c9ee46c3 | 313 | return str; |
2bda0e17 KB |
314 | } |
315 | ||
c42404a5 | 316 | int wxJoystick::GetXMin() const |
2bda0e17 KB |
317 | { |
318 | JOYCAPS joyCaps; | |
319 | if (joyGetDevCaps(m_joystick, & joyCaps, sizeof(JOYCAPS)) != JOYERR_NOERROR) | |
320 | return 0; | |
321 | else | |
322 | return joyCaps.wXmin; | |
323 | } | |
324 | ||
c42404a5 | 325 | int wxJoystick::GetYMin() const |
2bda0e17 KB |
326 | { |
327 | JOYCAPS joyCaps; | |
328 | if (joyGetDevCaps(m_joystick, & joyCaps, sizeof(JOYCAPS)) != JOYERR_NOERROR) | |
329 | return 0; | |
330 | else | |
331 | return joyCaps.wYmin; | |
332 | } | |
333 | ||
c42404a5 | 334 | int wxJoystick::GetZMin() const |
2bda0e17 KB |
335 | { |
336 | JOYCAPS joyCaps; | |
337 | if (joyGetDevCaps(m_joystick, & joyCaps, sizeof(JOYCAPS)) != JOYERR_NOERROR) | |
338 | return 0; | |
339 | else | |
340 | return joyCaps.wZmin; | |
341 | } | |
342 | ||
c42404a5 | 343 | int wxJoystick::GetXMax() const |
2bda0e17 KB |
344 | { |
345 | JOYCAPS joyCaps; | |
346 | if (joyGetDevCaps(m_joystick, & joyCaps, sizeof(JOYCAPS)) != JOYERR_NOERROR) | |
347 | return 0; | |
348 | else | |
349 | return joyCaps.wXmax; | |
350 | } | |
351 | ||
c42404a5 | 352 | int wxJoystick::GetYMax() const |
2bda0e17 KB |
353 | { |
354 | JOYCAPS joyCaps; | |
355 | if (joyGetDevCaps(m_joystick, & joyCaps, sizeof(JOYCAPS)) != JOYERR_NOERROR) | |
356 | return 0; | |
357 | else | |
358 | return joyCaps.wYmax; | |
359 | } | |
360 | ||
c42404a5 | 361 | int wxJoystick::GetZMax() const |
2bda0e17 KB |
362 | { |
363 | JOYCAPS joyCaps; | |
364 | if (joyGetDevCaps(m_joystick, & joyCaps, sizeof(JOYCAPS)) != JOYERR_NOERROR) | |
365 | return 0; | |
366 | else | |
367 | return joyCaps.wZmax; | |
368 | } | |
369 | ||
c42404a5 | 370 | int wxJoystick::GetNumberButtons() const |
2bda0e17 KB |
371 | { |
372 | JOYCAPS joyCaps; | |
373 | if (joyGetDevCaps(m_joystick, & joyCaps, sizeof(JOYCAPS)) != JOYERR_NOERROR) | |
374 | return 0; | |
375 | else | |
376 | return joyCaps.wNumButtons; | |
377 | } | |
378 | ||
c42404a5 | 379 | int wxJoystick::GetNumberAxes() const |
2bda0e17 | 380 | { |
b39dbf34 | 381 | #if defined(__WIN32__) |
2bda0e17 KB |
382 | JOYCAPS joyCaps; |
383 | if (joyGetDevCaps(m_joystick, & joyCaps, sizeof(JOYCAPS)) != JOYERR_NOERROR) | |
384 | return 0; | |
385 | else | |
386 | return joyCaps.wNumAxes; | |
387 | #else | |
388 | return 0; | |
389 | #endif | |
390 | } | |
391 | ||
c42404a5 | 392 | int wxJoystick::GetMaxButtons() const |
2bda0e17 | 393 | { |
b39dbf34 | 394 | #if defined(__WIN32__) |
2bda0e17 KB |
395 | JOYCAPS joyCaps; |
396 | if (joyGetDevCaps(m_joystick, & joyCaps, sizeof(JOYCAPS)) != JOYERR_NOERROR) | |
397 | return 0; | |
398 | else | |
399 | return joyCaps.wMaxButtons; | |
400 | #else | |
401 | return 0; | |
402 | #endif | |
403 | } | |
404 | ||
c42404a5 | 405 | int wxJoystick::GetMaxAxes() const |
2bda0e17 | 406 | { |
b39dbf34 | 407 | #if defined(__WIN32__) |
2bda0e17 KB |
408 | JOYCAPS joyCaps; |
409 | if (joyGetDevCaps(m_joystick, & joyCaps, sizeof(JOYCAPS)) != JOYERR_NOERROR) | |
410 | return 0; | |
411 | else | |
412 | return joyCaps.wMaxAxes; | |
413 | #else | |
414 | return 0; | |
415 | #endif | |
416 | } | |
417 | ||
c42404a5 | 418 | int wxJoystick::GetPollingMin() const |
2bda0e17 KB |
419 | { |
420 | JOYCAPS joyCaps; | |
421 | if (joyGetDevCaps(m_joystick, & joyCaps, sizeof(JOYCAPS)) != JOYERR_NOERROR) | |
422 | return 0; | |
423 | else | |
424 | return joyCaps.wPeriodMin; | |
425 | } | |
426 | ||
c42404a5 | 427 | int wxJoystick::GetPollingMax() const |
2bda0e17 KB |
428 | { |
429 | JOYCAPS joyCaps; | |
430 | if (joyGetDevCaps(m_joystick, & joyCaps, sizeof(JOYCAPS)) != JOYERR_NOERROR) | |
431 | return 0; | |
432 | else | |
433 | return joyCaps.wPeriodMax; | |
434 | } | |
435 | ||
c42404a5 | 436 | int wxJoystick::GetRudderMin() const |
2bda0e17 | 437 | { |
b39dbf34 | 438 | #if defined(__WIN32__) |
2bda0e17 KB |
439 | JOYCAPS joyCaps; |
440 | if (joyGetDevCaps(m_joystick, & joyCaps, sizeof(JOYCAPS)) != JOYERR_NOERROR) | |
441 | return 0; | |
442 | else | |
443 | return joyCaps.wRmin; | |
444 | #else | |
445 | return 0; | |
446 | #endif | |
447 | } | |
448 | ||
c42404a5 | 449 | int wxJoystick::GetRudderMax() const |
2bda0e17 | 450 | { |
b39dbf34 | 451 | #if defined(__WIN32__) |
2bda0e17 KB |
452 | JOYCAPS joyCaps; |
453 | if (joyGetDevCaps(m_joystick, & joyCaps, sizeof(JOYCAPS)) != JOYERR_NOERROR) | |
454 | return 0; | |
455 | else | |
456 | return joyCaps.wRmax; | |
457 | #else | |
458 | return 0; | |
459 | #endif | |
460 | } | |
461 | ||
c42404a5 | 462 | int wxJoystick::GetUMin() const |
2bda0e17 | 463 | { |
b39dbf34 | 464 | #if defined(__WIN32__) |
2bda0e17 KB |
465 | JOYCAPS joyCaps; |
466 | if (joyGetDevCaps(m_joystick, & joyCaps, sizeof(JOYCAPS)) != JOYERR_NOERROR) | |
467 | return 0; | |
468 | else | |
469 | return joyCaps.wUmin; | |
470 | #else | |
471 | return 0; | |
472 | #endif | |
473 | } | |
474 | ||
c42404a5 | 475 | int wxJoystick::GetUMax() const |
2bda0e17 | 476 | { |
b39dbf34 | 477 | #if defined(__WIN32__) |
2bda0e17 KB |
478 | JOYCAPS joyCaps; |
479 | if (joyGetDevCaps(m_joystick, & joyCaps, sizeof(JOYCAPS)) != JOYERR_NOERROR) | |
480 | return 0; | |
481 | else | |
482 | return joyCaps.wUmax; | |
483 | #else | |
484 | return 0; | |
485 | #endif | |
486 | } | |
487 | ||
c42404a5 | 488 | int wxJoystick::GetVMin() const |
2bda0e17 | 489 | { |
b39dbf34 | 490 | #if defined(__WIN32__) |
2bda0e17 KB |
491 | JOYCAPS joyCaps; |
492 | if (joyGetDevCaps(m_joystick, & joyCaps, sizeof(JOYCAPS)) != JOYERR_NOERROR) | |
493 | return 0; | |
494 | else | |
495 | return joyCaps.wVmin; | |
496 | #else | |
497 | return 0; | |
498 | #endif | |
499 | } | |
500 | ||
c42404a5 | 501 | int wxJoystick::GetVMax() const |
2bda0e17 | 502 | { |
b39dbf34 | 503 | #if defined(__WIN32__) |
2bda0e17 KB |
504 | JOYCAPS joyCaps; |
505 | if (joyGetDevCaps(m_joystick, & joyCaps, sizeof(JOYCAPS)) != JOYERR_NOERROR) | |
506 | return 0; | |
507 | else | |
508 | return joyCaps.wVmax; | |
509 | #else | |
510 | return 0; | |
511 | #endif | |
512 | } | |
513 | ||
514 | ||
c42404a5 | 515 | bool wxJoystick::HasRudder() const |
2bda0e17 | 516 | { |
b39dbf34 | 517 | #if defined(__WIN32__) |
2bda0e17 KB |
518 | JOYCAPS joyCaps; |
519 | if (joyGetDevCaps(m_joystick, & joyCaps, sizeof(JOYCAPS)) != JOYERR_NOERROR) | |
598ddd96 | 520 | return false; |
2bda0e17 KB |
521 | else |
522 | return ((joyCaps.wCaps & JOYCAPS_HASR) == JOYCAPS_HASR); | |
523 | #else | |
598ddd96 | 524 | return false; |
2bda0e17 KB |
525 | #endif |
526 | } | |
527 | ||
c42404a5 | 528 | bool wxJoystick::HasZ() const |
2bda0e17 | 529 | { |
b39dbf34 | 530 | #if defined(__WIN32__) |
2bda0e17 KB |
531 | JOYCAPS joyCaps; |
532 | if (joyGetDevCaps(m_joystick, & joyCaps, sizeof(JOYCAPS)) != JOYERR_NOERROR) | |
598ddd96 | 533 | return false; |
2bda0e17 KB |
534 | else |
535 | return ((joyCaps.wCaps & JOYCAPS_HASZ) == JOYCAPS_HASZ); | |
536 | #else | |
598ddd96 | 537 | return false; |
2bda0e17 KB |
538 | #endif |
539 | } | |
540 | ||
c42404a5 | 541 | bool wxJoystick::HasU() const |
2bda0e17 | 542 | { |
b39dbf34 | 543 | #if defined(__WIN32__) |
2bda0e17 KB |
544 | JOYCAPS joyCaps; |
545 | if (joyGetDevCaps(m_joystick, & joyCaps, sizeof(JOYCAPS)) != JOYERR_NOERROR) | |
598ddd96 | 546 | return false; |
2bda0e17 KB |
547 | else |
548 | return ((joyCaps.wCaps & JOYCAPS_HASU) == JOYCAPS_HASU); | |
549 | #else | |
598ddd96 | 550 | return false; |
2bda0e17 KB |
551 | #endif |
552 | } | |
553 | ||
c42404a5 | 554 | bool wxJoystick::HasV() const |
2bda0e17 | 555 | { |
b39dbf34 | 556 | #if defined(__WIN32__) |
2bda0e17 KB |
557 | JOYCAPS joyCaps; |
558 | if (joyGetDevCaps(m_joystick, & joyCaps, sizeof(JOYCAPS)) != JOYERR_NOERROR) | |
598ddd96 | 559 | return false; |
2bda0e17 KB |
560 | else |
561 | return ((joyCaps.wCaps & JOYCAPS_HASV) == JOYCAPS_HASV); | |
562 | #else | |
598ddd96 | 563 | return false; |
2bda0e17 KB |
564 | #endif |
565 | } | |
566 | ||
c42404a5 | 567 | bool wxJoystick::HasPOV() const |
2bda0e17 | 568 | { |
b39dbf34 | 569 | #if defined(__WIN32__) |
2bda0e17 KB |
570 | JOYCAPS joyCaps; |
571 | if (joyGetDevCaps(m_joystick, & joyCaps, sizeof(JOYCAPS)) != JOYERR_NOERROR) | |
598ddd96 | 572 | return false; |
2bda0e17 KB |
573 | else |
574 | return ((joyCaps.wCaps & JOYCAPS_HASPOV) == JOYCAPS_HASPOV); | |
575 | #else | |
598ddd96 | 576 | return false; |
2bda0e17 KB |
577 | #endif |
578 | } | |
579 | ||
c42404a5 | 580 | bool wxJoystick::HasPOV4Dir() const |
2bda0e17 | 581 | { |
b39dbf34 | 582 | #if defined(__WIN32__) |
2bda0e17 KB |
583 | JOYCAPS joyCaps; |
584 | if (joyGetDevCaps(m_joystick, & joyCaps, sizeof(JOYCAPS)) != JOYERR_NOERROR) | |
598ddd96 | 585 | return false; |
2bda0e17 KB |
586 | else |
587 | return ((joyCaps.wCaps & JOYCAPS_POV4DIR) == JOYCAPS_POV4DIR); | |
588 | #else | |
598ddd96 | 589 | return false; |
2bda0e17 KB |
590 | #endif |
591 | } | |
592 | ||
c42404a5 | 593 | bool wxJoystick::HasPOVCTS() const |
2bda0e17 | 594 | { |
b39dbf34 | 595 | #if defined(__WIN32__) |
2bda0e17 KB |
596 | JOYCAPS joyCaps; |
597 | if (joyGetDevCaps(m_joystick, & joyCaps, sizeof(JOYCAPS)) != JOYERR_NOERROR) | |
598ddd96 | 598 | return false; |
2bda0e17 KB |
599 | else |
600 | return ((joyCaps.wCaps & JOYCAPS_POVCTS) == JOYCAPS_POVCTS); | |
601 | #else | |
598ddd96 | 602 | return false; |
2bda0e17 KB |
603 | #endif |
604 | } | |
605 | ||
606 | // Operations | |
607 | //////////////////////////////////////////////////////////////////////////// | |
608 | ||
609 | bool wxJoystick::SetCapture(wxWindow* win, int pollingFreq) | |
610 | { | |
611 | BOOL changed = (pollingFreq == 0); | |
612 | MMRESULT res = joySetCapture((HWND) win->GetHWND(), m_joystick, pollingFreq, changed); | |
613 | return (res == JOYERR_NOERROR); | |
614 | } | |
615 | ||
c42404a5 | 616 | bool wxJoystick::ReleaseCapture() |
2bda0e17 KB |
617 | { |
618 | MMRESULT res = joyReleaseCapture(m_joystick); | |
619 | return (res == JOYERR_NOERROR); | |
620 | } | |
621 |