Fixed the number of supported joysticks in sf::Input

git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/trunk@1327 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
LaurentGom 2010-01-06 08:36:55 +00:00
parent 42b97d230f
commit e2d0ffcdcf
3 changed files with 56 additions and 42 deletions

View File

@ -420,7 +420,7 @@
>
</File>
<File
RelativePath="..\..\src\SFML\Window\Input.hpp"
RelativePath="..\..\include\SFML\Window\Input.hpp"
>
</File>
<File
@ -436,7 +436,7 @@
>
</File>
<File
RelativePath="..\..\src\SFML\Window\VideoMode.hpp"
RelativePath="..\..\include\SFML\Window\VideoMode.hpp"
>
</File>
<File
@ -448,11 +448,11 @@
>
</File>
<File
RelativePath="..\..\src\SFML\Window\Window.hpp"
RelativePath="..\..\include\SFML\Window\Window.hpp"
>
</File>
<File
RelativePath="..\..\src\SFML\Window\WindowHandle.hpp"
RelativePath="..\..\include\SFML\Window\WindowHandle.hpp"
>
</File>
<File
@ -464,7 +464,7 @@
>
</File>
<File
RelativePath="..\..\src\SFML\Window\WindowListener.hpp"
RelativePath="..\..\include\SFML\Window\WindowListener.hpp"
>
</File>
<File
@ -472,7 +472,7 @@
>
</File>
<File
RelativePath="..\..\src\SFML\Window\WindowStyle.hpp"
RelativePath="..\..\include\SFML\Window\WindowStyle.hpp"
>
</File>
</Files>

View File

@ -117,15 +117,30 @@ private :
////////////////////////////////////////////////////////////
virtual void OnEvent(const Event& EventReceived);
////////////////////////////////////////////////////////////
/// Reset all the states
///
////////////////////////////////////////////////////////////
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
bool myJoystickButtons[2][16]; ///< Array containing the state of all joysticks buttons
int myMouseX; ///< Mouse position on X
int myMouseY; ///< Mouse position on Y
float myJoystickAxis[2][Joy::Count]; ///< Joysticks position on each axis
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
};
} // namespace sf

View File

@ -37,23 +37,7 @@ Input::Input() :
myMouseX(0),
myMouseY(0)
{
for (int i = 0; i < Key::Count; ++i)
myKeys[i] = false;
for (int i = 0; i < Mouse::Count; ++i)
myMouseButtons[i] = false;
for (int i = 0; i < 16; ++i)
{
myJoystickButtons[0][i] = false;
myJoystickButtons[1][i] = false;
}
for (int i = 0; i < Joy::Count; ++i)
{
myJoystickAxis[0][i] = 0.f;
myJoystickAxis[1][i] = 0.f;
}
ResetStates();
}
@ -80,7 +64,7 @@ bool Input::IsMouseButtonDown(Mouse::Button Button) const
////////////////////////////////////////////////////////////
bool Input::IsJoystickButtonDown(unsigned int JoyId, unsigned int Button) const
{
if ((JoyId < 2) && (Button < 16))
if ((JoyId < NbJoysticks) && (Button < NbJoystickButtons))
return myJoystickButtons[JoyId][Button];
else
return false;
@ -110,7 +94,10 @@ int Input::GetMouseY() const
////////////////////////////////////////////////////////////
float Input::GetJoystickAxis(unsigned int JoyId, Joy::Axis Axis) const
{
return myJoystickAxis[JoyId][Axis];
if (JoyId < NbJoysticks)
return myJoystickAxis[JoyId][Axis];
else
return 0.f;
}
@ -147,17 +134,7 @@ void Input::OnEvent(const Event& EventReceived)
// Lost focus event : we must reset all persistent states
case Event::LostFocus :
{
for (int i = 0; i < Key::Count; ++i)
myKeys[i] = false;
for (int i = 0; i < Mouse::Count; ++i)
myMouseButtons[i] = false;
for (int i = 0; i < 16; ++i)
{
myJoystickButtons[0][i] = false;
myJoystickButtons[1][i] = false;
}
ResetStates();
break;
}
@ -166,4 +143,26 @@ void Input::OnEvent(const Event& EventReceived)
}
}
////////////////////////////////////////////////////////////
/// Reset all the states
////////////////////////////////////////////////////////////
void Input::ResetStates()
{
for (int i = 0; i < Key::Count; ++i)
myKeys[i] = false;
for (int i = 0; i < Mouse::Count; ++i)
myMouseButtons[i] = false;
for (int i = 0; i < NbJoysticks; ++i)
{
for (int j = 0; j < NbJoystickButtons; ++j)
myJoystickButtons[i][j] = false;
for (int j = 0; j < Joy::Count; ++j)
myJoystickAxis[i][j] = 0.f;
}
}
} // namespace sf