TouchEvent.h
1/*
2 Copyright (C) 2015 Marc Boris Duerner
3 Copyright (C) 2015 Laurentiu-Gheorghe Crisan
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 As a special exception, you may use this file as part of a free
11 software library without restriction. Specifically, if other files
12 instantiate templates or use macros or inline functions from this
13 file, or you compile this file and link it with other files to
14 produce an executable, this file does not by itself cause the
15 resulting executable to be covered by the GNU General Public
16 License. This exception does not however invalidate any other
17 reasons why the executable file might be covered by the GNU Library
18 General Public License.
19
20 This library is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 Lesser General Public License for more details.
24
25 You should have received a copy of the GNU Lesser General Public
26 License along with this library; if not, write to the Free Software
27 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
28 MA 02110-1301 USA
29*/
30
31#ifndef Pt_Forms_TouchEvent_h
32#define Pt_Forms_TouchEvent_h
33
34#include <Pt/Forms/Api.h>
35#include <Pt/Forms/Widget.h>
36#include <Pt/Gfx/Point.h>
37#include <Pt/Event.h>
38
39namespace Pt {
40
41namespace Forms {
42
50class TouchEvent : public Pt::BasicEvent<TouchEvent>
51{
52 private:
55 enum Action
56 {
57 Move = 0,
58 Press = 1,
59 Release = 2
60 };
61
62 public:
65 explicit TouchEvent()
66 : _widgetId(0)
67 , _widget()
68 , _pos(0, 0)
69 , _action(Move)
70 , _trackingId(0)
71 , _pressure(1.0)
72 { }
73
77 : _widgetId( widget.id() )
78 , _widget(&widget)
79 , _pos(0, 0)
80 , _action(Move)
81 , _trackingId(0)
82 , _pressure(1.0)
83 { }
84
87 void clear()
88 {
89 _pos.set(0, 0);
90 _action = Move;
91 _trackingId = 0;
92 _pressure = 1.0;
93 }
94
98 {
99 _widgetId = widgetId;
100 }
101
105 {
106 return _widgetId;
107 }
108
111 Widget* widget() const
112 {
113 return _widget;
114 }
115
119 {
120 _widget = widget;
121 _widgetId = widget ? widget->id() : 0;
122 }
123
126 const Gfx::PointF& position() const
127 {
128 return _pos;
129 }
130
133 void setPosition(const Gfx::PointF& pos)
134 {
135 _pos = pos;
136 }
137
140 double x() const
141 {
142 return _pos.x();
143 }
144
147 void setX(double x)
148 {
149 _pos.setX(x);
150 }
151
154 double y() const
155 {
156 return _pos.y();
157 }
158
161 void setY(double y)
162 {
163 _pos.setY(y);
164 }
165
169 {
170 return _trackingId;
171 }
172
176 {
177 _trackingId = tid;
178 }
179
182 double pressure() const
183 {
184 return _pressure;
185 }
186
189 void setPressure(double p)
190 {
191 _pressure = p;
192 }
193
196 bool isMove() const
197 {
198 return _action == Move;
199 }
200
203 void setMove()
204 {
205 _action = Move;
206 }
207
210 bool isPressed() const
211 {
212 return _action == Move || _action == Press;
213 }
214
217 bool isPress() const
218 {
219 return _action == Press;
220 }
221
224 void setPress()
225 {
226 _action = Press;
227 }
228
231 bool isRelease() const
232 {
233 return _action == Release;
234 }
235
239 {
240 _action = Release;
241 }
242
243 private:
244 Pt::uint64_t _widgetId;
245 Widget* _widget;
246 Gfx::PointF _pos;
247 Action _action;
248 Pt::uint32_t _trackingId;
249 double _pressure;
250};
251
252} // namespace
253
254} // namespace
255
256#endif
Event base that clones, destroys and identifies a derived type T.
Definition Event.h:144
void setPosition(const Gfx::PointF &pos)
Sets the touch position to pos.
Definition TouchEvent.h:133
Pt::uint32_t trackingId() const
Returns the identity of the tracked touch.
Definition TouchEvent.h:168
TouchEvent()
Creates an event without a target.
Definition TouchEvent.h:65
void setWidget(Widget *widget)
Sets the target widget and its ID.
Definition TouchEvent.h:118
double pressure() const
Returns the touch pressure.
Definition TouchEvent.h:182
bool isMove() const
Returns true when the event reports touch movement.
Definition TouchEvent.h:196
void setPress()
Changes the event to a touch press.
Definition TouchEvent.h:224
void setMove()
Changes the event to touch movement.
Definition TouchEvent.h:203
bool isRelease() const
Returns true if touch device was released.
Definition TouchEvent.h:231
void setTrackingId(Pt::uint32_t tid)
Sets the tracked touch identity to tid.
Definition TouchEvent.h:175
void setId(Pt::uint64_t widgetId)
Sets the target widget ID to widgetId.
Definition TouchEvent.h:97
TouchEvent(Widget &widget)
Creates an event targeted at widget.
Definition TouchEvent.h:76
bool isPressed() const
Returns true if touch device is in pressed state.
Definition TouchEvent.h:210
const Gfx::PointF & position() const
Returns the touch position in local coordinates.
Definition TouchEvent.h:126
void setY(double y)
Sets the local vertical touch position to y.
Definition TouchEvent.h:161
double x() const
Returns the local horizontal touch position.
Definition TouchEvent.h:140
void setRelease()
Changes the event to a touch release.
Definition TouchEvent.h:238
void setX(double x)
Sets the local horizontal touch position to x.
Definition TouchEvent.h:147
Widget * widget() const
Returns the target widget, or 0 when no target is set.
Definition TouchEvent.h:111
Pt::uint64_t widgetId() const
Returns the target widget ID.
Definition TouchEvent.h:104
void clear()
Resets the touch data while retaining the target.
Definition TouchEvent.h:87
double y() const
Returns the local vertical touch position.
Definition TouchEvent.h:154
bool isPress() const
Returns true if touch device was just pressed.
Definition TouchEvent.h:217
void setPressure(double p)
Sets the touch pressure to p.
Definition TouchEvent.h:189
Common type of every visual Forms object.
Definition Widget.h:105
Pt::uint64_t id() const
Returns the application-unique ID of this live widget.
uint_type uint32_t
Unsigned 32-bit integer type.
Definition Api-Types.h:52
uint_type uint64_t
Unsigned 64-bit integer type.
Definition Api-Types.h:66
Graphical user interfaces.
Definition ActivateEvent.h:40
Core module.
Definition Allocator.h:33