Aurore
A Switch-like interface for your app, on every screen
Loading...
Searching...
No Matches
gesture.hpp
Go to the documentation of this file.
1/*
2 Copyright 2021 XITRIX
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15*/
16
17#pragma once
18
19#include <functional>
20#include <aurore/core/audio.hpp>
21#include <aurore/core/input.hpp>
22
23namespace aurore
24{
25
26class View;
27
28// Represents current gesture state
29enum class GestureState
30{
31 INTERRUPTED, // Gesture has been interupted, no callbacks will come
32 UNSURE, // Gesture started recognition and not sure if it should interupt other recognizers
33 START, // Gesture sure that it match to conditions and will interupt other recognizers
34 STAY, // Gesture in process, user still hold finger on screen
35 END, // User released their finger from screen, final frame of gesture
36 FAILED, // Gesture failed conditions
37};
38
39/*
40 * Superclass for all recognizers
41 *
42 * To create a new type of gesture recognizer, you should implement
43 * recognitionLoop method.
44 *
45 * It should contain logic with changing gesture's state.
46 * Recognizers' first state is UNSURE, in that state calling stack cannot tell
47 * which gesture user tries to apply. I.E. user puts and holds finger on the screen, so it can't be
48 * told whether it's going to be a tap or a swipe
49 *
50 * If gesture has been recognized, change its state to START, but ONLY for the first frame,
51 * on the next frame it should be changed to STAY and remain the same until the end, then it
52 * should change state to END.
53 *
54 * When any recognizer changes its state to START, it sends an interrupt event to every recognizer in the stack,
55 * so don't forget to handle that case.
56 *
57 * If gesture does not apply to recognizer's pattern, change its state to FAILED.
58 * It could also be used as a placerholder when recognizer is not in use.
59 *
60 * Use touch argument to get current state of touch.
61 *
62 * View argument contains the view to which this recognizer is attached.
63 *
64 * Use soundToPlay pointer to set sound which will be played in current frame.
65 * Leave it empty or use SOUND_NONE to not play any sound.
66 */
68{
69 public:
70 virtual ~GestureRecognizer() { }
71
72 // Main recognition loop, for internal usage only, should not be called anywhere, but Application
73 virtual GestureState recognitionLoop(TouchState touch, MouseState mouse, View* view, Sound* soundToPlay);
74
75 // Interrupt this recognizer
76 // If onlyIfUnsureState == true recognizer will be interupted
77 // only if current state is UNSURE
78 void interrupt(bool onlyIfUnsureState);
79
80 // If false, this recognizer will be skipped
81 bool isEnabled() const { return this->enabled; }
82
83 // If false, this recognizer will be skipped
84 void setEnabled(bool enabled) { this->enabled = enabled; }
85
86 // Get the current state of recognizer
87 GestureState getState() const { return state; }
88
89 protected:
91 bool enabled = true;
92};
93
94} // namespace aurore
Definition gesture.hpp:68
virtual ~GestureRecognizer()
Definition gesture.hpp:70
void setEnabled(bool enabled)
Definition gesture.hpp:84
GestureState getState() const
Definition gesture.hpp:87
GestureState state
Definition gesture.hpp:90
virtual GestureState recognitionLoop(TouchState touch, MouseState mouse, View *view, Sound *soundToPlay)
bool enabled
Definition gesture.hpp:91
void interrupt(bool onlyIfUnsureState)
bool isEnabled() const
Definition gesture.hpp:81
Definition view.hpp:232
Definition actions.hpp:25
Sound
Definition audio.hpp:23
GestureState
Definition gesture.hpp:30
Definition input.hpp:321
Definition input.hpp:277