Improved pan gesture prediction
[platform/core/uifw/dali-core.git] / dali / internal / event / events / tap-gesture-detector-impl.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali/internal/event/events/tap-gesture-detector-impl.h>
20
21 // INTERNAL INCLUDES
22 #include <dali/public-api/events/tap-gesture.h>
23 #include <dali/public-api/object/type-registry.h>
24 #include <dali/integration-api/debug.h>
25 #include <dali/internal/event/events/gesture-event-processor.h>
26
27 namespace Dali
28 {
29
30 namespace Internal
31 {
32
33 namespace
34 {
35 BaseHandle Create()
36 {
37   return Dali::TapGestureDetector::New();
38 }
39
40 TypeRegistration mType( typeid(Dali::TapGestureDetector), typeid(Dali::GestureDetector), Create );
41
42 SignalConnectorType signalConnector1( mType, Dali::TapGestureDetector::SIGNAL_TAP_DETECTED, &TapGestureDetector::DoConnectSignal );
43
44 }
45
46 TapGestureDetectorPtr TapGestureDetector::New()
47 {
48   return new TapGestureDetector;
49 }
50
51 TapGestureDetectorPtr TapGestureDetector::New(unsigned int tapsRequired, unsigned int touchesRequired)
52 {
53   return new TapGestureDetector(tapsRequired, touchesRequired);
54 }
55
56 TapGestureDetector::TapGestureDetector()
57 : GestureDetector(Gesture::Tap),
58   mTapsRequired(1),
59   mTouchesRequired(1)
60 {
61 }
62
63 TapGestureDetector::TapGestureDetector(unsigned int tapsRequired, unsigned int touchesRequired)
64 : GestureDetector(Gesture::Tap),
65   mTapsRequired(tapsRequired),
66   mTouchesRequired(touchesRequired)
67 {
68 }
69
70 TapGestureDetector::~TapGestureDetector()
71 {
72 }
73
74 void TapGestureDetector::SetTapsRequired(unsigned int taps)
75 {
76   DALI_ASSERT_ALWAYS(taps > 0 && "Can only set a positive number of taps" );
77
78   if (mTapsRequired != taps)
79   {
80     mTapsRequired = taps;
81
82     if (!mAttachedActors.empty())
83     {
84       mGestureEventProcessor.GestureDetectorUpdated(this);
85     }
86   }
87 }
88
89 void TapGestureDetector::SetTouchesRequired(unsigned int touches)
90 {
91   DALI_ASSERT_ALWAYS(touches > 0 && "Can only set a positive number of touches" );
92
93   if (mTouchesRequired != touches)
94   {
95     mTouchesRequired = touches;
96
97     if (!mAttachedActors.empty())
98     {
99       mGestureEventProcessor.GestureDetectorUpdated(this);
100     }
101   }
102 }
103
104 unsigned int TapGestureDetector::GetTapsRequired() const
105 {
106   return mTapsRequired;
107 }
108
109 unsigned int TapGestureDetector::GetTouchesRequired() const
110 {
111   return mTouchesRequired;
112 }
113
114 void TapGestureDetector::EmitTapGestureSignal(Dali::Actor tappedActor, const TapGesture& tap)
115 {
116   // Guard against destruction during signal emission
117   Dali::TapGestureDetector handle( this );
118
119   mDetectedSignal.Emit( tappedActor, tap );
120 }
121
122 bool TapGestureDetector::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
123 {
124   bool connected( true );
125   TapGestureDetector* gesture = dynamic_cast<TapGestureDetector*>(object);
126
127   if ( Dali::TapGestureDetector::SIGNAL_TAP_DETECTED  == signalName )
128   {
129     gesture->DetectedSignal().Connect( tracker, functor );
130   }
131   else
132   {
133     // signalName does not match any signal
134     connected = false;
135   }
136
137   return connected;
138 }
139
140 void TapGestureDetector::OnActorAttach(Actor& actor)
141 {
142   // Do nothing
143 }
144
145 void TapGestureDetector::OnActorDetach(Actor& actor)
146 {
147   // Do nothing
148 }
149
150 void TapGestureDetector::OnActorDestroyed(Object& object)
151 {
152   // Do nothing
153 }
154
155 } // namespace Internal
156
157 } // namespace Dali