]>
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"
19 #if defined(__BORLANDC__)
29 #if !defined(__WIN32__) && !defined(_MMRESULT_)
30 typedef UINT MMRESULT
;
34 #include <wx/msw/gnuwin32/extra.h>
37 // Why doesn't BC++ have joyGetPosEx?
38 #if !defined(__WIN32__) || defined(__BORLANDC__)
39 #define NO_JOYGETPOSEX
42 #include <wx/msw/joystick.h>
44 IMPLEMENT_DYNAMIC_CLASS(wxJoystick
, wxObject
)
47 ////////////////////////////////////////////////////////////////////////////
49 wxPoint
wxJoystick::GetPosition(void) const
52 MMRESULT res
= joyGetPos(m_joystick
, & joyInfo
);
53 if (res
== JOYERR_NOERROR
)
54 return wxPoint(joyInfo
.wXpos
, joyInfo
.wYpos
);
59 int wxJoystick::GetZPosition(void) const
62 MMRESULT res
= joyGetPos(m_joystick
, & joyInfo
);
63 if (res
== JOYERR_NOERROR
)
69 int wxJoystick::GetButtonState(void) const
72 MMRESULT res
= joyGetPos(m_joystick
, & joyInfo
);
73 if (res
== JOYERR_NOERROR
)
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
;
91 int wxJoystick::GetPOVPosition(void) const
93 #ifndef NO_JOYGETPOSEX
95 joyInfo
.dwFlags
= JOY_RETURNPOV
;
96 MMRESULT res
= joyGetPosEx(m_joystick
, & joyInfo
);
97 if (res
== JOYERR_NOERROR
)
108 int wxJoystick::GetPOVCTSPosition(void) const
110 #ifndef NO_JOYGETPOSEX
112 joyInfo
.dwFlags
= JOY_RETURNPOVCTS
;
113 MMRESULT res
= joyGetPosEx(m_joystick
, & joyInfo
);
114 if (res
== JOYERR_NOERROR
)
116 return joyInfo
.dwPOV
;
125 int wxJoystick::GetRudderPosition(void) const
127 #ifndef NO_JOYGETPOSEX
129 joyInfo
.dwFlags
= JOY_RETURNR
;
130 MMRESULT res
= joyGetPosEx(m_joystick
, & joyInfo
);
131 if (res
== JOYERR_NOERROR
)
133 return joyInfo
.dwRpos
;
142 int wxJoystick::GetUPosition(void) const
144 #ifndef NO_JOYGETPOSEX
146 joyInfo
.dwFlags
= JOY_RETURNU
;
147 MMRESULT res
= joyGetPosEx(m_joystick
, & joyInfo
);
148 if (res
== JOYERR_NOERROR
)
150 return joyInfo
.dwUpos
;
159 int wxJoystick::GetVPosition(void) const
161 #ifndef NO_JOYGETPOSEX
163 joyInfo
.dwFlags
= JOY_RETURNV
;
164 MMRESULT res
= joyGetPosEx(m_joystick
, & joyInfo
);
165 if (res
== JOYERR_NOERROR
)
167 return joyInfo
.dwVpos
;
176 int wxJoystick::GetMovementThreshold(void) const
179 MMRESULT res
= joyGetThreshold(m_joystick
, & thresh
);
180 if (res
== JOYERR_NOERROR
)
188 void wxJoystick::SetMovementThreshold(int threshold
)
190 UINT thresh
= threshold
;
191 joySetThreshold(m_joystick
, thresh
);
195 ////////////////////////////////////////////////////////////////////////////
197 bool wxJoystick::IsOk(void) const
200 MMRESULT res
= joyGetPos(m_joystick
, & joyInfo
);
201 return ((joyGetNumDevs() > 0) || (res
== JOYERR_NOERROR
));
204 int wxJoystick::GetNumberJoysticks(void) const
206 return joyGetNumDevs();
209 int wxJoystick::GetManufacturerId(void) const
212 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
218 int wxJoystick::GetProductId(void) const
221 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
227 wxString
wxJoystick::GetProductName(void) const
230 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
233 return wxString(joyCaps
.szPname
);
236 int wxJoystick::GetXMin(void) const
239 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
242 return joyCaps
.wXmin
;
245 int wxJoystick::GetYMin(void) const
248 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
251 return joyCaps
.wYmin
;
254 int wxJoystick::GetZMin(void) const
257 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
260 return joyCaps
.wZmin
;
263 int wxJoystick::GetXMax(void) const
266 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
269 return joyCaps
.wXmax
;
272 int wxJoystick::GetYMax(void) const
275 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
278 return joyCaps
.wYmax
;
281 int wxJoystick::GetZMax(void) const
284 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
287 return joyCaps
.wZmax
;
290 int wxJoystick::GetNumberButtons(void) const
293 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
296 return joyCaps
.wNumButtons
;
299 int wxJoystick::GetNumberAxes(void) const
303 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
306 return joyCaps
.wNumAxes
;
312 int wxJoystick::GetMaxButtons(void) const
316 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
319 return joyCaps
.wMaxButtons
;
325 int wxJoystick::GetMaxAxes(void) const
329 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
332 return joyCaps
.wMaxAxes
;
338 int wxJoystick::GetPollingMin(void) const
341 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
344 return joyCaps
.wPeriodMin
;
347 int wxJoystick::GetPollingMax(void) const
350 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
353 return joyCaps
.wPeriodMax
;
356 int wxJoystick::GetRudderMin(void) const
360 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
363 return joyCaps
.wRmin
;
369 int wxJoystick::GetRudderMax(void) const
373 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
376 return joyCaps
.wRmax
;
382 int wxJoystick::GetUMin(void) const
386 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
389 return joyCaps
.wUmin
;
395 int wxJoystick::GetUMax(void) const
399 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
402 return joyCaps
.wUmax
;
408 int wxJoystick::GetVMin(void) const
412 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
415 return joyCaps
.wVmin
;
421 int wxJoystick::GetVMax(void) const
425 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
428 return joyCaps
.wVmax
;
435 bool wxJoystick::HasRudder(void) const
439 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
442 return ((joyCaps
.wCaps
& JOYCAPS_HASR
) == JOYCAPS_HASR
);
448 bool wxJoystick::HasZ(void) const
452 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
455 return ((joyCaps
.wCaps
& JOYCAPS_HASZ
) == JOYCAPS_HASZ
);
461 bool wxJoystick::HasU(void) const
465 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
468 return ((joyCaps
.wCaps
& JOYCAPS_HASU
) == JOYCAPS_HASU
);
474 bool wxJoystick::HasV(void) const
478 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
481 return ((joyCaps
.wCaps
& JOYCAPS_HASV
) == JOYCAPS_HASV
);
487 bool wxJoystick::HasPOV(void) const
491 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
494 return ((joyCaps
.wCaps
& JOYCAPS_HASPOV
) == JOYCAPS_HASPOV
);
500 bool wxJoystick::HasPOV4Dir(void) const
504 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
507 return ((joyCaps
.wCaps
& JOYCAPS_POV4DIR
) == JOYCAPS_POV4DIR
);
513 bool wxJoystick::HasPOVCTS(void) const
517 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
520 return ((joyCaps
.wCaps
& JOYCAPS_POVCTS
) == JOYCAPS_POVCTS
);
527 ////////////////////////////////////////////////////////////////////////////
529 bool wxJoystick::SetCapture(wxWindow
* win
, int pollingFreq
)
531 BOOL changed
= (pollingFreq
== 0);
532 MMRESULT res
= joySetCapture((HWND
) win
->GetHWND(), m_joystick
, pollingFreq
, changed
);
533 return (res
== JOYERR_NOERROR
);
536 bool wxJoystick::ReleaseCapture(void)
538 MMRESULT res
= joyReleaseCapture(m_joystick
);
539 return (res
== JOYERR_NOERROR
);