mirror of
https://github.com/SFML/CSFML.git
synced 2026-10-26 21:16:13 +01:00
Merge pull request #65 from zsbzsb/feature/sensor_touch_events
Added support for sensor and touch events
This commit is contained in:
commit
91a09b3ce5
2 files changed
+76
-31
No files matched your search
+61
-31
@@ -32,6 +32,7 @@
|
|||||||
#include <SFML/Window/Joystick.h>
|
#include <SFML/Window/Joystick.h>
|
||||||
#include <SFML/Window/Keyboard.h>
|
#include <SFML/Window/Keyboard.h>
|
||||||
#include <SFML/Window/Mouse.h>
|
#include <SFML/Window/Mouse.h>
|
||||||
|
#include <SFML/Window/Sensor.h>
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
@@ -40,24 +41,30 @@
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
sfEvtClosed,
|
sfEvtClosed, ///< The window requested to be closed (no data)
|
||||||
sfEvtResized,
|
sfEvtResized, ///< The window was resized (data in event.size)
|
||||||
sfEvtLostFocus,
|
sfEvtLostFocus, ///< The window lost the focus (no data)
|
||||||
sfEvtGainedFocus,
|
sfEvtGainedFocus, ///< The window gained the focus (no data)
|
||||||
sfEvtTextEntered,
|
sfEvtTextEntered, ///< A character was entered (data in event.text)
|
||||||
sfEvtKeyPressed,
|
sfEvtKeyPressed, ///< A key was pressed (data in event.key)
|
||||||
sfEvtKeyReleased,
|
sfEvtKeyReleased, ///< A key was released (data in event.key)
|
||||||
sfEvtMouseWheelMoved,
|
sfEvtMouseWheelMoved, ///< The mouse wheel was scrolled (data in event.mouseWheel)
|
||||||
sfEvtMouseButtonPressed,
|
sfEvtMouseButtonPressed, ///< A mouse button was pressed (data in event.mouseButton)
|
||||||
sfEvtMouseButtonReleased,
|
sfEvtMouseButtonReleased, ///< A mouse button was released (data in event.mouseButton)
|
||||||
sfEvtMouseMoved,
|
sfEvtMouseMoved, ///< The mouse cursor moved (data in event.mouseMove)
|
||||||
sfEvtMouseEntered,
|
sfEvtMouseEntered, ///< The mouse cursor entered the area of the window (no data)
|
||||||
sfEvtMouseLeft,
|
sfEvtMouseLeft, ///< The mouse cursor left the area of the window (no data)
|
||||||
sfEvtJoystickButtonPressed,
|
sfEvtJoystickButtonPressed, ///< A joystick button was pressed (data in event.joystickButton)
|
||||||
sfEvtJoystickButtonReleased,
|
sfEvtJoystickButtonReleased, ///< A joystick button was released (data in event.joystickButton)
|
||||||
sfEvtJoystickMoved,
|
sfEvtJoystickMoved, ///< The joystick moved along an axis (data in event.joystickMove)
|
||||||
sfEvtJoystickConnected,
|
sfEvtJoystickConnected, ///< A joystick was connected (data in event.joystickConnect)
|
||||||
sfEvtJoystickDisconnected
|
sfEvtJoystickDisconnected, ///< A joystick was disconnected (data in event.joystickConnect)
|
||||||
|
sfEvtTouchBegan, ///< A touch event began (data in event.touch)
|
||||||
|
sfEvtTouchMoved, ///< A touch moved (data in event.touch)
|
||||||
|
sfEvtTouchEnded, ///< A touch event ended (data in event.touch)
|
||||||
|
sfEvtSensorChanged, ///< A sensor value changed (data in event.sensor)
|
||||||
|
|
||||||
|
sfEvtCount, ///< Keep last -- the total number of event types
|
||||||
} sfEventType;
|
} sfEventType;
|
||||||
|
|
||||||
|
|
||||||
@@ -164,6 +171,30 @@ typedef struct
|
|||||||
unsigned int height;
|
unsigned int height;
|
||||||
} sfSizeEvent;
|
} sfSizeEvent;
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
/// \brief Touch events parameters
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
sfEventType type;
|
||||||
|
unsigned int finger;
|
||||||
|
int x;
|
||||||
|
int y;
|
||||||
|
} sfTouchEvent;
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
/// \brief Sensor event parameters
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
sfEventType type;
|
||||||
|
sfSensorType sensorType;
|
||||||
|
float x;
|
||||||
|
float y;
|
||||||
|
float z;
|
||||||
|
} sfSensorEvent;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief sfEvent defines a system event and its parameters
|
/// \brief sfEvent defines a system event and its parameters
|
||||||
@@ -171,19 +202,18 @@ typedef struct
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
typedef union
|
typedef union
|
||||||
{
|
{
|
||||||
////////////////////////////////////////////////////////////
|
sfEventType type; ///< Type of the event
|
||||||
// Member data
|
sfSizeEvent size; ///< Size event parameters
|
||||||
////////////////////////////////////////////////////////////
|
sfKeyEvent key; ///< Key event parameters
|
||||||
sfEventType type; ///< Type of the event
|
sfTextEvent text; ///< Text event parameters
|
||||||
sfSizeEvent size;
|
sfMouseMoveEvent mouseMove; ///< Mouse move event parameters
|
||||||
sfKeyEvent key;
|
sfMouseButtonEvent mouseButton; ///< Mouse button event parameters
|
||||||
sfTextEvent text;
|
sfMouseWheelEvent mouseWheel; ///< Mouse wheel event parameters
|
||||||
sfMouseMoveEvent mouseMove;
|
sfJoystickMoveEvent joystickMove; ///< Joystick move event parameters
|
||||||
sfMouseButtonEvent mouseButton;
|
sfJoystickButtonEvent joystickButton; ///< Joystick button event parameters
|
||||||
sfMouseWheelEvent mouseWheel;
|
sfJoystickConnectEvent joystickConnect; ///< Joystick (dis)connect event parameters
|
||||||
sfJoystickMoveEvent joystickMove;
|
sfTouchEvent touch; ///< Touch events parameters
|
||||||
sfJoystickButtonEvent joystickButton;
|
sfSensorEvent sensor; ///< Sensor event parameters
|
||||||
sfJoystickConnectEvent joystickConnect;
|
|
||||||
} sfEvent;
|
} sfEvent;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -96,6 +96,21 @@ inline void convertEvent(const sf::Event& SFMLEvent, sfEvent* event)
|
|||||||
event->joystickConnect.joystickId = SFMLEvent.joystickConnect.joystickId;
|
event->joystickConnect.joystickId = SFMLEvent.joystickConnect.joystickId;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case sfEvtTouchBegan :
|
||||||
|
case sfEvtTouchMoved :
|
||||||
|
case sfEvtTouchEnded :
|
||||||
|
event->touch.finger = SFMLEvent.touch.finger;
|
||||||
|
event->touch.x = SFMLEvent.touch.x;
|
||||||
|
event->touch.y = SFMLEvent.touch.y;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case sfEvtSensorChanged :
|
||||||
|
event->sensor.sensorType = static_cast<sfSensorType>(SFMLEvent.sensor.type);
|
||||||
|
event->sensor.x = SFMLEvent.sensor.x;
|
||||||
|
event->sensor.y = SFMLEvent.sensor.y;
|
||||||
|
event->sensor.z = SFMLEvent.sensor.z;
|
||||||
|
break;
|
||||||
|
|
||||||
default :
|
default :
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user