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