2
* Copyright (C) 2012 - Canonical Ltd.
4
* This program is free software: you can redistribute it and/or modify it
5
* under the terms of the GNU Lesser General Public License, as
6
* published by the Free Software Foundation; either version 2.1 or 3.0
9
* This program is distributed in the hope that it will be useful, but
10
* WITHOUT ANY WARRANTY; without even the implied warranties of
11
* MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
12
* PURPOSE. See the applicable version of the GNU Lesser General Public
13
* License for more details.
15
* You should have received a copy of both the GNU Lesser General Public
16
* License along with this program. If not, see <http://www.gnu.org/licenses/>
18
* Authored by: Daniel d'Andrada <daniel.dandrada@canonical.com>
24
#ifdef NUX_GESTURES_SUPPORT
28
#include "NuxGraphics/GestureEvent.h"
31
A collection of helper classes used by WindowCompositor for the task of
32
delivering GestureEvents to their correct target InputAreas and in the
33
decision of whether a gesture should be accepted or rejected.
40
Interface for gesture targets.
47
Called whenever there's a new gesture event for this target.
48
\param event GestureEvent to be processed by the target.
49
\return A request about the delivery of events for the related gesture.
51
virtual GestureDeliveryRequest GestureEvent(const GestureEvent &event) = 0;
53
bool operator ==(const GestureTarget& other) const
60
For some types of target, different instances may wrap the same actual target,
61
in which case reimplementing this method is necessary.
63
virtual bool Equals(const GestureTarget& other) const
65
return this == &other;
68
typedef std::shared_ptr<GestureTarget> ShPtGestureTarget;
70
class InputAreaTarget : public GestureTarget
73
InputAreaTarget(InputArea *input_area);
74
virtual GestureDeliveryRequest GestureEvent(const nux::GestureEvent &event);
77
virtual bool Equals(const GestureTarget& other) const;
78
ObjectWeakPtr<InputArea> input_area_;
81
//! A class that relates a multitouch gesture to its target entity
83
It relates a gesture to its target, which can be either a window or
86
It's fed with GestureEvents via Update().
87
It stores those GestureEvents in a queue until EnableEventDelivery() is
88
called, when all queued events are finally acted upon. After
89
that, further events fed via Update() will have an immediate effect over its
90
target instead of being queued.
96
Gesture(const GestureEvent &event);
98
void AddTarget(ShPtGestureTarget target);
99
void RemoveTarget(ShPtGestureTarget target);
100
const std::list<ShPtGestureTarget> &GetTargetList() const {return target_list_;}
102
void EnableEventDelivery();
103
void Update(const GestureEvent& event);
104
bool IsConstructionFinished() const;
105
bool IsDeliveringEvents() const {return event_delivery_enabled_;}
107
const std::vector<TouchPoint> &GetTouches() const;
109
//! Returns whether the given gesture has any touches in common with this one.
110
bool HasTouchesInCommon(const std::shared_ptr<Gesture> &other_gesture) const;
112
//! Rejects the gesture.
114
After rejection a gesture is no longer valid
118
//! Accepts the gesture
121
enum class AcceptanceStatus
128
AcceptanceStatus GetAcceptanceStatus() const {return acceptance_status_;}
131
const GestureEvent &GetLatestEvent() const;
132
GestureEvent &GetLatestEvent();
133
void DeliverEvent(const GestureEvent &event);
134
void ExecuteTargetExclusivityRequest(const GestureEvent &event,
135
std::list<ShPtGestureTarget>::iterator &it_requestor);
137
std::list<ShPtGestureTarget> target_list_;
139
// events that are waiting to be delivered
140
std::vector<GestureEvent> queued_events_;
142
// last event delivered
143
GestureEvent last_event_;
145
bool event_delivery_enabled_;
146
AcceptanceStatus acceptance_status_;
150
Stores information on all curently active gestures.
155
void Add(Gesture *gesture);
156
void Add(std::shared_ptr<Gesture> &gesture);
157
std::shared_ptr<Gesture> FindFromGestureId(int gesture_id);
158
std::shared_ptr<Gesture> FindFromTarget(ShPtGestureTarget target);
159
void Remove(std::shared_ptr<Gesture> &gesture);
161
std::vector< std::shared_ptr<Gesture> >
162
GetConflictingGestures(std::shared_ptr<Gesture> &gesture);
165
std::map<int, std::shared_ptr<Gesture> > map_id_to_gesture_;
169
#endif // NUX_GESTURES_SUPPORT
170
#endif // NUX_GESTURE_H