]>
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__ ) || defined(wxUSE_NORLANDER_HEADERS)
31 #if !defined(__WIN32__) && !defined(_MMRESULT_)
32 typedef UINT MMRESULT
;
37 #ifndef wxUSE_NORLANDER_HEADERS
38 #include <wx/msw/gnuwin32/extra.h>
43 // Why doesn't BC++ have joyGetPosEx?
44 #if !defined(__WIN32__) || defined(__BORLANDC__) || defined(__TWIN32__)
45 #define NO_JOYGETPOSEX
48 #include <wx/window.h>
49 #include <wx/msw/joystick.h>
51 IMPLEMENT_DYNAMIC_CLASS(wxJoystick
, wxObject
)
54 ////////////////////////////////////////////////////////////////////////////
56 wxPoint
wxJoystick::GetPosition(void) const
59 MMRESULT res
= joyGetPos(m_joystick
, & joyInfo
);
60 if (res
== JOYERR_NOERROR
)
61 return wxPoint(joyInfo
.wXpos
, joyInfo
.wYpos
);
66 int wxJoystick::GetZPosition(void) const
69 MMRESULT res
= joyGetPos(m_joystick
, & joyInfo
);
70 if (res
== JOYERR_NOERROR
)
76 int wxJoystick::GetButtonState(void) const
79 MMRESULT res
= joyGetPos(m_joystick
, & joyInfo
);
80 if (res
== JOYERR_NOERROR
)
84 if (joyInfo
.wButtons
& JOY_BUTTON1
)
85 buttons
|= wxJOY_BUTTON1
;
86 if (joyInfo
.wButtons
& JOY_BUTTON2
)
87 buttons
|= wxJOY_BUTTON2
;
88 if (joyInfo
.wButtons
& JOY_BUTTON3
)
89 buttons
|= wxJOY_BUTTON3
;
90 if (joyInfo
.wButtons
& JOY_BUTTON4
)
91 buttons
|= wxJOY_BUTTON4
;
98 int wxJoystick::GetPOVPosition(void) const
100 #ifndef NO_JOYGETPOSEX
102 joyInfo
.dwFlags
= JOY_RETURNPOV
;
103 MMRESULT res
= joyGetPosEx(m_joystick
, & joyInfo
);
104 if (res
== JOYERR_NOERROR
)
106 return joyInfo
.dwPOV
;
115 int wxJoystick::GetPOVCTSPosition(void) const
117 #ifndef NO_JOYGETPOSEX
119 joyInfo
.dwFlags
= JOY_RETURNPOVCTS
;
120 MMRESULT res
= joyGetPosEx(m_joystick
, & joyInfo
);
121 if (res
== JOYERR_NOERROR
)
123 return joyInfo
.dwPOV
;
132 int wxJoystick::GetRudderPosition(void) const
134 #ifndef NO_JOYGETPOSEX
136 joyInfo
.dwFlags
= JOY_RETURNR
;
137 MMRESULT res
= joyGetPosEx(m_joystick
, & joyInfo
);
138 if (res
== JOYERR_NOERROR
)
140 return joyInfo
.dwRpos
;
149 int wxJoystick::GetUPosition(void) const
151 #ifndef NO_JOYGETPOSEX
153 joyInfo
.dwFlags
= JOY_RETURNU
;
154 MMRESULT res
= joyGetPosEx(m_joystick
, & joyInfo
);
155 if (res
== JOYERR_NOERROR
)
157 return joyInfo
.dwUpos
;
166 int wxJoystick::GetVPosition(void) const
168 #ifndef NO_JOYGETPOSEX
170 joyInfo
.dwFlags
= JOY_RETURNV
;
171 MMRESULT res
= joyGetPosEx(m_joystick
, & joyInfo
);
172 if (res
== JOYERR_NOERROR
)
174 return joyInfo
.dwVpos
;
183 int wxJoystick::GetMovementThreshold(void) const
186 MMRESULT res
= joyGetThreshold(m_joystick
, & thresh
);
187 if (res
== JOYERR_NOERROR
)
195 void wxJoystick::SetMovementThreshold(int threshold
)
197 UINT thresh
= threshold
;
198 joySetThreshold(m_joystick
, thresh
);
202 ////////////////////////////////////////////////////////////////////////////
204 bool wxJoystick::IsOk(void) const
207 MMRESULT res
= joyGetPos(m_joystick
, & joyInfo
);
208 return ((joyGetNumDevs() > 0) || (res
== JOYERR_NOERROR
));
211 int wxJoystick::GetNumberJoysticks(void) const
213 return joyGetNumDevs();
216 int wxJoystick::GetManufacturerId(void) const
219 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
225 int wxJoystick::GetProductId(void) const
228 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
234 wxString
wxJoystick::GetProductName(void) const
237 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
240 return wxString(joyCaps
.szPname
);
243 int wxJoystick::GetXMin(void) const
246 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
249 return joyCaps
.wXmin
;
252 int wxJoystick::GetYMin(void) const
255 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
258 return joyCaps
.wYmin
;
261 int wxJoystick::GetZMin(void) const
264 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
267 return joyCaps
.wZmin
;
270 int wxJoystick::GetXMax(void) const
273 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
276 return joyCaps
.wXmax
;
279 int wxJoystick::GetYMax(void) const
282 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
285 return joyCaps
.wYmax
;
288 int wxJoystick::GetZMax(void) const
291 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
294 return joyCaps
.wZmax
;
297 int wxJoystick::GetNumberButtons(void) const
300 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
303 return joyCaps
.wNumButtons
;
306 int wxJoystick::GetNumberAxes(void) const
308 #if defined(__WIN32__) && !defined(__TWIN32__)
310 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
313 return joyCaps
.wNumAxes
;
319 int wxJoystick::GetMaxButtons(void) const
321 #if defined(__WIN32__) && !defined(__TWIN32__)
323 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
326 return joyCaps
.wMaxButtons
;
332 int wxJoystick::GetMaxAxes(void) const
334 #if defined(__WIN32__) && !defined(__TWIN32__)
336 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
339 return joyCaps
.wMaxAxes
;
345 int wxJoystick::GetPollingMin(void) const
348 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
351 return joyCaps
.wPeriodMin
;
354 int wxJoystick::GetPollingMax(void) const
357 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
360 return joyCaps
.wPeriodMax
;
363 int wxJoystick::GetRudderMin(void) const
365 #if defined(__WIN32__) && !defined(__TWIN32__)
367 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
370 return joyCaps
.wRmin
;
376 int wxJoystick::GetRudderMax(void) const
378 #if defined(__WIN32__) && !defined(__TWIN32__)
380 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
383 return joyCaps
.wRmax
;
389 int wxJoystick::GetUMin(void) const
391 #if defined(__WIN32__) && !defined(__TWIN32__)
393 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
396 return joyCaps
.wUmin
;
402 int wxJoystick::GetUMax(void) const
404 #if defined(__WIN32__) && !defined(__TWIN32__)
406 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
409 return joyCaps
.wUmax
;
415 int wxJoystick::GetVMin(void) const
417 #if defined(__WIN32__) && !defined(__TWIN32__)
419 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
422 return joyCaps
.wVmin
;
428 int wxJoystick::GetVMax(void) const
430 #if defined(__WIN32__) && !defined(__TWIN32__)
432 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
435 return joyCaps
.wVmax
;
442 bool wxJoystick::HasRudder(void) const
444 #if defined(__WIN32__) && !defined(__TWIN32__)
446 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
449 return ((joyCaps
.wCaps
& JOYCAPS_HASR
) == JOYCAPS_HASR
);
455 bool wxJoystick::HasZ(void) const
457 #if defined(__WIN32__) && !defined(__TWIN32__)
459 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
462 return ((joyCaps
.wCaps
& JOYCAPS_HASZ
) == JOYCAPS_HASZ
);
468 bool wxJoystick::HasU(void) const
470 #if defined(__WIN32__) && !defined(__TWIN32__)
472 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
475 return ((joyCaps
.wCaps
& JOYCAPS_HASU
) == JOYCAPS_HASU
);
481 bool wxJoystick::HasV(void) const
483 #if defined(__WIN32__) && !defined(__TWIN32__)
485 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
488 return ((joyCaps
.wCaps
& JOYCAPS_HASV
) == JOYCAPS_HASV
);
494 bool wxJoystick::HasPOV(void) const
496 #if defined(__WIN32__) && !defined(__TWIN32__)
498 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
501 return ((joyCaps
.wCaps
& JOYCAPS_HASPOV
) == JOYCAPS_HASPOV
);
507 bool wxJoystick::HasPOV4Dir(void) const
509 #if defined(__WIN32__) && !defined(__TWIN32__)
511 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
514 return ((joyCaps
.wCaps
& JOYCAPS_POV4DIR
) == JOYCAPS_POV4DIR
);
520 bool wxJoystick::HasPOVCTS(void) const
522 #if defined(__WIN32__) && !defined(__TWIN32__)
524 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
527 return ((joyCaps
.wCaps
& JOYCAPS_POVCTS
) == JOYCAPS_POVCTS
);
534 ////////////////////////////////////////////////////////////////////////////
536 bool wxJoystick::SetCapture(wxWindow
* win
, int pollingFreq
)
538 BOOL changed
= (pollingFreq
== 0);
539 MMRESULT res
= joySetCapture((HWND
) win
->GetHWND(), m_joystick
, pollingFreq
, changed
);
540 return (res
== JOYERR_NOERROR
);
543 bool wxJoystick::ReleaseCapture(void)
545 MMRESULT res
= joyReleaseCapture(m_joystick
);
546 return (res
== JOYERR_NOERROR
);