1.10
mousegesture.h
1/*
2 * Copyright (C) 2018 Microchip Technology Inc. All rights reserved.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6#ifndef EGT_DETAIL_MOUSEGESTURE_H
7#define EGT_DETAIL_MOUSEGESTURE_H
8
14#include <chrono>
15#include <egt/detail/meta.h>
16#include <egt/event.h>
17#include <egt/geometry.h>
18#include <egt/timer.h>
19#include <string>
20#include <vector>
21
22namespace egt
23{
24inline namespace v1
25{
26namespace detail
27{
28
37class EGT_API MouseGesture
38{
39public:
40
41 MouseGesture() noexcept;
42
44 using MouseCallback = std::function<void(Event& event)>;
45
49 void on_async_event(MouseCallback callback);
50
54 Event handle(const Event& event);
55
59 void start(const DisplayPoint& point);
60
62 EGT_NODISCARD const DisplayPoint& mouse_start() const
63 {
64 return m_mouse_start_pos;
65 }
66
68 EGT_NODISCARD bool active() const { return m_active; }
69
71 EGT_NODISCARD bool dragging() const { return m_dragging; }
72
76 void stop();
77
81 EGT_NODISCARD static DefaultDim drag_enable_distance()
82 {
83 return m_drag_enable_distance;
84 }
85
89 static void drag_enable_distance(DefaultDim distance)
90 {
91 m_drag_enable_distance = distance;
92 }
93
94protected:
95
97 void invoke_handlers(Event& event);
98
100 bool m_active{false};
101
103 bool m_dragging{false};
104
106 bool m_holding{false};
107
110
112 using CallbackArray = std::vector<MouseCallback>;
113
116
119
122};
123
124}
125
126}
127}
128
129#endif
Periodic timer.
Definition timer.h:281
Basic class for interpreting mouse events.
Definition mousegesture.h:38
EGT_NODISCARD bool active() const
Is active?
Definition mousegesture.h:68
static EGT_NODISCARD DefaultDim drag_enable_distance()
Get the distance to travel to enable the drag mode.
Definition mousegesture.h:81
CallbackArray m_callbacks
Registered callback functions.
Definition mousegesture.h:115
std::vector< MouseCallback > CallbackArray
Type for array of registered callbacks.
Definition mousegesture.h:112
EGT_NODISCARD bool dragging() const
Is dragging?
Definition mousegesture.h:71
void invoke_handlers(Event &event)
Invoke an event on each of the handlers.
DisplayPoint m_mouse_start_pos
The starting position of the mouse.
Definition mousegesture.h:109
static void drag_enable_distance(DefaultDim distance)
Set the distance to travel to enable the drag mode.
Definition mousegesture.h:89
void stop()
Stop any active dragging state.
PeriodicTimer m_long_click_timer
Async timer for detecting long clicks.
Definition mousegesture.h:118
std::function< void(Event &event)> MouseCallback
Type for mouse event callback.
Definition mousegesture.h:44
static DefaultDim m_drag_enable_distance
Cursor distance to enable the drag mode.
Definition mousegesture.h:121
int DefaultDim
Define the default dimension type used for geometry.
Definition geometry.h:34
EGT framework namespace.
Definition animation.h:24
A single event that has information about the event and state for the event.
Definition event.h:255