~sil2100/nux/revert_640

« back to all changes in this revision

Viewing changes to Nux/Gesture.h

  • Committer: Łukasz 'sil2100' Zemczak
  • Date: 2012-08-08 12:58:24 UTC
  • Revision ID: lukasz.zemczak@canonical.com-20120808125824-12o0md3gbv5jrawm
Reverting revision 640, as it was causing many serious regressions. The direct cause seems to be libgeis, not the nux changes themselves - but this is the easiest way of resolving the problem. This code can be re-added once geis is fixed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright (C) 2012 - Canonical Ltd.
3
 
 *
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
7
 
 * of the License.
8
 
 *
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.
14
 
 *
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/>
17
 
 *
18
 
 * Authored by: Daniel d'Andrada <daniel.dandrada@canonical.com>
19
 
 */
20
 
 
21
 
#ifndef NUX_GESTURE_H
22
 
#define NUX_GESTURE_H
23
 
#include "Features.h"
24
 
#ifdef NUX_GESTURES_SUPPORT
25
 
 
26
 
#include <memory>
27
 
 
28
 
#include "NuxGraphics/GestureEvent.h"
29
 
 
30
 
/*
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.
34
 
 */
35
 
namespace nux
36
 
{
37
 
class InputArea;
38
 
 
39
 
/*
40
 
  Interface for gesture targets.
41
 
 */
42
 
class GestureTarget
43
 
{
44
 
  public:
45
 
 
46
 
    /*!
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.
50
 
     */
51
 
    virtual GestureDeliveryRequest GestureEvent(const GestureEvent &event) = 0;
52
 
 
53
 
    bool operator ==(const GestureTarget& other) const
54
 
    {
55
 
      return Equals(other);
56
 
    }
57
 
 
58
 
  private:
59
 
    /*!
60
 
      For some types of target, different instances may wrap the same actual target,
61
 
      in which case reimplementing this method is necessary.
62
 
     */
63
 
    virtual bool Equals(const GestureTarget& other) const
64
 
    {
65
 
      return this == &other;
66
 
    }
67
 
};
68
 
typedef std::shared_ptr<GestureTarget> ShPtGestureTarget;
69
 
 
70
 
class InputAreaTarget : public GestureTarget
71
 
{
72
 
  public:
73
 
    InputAreaTarget(InputArea *input_area);
74
 
    virtual GestureDeliveryRequest GestureEvent(const nux::GestureEvent &event);
75
 
 
76
 
  private:
77
 
    virtual bool Equals(const GestureTarget& other) const;
78
 
    ObjectWeakPtr<InputArea> input_area_;
79
 
};
80
 
 
81
 
//! A class that relates a multitouch gesture to its target entity
82
 
/*!
83
 
  It relates a gesture to its target, which can be either a window or
84
 
  unity.
85
 
 
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.
91
 
 */
92
 
class Gesture
93
 
{
94
 
  public:
95
 
 
96
 
    Gesture(const GestureEvent &event);
97
 
 
98
 
    void AddTarget(ShPtGestureTarget target);
99
 
    void RemoveTarget(ShPtGestureTarget target);
100
 
    const std::list<ShPtGestureTarget> &GetTargetList() const {return target_list_;}
101
 
 
102
 
    void EnableEventDelivery();
103
 
    void Update(const GestureEvent& event);
104
 
    bool IsConstructionFinished() const;
105
 
    bool IsDeliveringEvents() const {return event_delivery_enabled_;}
106
 
    int GetId() const;
107
 
    const std::vector<TouchPoint> &GetTouches() const;
108
 
 
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;
111
 
 
112
 
    //! Rejects the gesture.
113
 
    /*
114
 
      After rejection a gesture is no longer valid
115
 
     */
116
 
    void Reject();
117
 
 
118
 
    //! Accepts the gesture
119
 
    void Accept();
120
 
 
121
 
    enum class AcceptanceStatus
122
 
    {
123
 
      UNDECIDED,
124
 
      ACCEPTED,
125
 
      REJECTED
126
 
    };
127
 
 
128
 
    AcceptanceStatus GetAcceptanceStatus() const {return acceptance_status_;}
129
 
 
130
 
  private:
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);
136
 
 
137
 
    std::list<ShPtGestureTarget> target_list_;
138
 
 
139
 
    // events that are waiting to be delivered
140
 
    std::vector<GestureEvent> queued_events_;
141
 
 
142
 
    // last event delivered
143
 
    GestureEvent last_event_;
144
 
 
145
 
    bool event_delivery_enabled_;
146
 
    AcceptanceStatus acceptance_status_;
147
 
};
148
 
 
149
 
/*
150
 
  Stores information on all curently active gestures.
151
 
 */
152
 
class GestureSet
153
 
{
154
 
  public:
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);
160
 
 
161
 
    std::vector< std::shared_ptr<Gesture> >
162
 
      GetConflictingGestures(std::shared_ptr<Gesture> &gesture);
163
 
 
164
 
  private:
165
 
    std::map<int, std::shared_ptr<Gesture> > map_id_to_gesture_;
166
 
};
167
 
 
168
 
} // namespace nux
169
 
#endif // NUX_GESTURES_SUPPORT
170
 
#endif // NUX_GESTURE_H