5#include <unordered_map>
9 using PointerId = size_t;
11 enum class PointerType
82 enum struct Kind : uint32_t
120 Gesture() { memset((
void*)
this, 0,
sizeof(*
this)); }
121 Gesture(
const Gesture& src) { memcpy((
void*)
this, &src,
sizeof(*
this)); }
122 void operator =(
const Gesture& src) { memcpy((
void*)
this, &src,
sizeof(*
this)); }
129 bool hoverEnable =
true;
130 bool wheelEnable =
true;
131 bool tapEnable =
true;
132 bool doubleTapEnable =
true;
133 bool pressEnable =
true;
134 bool dragEnable =
true;
135 bool swipeEnable =
true;
136 bool panEnable =
true;
137 bool rotateEnable =
true;
138 bool pinchEnable =
true;
141 uint32_t tapMaxDuration = 250;
142 uint32_t doubleTapTreshold = 300;
143 uint32_t swipeMaxDuration = 200;
144 float mouseMoveThreshold = 1.f;
145 float touchMoveThreshold = 16.f;
146 float touchVelocityThreshold = 500.f;
147 float mouseVelocityThreshold = 100.f;
148 float rotateThreshold = 0.05f;
149 float pinchThreshold = 0.1f;
153 void setDisplayScale(
float scale) { displayScale = scale; }
155 void pointerDown(PointerType pointerType, PointerId pointerId, MouseButton button, glm::vec2 position,
double timestamp_ms);
156 void pointerUp(PointerType pointerType, PointerId pointerId, MouseButton button, glm::vec2 position,
double timestamp_ms);
157 void pointerMove(PointerType pointerType, PointerId pointerId, glm::vec2 position,
double timestamp_ms);
158 void mouseWheelMove(int32_t delta);
162 PointerType getPointerType();
165 const std::vector<Gesture>&
getGestures()
const {
return presentedGestures; }
168 float displayScale = 1.0f;
170 PointerType currPointerType = PointerType::Unknown;
172 std::vector<Gesture> presentedGestures;
173 std::vector<Gesture> currentGestures;
176 double lastTapTimestamp = 0;
178 std::optional<Gesture> currPress = std::nullopt;
179 std::optional<Gesture> currDrag = std::nullopt;
180 std::optional<Gesture> currPan = std::nullopt;
181 std::optional<Gesture> currRotate = std::nullopt;
182 std::optional<Gesture> currPinch = std::nullopt;
196 double timestamp_ms = 0.0;
200 PointerType type = PointerType::Unknown;
201 MouseButton button = MouseButton::NoButton;
202 State state = State::None;
210 uint32_t idCounter = 0;
211 [[nodiscard]] uint32_t nextGestureId() {
return idCounter++; }
214 void endUpdatingGesture(std::optional<Gesture>& gesture,
Gesture::State state);
const std::vector< Gesture > & getGestures() const
Return all gestures recognised in the previous frame. Use id to differentiate between gestures.
std::unordered_map< PointerId, PointerState > currentPointers
Set of currently active pointers.
Contains all Cogs related functionality.
glm::vec2 coord
Pointer position when the event was triggered.
MouseButton button
Button that was tapped.
glm::vec2 currCoord
Pointer position when the event was triggered.
MouseButton button
Button that was tapped.
glm::vec2 startCoord
Pointer position when the gesture has started.
glm::vec2 coord
Pointer position when the event was triggered.
glm::vec2 midStartCoord
Mid position between the two pointer positions when the gesture has started.
glm::vec2 midCurrCoord
Mid position between the two pointer positions when the event was triggered.
glm::vec2 center
Mid position between the two pointer positions when the event was triggered.
float scale
Scale factor, 1 when the gesture starts.
MouseButton button
Button that was tapped.
glm::vec2 coord
Pointer position when the event was triggered.
glm::vec2 center
Mid position between the two pointer positions when the event was triggered.
float angle
Rotation angle in radians, 0 when the gesture starts.
Direction direction
Swipe general direction.
glm::vec2 startCoord
Pointer position when the gesture has started.
float velocity
Pointer velocity relative to startCoord.
MouseButton button
Button that was tapped.
glm::vec2 coord
Pointer position when the event was triggered.
MouseButton button
Button that was tapped.
glm::vec2 coord
Pointer position when the event was triggered.
int32_t delta
Amount by which the mouse wheel was moved.
@ Ended
Gesture ended or single-fire events, used by all gestures.
@ Changed
Gesture changed, used by: Drag, Swipe, Pan, Rotate, Pinch.
@ Started
Gesture started, used by: Press, Drag, Swipe, Pan, Rotate, Pinch.
@ Cancelled
Gesture cancelled, used by: Press, Drag, Swipe, Pan, Rotate, Pinch.
Hover hover
< Specific gesture data.
Kind kind
Gesture type, see Kind.
State state
Gesture state, see State.
uint32_t id
Unique gesture id.
glm::vec2 position
Pixel x and y position.
Data curr
Current pointer data.
Data init
Pointer data when pointer was pressed.
Data prev
Pointer data before previous update.