From db72c6e47c13db097b13501d1d3a4744b087ec4a Mon Sep 17 00:00:00 2001 From: LaurentGom Date: Wed, 6 Jan 2010 08:48:57 +0000 Subject: [PATCH] Renamed Mouse::Count to Mouse::ButtonCount Renamed Joy::Count to Joy::AxisCount Added Joy::Count and Joy::ButtonCount git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/trunk@1328 4e206d99-4929-0410-ac5d-dfc041789085 --- include/SFML/Window/Event.hpp | 10 ++++++++-- include/SFML/Window/Input.hpp | 21 ++++++--------------- src/SFML/Window/Input.cpp | 12 ++++++------ src/SFML/Window/Joystick.hpp | 6 ++---- src/SFML/Window/Linux/Joystick.cpp | 10 ++++++---- src/SFML/Window/Linux/Joystick.hpp | 12 ++++++------ src/SFML/Window/Win32/Joystick.cpp | 6 +++--- src/SFML/Window/Win32/Joystick.hpp | 10 +++++----- src/SFML/Window/WindowImpl.cpp | 6 +++--- src/SFML/Window/WindowImpl.hpp | 13 ++++--------- 10 files changed, 49 insertions(+), 57 deletions(-) diff --git a/include/SFML/Window/Event.hpp b/include/SFML/Window/Event.hpp index c436d791f..35ac57553 100644 --- a/include/SFML/Window/Event.hpp +++ b/include/SFML/Window/Event.hpp @@ -160,7 +160,7 @@ namespace Mouse XButton1, XButton2, - Count // Keep last -- total number of mouse buttons + ButtonCount // Keep last -- total number of mouse buttons }; } @@ -180,7 +180,13 @@ namespace Joy AxisV, AxisPOV, - Count // Keep last -- total number of joystick axis + AxisCount // Keep last -- total number of joystick axis + }; + + enum + { + Count = 4, ///< Total number of supported joysticks + ButtonCount = 32 ///< Total number of supported joystick buttons }; } diff --git a/include/SFML/Window/Input.hpp b/include/SFML/Window/Input.hpp index 3485b80a2..e9e9c5e4a 100644 --- a/include/SFML/Window/Input.hpp +++ b/include/SFML/Window/Input.hpp @@ -123,24 +123,15 @@ private : //////////////////////////////////////////////////////////// void ResetStates(); - //////////////////////////////////////////////////////////// - // Joystick limits - //////////////////////////////////////////////////////////// - enum - { - NbJoysticks = 4, - NbJoystickButtons = 32 - }; - //////////////////////////////////////////////////////////// // Member data //////////////////////////////////////////////////////////// - bool myKeys[Key::Count]; ///< Array containing the state of all keyboard keys - bool myMouseButtons[Mouse::Count]; ///< Array containing the state of all mouse buttons - int myMouseX; ///< Mouse position on X - int myMouseY; ///< Mouse position on Y - bool myJoystickButtons[NbJoysticks][NbJoystickButtons]; ///< Array containing the state of all joysticks buttons - float myJoystickAxis[NbJoysticks][Joy::Count]; ///< Joysticks position on each axis + bool myKeys[Key::Count]; ///< Array containing the state of all keyboard keys + bool myMouseButtons[Mouse::ButtonCount]; ///< Array containing the state of all mouse buttons + int myMouseX; ///< Mouse position on X + int myMouseY; ///< Mouse position on Y + bool myJoystickButtons[Joy::Count][Joy::ButtonCount]; ///< Array containing the state of all joysticks buttons + float myJoystickAxis[Joy::Count][Joy::AxisCount]; ///< Joysticks position on each axis }; } // namespace sf diff --git a/src/SFML/Window/Input.cpp b/src/SFML/Window/Input.cpp index 06397d443..33b7161e0 100644 --- a/src/SFML/Window/Input.cpp +++ b/src/SFML/Window/Input.cpp @@ -64,7 +64,7 @@ bool Input::IsMouseButtonDown(Mouse::Button Button) const //////////////////////////////////////////////////////////// bool Input::IsJoystickButtonDown(unsigned int JoyId, unsigned int Button) const { - if ((JoyId < NbJoysticks) && (Button < NbJoystickButtons)) + if ((JoyId < Joy::Count) && (Button < Joy::ButtonCount)) return myJoystickButtons[JoyId][Button]; else return false; @@ -94,7 +94,7 @@ int Input::GetMouseY() const //////////////////////////////////////////////////////////// float Input::GetJoystickAxis(unsigned int JoyId, Joy::Axis Axis) const { - if (JoyId < NbJoysticks) + if (JoyId < Joy::Count) return myJoystickAxis[JoyId][Axis]; else return 0.f; @@ -152,15 +152,15 @@ void Input::ResetStates() for (int i = 0; i < Key::Count; ++i) myKeys[i] = false; - for (int i = 0; i < Mouse::Count; ++i) + for (int i = 0; i < Mouse::ButtonCount; ++i) myMouseButtons[i] = false; - for (int i = 0; i < NbJoysticks; ++i) + for (int i = 0; i < Joy::Count; ++i) { - for (int j = 0; j < NbJoystickButtons; ++j) + for (int j = 0; j < Joy::ButtonCount; ++j) myJoystickButtons[i][j] = false; - for (int j = 0; j < Joy::Count; ++j) + for (int j = 0; j < Joy::AxisCount; ++j) myJoystickAxis[i][j] = 0.f; } } diff --git a/src/SFML/Window/Joystick.hpp b/src/SFML/Window/Joystick.hpp index 4a17f4ef1..33e684e1a 100644 --- a/src/SFML/Window/Joystick.hpp +++ b/src/SFML/Window/Joystick.hpp @@ -41,10 +41,8 @@ namespace priv //////////////////////////////////////////////////////////// struct JoystickState { - enum {MaxButtons = 32}; - - float Axis[Joy::Count]; ///< Position on each axis in range [-100, 100] (except POV which is [0, 360]) - bool Buttons[MaxButtons]; ///< Status of each button (true = pressed) + float Axis[Joy::AxisCount]; ///< Position on each axis in range [-100, 100] (except POV which is [0, 360]) + bool Buttons[Joy::ButtonCount]; ///< Status of each button (true = pressed) }; } // namespace priv diff --git a/src/SFML/Window/Linux/Joystick.cpp b/src/SFML/Window/Linux/Joystick.cpp index c525ccb88..b14a292b0 100644 --- a/src/SFML/Window/Linux/Joystick.cpp +++ b/src/SFML/Window/Linux/Joystick.cpp @@ -51,11 +51,11 @@ void Joystick::Initialize(unsigned int Index) myNbButtons = 0; myPovX = 0; myPovY = 0; - for (int i = 0; i < JoystickState::MaxButtons; ++i) + for (int i = 0; i < Joy::ButtonCount; ++i) { myState.Buttons[i] = false; } - for (int i = 0; i < Joy::Count; ++i) + for (int i = 0; i < Joy::AxisCount; ++i) { myState.Axis[i] = 0.f; myAxes[i] = false; @@ -74,6 +74,8 @@ void Joystick::Initialize(unsigned int Index) char NbButtons; ioctl(myDescriptor, JSIOCGBUTTONS, &NbButtons); myNbButtons = NbButtons; + if (myNbButtons > Joy::ButtonCount) + myNbButtons = Joy::ButtonCount; // Get the supported axes char NbAxes, Axes[ABS_MAX + 1]; @@ -120,8 +122,8 @@ JoystickState Joystick::UpdateState() case ABS_RZ: case ABS_RUDDER: myState.Axis[Joy::AxisR] = JoyState.value * 100.f / 32767.f; break; case ABS_RX : myState.Axis[Joy::AxisU] = JoyState.value * 100.f / 32767.f; break; case ABS_RY : myState.Axis[Joy::AxisV] = JoyState.value * 100.f / 32767.f; break; - case ABS_HAT0X : myPovX = JoyState.value; break; - case ABS_HAT0Y : myPovY = JoyState.value; break; + case ABS_HAT0X : myPovX = JoyState.value; break; + case ABS_HAT0Y : myPovY = JoyState.value; break; default : break; } break; diff --git a/src/SFML/Window/Linux/Joystick.hpp b/src/SFML/Window/Linux/Joystick.hpp index 48855e92d..ea780f493 100644 --- a/src/SFML/Window/Linux/Joystick.hpp +++ b/src/SFML/Window/Linux/Joystick.hpp @@ -80,12 +80,12 @@ private : //////////////////////////////////////////////////////////// // Member data //////////////////////////////////////////////////////////// - int myDescriptor; ///< Linux descriptor of the joystick - unsigned int myNbButtons; ///< Number of buttons supported by the joystick - bool myAxes[Joy::Count]; ///< Supported axes - JoystickState myState; ///< Current state of the joystick - int myPovX; ///< Last X position of the POV - int myPovY; ///< Last Y position of the POV + int myDescriptor; ///< Linux descriptor of the joystick + unsigned int myNbButtons; ///< Number of buttons supported by the joystick + bool myAxes[Joy::AxisCount]; ///< Supported axes + JoystickState myState; ///< Current state of the joystick + int myPovX; ///< Last X position of the POV + int myPovY; ///< Last Y position of the POV }; } // namespace priv diff --git a/src/SFML/Window/Win32/Joystick.cpp b/src/SFML/Window/Win32/Joystick.cpp index 9d489aef9..486bbb403 100644 --- a/src/SFML/Window/Win32/Joystick.cpp +++ b/src/SFML/Window/Win32/Joystick.cpp @@ -46,7 +46,7 @@ void Joystick::Initialize(unsigned int Index) myNbButtons = 0; myIsConnected = false; myHasContinuousPOV = false; - for (int i = 0; i < Joy::Count; ++i) + for (int i = 0; i < Joy::AxisCount; ++i) myAxes[i] = false; // Get the Index-th connected joystick @@ -67,8 +67,8 @@ void Joystick::Initialize(unsigned int Index) JOYCAPS Caps; joyGetDevCaps(myIndex, &Caps, sizeof(Caps)); myNbButtons = Caps.wNumButtons; - if (myNbButtons > JoystickState::MaxButtons) - myNbButtons = JoystickState::MaxButtons; + if (myNbButtons > Joy::ButtonCount) + myNbButtons = Joy::ButtonCount; myAxes[Joy::AxisX] = true; myAxes[Joy::AxisY] = true; diff --git a/src/SFML/Window/Win32/Joystick.hpp b/src/SFML/Window/Win32/Joystick.hpp index 51666e5fb..153806944 100644 --- a/src/SFML/Window/Win32/Joystick.hpp +++ b/src/SFML/Window/Win32/Joystick.hpp @@ -80,11 +80,11 @@ private : //////////////////////////////////////////////////////////// // Member data //////////////////////////////////////////////////////////// - bool myIsConnected; ///< Is there a joystick connected? - unsigned int myIndex; ///< Windows ID of the joystick - unsigned int myNbButtons; ///< Number of buttons supported by the joystick - bool myAxes[Joy::Count]; ///< Supported axes - bool myHasContinuousPOV; ///< True if the driver supports continuous values for the POV + bool myIsConnected; ///< Is there a joystick connected? + unsigned int myIndex; ///< Windows ID of the joystick + unsigned int myNbButtons; ///< Number of buttons supported by the joystick + bool myAxes[Joy::AxisCount]; ///< Supported axes + bool myHasContinuousPOV; ///< True if the driver supports continuous values for the POV }; } // namespace priv diff --git a/src/SFML/Window/WindowImpl.cpp b/src/SFML/Window/WindowImpl.cpp index 7337fcabb..dd0584fb5 100644 --- a/src/SFML/Window/WindowImpl.cpp +++ b/src/SFML/Window/WindowImpl.cpp @@ -125,7 +125,7 @@ void WindowImpl::RemoveListener(WindowListener* Listener) void WindowImpl::Initialize() { // Initialize the joysticks - for (unsigned int i = 0; i < JoysticksCount; ++i) + for (unsigned int i = 0; i < Joy::Count; ++i) { myJoysticks[i].Initialize(i); myJoyStates[i] = myJoysticks[i].UpdateState(); @@ -214,14 +214,14 @@ int WindowImpl::EvaluateConfig(const VideoMode& Mode, const WindowSettings& Sett //////////////////////////////////////////////////////////// void WindowImpl::ProcessJoystickEvents() { - for (unsigned int i = 0; i < JoysticksCount; ++i) + for (unsigned int i = 0; i < Joy::Count; ++i) { // Copy the previous state of the joystick and get the new one JoystickState PreviousState = myJoyStates[i]; myJoyStates[i] = myJoysticks[i].UpdateState(); // Axis - for (unsigned int j = 0; j < Joy::Count; ++j) + for (unsigned int j = 0; j < Joy::AxisCount; ++j) { Joy::Axis Axis = static_cast(j); if (myJoysticks[i].HasAxis(Axis)) diff --git a/src/SFML/Window/WindowImpl.hpp b/src/SFML/Window/WindowImpl.hpp index 2e0198094..09f8b54ab 100644 --- a/src/SFML/Window/WindowImpl.hpp +++ b/src/SFML/Window/WindowImpl.hpp @@ -290,18 +290,13 @@ private : //////////////////////////////////////////////////////////// virtual void ProcessEvents() = 0; - //////////////////////////////////////////////////////////// - // Total number of joysticks supported - //////////////////////////////////////////////////////////// - enum {JoysticksCount = 4}; - //////////////////////////////////////////////////////////// // Member data //////////////////////////////////////////////////////////// - std::set myListeners; ///< Array of listeners connected to the window - Joystick myJoysticks[JoysticksCount]; ///< Joysticks to observe - JoystickState myJoyStates[JoysticksCount]; ///< Current states of the joysticks - float myJoyThreshold; ///< Joystick threshold (minimum motion for MOVE event to be generated) + std::set myListeners; ///< Array of listeners connected to the window + Joystick myJoysticks[Joy::Count]; ///< Joysticks to observe + JoystickState myJoyStates[Joy::Count]; ///< Current states of the joysticks + float myJoyThreshold; ///< Joystick threshold (minimum motion for MOVE event to be generated) }; } // namespace priv