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
This commit is contained in:
LaurentGom 2010-01-06 08:48:57 +00:00
parent e2d0ffcdcf
commit db72c6e47c
10 changed files with 49 additions and 57 deletions

View File

@ -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
};
}

View File

@ -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

View File

@ -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;
}
}

View File

@ -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

View File

@ -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;

View File

@ -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

View File

@ -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;

View File

@ -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

View File

@ -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<Joy::Axis>(j);
if (myJoysticks[i].HasAxis(Axis))

View File

@ -290,18 +290,13 @@ private :
////////////////////////////////////////////////////////////
virtual void ProcessEvents() = 0;
////////////////////////////////////////////////////////////
// Total number of joysticks supported
////////////////////////////////////////////////////////////
enum {JoysticksCount = 4};
////////////////////////////////////////////////////////////
// Member data
////////////////////////////////////////////////////////////
std::set<WindowListener*> 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<WindowListener*> 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