]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/joystick.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxJoystick class
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "joystick.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
23 #include "wx/string.h"
24 #include "wx/window.h"
25 #include "wx/msw/private.h"
27 #if !defined(__GNUWIN32_OLD__) || defined(__CYGWIN10__)
31 #if !defined(__WIN32__) && !defined(_MMRESULT_)
32 typedef UINT MMRESULT
;
36 #ifdef __GNUWIN32_OLD__
37 #include "wx/msw/gnuwin32/extra.h"
41 // Why doesn't BC++ have joyGetPosEx?
42 #if !defined(__WIN32__) || defined(__BORLANDC__) || defined(__TWIN32__)
43 #define NO_JOYGETPOSEX
46 #include "wx/window.h"
47 #include "wx/msw/joystick.h"
49 IMPLEMENT_DYNAMIC_CLASS(wxJoystick
, wxObject
)
52 ////////////////////////////////////////////////////////////////////////////
54 wxPoint
wxJoystick::GetPosition() const
57 MMRESULT res
= joyGetPos(m_joystick
, & joyInfo
);
58 if (res
== JOYERR_NOERROR
)
59 return wxPoint(joyInfo
.wXpos
, joyInfo
.wYpos
);
64 int wxJoystick::GetZPosition() const
67 MMRESULT res
= joyGetPos(m_joystick
, & joyInfo
);
68 if (res
== JOYERR_NOERROR
)
74 int wxJoystick::GetButtonState() const
77 MMRESULT res
= joyGetPos(m_joystick
, & joyInfo
);
78 if (res
== JOYERR_NOERROR
)
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
;
96 int wxJoystick::GetPOVPosition() const
98 #ifndef NO_JOYGETPOSEX
100 joyInfo
.dwFlags
= JOY_RETURNPOV
;
101 joyInfo
.dwSize
= sizeof(joyInfo
);
102 MMRESULT res
= joyGetPosEx(m_joystick
, & joyInfo
);
103 if (res
== JOYERR_NOERROR
)
105 return joyInfo
.dwPOV
;
114 int wxJoystick::GetPOVCTSPosition() const
116 #ifndef NO_JOYGETPOSEX
118 joyInfo
.dwFlags
= JOY_RETURNPOVCTS
;
119 joyInfo
.dwSize
= sizeof(joyInfo
);
120 MMRESULT res
= joyGetPosEx(m_joystick
, & joyInfo
);
121 if (res
== JOYERR_NOERROR
)
123 return joyInfo
.dwPOV
;
132 int wxJoystick::GetRudderPosition() const
134 #ifndef NO_JOYGETPOSEX
136 joyInfo
.dwFlags
= JOY_RETURNR
;
137 joyInfo
.dwSize
= sizeof(joyInfo
);
138 MMRESULT res
= joyGetPosEx(m_joystick
, & joyInfo
);
139 if (res
== JOYERR_NOERROR
)
141 return joyInfo
.dwRpos
;
150 int wxJoystick::GetUPosition() const
152 #ifndef NO_JOYGETPOSEX
154 joyInfo
.dwFlags
= JOY_RETURNU
;
155 joyInfo
.dwSize
= sizeof(joyInfo
);
156 MMRESULT res
= joyGetPosEx(m_joystick
, & joyInfo
);
157 if (res
== JOYERR_NOERROR
)
159 return joyInfo
.dwUpos
;
168 int wxJoystick::GetVPosition() const
170 #ifndef NO_JOYGETPOSEX
172 joyInfo
.dwFlags
= JOY_RETURNV
;
173 joyInfo
.dwSize
= sizeof(joyInfo
);
174 MMRESULT res
= joyGetPosEx(m_joystick
, & joyInfo
);
175 if (res
== JOYERR_NOERROR
)
177 return joyInfo
.dwVpos
;
186 int wxJoystick::GetMovementThreshold() const
189 MMRESULT res
= joyGetThreshold(m_joystick
, & thresh
);
190 if (res
== JOYERR_NOERROR
)
198 void wxJoystick::SetMovementThreshold(int threshold
)
200 UINT thresh
= threshold
;
201 joySetThreshold(m_joystick
, thresh
);
205 ////////////////////////////////////////////////////////////////////////////
207 bool wxJoystick::IsOk() const
210 MMRESULT res
= joyGetPos(m_joystick
, & joyInfo
);
211 return ((joyGetNumDevs() > 0) || (res
== JOYERR_NOERROR
));
214 int wxJoystick::GetNumberJoysticks() const
216 return joyGetNumDevs();
219 int wxJoystick::GetManufacturerId() const
222 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
228 int wxJoystick::GetProductId() const
231 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
237 wxString
wxJoystick::GetProductName() const
240 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
243 return wxString(joyCaps
.szPname
);
246 int wxJoystick::GetXMin() const
249 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
252 return joyCaps
.wXmin
;
255 int wxJoystick::GetYMin() const
258 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
261 return joyCaps
.wYmin
;
264 int wxJoystick::GetZMin() const
267 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
270 return joyCaps
.wZmin
;
273 int wxJoystick::GetXMax() const
276 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
279 return joyCaps
.wXmax
;
282 int wxJoystick::GetYMax() const
285 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
288 return joyCaps
.wYmax
;
291 int wxJoystick::GetZMax() const
294 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
297 return joyCaps
.wZmax
;
300 int wxJoystick::GetNumberButtons() const
303 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
306 return joyCaps
.wNumButtons
;
309 int wxJoystick::GetNumberAxes() const
311 #if defined(__WIN32__) && !defined(__TWIN32__)
313 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
316 return joyCaps
.wNumAxes
;
322 int wxJoystick::GetMaxButtons() const
324 #if defined(__WIN32__) && !defined(__TWIN32__)
326 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
329 return joyCaps
.wMaxButtons
;
335 int wxJoystick::GetMaxAxes() const
337 #if defined(__WIN32__) && !defined(__TWIN32__)
339 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
342 return joyCaps
.wMaxAxes
;
348 int wxJoystick::GetPollingMin() const
351 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
354 return joyCaps
.wPeriodMin
;
357 int wxJoystick::GetPollingMax() const
360 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
363 return joyCaps
.wPeriodMax
;
366 int wxJoystick::GetRudderMin() const
368 #if defined(__WIN32__) && !defined(__TWIN32__)
370 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
373 return joyCaps
.wRmin
;
379 int wxJoystick::GetRudderMax() const
381 #if defined(__WIN32__) && !defined(__TWIN32__)
383 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
386 return joyCaps
.wRmax
;
392 int wxJoystick::GetUMin() const
394 #if defined(__WIN32__) && !defined(__TWIN32__)
396 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
399 return joyCaps
.wUmin
;
405 int wxJoystick::GetUMax() const
407 #if defined(__WIN32__) && !defined(__TWIN32__)
409 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
412 return joyCaps
.wUmax
;
418 int wxJoystick::GetVMin() const
420 #if defined(__WIN32__) && !defined(__TWIN32__)
422 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
425 return joyCaps
.wVmin
;
431 int wxJoystick::GetVMax() const
433 #if defined(__WIN32__) && !defined(__TWIN32__)
435 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
438 return joyCaps
.wVmax
;
445 bool wxJoystick::HasRudder() const
447 #if defined(__WIN32__) && !defined(__TWIN32__)
449 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
452 return ((joyCaps
.wCaps
& JOYCAPS_HASR
) == JOYCAPS_HASR
);
458 bool wxJoystick::HasZ() const
460 #if defined(__WIN32__) && !defined(__TWIN32__)
462 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
465 return ((joyCaps
.wCaps
& JOYCAPS_HASZ
) == JOYCAPS_HASZ
);
471 bool wxJoystick::HasU() const
473 #if defined(__WIN32__) && !defined(__TWIN32__)
475 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
478 return ((joyCaps
.wCaps
& JOYCAPS_HASU
) == JOYCAPS_HASU
);
484 bool wxJoystick::HasV() const
486 #if defined(__WIN32__) && !defined(__TWIN32__)
488 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
491 return ((joyCaps
.wCaps
& JOYCAPS_HASV
) == JOYCAPS_HASV
);
497 bool wxJoystick::HasPOV() const
499 #if defined(__WIN32__) && !defined(__TWIN32__)
501 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
504 return ((joyCaps
.wCaps
& JOYCAPS_HASPOV
) == JOYCAPS_HASPOV
);
510 bool wxJoystick::HasPOV4Dir() const
512 #if defined(__WIN32__) && !defined(__TWIN32__)
514 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
517 return ((joyCaps
.wCaps
& JOYCAPS_POV4DIR
) == JOYCAPS_POV4DIR
);
523 bool wxJoystick::HasPOVCTS() const
525 #if defined(__WIN32__) && !defined(__TWIN32__)
527 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
530 return ((joyCaps
.wCaps
& JOYCAPS_POVCTS
) == JOYCAPS_POVCTS
);
537 ////////////////////////////////////////////////////////////////////////////
539 bool wxJoystick::SetCapture(wxWindow
* win
, int pollingFreq
)
541 BOOL changed
= (pollingFreq
== 0);
542 MMRESULT res
= joySetCapture((HWND
) win
->GetHWND(), m_joystick
, pollingFreq
, changed
);
543 return (res
== JOYERR_NOERROR
);
546 bool wxJoystick::ReleaseCapture()
548 MMRESULT res
= joyReleaseCapture(m_joystick
);
549 return (res
== JOYERR_NOERROR
);