X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/c42404a58eac2c9eb0557565a471a794c387a715..739c5499fcab1c165b8dd0591c9fd9e2329b3cf9:/src/msw/joystick.cpp diff --git a/src/msw/joystick.cpp b/src/msw/joystick.cpp index 28c0752f05..158c0b64b8 100644 --- a/src/msw/joystick.cpp +++ b/src/msw/joystick.cpp @@ -1,56 +1,81 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: joystick.cpp +// Name: src/msw/joystick.cpp // Purpose: wxJoystick class // Author: Julian Smart // Modified by: // Created: 04/01/98 // RCS-ID: $Id$ -// Copyright: (c) Julian Smart and Markus Holzem -// Licence: wxWindows license +// Copyright: (c) Julian Smart +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -#ifdef __GNUG__ -#pragma implementation "joystick.h" -#endif - // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" #ifdef __BORLANDC__ -#pragma hdrstop + #pragma hdrstop #endif -#include "wx/string.h" -#include "wx/window.h" -#include "wx/msw/private.h" +#if wxUSE_JOYSTICK -#ifndef __GNUWIN32_OLD__ - #include -#endif +#include "wx/joystick.h" -#if !defined(__WIN32__) && !defined(_MMRESULT_) -typedef UINT MMRESULT; +#ifndef WX_PRECOMP + #include "wx/string.h" + #include "wx/window.h" #endif -#ifndef __TWIN32__ -#ifdef __GNUWIN32_OLD__ -#include "wx/msw/gnuwin32/extra.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__) || defined(__TWIN32__) +#if !defined(__WIN32__) || defined(__BORLANDC__) #define NO_JOYGETPOSEX #endif -#include "wx/window.h" -#include "wx/msw/joystick.h" +#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 0; + return -1; #else - return 0; + 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 0; + return -1; #else - return 0; + return -1; #endif } @@ -132,6 +204,7 @@ 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 ) { @@ -149,6 +222,7 @@ 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 ) { @@ -166,6 +240,7 @@ 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 ) { @@ -199,16 +274,36 @@ void wxJoystick::SetMovementThreshold(int threshold) // Capabilities //////////////////////////////////////////////////////////////////////////// -bool wxJoystick::IsOk() const +/** + johan@linkdata.se 2002-08-20: + Now returns the number of connected, functioning + joysticks, as intended. +*/ +int wxJoystick::GetNumberJoysticks() { JOYINFO joyInfo; - MMRESULT res = joyGetPos(m_joystick, & joyInfo); - return ((joyGetNumDevs() > 0) || (res == JOYERR_NOERROR)); + int i, maxsticks, actualsticks; + maxsticks = joyGetNumDevs(); + actualsticks = 0; + for( i=0; iGetHWND(), m_joystick, pollingFreq, changed); return (res == JOYERR_NOERROR); +#else + wxUnusedVar(win); + wxUnusedVar(pollingFreq); + return false; +#endif } bool wxJoystick::ReleaseCapture() @@ -544,3 +658,4 @@ bool wxJoystick::ReleaseCapture() return (res == JOYERR_NOERROR); } +#endif // wxUSE_JOYSTICK