Player12
An open source football management simulator
Loading...
Searching...
No Matches
SwipeGesture Class Reference

Recognises a two-finger sideways swipe from wheel samples. More...

#include <swipe_gesture.h>

Public Types

enum class  Step : uint8_t { NONE , BACK , FORWARD }
 

Public Member Functions

 SwipeGesture ()=default
 
 SwipeGesture (const SwipeTuning &settings)
 
Step feed (float dx, float dy, std::uint64_t timestamp_ns)
 Adds a wheel sample; returns the step it completes, if any.
 
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 while a dialog is open.
 
void reset ()
 Forgets the gesture in progress.
 
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 Forward (±1 once it stepped).
 
const SwipeTuning & getTuning () const
 

Private Types

enum class  Phase : uint8_t {
  IDLE , UNDECIDED , SIDEWAYS , IGNORED ,
  DONE
}
 

Private Member Functions

bool expired (std::uint64_t now_ns) const
 

Private Attributes

SwipeTuning tuning
 
Phase phase = Phase::IDLE
 
float travel_x = 0.0f
 
float travel_y = 0.0f
 
std::uint64_t last_ns = 0
 

Detailed Description

Recognises a two-finger sideways swipe from wheel samples.

Fed with each wheel sample (dx > 0: the fingers moved right), it reports one step per gesture once the sideways travel passes the threshold, and then ignores the rest of that gesture. A gesture that starts vertically is a page scroll and is ignored until it ends; so is one that drifts into a vertical scroll. A pause longer than the idle gap starts a new gesture.

Member Enumeration Documentation

◆ Phase

enum class SwipeGesture::Phase : uint8_t
strongprivate
Enumerator
IDLE 
UNDECIDED 
SIDEWAYS 
IGNORED 
DONE 

◆ Step

enum class SwipeGesture::Step : uint8_t
strong
Enumerator
NONE 
BACK 

Fingers moved right: the previous screen.

FORWARD 

Fingers moved left: the next screen.

Constructor & Destructor Documentation

◆ SwipeGesture() [1/2]

SwipeGesture::SwipeGesture ( )
default

◆ SwipeGesture() [2/2]

SwipeGesture::SwipeGesture ( const SwipeTuning &  settings)
inlineexplicit

Member Function Documentation

◆ expired()

bool SwipeGesture::expired ( std::uint64_t  now_ns) const
private

◆ feed()

SwipeGesture::Step SwipeGesture::feed ( float  dx,
float  dy,
std::uint64_t  timestamp_ns 
)

Adds a wheel sample; returns the step it completes, if any.

◆ getTuning()

const SwipeTuning & SwipeGesture::getTuning ( ) const
inline

◆ progress()

float SwipeGesture::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 Forward (±1 once it stepped).

◆ reset()

void SwipeGesture::reset ( )

Forgets the gesture in progress.

◆ suppress()

void SwipeGesture::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 while a dialog is open.

Member Data Documentation

◆ last_ns

std::uint64_t SwipeGesture::last_ns = 0
private

◆ phase

Phase SwipeGesture::phase = Phase::IDLE
private

◆ travel_x

float SwipeGesture::travel_x = 0.0f
private

◆ travel_y

float SwipeGesture::travel_y = 0.0f
private

◆ tuning

SwipeTuning SwipeGesture::tuning
private

The documentation for this class was generated from the following files: