|
|
|||
File indexing completed on 2026-06-02 08:58:15
0001 //////////////////////////////////////////////////////////// 0002 // 0003 // SFML - Simple and Fast Multimedia Library 0004 // Copyright (C) 2007-2023 Laurent Gomila (laurent@sfml-dev.org) 0005 // 0006 // This software is provided 'as-is', without any express or implied warranty. 0007 // In no event will the authors be held liable for any damages arising from the use of this software. 0008 // 0009 // Permission is granted to anyone to use this software for any purpose, 0010 // including commercial applications, and to alter it and redistribute it freely, 0011 // subject to the following restrictions: 0012 // 0013 // 1. The origin of this software must not be misrepresented; 0014 // you must not claim that you wrote the original software. 0015 // If you use this software in a product, an acknowledgment 0016 // in the product documentation would be appreciated but is not required. 0017 // 0018 // 2. Altered source versions must be plainly marked as such, 0019 // and must not be misrepresented as being the original software. 0020 // 0021 // 3. This notice may not be removed or altered from any source distribution. 0022 // 0023 //////////////////////////////////////////////////////////// 0024 0025 #ifndef SFML_EVENT_HPP 0026 #define SFML_EVENT_HPP 0027 0028 //////////////////////////////////////////////////////////// 0029 // Headers 0030 //////////////////////////////////////////////////////////// 0031 #include <SFML/Config.hpp> 0032 #include <SFML/Window/Joystick.hpp> 0033 #include <SFML/Window/Keyboard.hpp> 0034 #include <SFML/Window/Mouse.hpp> 0035 #include <SFML/Window/Sensor.hpp> 0036 0037 0038 namespace sf 0039 { 0040 //////////////////////////////////////////////////////////// 0041 /// \brief Defines a system event and its parameters 0042 /// 0043 //////////////////////////////////////////////////////////// 0044 class Event 0045 { 0046 public: 0047 0048 //////////////////////////////////////////////////////////// 0049 /// \brief Size events parameters (Resized) 0050 /// 0051 //////////////////////////////////////////////////////////// 0052 struct SizeEvent 0053 { 0054 unsigned int width; //!< New width, in pixels 0055 unsigned int height; //!< New height, in pixels 0056 }; 0057 0058 //////////////////////////////////////////////////////////// 0059 /// \brief Keyboard event parameters (KeyPressed, KeyReleased) 0060 /// 0061 //////////////////////////////////////////////////////////// 0062 struct KeyEvent 0063 { 0064 Keyboard::Key code; //!< Code of the key that has been pressed 0065 Keyboard::Scancode scancode; //!< Physical code of the key that has been pressed 0066 bool alt; //!< Is the Alt key pressed? 0067 bool control; //!< Is the Control key pressed? 0068 bool shift; //!< Is the Shift key pressed? 0069 bool system; //!< Is the System key pressed? 0070 }; 0071 0072 //////////////////////////////////////////////////////////// 0073 /// \brief Text event parameters (TextEntered) 0074 /// 0075 //////////////////////////////////////////////////////////// 0076 struct TextEvent 0077 { 0078 Uint32 unicode; //!< UTF-32 Unicode value of the character 0079 }; 0080 0081 //////////////////////////////////////////////////////////// 0082 /// \brief Mouse move event parameters (MouseMoved) 0083 /// 0084 //////////////////////////////////////////////////////////// 0085 struct MouseMoveEvent 0086 { 0087 int x; //!< X position of the mouse pointer, relative to the left of the owner window 0088 int y; //!< Y position of the mouse pointer, relative to the top of the owner window 0089 }; 0090 0091 //////////////////////////////////////////////////////////// 0092 /// \brief Mouse buttons events parameters 0093 /// (MouseButtonPressed, MouseButtonReleased) 0094 /// 0095 //////////////////////////////////////////////////////////// 0096 struct MouseButtonEvent 0097 { 0098 Mouse::Button button; //!< Code of the button that has been pressed 0099 int x; //!< X position of the mouse pointer, relative to the left of the owner window 0100 int y; //!< Y position of the mouse pointer, relative to the top of the owner window 0101 }; 0102 0103 //////////////////////////////////////////////////////////// 0104 /// \brief Mouse wheel events parameters (MouseWheelMoved) 0105 /// 0106 /// \deprecated This event is deprecated and potentially inaccurate. 0107 /// Use MouseWheelScrollEvent instead. 0108 /// 0109 //////////////////////////////////////////////////////////// 0110 struct MouseWheelEvent 0111 { 0112 int delta; //!< Number of ticks the wheel has moved (positive is up, negative is down) 0113 int x; //!< X position of the mouse pointer, relative to the left of the owner window 0114 int y; //!< Y position of the mouse pointer, relative to the top of the owner window 0115 }; 0116 0117 //////////////////////////////////////////////////////////// 0118 /// \brief Mouse wheel events parameters (MouseWheelScrolled) 0119 /// 0120 //////////////////////////////////////////////////////////// 0121 struct MouseWheelScrollEvent 0122 { 0123 Mouse::Wheel wheel; //!< Which wheel (for mice with multiple ones) 0124 float delta; //!< Wheel offset (positive is up/left, negative is down/right). High-precision mice may use non-integral offsets. 0125 int x; //!< X position of the mouse pointer, relative to the left of the owner window 0126 int y; //!< Y position of the mouse pointer, relative to the top of the owner window 0127 }; 0128 0129 //////////////////////////////////////////////////////////// 0130 /// \brief Joystick connection events parameters 0131 /// (JoystickConnected, JoystickDisconnected) 0132 /// 0133 //////////////////////////////////////////////////////////// 0134 struct JoystickConnectEvent 0135 { 0136 unsigned int joystickId; //!< Index of the joystick (in range [0 .. Joystick::Count - 1]) 0137 }; 0138 0139 //////////////////////////////////////////////////////////// 0140 /// \brief Joystick axis move event parameters (JoystickMoved) 0141 /// 0142 //////////////////////////////////////////////////////////// 0143 struct JoystickMoveEvent 0144 { 0145 unsigned int joystickId; //!< Index of the joystick (in range [0 .. Joystick::Count - 1]) 0146 Joystick::Axis axis; //!< Axis on which the joystick moved 0147 float position; //!< New position on the axis (in range [-100 .. 100]) 0148 }; 0149 0150 //////////////////////////////////////////////////////////// 0151 /// \brief Joystick buttons events parameters 0152 /// (JoystickButtonPressed, JoystickButtonReleased) 0153 /// 0154 //////////////////////////////////////////////////////////// 0155 struct JoystickButtonEvent 0156 { 0157 unsigned int joystickId; //!< Index of the joystick (in range [0 .. Joystick::Count - 1]) 0158 unsigned int button; //!< Index of the button that has been pressed (in range [0 .. Joystick::ButtonCount - 1]) 0159 }; 0160 0161 //////////////////////////////////////////////////////////// 0162 /// \brief Touch events parameters (TouchBegan, TouchMoved, TouchEnded) 0163 /// 0164 //////////////////////////////////////////////////////////// 0165 struct TouchEvent 0166 { 0167 unsigned int finger; //!< Index of the finger in case of multi-touch events 0168 int x; //!< X position of the touch, relative to the left of the owner window 0169 int y; //!< Y position of the touch, relative to the top of the owner window 0170 }; 0171 0172 //////////////////////////////////////////////////////////// 0173 /// \brief Sensor event parameters (SensorChanged) 0174 /// 0175 //////////////////////////////////////////////////////////// 0176 struct SensorEvent 0177 { 0178 Sensor::Type type; //!< Type of the sensor 0179 float x; //!< Current value of the sensor on X axis 0180 float y; //!< Current value of the sensor on Y axis 0181 float z; //!< Current value of the sensor on Z axis 0182 }; 0183 0184 //////////////////////////////////////////////////////////// 0185 /// \brief Enumeration of the different types of events 0186 /// 0187 //////////////////////////////////////////////////////////// 0188 enum EventType 0189 { 0190 Closed, //!< The window requested to be closed (no data) 0191 Resized, //!< The window was resized (data in event.size) 0192 LostFocus, //!< The window lost the focus (no data) 0193 GainedFocus, //!< The window gained the focus (no data) 0194 TextEntered, //!< A character was entered (data in event.text) 0195 KeyPressed, //!< A key was pressed (data in event.key) 0196 KeyReleased, //!< A key was released (data in event.key) 0197 MouseWheelMoved, //!< The mouse wheel was scrolled (data in event.mouseWheel) (deprecated) 0198 MouseWheelScrolled, //!< The mouse wheel was scrolled (data in event.mouseWheelScroll) 0199 MouseButtonPressed, //!< A mouse button was pressed (data in event.mouseButton) 0200 MouseButtonReleased, //!< A mouse button was released (data in event.mouseButton) 0201 MouseMoved, //!< The mouse cursor moved (data in event.mouseMove) 0202 MouseEntered, //!< The mouse cursor entered the area of the window (no data) 0203 MouseLeft, //!< The mouse cursor left the area of the window (no data) 0204 JoystickButtonPressed, //!< A joystick button was pressed (data in event.joystickButton) 0205 JoystickButtonReleased, //!< A joystick button was released (data in event.joystickButton) 0206 JoystickMoved, //!< The joystick moved along an axis (data in event.joystickMove) 0207 JoystickConnected, //!< A joystick was connected (data in event.joystickConnect) 0208 JoystickDisconnected, //!< A joystick was disconnected (data in event.joystickConnect) 0209 TouchBegan, //!< A touch event began (data in event.touch) 0210 TouchMoved, //!< A touch moved (data in event.touch) 0211 TouchEnded, //!< A touch event ended (data in event.touch) 0212 SensorChanged, //!< A sensor value changed (data in event.sensor) 0213 0214 Count //!< Keep last -- the total number of event types 0215 }; 0216 0217 //////////////////////////////////////////////////////////// 0218 // Member data 0219 //////////////////////////////////////////////////////////// 0220 EventType type; //!< Type of the event 0221 0222 union 0223 { 0224 SizeEvent size; //!< Size event parameters (Event::Resized) 0225 KeyEvent key; //!< Key event parameters (Event::KeyPressed, Event::KeyReleased) 0226 TextEvent text; //!< Text event parameters (Event::TextEntered) 0227 MouseMoveEvent mouseMove; //!< Mouse move event parameters (Event::MouseMoved) 0228 MouseButtonEvent mouseButton; //!< Mouse button event parameters (Event::MouseButtonPressed, Event::MouseButtonReleased) 0229 MouseWheelEvent mouseWheel; //!< Mouse wheel event parameters (Event::MouseWheelMoved) (deprecated) 0230 MouseWheelScrollEvent mouseWheelScroll; //!< Mouse wheel event parameters (Event::MouseWheelScrolled) 0231 JoystickMoveEvent joystickMove; //!< Joystick move event parameters (Event::JoystickMoved) 0232 JoystickButtonEvent joystickButton; //!< Joystick button event parameters (Event::JoystickButtonPressed, Event::JoystickButtonReleased) 0233 JoystickConnectEvent joystickConnect; //!< Joystick (dis)connect event parameters (Event::JoystickConnected, Event::JoystickDisconnected) 0234 TouchEvent touch; //!< Touch events parameters (Event::TouchBegan, Event::TouchMoved, Event::TouchEnded) 0235 SensorEvent sensor; //!< Sensor event parameters (Event::SensorChanged) 0236 }; 0237 }; 0238 0239 } // namespace sf 0240 0241 0242 #endif // SFML_EVENT_HPP 0243 0244 0245 //////////////////////////////////////////////////////////// 0246 /// \class sf::Event 0247 /// \ingroup window 0248 /// 0249 /// sf::Event holds all the informations about a system event 0250 /// that just happened. Events are retrieved using the 0251 /// sf::Window::pollEvent and sf::Window::waitEvent functions. 0252 /// 0253 /// A sf::Event instance contains the type of the event 0254 /// (mouse moved, key pressed, window closed, ...) as well 0255 /// as the details about this particular event. Please note that 0256 /// the event parameters are defined in a union, which means that 0257 /// only the member matching the type of the event will be properly 0258 /// filled; all other members will have undefined values and must not 0259 /// be read if the type of the event doesn't match. For example, 0260 /// if you received a KeyPressed event, then you must read the 0261 /// event.key member, all other members such as event.mouseMove 0262 /// or event.text will have undefined values. 0263 /// 0264 /// Usage example: 0265 /// \code 0266 /// sf::Event event; 0267 /// while (window.pollEvent(event)) 0268 /// { 0269 /// // Request for closing the window 0270 /// if (event.type == sf::Event::Closed) 0271 /// window.close(); 0272 /// 0273 /// // The escape key was pressed 0274 /// if ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Escape)) 0275 /// window.close(); 0276 /// 0277 /// // The window was resized 0278 /// if (event.type == sf::Event::Resized) 0279 /// doSomethingWithTheNewSize(event.size.width, event.size.height); 0280 /// 0281 /// // etc ... 0282 /// } 0283 /// \endcode 0284 /// 0285 ////////////////////////////////////////////////////////////
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|