1 ////////////////////////////////////////////////////////////
\r
3 // SFML - Simple and Fast Multimedia Library
\r
4 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
\r
6 // This software is provided 'as-is', without any express or implied warranty.
\r
7 // In no event will the authors be held liable for any damages arising from the use of this software.
\r
9 // Permission is granted to anyone to use this software for any purpose,
\r
10 // including commercial applications, and to alter it and redistribute it freely,
\r
11 // subject to the following restrictions:
\r
13 // 1. The origin of this software must not be misrepresented;
\r
14 // you must not claim that you wrote the original software.
\r
15 // If you use this software in a product, an acknowledgment
\r
16 // in the product documentation would be appreciated but is not required.
\r
18 // 2. Altered source versions must be plainly marked as such,
\r
19 // and must not be misrepresented as being the original software.
\r
21 // 3. This notice may not be removed or altered from any source distribution.
\r
23 ////////////////////////////////////////////////////////////
\r
25 #ifndef SFML_INPUT_HPP
\r
26 #define SFML_INPUT_HPP
\r
28 ////////////////////////////////////////////////////////////
\r
30 ////////////////////////////////////////////////////////////
\r
31 #include <SFML/Config.hpp>
\r
32 #include <SFML/System/NonCopyable.hpp>
\r
33 #include <SFML/Window/Event.hpp>
\r
34 #include <SFML/Window/WindowListener.hpp>
\r
39 ////////////////////////////////////////////////////////////
\r
40 /// Input handles real-time input from keyboard and mouse.
\r
41 /// Use it instead of events to handle continuous moves and more
\r
42 /// game-friendly inputs
\r
43 ////////////////////////////////////////////////////////////
\r
44 class SFML_API Input : public WindowListener, NonCopyable
\r
48 ////////////////////////////////////////////////////////////
\r
49 /// Default constructor
\r
51 ////////////////////////////////////////////////////////////
\r
54 ////////////////////////////////////////////////////////////
\r
55 /// Get the state of a key
\r
57 /// \param KeyCode : Key to check
\r
59 /// \return True if key is down, false if key is up
\r
61 ////////////////////////////////////////////////////////////
\r
62 bool IsKeyDown(Key::Code KeyCode) const;
\r
64 ////////////////////////////////////////////////////////////
\r
65 /// Get the state of a mouse button
\r
67 /// \param Button : Button to check
\r
69 /// \return True if button is down, false if button is up
\r
71 ////////////////////////////////////////////////////////////
\r
72 bool IsMouseButtonDown(Mouse::Button Button) const;
\r
74 ////////////////////////////////////////////////////////////
\r
75 /// Get the state of a joystick button
\r
77 /// \param JoyId : Identifier of the joystick to check (0 or 1)
\r
78 /// \param Button : Button to check
\r
80 /// \return True if button is down, false if button is up
\r
82 ////////////////////////////////////////////////////////////
\r
83 bool IsJoystickButtonDown(unsigned int JoyId, unsigned int Button) const;
\r
85 ////////////////////////////////////////////////////////////
\r
86 /// Get the mouse X position
\r
88 /// \return Current mouse left position, relative to owner window
\r
90 ////////////////////////////////////////////////////////////
\r
91 int GetMouseX() const;
\r
93 ////////////////////////////////////////////////////////////
\r
94 /// Get the mouse Y position
\r
96 /// \return Current mouse top position, relative to owner window
\r
98 ////////////////////////////////////////////////////////////
\r
99 int GetMouseY() const;
\r
101 ////////////////////////////////////////////////////////////
\r
102 /// Get a joystick axis position
\r
104 /// \param JoyId : Identifier of the joystick to check (0 or 1)
\r
105 /// \param Axis : Axis to get
\r
107 /// \return Current axis position, in the range [-100, 100] (except for POV, which is [0, 360])
\r
109 ////////////////////////////////////////////////////////////
\r
110 float GetJoystickAxis(unsigned int JoyId, Joy::Axis Axis) const;
\r
114 ////////////////////////////////////////////////////////////
\r
115 /// /see WindowListener::OnEvent
\r
117 ////////////////////////////////////////////////////////////
\r
118 virtual void OnEvent(const Event& EventReceived);
\r
120 ////////////////////////////////////////////////////////////
\r
121 /// Reset all the states
\r
123 ////////////////////////////////////////////////////////////
\r
124 void ResetStates();
\r
126 ////////////////////////////////////////////////////////////
\r
128 ////////////////////////////////////////////////////////////
\r
129 bool myKeys[Key::Count]; ///< Array containing the state of all keyboard keys
\r
130 bool myMouseButtons[Mouse::ButtonCount]; ///< Array containing the state of all mouse buttons
\r
131 int myMouseX; ///< Mouse position on X
\r
132 int myMouseY; ///< Mouse position on Y
\r
133 bool myJoystickButtons[Joy::Count][Joy::ButtonCount]; ///< Array containing the state of all joysticks buttons
\r
134 float myJoystickAxis[Joy::Count][Joy::AxisCount]; ///< Joysticks position on each axis
\r
140 #endif // SFML_INPUT_HPP
\r