X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/2bda0e173844e8e0f8acf4e8ad8b5c26e5c6fe5d..d8abb95f4a6330f6207fe027264c238178fa0d59:/src/msw/joystick.cpp diff --git a/src/msw/joystick.cpp b/src/msw/joystick.cpp index 7911b1338f..1b9f8b04ce 100644 --- a/src/msw/joystick.cpp +++ b/src/msw/joystick.cpp @@ -1,37 +1,34 @@ ///////////////////////////////////////////////////////////////////////////// -// 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" -#if defined(__BORLANDC__) -#pragma hdrstop +#ifdef __BORLANDC__ + #pragma hdrstop #endif -#include +#if wxUSE_JOYSTICK -#ifndef __GNUWIN32__ -#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 -#ifdef __GNUWIN32__ -#include +#include "wx/msw/private.h" + +#if !defined(__GNUWIN32_OLD__) || defined(__CYGWIN10__) + #include #endif // Why doesn't BC++ have joyGetPosEx? @@ -39,24 +36,77 @@ typedef UINT MMRESULT; #define NO_JOYGETPOSEX #endif -#include +#include "wx/msw/registry.h" + +#include IMPLEMENT_DYNAMIC_CLASS(wxJoystick, wxObject) // Attributes //////////////////////////////////////////////////////////////////////////// -wxPoint wxJoystick::GetPosition(void) const +/** + 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 } -int wxJoystick::GetPOVCTSPosition(void) const +/** + 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 } -int wxJoystick::GetRudderPosition(void) const +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 ) { @@ -139,11 +217,12 @@ int wxJoystick::GetRudderPosition(void) const #endif } -int wxJoystick::GetUPosition(void) const +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 ) { @@ -156,11 +235,12 @@ int wxJoystick::GetUPosition(void) const #endif } -int wxJoystick::GetVPosition(void) const +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 ) { @@ -173,7 +253,7 @@ int wxJoystick::GetVPosition(void) const #endif } -int wxJoystick::GetMovementThreshold(void) const +int wxJoystick::GetMovementThreshold() const { UINT thresh = 0; MMRESULT res = joyGetThreshold(m_joystick, & thresh); @@ -194,19 +274,39 @@ void wxJoystick::SetMovementThreshold(int threshold) // Capabilities //////////////////////////////////////////////////////////////////////////// -bool wxJoystick::IsOk(void) 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; i