///////////////////////////////////////////////////////////////////////////// // Name: src/msw/joystick.cpp // Purpose: wxJoystick class // Author: Julian Smart // Modified by: // Created: 04/01/98 // RCS-ID: $Id$ // Copyright: (c) Julian Smart // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" #ifdef __BORLANDC__ #pragma hdrstop #endif #if wxUSE_JOYSTICK #include "wx/joystick.h" #ifndef WX_PRECOMP #include "wx/string.h" #include "wx/window.h" #endif #include "wx/msw/private.h" #if !defined(__GNUWIN32_OLD__) || defined(__CYGWIN10__) #include #endif // Why doesn't BC++ have joyGetPosEx? #if !defined(__WIN32__) || defined(__BORLANDC__) #define NO_JOYGETPOSEX #endif #include "wx/msw/registry.h" #include IMPLEMENT_DYNAMIC_CLASS(wxJoystick, wxObject) // Attributes //////////////////////////////////////////////////////////////////////////// /** johan@linkdata.se 2002-08-20: Now returns only valid, functioning joysticks, counting from the first available and upwards. */ wxJoystick::wxJoystick(int joystick) { JOYINFO joyInfo; int i, maxsticks; maxsticks = joyGetNumDevs(); for( i=0; i sizeof(int) * 8) return false; return (GetButtonState() & (1 << id)) != 0; } /** JLI 2002-08-20: Returns -1 to signify error. */ int wxJoystick::GetPOVPosition() const { #ifndef NO_JOYGETPOSEX JOYINFOEX joyInfo; joyInfo.dwFlags = JOY_RETURNPOV; joyInfo.dwSize = sizeof(joyInfo); MMRESULT res = joyGetPosEx(m_joystick, & joyInfo); if (res == JOYERR_NOERROR ) { return joyInfo.dwPOV; } else return -1; #else return -1; #endif } /** johan@linkdata.se 2002-08-20: Returns -1 to signify error. */ int wxJoystick::GetPOVCTSPosition() const { #ifndef NO_JOYGETPOSEX JOYINFOEX joyInfo; joyInfo.dwFlags = JOY_RETURNPOVCTS; joyInfo.dwSize = sizeof(joyInfo); MMRESULT res = joyGetPosEx(m_joystick, & joyInfo); if (res == JOYERR_NOERROR ) { return joyInfo.dwPOV; } else return -1; #else return -1; #endif } int wxJoystick::GetRudderPosition() const { #ifndef NO_JOYGETPOSEX JOYINFOEX joyInfo; joyInfo.dwFlags = JOY_RETURNR; joyInfo.dwSize = sizeof(joyInfo); MMRESULT res = joyGetPosEx(m_joystick, & joyInfo); if (res == JOYERR_NOERROR ) { return joyInfo.dwRpos; } else return 0; #else return 0; #endif } int wxJoystick::GetUPosition() const { #ifndef NO_JOYGETPOSEX JOYINFOEX joyInfo; joyInfo.dwFlags = JOY_RETURNU; joyInfo.dwSize = sizeof(joyInfo); MMRESULT res = joyGetPosEx(m_joystick, & joyInfo); if (res == JOYERR_NOERROR ) { return joyInfo.dwUpos; } else return 0; #else return 0; #endif } int wxJoystick::GetVPosition() const { #ifndef NO_JOYGETPOSEX JOYINFOEX joyInfo; joyInfo.dwFlags = JOY_RETURNV; joyInfo.dwSize = sizeof(joyInfo); MMRESULT res = joyGetPosEx(m_joystick, & joyInfo); if (res == JOYERR_NOERROR ) { return joyInfo.dwVpos; } else return 0; #else return 0; #endif } int wxJoystick::GetMovementThreshold() const { UINT thresh = 0; MMRESULT res = joyGetThreshold(m_joystick, & thresh); if (res == JOYERR_NOERROR ) { return thresh; } else return 0; } void wxJoystick::SetMovementThreshold(int threshold) { UINT thresh = threshold; joySetThreshold(m_joystick, thresh); } // Capabilities //////////////////////////////////////////////////////////////////////////// /** johan@linkdata.se 2002-08-20: Now returns the number of connected, functioning joysticks, as intended. */ int wxJoystick::GetNumberJoysticks() { JOYINFO joyInfo; int i, maxsticks, actualsticks; maxsticks = joyGetNumDevs(); actualsticks = 0; for( i=0; iGetHWND(), m_joystick, pollingFreq, changed); return (res == JOYERR_NOERROR); } bool wxJoystick::ReleaseCapture() { MMRESULT res = joyReleaseCapture(m_joystick); return (res == JOYERR_NOERROR); } #endif // wxUSE_JOYSTICK