]>
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
;
35 #include <wx/msw/gnuwin32/extra.h>
39 // Why doesn't BC++ have joyGetPosEx?
40 #if !defined(__WIN32__) || defined(__BORLANDC__) || defined(__TWIN32__)
41 #define NO_JOYGETPOSEX
44 #include <wx/window.h>
45 #include <wx/msw/joystick.h>
47 IMPLEMENT_DYNAMIC_CLASS(wxJoystick
, wxObject
)
50 ////////////////////////////////////////////////////////////////////////////
52 wxPoint
wxJoystick::GetPosition(void) const
55 MMRESULT res
= joyGetPos(m_joystick
, & joyInfo
);
56 if (res
== JOYERR_NOERROR
)
57 return wxPoint(joyInfo
.wXpos
, joyInfo
.wYpos
);
62 int wxJoystick::GetZPosition(void) const
65 MMRESULT res
= joyGetPos(m_joystick
, & joyInfo
);
66 if (res
== JOYERR_NOERROR
)
72 int wxJoystick::GetButtonState(void) const
75 MMRESULT res
= joyGetPos(m_joystick
, & joyInfo
);
76 if (res
== JOYERR_NOERROR
)
80 if (joyInfo
.wButtons
& JOY_BUTTON1
)
81 buttons
|= wxJOY_BUTTON1
;
82 if (joyInfo
.wButtons
& JOY_BUTTON2
)
83 buttons
|= wxJOY_BUTTON2
;
84 if (joyInfo
.wButtons
& JOY_BUTTON3
)
85 buttons
|= wxJOY_BUTTON3
;
86 if (joyInfo
.wButtons
& JOY_BUTTON4
)
87 buttons
|= wxJOY_BUTTON4
;
94 int wxJoystick::GetPOVPosition(void) const
96 #ifndef NO_JOYGETPOSEX
98 joyInfo
.dwFlags
= JOY_RETURNPOV
;
99 MMRESULT res
= joyGetPosEx(m_joystick
, & joyInfo
);
100 if (res
== JOYERR_NOERROR
)
102 return joyInfo
.dwPOV
;
111 int wxJoystick::GetPOVCTSPosition(void) const
113 #ifndef NO_JOYGETPOSEX
115 joyInfo
.dwFlags
= JOY_RETURNPOVCTS
;
116 MMRESULT res
= joyGetPosEx(m_joystick
, & joyInfo
);
117 if (res
== JOYERR_NOERROR
)
119 return joyInfo
.dwPOV
;
128 int wxJoystick::GetRudderPosition(void) const
130 #ifndef NO_JOYGETPOSEX
132 joyInfo
.dwFlags
= JOY_RETURNR
;
133 MMRESULT res
= joyGetPosEx(m_joystick
, & joyInfo
);
134 if (res
== JOYERR_NOERROR
)
136 return joyInfo
.dwRpos
;
145 int wxJoystick::GetUPosition(void) const
147 #ifndef NO_JOYGETPOSEX
149 joyInfo
.dwFlags
= JOY_RETURNU
;
150 MMRESULT res
= joyGetPosEx(m_joystick
, & joyInfo
);
151 if (res
== JOYERR_NOERROR
)
153 return joyInfo
.dwUpos
;
162 int wxJoystick::GetVPosition(void) const
164 #ifndef NO_JOYGETPOSEX
166 joyInfo
.dwFlags
= JOY_RETURNV
;
167 MMRESULT res
= joyGetPosEx(m_joystick
, & joyInfo
);
168 if (res
== JOYERR_NOERROR
)
170 return joyInfo
.dwVpos
;
179 int wxJoystick::GetMovementThreshold(void) const
182 MMRESULT res
= joyGetThreshold(m_joystick
, & thresh
);
183 if (res
== JOYERR_NOERROR
)
191 void wxJoystick::SetMovementThreshold(int threshold
)
193 UINT thresh
= threshold
;
194 joySetThreshold(m_joystick
, thresh
);
198 ////////////////////////////////////////////////////////////////////////////
200 bool wxJoystick::IsOk(void) const
203 MMRESULT res
= joyGetPos(m_joystick
, & joyInfo
);
204 return ((joyGetNumDevs() > 0) || (res
== JOYERR_NOERROR
));
207 int wxJoystick::GetNumberJoysticks(void) const
209 return joyGetNumDevs();
212 int wxJoystick::GetManufacturerId(void) const
215 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
221 int wxJoystick::GetProductId(void) const
224 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
230 wxString
wxJoystick::GetProductName(void) const
233 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
236 return wxString(joyCaps
.szPname
);
239 int wxJoystick::GetXMin(void) const
242 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
245 return joyCaps
.wXmin
;
248 int wxJoystick::GetYMin(void) const
251 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
254 return joyCaps
.wYmin
;
257 int wxJoystick::GetZMin(void) const
260 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
263 return joyCaps
.wZmin
;
266 int wxJoystick::GetXMax(void) const
269 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
272 return joyCaps
.wXmax
;
275 int wxJoystick::GetYMax(void) const
278 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
281 return joyCaps
.wYmax
;
284 int wxJoystick::GetZMax(void) const
287 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
290 return joyCaps
.wZmax
;
293 int wxJoystick::GetNumberButtons(void) const
296 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
299 return joyCaps
.wNumButtons
;
302 int wxJoystick::GetNumberAxes(void) const
304 #if defined(__WIN32__) && !defined(__TWIN32__)
306 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
309 return joyCaps
.wNumAxes
;
315 int wxJoystick::GetMaxButtons(void) const
317 #if defined(__WIN32__) && !defined(__TWIN32__)
319 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
322 return joyCaps
.wMaxButtons
;
328 int wxJoystick::GetMaxAxes(void) const
330 #if defined(__WIN32__) && !defined(__TWIN32__)
332 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
335 return joyCaps
.wMaxAxes
;
341 int wxJoystick::GetPollingMin(void) const
344 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
347 return joyCaps
.wPeriodMin
;
350 int wxJoystick::GetPollingMax(void) const
353 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
356 return joyCaps
.wPeriodMax
;
359 int wxJoystick::GetRudderMin(void) const
361 #if defined(__WIN32__) && !defined(__TWIN32__)
363 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
366 return joyCaps
.wRmin
;
372 int wxJoystick::GetRudderMax(void) const
374 #if defined(__WIN32__) && !defined(__TWIN32__)
376 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
379 return joyCaps
.wRmax
;
385 int wxJoystick::GetUMin(void) const
387 #if defined(__WIN32__) && !defined(__TWIN32__)
389 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
392 return joyCaps
.wUmin
;
398 int wxJoystick::GetUMax(void) const
400 #if defined(__WIN32__) && !defined(__TWIN32__)
402 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
405 return joyCaps
.wUmax
;
411 int wxJoystick::GetVMin(void) const
413 #if defined(__WIN32__) && !defined(__TWIN32__)
415 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
418 return joyCaps
.wVmin
;
424 int wxJoystick::GetVMax(void) const
426 #if defined(__WIN32__) && !defined(__TWIN32__)
428 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
431 return joyCaps
.wVmax
;
438 bool wxJoystick::HasRudder(void) const
440 #if defined(__WIN32__) && !defined(__TWIN32__)
442 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
445 return ((joyCaps
.wCaps
& JOYCAPS_HASR
) == JOYCAPS_HASR
);
451 bool wxJoystick::HasZ(void) const
453 #if defined(__WIN32__) && !defined(__TWIN32__)
455 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
458 return ((joyCaps
.wCaps
& JOYCAPS_HASZ
) == JOYCAPS_HASZ
);
464 bool wxJoystick::HasU(void) const
466 #if defined(__WIN32__) && !defined(__TWIN32__)
468 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
471 return ((joyCaps
.wCaps
& JOYCAPS_HASU
) == JOYCAPS_HASU
);
477 bool wxJoystick::HasV(void) const
479 #if defined(__WIN32__) && !defined(__TWIN32__)
481 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
484 return ((joyCaps
.wCaps
& JOYCAPS_HASV
) == JOYCAPS_HASV
);
490 bool wxJoystick::HasPOV(void) const
492 #if defined(__WIN32__) && !defined(__TWIN32__)
494 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
497 return ((joyCaps
.wCaps
& JOYCAPS_HASPOV
) == JOYCAPS_HASPOV
);
503 bool wxJoystick::HasPOV4Dir(void) const
505 #if defined(__WIN32__) && !defined(__TWIN32__)
507 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
510 return ((joyCaps
.wCaps
& JOYCAPS_POV4DIR
) == JOYCAPS_POV4DIR
);
516 bool wxJoystick::HasPOVCTS(void) const
518 #if defined(__WIN32__) && !defined(__TWIN32__)
520 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
523 return ((joyCaps
.wCaps
& JOYCAPS_POVCTS
) == JOYCAPS_POVCTS
);
530 ////////////////////////////////////////////////////////////////////////////
532 bool wxJoystick::SetCapture(wxWindow
* win
, int pollingFreq
)
534 BOOL changed
= (pollingFreq
== 0);
535 MMRESULT res
= joySetCapture((HWND
) win
->GetHWND(), m_joystick
, pollingFreq
, changed
);
536 return (res
== JOYERR_NOERROR
);
539 bool wxJoystick::ReleaseCapture(void)
541 MMRESULT res
= joyReleaseCapture(m_joystick
);
542 return (res
== JOYERR_NOERROR
);