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 
39 namespace Pt {
40 
41 namespace Forms {
42 
43 class TouchEvent : public Pt::BasicEvent<TouchEvent>
44 {
45  private:
46  enum Action
47  {
48  Move = 0,
49  Press = 1,
50  Release = 2
51  };
52 
53  public:
54  explicit TouchEvent()
55  : _widgetId(0)
56  , _widget()
57  , _pos(0, 0)
58  , _action(Move)
59  , _trackingId(0)
60  , _pressure(1.0)
61  { }
62 
63  TouchEvent(Widget& widget)
64  : _widgetId( widget.id() )
65  , _widget(&widget)
66  , _pos(0, 0)
67  , _action(Move)
68  , _trackingId(0)
69  , _pressure(1.0)
70  { }
71 
72  void clear()
73  {
74  _pos.set(0, 0);
75  _action = Move;
76  _trackingId = 0;
77  _pressure = 1.0;
78  }
79 
80  void setId(Pt::uint64_t widgetId)
81  {
82  _widgetId = widgetId;
83  }
84 
85  Pt::uint64_t widgetId() const
86  {
87  return _widgetId;
88  }
89 
90  Widget* widget() const
91  {
92  return _widget;
93  }
94 
95  void setWidget(Widget* widget)
96  {
97  _widget = widget;
98  _widgetId = widget ? widget->id() : 0;
99  }
100 
101  const Gfx::PointF& position() const
102  {
103  return _pos;
104  }
105 
106  void setPosition(const Gfx::PointF& pos)
107  {
108  _pos = pos;
109  }
110 
111  double x() const
112  {
113  return _pos.x();
114  }
115 
116  void setX(double x)
117  {
118  _pos.setX(x);
119  }
120 
121  double y() const
122  {
123  return _pos.y();
124  }
125 
126  void setY(double y)
127  {
128  _pos.setY(y);
129  }
130 
131  Pt::uint32_t trackingId() const
132  {
133  return _trackingId;
134  }
135 
136  void setTrackingId(Pt::uint32_t tid)
137  {
138  _trackingId = tid;
139  }
140 
141  double pressure() const
142  {
143  return _pressure;
144  }
145 
146  void setPressure(double p)
147  {
148  _pressure = p;
149  }
150 
151  bool isMove() const
152  {
153  return _action == Move;
154  }
155 
156  void setMove()
157  {
158  _action = Move;
159  }
160 
163  bool isPressed() const
164  {
165  return _action == Move || _action == Press;
166  }
167 
170  bool isPress() const
171  {
172  return _action == Press;
173  }
174 
175  void setPress()
176  {
177  _action = Press;
178  }
179 
182  bool isRelease() const
183  {
184  return _action == Release;
185  }
186 
187  void setRelease()
188  {
189  _action = Release;
190  }
191 
192  private:
193  Pt::uint64_t _widgetId;
194  Widget* _widget;
195  Gfx::PointF _pos;
196  Action _action;
197  Pt::uint32_t _trackingId;
198  double _pressure;
199 };
200 
201 } // namespace
202 
203 } // namespace
204 
205 #endif
uint_type uint64_t
Unsigned 64-bit integer type.
Definition: Types.h:54
uint_type uint32_t
Unsigned 32-bit integer type.
Definition: Types.h:42