mirror of
https://github.com/SFML/SFML.git
synced 2024-11-28 22:31:09 +08:00
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:
parent
42b97d230f
commit
e2d0ffcdcf
@ -420,7 +420,7 @@
|
|||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath="..\..\src\SFML\Window\Input.hpp"
|
RelativePath="..\..\include\SFML\Window\Input.hpp"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
<File
|
||||||
@ -436,7 +436,7 @@
|
|||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath="..\..\src\SFML\Window\VideoMode.hpp"
|
RelativePath="..\..\include\SFML\Window\VideoMode.hpp"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
<File
|
||||||
@ -448,11 +448,11 @@
|
|||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath="..\..\src\SFML\Window\Window.hpp"
|
RelativePath="..\..\include\SFML\Window\Window.hpp"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath="..\..\src\SFML\Window\WindowHandle.hpp"
|
RelativePath="..\..\include\SFML\Window\WindowHandle.hpp"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
<File
|
||||||
@ -464,7 +464,7 @@
|
|||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath="..\..\src\SFML\Window\WindowListener.hpp"
|
RelativePath="..\..\include\SFML\Window\WindowListener.hpp"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
<File
|
||||||
@ -472,7 +472,7 @@
|
|||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath="..\..\src\SFML\Window\WindowStyle.hpp"
|
RelativePath="..\..\include\SFML\Window\WindowStyle.hpp"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
</Files>
|
</Files>
|
||||||
|
@ -117,15 +117,30 @@ private :
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
virtual void OnEvent(const Event& EventReceived);
|
virtual void OnEvent(const Event& EventReceived);
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
/// Reset all the states
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
void ResetStates();
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
// Joystick limits
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
NbJoysticks = 4,
|
||||||
|
NbJoystickButtons = 32
|
||||||
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Member data
|
// Member data
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
bool myKeys[Key::Count]; ///< Array containing the state of all keyboard keys
|
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 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 myMouseX; ///< Mouse position on X
|
int myMouseY; ///< Mouse position on Y
|
||||||
int myMouseY; ///< Mouse position on Y
|
bool myJoystickButtons[NbJoysticks][NbJoystickButtons]; ///< Array containing the state of all joysticks buttons
|
||||||
float myJoystickAxis[2][Joy::Count]; ///< Joysticks position on each axis
|
float myJoystickAxis[NbJoysticks][Joy::Count]; ///< Joysticks position on each axis
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace sf
|
} // namespace sf
|
||||||
|
@ -37,23 +37,7 @@ Input::Input() :
|
|||||||
myMouseX(0),
|
myMouseX(0),
|
||||||
myMouseY(0)
|
myMouseY(0)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < Key::Count; ++i)
|
ResetStates();
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -80,7 +64,7 @@ bool Input::IsMouseButtonDown(Mouse::Button Button) const
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
bool Input::IsJoystickButtonDown(unsigned int JoyId, unsigned int 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];
|
return myJoystickButtons[JoyId][Button];
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
@ -110,7 +94,10 @@ int Input::GetMouseY() const
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
float Input::GetJoystickAxis(unsigned int JoyId, Joy::Axis Axis) 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
|
// Lost focus event : we must reset all persistent states
|
||||||
case Event::LostFocus :
|
case Event::LostFocus :
|
||||||
{
|
{
|
||||||
for (int i = 0; i < Key::Count; ++i)
|
ResetStates();
|
||||||
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;
|
|
||||||
}
|
|
||||||
break;
|
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
|
} // namespace sf
|
||||||
|
Loading…
Reference in New Issue
Block a user