5#include <unordered_map>
9 using PointerId = size_t;
11 enum class PointerType
87 enum struct Kind : uint32_t
130 bool hoverEnable =
true;
131 bool wheelEnable =
true;
132 bool tapEnable =
true;
133 bool doubleTapEnable =
true;
134 bool pressEnable =
true;
135 bool dragEnable =
true;
136 bool swipeEnable =
true;
137 bool panEnable =
true;
138 bool rotateEnable =
true;
139 bool pinchEnable =
true;
142 uint32_t tapMaxDuration = 250;
143 uint32_t doubleTapTreshold = 300;
144 uint32_t swipeMaxDuration = 200;
145 float mouseMoveThreshold = 1.f;
146 float touchMoveThreshold = 16.f;
147 float touchVelocityThreshold = 500.f;
148 float mouseVelocityThreshold = 100.f;
149 float rotateThreshold = 0.05f;
150 float pinchThreshold = 0.1f;
154 void setDisplayScale(
float scale) { displayScale = scale; }
156 void pointerDown(PointerType pointerType, PointerId pointerId, MouseButton button, glm::ivec2 position,
double timestamp_ms);
157 void pointerUp(PointerType pointerType, PointerId pointerId, MouseButton button, glm::ivec2 position,
double timestamp_ms);
158 void pointerMove(PointerType pointerType, PointerId pointerId, glm::ivec2 position,
double timestamp_ms);
159 void mouseWheelMove(int32_t delta);
163 PointerType getPointerType();
166 const std::vector<Gesture>&
getGestures()
const {
return presentedGestures; }
169 float displayScale = 1.0f;
171 PointerType currPointerType = PointerType::Unknown;
173 std::vector<Gesture> presentedGestures;
174 std::vector<Gesture> currentGestures;
177 double lastTapTimestamp = 0;
179 std::optional<Gesture> currPress = std::nullopt;
180 std::optional<Gesture> currDrag = std::nullopt;
181 std::optional<Gesture> currPan = std::nullopt;
182 std::optional<Gesture> currRotate = std::nullopt;
183 std::optional<Gesture> currPinch = std::nullopt;
197 double timestamp_ms = 0.0;
201 PointerType type = PointerType::Unknown;
202 MouseButton button = MouseButton::NoButton;
203 State state = State::None;
211 uint32_t idCounter = 0;
212 [[nodiscard]] uint32_t nextGestureId() {
return idCounter++; }
215 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.
MouseButton button
Button that was tapped.
Coord coord
Pointer position when the event was triggered.
Coord currCoord
Pointer position when the event was triggered.
MouseButton button
Button that was tapped.
Coord startCoord
Pointer position when the gesture has started.
Coord coord
Pointer position when the event was triggered.
Coord midStartCoord
Mid position between the two pointer positions when the gesture has started.
Coord midCurrCoord
Mid position between the two pointer positions when the event was triggered.
Coord center
Mid position between the two pointer positions when the event was triggered.
float scale
Scale factor, 1 when the gesture starts.
Coord coord
Pointer position when the event was triggered.
MouseButton button
Button that was tapped.
float angle
Rotation angle in radians, 0 when the gesture starts.
Coord center
Mid position between the two pointer positions when the event was triggered.
Direction direction
Swipe general direction.
Coord startCoord
Pointer position when the gesture has started.
float velocity
Pointer velocity relative to startCoord.
MouseButton button
Button that was tapped.
Coord coord
Pointer position when the event was triggered.
MouseButton button
Button that was tapped.
Coord 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::ivec2 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.