]>
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"
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/window.h>
43 #include <wx/msw/joystick.h>
45 IMPLEMENT_DYNAMIC_CLASS(wxJoystick
, wxObject
)
48 ////////////////////////////////////////////////////////////////////////////
50 wxPoint
wxJoystick::GetPosition(void) const
53 MMRESULT res
= joyGetPos(m_joystick
, & joyInfo
);
54 if (res
== JOYERR_NOERROR
)
55 return wxPoint(joyInfo
.wXpos
, joyInfo
.wYpos
);
60 int wxJoystick::GetZPosition(void) const
63 MMRESULT res
= joyGetPos(m_joystick
, & joyInfo
);
64 if (res
== JOYERR_NOERROR
)
70 int wxJoystick::GetButtonState(void) const
73 MMRESULT res
= joyGetPos(m_joystick
, & joyInfo
);
74 if (res
== JOYERR_NOERROR
)
78 if (joyInfo
.wButtons
& JOY_BUTTON1
)
79 buttons
|= wxJOY_BUTTON1
;
80 if (joyInfo
.wButtons
& JOY_BUTTON2
)
81 buttons
|= wxJOY_BUTTON2
;
82 if (joyInfo
.wButtons
& JOY_BUTTON3
)
83 buttons
|= wxJOY_BUTTON3
;
84 if (joyInfo
.wButtons
& JOY_BUTTON4
)
85 buttons
|= wxJOY_BUTTON4
;
92 int wxJoystick::GetPOVPosition(void) const
94 #ifndef NO_JOYGETPOSEX
96 joyInfo
.dwFlags
= JOY_RETURNPOV
;
97 MMRESULT res
= joyGetPosEx(m_joystick
, & joyInfo
);
98 if (res
== JOYERR_NOERROR
)
100 return joyInfo
.dwPOV
;
109 int wxJoystick::GetPOVCTSPosition(void) const
111 #ifndef NO_JOYGETPOSEX
113 joyInfo
.dwFlags
= JOY_RETURNPOVCTS
;
114 MMRESULT res
= joyGetPosEx(m_joystick
, & joyInfo
);
115 if (res
== JOYERR_NOERROR
)
117 return joyInfo
.dwPOV
;
126 int wxJoystick::GetRudderPosition(void) const
128 #ifndef NO_JOYGETPOSEX
130 joyInfo
.dwFlags
= JOY_RETURNR
;
131 MMRESULT res
= joyGetPosEx(m_joystick
, & joyInfo
);
132 if (res
== JOYERR_NOERROR
)
134 return joyInfo
.dwRpos
;
143 int wxJoystick::GetUPosition(void) const
145 #ifndef NO_JOYGETPOSEX
147 joyInfo
.dwFlags
= JOY_RETURNU
;
148 MMRESULT res
= joyGetPosEx(m_joystick
, & joyInfo
);
149 if (res
== JOYERR_NOERROR
)
151 return joyInfo
.dwUpos
;
160 int wxJoystick::GetVPosition(void) const
162 #ifndef NO_JOYGETPOSEX
164 joyInfo
.dwFlags
= JOY_RETURNV
;
165 MMRESULT res
= joyGetPosEx(m_joystick
, & joyInfo
);
166 if (res
== JOYERR_NOERROR
)
168 return joyInfo
.dwVpos
;
177 int wxJoystick::GetMovementThreshold(void) const
180 MMRESULT res
= joyGetThreshold(m_joystick
, & thresh
);
181 if (res
== JOYERR_NOERROR
)
189 void wxJoystick::SetMovementThreshold(int threshold
)
191 UINT thresh
= threshold
;
192 joySetThreshold(m_joystick
, thresh
);
196 ////////////////////////////////////////////////////////////////////////////
198 bool wxJoystick::IsOk(void) const
201 MMRESULT res
= joyGetPos(m_joystick
, & joyInfo
);
202 return ((joyGetNumDevs() > 0) || (res
== JOYERR_NOERROR
));
205 int wxJoystick::GetNumberJoysticks(void) const
207 return joyGetNumDevs();
210 int wxJoystick::GetManufacturerId(void) const
213 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
219 int wxJoystick::GetProductId(void) const
222 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
228 wxString
wxJoystick::GetProductName(void) const
231 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
234 return wxString(joyCaps
.szPname
);
237 int wxJoystick::GetXMin(void) const
240 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
243 return joyCaps
.wXmin
;
246 int wxJoystick::GetYMin(void) const
249 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
252 return joyCaps
.wYmin
;
255 int wxJoystick::GetZMin(void) const
258 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
261 return joyCaps
.wZmin
;
264 int wxJoystick::GetXMax(void) const
267 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
270 return joyCaps
.wXmax
;
273 int wxJoystick::GetYMax(void) const
276 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
279 return joyCaps
.wYmax
;
282 int wxJoystick::GetZMax(void) const
285 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
288 return joyCaps
.wZmax
;
291 int wxJoystick::GetNumberButtons(void) const
294 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
297 return joyCaps
.wNumButtons
;
300 int wxJoystick::GetNumberAxes(void) const
304 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
307 return joyCaps
.wNumAxes
;
313 int wxJoystick::GetMaxButtons(void) const
317 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
320 return joyCaps
.wMaxButtons
;
326 int wxJoystick::GetMaxAxes(void) const
330 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
333 return joyCaps
.wMaxAxes
;
339 int wxJoystick::GetPollingMin(void) const
342 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
345 return joyCaps
.wPeriodMin
;
348 int wxJoystick::GetPollingMax(void) const
351 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
354 return joyCaps
.wPeriodMax
;
357 int wxJoystick::GetRudderMin(void) const
361 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
364 return joyCaps
.wRmin
;
370 int wxJoystick::GetRudderMax(void) const
374 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
377 return joyCaps
.wRmax
;
383 int wxJoystick::GetUMin(void) const
387 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
390 return joyCaps
.wUmin
;
396 int wxJoystick::GetUMax(void) const
400 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
403 return joyCaps
.wUmax
;
409 int wxJoystick::GetVMin(void) const
413 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
416 return joyCaps
.wVmin
;
422 int wxJoystick::GetVMax(void) const
426 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
429 return joyCaps
.wVmax
;
436 bool wxJoystick::HasRudder(void) const
440 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
443 return ((joyCaps
.wCaps
& JOYCAPS_HASR
) == JOYCAPS_HASR
);
449 bool wxJoystick::HasZ(void) const
453 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
456 return ((joyCaps
.wCaps
& JOYCAPS_HASZ
) == JOYCAPS_HASZ
);
462 bool wxJoystick::HasU(void) const
466 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
469 return ((joyCaps
.wCaps
& JOYCAPS_HASU
) == JOYCAPS_HASU
);
475 bool wxJoystick::HasV(void) const
479 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
482 return ((joyCaps
.wCaps
& JOYCAPS_HASV
) == JOYCAPS_HASV
);
488 bool wxJoystick::HasPOV(void) const
492 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
495 return ((joyCaps
.wCaps
& JOYCAPS_HASPOV
) == JOYCAPS_HASPOV
);
501 bool wxJoystick::HasPOV4Dir(void) const
505 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
508 return ((joyCaps
.wCaps
& JOYCAPS_POV4DIR
) == JOYCAPS_POV4DIR
);
514 bool wxJoystick::HasPOVCTS(void) const
518 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
521 return ((joyCaps
.wCaps
& JOYCAPS_POVCTS
) == JOYCAPS_POVCTS
);
528 ////////////////////////////////////////////////////////////////////////////
530 bool wxJoystick::SetCapture(wxWindow
* win
, int pollingFreq
)
532 BOOL changed
= (pollingFreq
== 0);
533 MMRESULT res
= joySetCapture((HWND
) win
->GetHWND(), m_joystick
, pollingFreq
, changed
);
534 return (res
== JOYERR_NOERROR
);
537 bool wxJoystick::ReleaseCapture(void)
539 MMRESULT res
= joyReleaseCapture(m_joystick
);
540 return (res
== JOYERR_NOERROR
);