Player12
An open source football management simulator
Loading...
Searching...
No Matches
swipe_gesture.h
Go to the documentation of this file.
1// -----------------------------------------------------------------------------
2// Football Management Project
3// Copyright (c) 2025 - 2026 Flavio Milinanni. All Rights Reserved.
4//
5// This file is part of the Football Management Project.
6// See the LICENSE file in the project root.
7// -----------------------------------------------------------------------------
8
9#pragma once
10
11#include <cstdint>
12
21{
23 float threshold = 10.0f;
25 float slop = 1.5f;
27 float dominance = 2.0f;
29 std::uint64_t idle_ns = 200'000'000;
30};
31
42{
43 public:
44 enum class Step : uint8_t
45 {
46 NONE,
47 BACK,
48 FORWARD
49 };
50
51 SwipeGesture() = default;
52 explicit SwipeGesture(const SwipeTuning& settings) : tuning(settings) {}
53
55 Step feed(float dx, float dy, std::uint64_t timestamp_ns);
56
61 void suppress(std::uint64_t timestamp_ns);
62
64 void reset();
65
70 [[nodiscard]] float progress(std::uint64_t now_ns) const;
71
72 [[nodiscard]] const SwipeTuning& getTuning() const { return tuning; }
73
74 private:
75 enum class Phase : uint8_t
76 {
77 IDLE,
80 IGNORED,
81 DONE
82 };
83
84 [[nodiscard]] bool expired(std::uint64_t now_ns) const;
85
88 float travel_x = 0.0f;
89 float travel_y = 0.0f;
90 std::uint64_t last_ns = 0;
91};
Recognises a two-finger sideways swipe from wheel samples.
Definition swipe_gesture.h:42
Phase phase
Definition swipe_gesture.h:87
SwipeGesture(const SwipeTuning &settings)
Definition swipe_gesture.h:52
std::uint64_t last_ns
Definition swipe_gesture.h:90
SwipeTuning tuning
Definition swipe_gesture.h:86
Step feed(float dx, float dy, std::uint64_t timestamp_ns)
Adds a wheel sample; returns the step it completes, if any.
Definition swipe_gesture.cpp:20
float progress(std::uint64_t now_ns) const
How far the gesture has gone at now_ns: 0 when none, up to 1 towards Back and down to -1 towards Forw...
Definition swipe_gesture.cpp:68
void reset()
Forgets the gesture in progress.
Definition swipe_gesture.cpp:59
Step
Definition swipe_gesture.h:45
const SwipeTuning & getTuning() const
Definition swipe_gesture.h:72
void suppress(std::uint64_t timestamp_ns)
Ignores the rest of the current gesture, e.g. while it runs over a list that scrolls sideways or whil...
Definition swipe_gesture.cpp:51
Phase
Definition swipe_gesture.h:76
float travel_x
Definition swipe_gesture.h:88
bool expired(std::uint64_t now_ns) const
Definition swipe_gesture.cpp:14
float travel_y
Definition swipe_gesture.h:89
SwipeGesture()=default
Thresholds of the sideways swipe, in mouse-wheel units.
Definition swipe_gesture.h:21
float dominance
Definition swipe_gesture.h:27
float threshold
Definition swipe_gesture.h:23
float slop
Definition swipe_gesture.h:25
std::uint64_t idle_ns
Definition swipe_gesture.h:29