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