]>
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 #ifndef __GNUWIN32_OLD__
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 MMRESULT res
= joyGetPosEx(m_joystick
, & joyInfo
);
102 if (res
== JOYERR_NOERROR
)
104 return joyInfo
.dwPOV
;
113 int wxJoystick::GetPOVCTSPosition() const
115 #ifndef NO_JOYGETPOSEX
117 joyInfo
.dwFlags
= JOY_RETURNPOVCTS
;
118 MMRESULT res
= joyGetPosEx(m_joystick
, & joyInfo
);
119 if (res
== JOYERR_NOERROR
)
121 return joyInfo
.dwPOV
;
130 int wxJoystick::GetRudderPosition() const
132 #ifndef NO_JOYGETPOSEX
134 joyInfo
.dwFlags
= JOY_RETURNR
;
135 MMRESULT res
= joyGetPosEx(m_joystick
, & joyInfo
);
136 if (res
== JOYERR_NOERROR
)
138 return joyInfo
.dwRpos
;
147 int wxJoystick::GetUPosition() const
149 #ifndef NO_JOYGETPOSEX
151 joyInfo
.dwFlags
= JOY_RETURNU
;
152 MMRESULT res
= joyGetPosEx(m_joystick
, & joyInfo
);
153 if (res
== JOYERR_NOERROR
)
155 return joyInfo
.dwUpos
;
164 int wxJoystick::GetVPosition() const
166 #ifndef NO_JOYGETPOSEX
168 joyInfo
.dwFlags
= JOY_RETURNV
;
169 MMRESULT res
= joyGetPosEx(m_joystick
, & joyInfo
);
170 if (res
== JOYERR_NOERROR
)
172 return joyInfo
.dwVpos
;
181 int wxJoystick::GetMovementThreshold() const
184 MMRESULT res
= joyGetThreshold(m_joystick
, & thresh
);
185 if (res
== JOYERR_NOERROR
)
193 void wxJoystick::SetMovementThreshold(int threshold
)
195 UINT thresh
= threshold
;
196 joySetThreshold(m_joystick
, thresh
);
200 ////////////////////////////////////////////////////////////////////////////
202 bool wxJoystick::IsOk() const
205 MMRESULT res
= joyGetPos(m_joystick
, & joyInfo
);
206 return ((joyGetNumDevs() > 0) || (res
== JOYERR_NOERROR
));
209 int wxJoystick::GetNumberJoysticks() const
211 return joyGetNumDevs();
214 int wxJoystick::GetManufacturerId() const
217 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
223 int wxJoystick::GetProductId() const
226 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
232 wxString
wxJoystick::GetProductName() const
235 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
238 return wxString(joyCaps
.szPname
);
241 int wxJoystick::GetXMin() const
244 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
247 return joyCaps
.wXmin
;
250 int wxJoystick::GetYMin() const
253 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
256 return joyCaps
.wYmin
;
259 int wxJoystick::GetZMin() const
262 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
265 return joyCaps
.wZmin
;
268 int wxJoystick::GetXMax() const
271 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
274 return joyCaps
.wXmax
;
277 int wxJoystick::GetYMax() const
280 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
283 return joyCaps
.wYmax
;
286 int wxJoystick::GetZMax() const
289 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
292 return joyCaps
.wZmax
;
295 int wxJoystick::GetNumberButtons() const
298 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
301 return joyCaps
.wNumButtons
;
304 int wxJoystick::GetNumberAxes() const
306 #if defined(__WIN32__) && !defined(__TWIN32__)
308 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
311 return joyCaps
.wNumAxes
;
317 int wxJoystick::GetMaxButtons() const
319 #if defined(__WIN32__) && !defined(__TWIN32__)
321 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
324 return joyCaps
.wMaxButtons
;
330 int wxJoystick::GetMaxAxes() const
332 #if defined(__WIN32__) && !defined(__TWIN32__)
334 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
337 return joyCaps
.wMaxAxes
;
343 int wxJoystick::GetPollingMin() const
346 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
349 return joyCaps
.wPeriodMin
;
352 int wxJoystick::GetPollingMax() const
355 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
358 return joyCaps
.wPeriodMax
;
361 int wxJoystick::GetRudderMin() const
363 #if defined(__WIN32__) && !defined(__TWIN32__)
365 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
368 return joyCaps
.wRmin
;
374 int wxJoystick::GetRudderMax() const
376 #if defined(__WIN32__) && !defined(__TWIN32__)
378 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
381 return joyCaps
.wRmax
;
387 int wxJoystick::GetUMin() const
389 #if defined(__WIN32__) && !defined(__TWIN32__)
391 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
394 return joyCaps
.wUmin
;
400 int wxJoystick::GetUMax() const
402 #if defined(__WIN32__) && !defined(__TWIN32__)
404 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
407 return joyCaps
.wUmax
;
413 int wxJoystick::GetVMin() const
415 #if defined(__WIN32__) && !defined(__TWIN32__)
417 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
420 return joyCaps
.wVmin
;
426 int wxJoystick::GetVMax() const
428 #if defined(__WIN32__) && !defined(__TWIN32__)
430 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
433 return joyCaps
.wVmax
;
440 bool wxJoystick::HasRudder() const
442 #if defined(__WIN32__) && !defined(__TWIN32__)
444 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
447 return ((joyCaps
.wCaps
& JOYCAPS_HASR
) == JOYCAPS_HASR
);
453 bool wxJoystick::HasZ() const
455 #if defined(__WIN32__) && !defined(__TWIN32__)
457 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
460 return ((joyCaps
.wCaps
& JOYCAPS_HASZ
) == JOYCAPS_HASZ
);
466 bool wxJoystick::HasU() const
468 #if defined(__WIN32__) && !defined(__TWIN32__)
470 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
473 return ((joyCaps
.wCaps
& JOYCAPS_HASU
) == JOYCAPS_HASU
);
479 bool wxJoystick::HasV() const
481 #if defined(__WIN32__) && !defined(__TWIN32__)
483 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
486 return ((joyCaps
.wCaps
& JOYCAPS_HASV
) == JOYCAPS_HASV
);
492 bool wxJoystick::HasPOV() const
494 #if defined(__WIN32__) && !defined(__TWIN32__)
496 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
499 return ((joyCaps
.wCaps
& JOYCAPS_HASPOV
) == JOYCAPS_HASPOV
);
505 bool wxJoystick::HasPOV4Dir() const
507 #if defined(__WIN32__) && !defined(__TWIN32__)
509 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
512 return ((joyCaps
.wCaps
& JOYCAPS_POV4DIR
) == JOYCAPS_POV4DIR
);
518 bool wxJoystick::HasPOVCTS() const
520 #if defined(__WIN32__) && !defined(__TWIN32__)
522 if (joyGetDevCaps(m_joystick
, & joyCaps
, sizeof(JOYCAPS
)) != JOYERR_NOERROR
)
525 return ((joyCaps
.wCaps
& JOYCAPS_POVCTS
) == JOYCAPS_POVCTS
);
532 ////////////////////////////////////////////////////////////////////////////
534 bool wxJoystick::SetCapture(wxWindow
* win
, int pollingFreq
)
536 BOOL changed
= (pollingFreq
== 0);
537 MMRESULT res
= joySetCapture((HWND
) win
->GetHWND(), m_joystick
, pollingFreq
, changed
);
538 return (res
== JOYERR_NOERROR
);
541 bool wxJoystick::ReleaseCapture()
543 MMRESULT res
= joyReleaseCapture(m_joystick
);
544 return (res
== JOYERR_NOERROR
);