2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <dali/internal/event/events/gesture-detector-impl.h>
25 #include <dali/integration-api/debug.h>
26 #include <dali/internal/event/events/actor-gesture-data.h>
27 #include <dali/internal/event/events/gesture-event-processor.h>
28 #include <dali/internal/event/common/thread-local-storage.h>
29 #include <dali/internal/event/common/stage-impl.h>
37 GestureDetector::GestureDetector(Gesture::Type type)
39 mGestureEventProcessor(ThreadLocalStorage::Get().GetGestureEventProcessor())
43 GestureDetector::~GestureDetector()
45 if ( !mAttachedActors.empty() )
47 for ( GestureDetectorActorContainer::iterator iter = mAttachedActors.begin(), endIter = mAttachedActors.end(); iter != endIter; ++iter )
49 Actor* actor( *iter );
50 actor->RemoveObserver( *this );
51 actor->GetGestureData().RemoveGestureDetector( *this );
54 mAttachedActors.clear();
56 // Guard to allow handle destruction after Core has been destroyed
57 if ( Stage::IsInstalled() )
59 mGestureEventProcessor.RemoveGestureDetector( this );
64 void GestureDetector::Attach(Actor& actor)
66 if ( !IsAttached(actor) )
68 // Register with EventProcessor if first actor being added
69 if ( mAttachedActors.empty() )
71 mGestureEventProcessor.AddGestureDetector(this);
74 mAttachedActors.push_back(&actor);
76 // We need to observe the actor's destruction
77 actor.AddObserver(*this);
79 // Add the detector to the actor (so the actor knows it requires this gesture when going through hit-test algorithm)
80 actor.GetGestureData().AddGestureDetector( *this );
82 // Notification for derived classes
87 void GestureDetector::Detach(Actor& actor)
89 if ( !mAttachedActors.empty() )
91 GestureDetectorActorContainer::iterator match = find(mAttachedActors.begin(), mAttachedActors.end(), &actor);
93 if ( match != mAttachedActors.end() )
95 // We no longer need to observe the actor's destruction
96 actor.RemoveObserver(*this);
98 // Remove detector from actor-gesture-data
99 actor.GetGestureData().RemoveGestureDetector( *this );
101 mAttachedActors.erase(match);
103 // Notification for derived classes
104 OnActorDetach(actor);
106 // Unregister from gesture event processor if we do not have any actors
107 if ( mAttachedActors.empty() )
109 mGestureEventProcessor.RemoveGestureDetector(this);
115 void GestureDetector::DetachAll()
117 if ( !mAttachedActors.empty() )
119 GestureDetectorActorContainer attachedActors(mAttachedActors);
121 // Clear mAttachedActors before we call OnActorDetach in case derived classes call a method which manipulates mAttachedActors.
122 mAttachedActors.clear();
124 for ( GestureDetectorActorContainer::iterator iter = attachedActors.begin(), endIter = attachedActors.end(); iter != endIter; ++iter )
128 // We no longer need to observe the actor's destruction
129 actor->RemoveObserver(*this);
131 // Remove detector from actor-gesture-data
132 actor->GetGestureData().RemoveGestureDetector( *this );
134 // Notification for derived classes
135 OnActorDetach(*actor);
138 // Unregister from gesture event processor
139 mGestureEventProcessor.RemoveGestureDetector(this);
143 size_t GestureDetector::GetAttachedActorCount() const
145 return mAttachedActors.size();
148 Dali::Actor GestureDetector::GetAttachedActor(size_t index) const
152 if( index < mAttachedActors.size() )
154 actor = Dali::Actor( mAttachedActors[index] );
160 bool GestureDetector::IsAttached(Actor& actor) const
162 return find(mAttachedActors.begin(), mAttachedActors.end(), &actor) != mAttachedActors.end();
165 void GestureDetector::ObjectDestroyed(Object& object)
167 if ( !mAttachedActors.empty() )
169 GestureDetectorActorContainer::iterator match = find(mAttachedActors.begin(), mAttachedActors.end(), &object);
171 if ( match != mAttachedActors.end() )
173 mAttachedActors.erase(match);
175 // Notification for derived classes
176 OnActorDestroyed(object);
178 // Unregister from gesture event processor if we do not have any actors
179 if ( mAttachedActors.empty() )
181 mGestureEventProcessor.RemoveGestureDetector(this);
187 unsigned int GestureDetector::GetDefaultPropertyCount() const
192 void GestureDetector::GetDefaultPropertyIndices( Property::IndexContainer& ) const
196 const char* GestureDetector::GetDefaultPropertyName( Property::Index index ) const
201 Property::Index GestureDetector::GetDefaultPropertyIndex(const std::string& name) const
206 bool GestureDetector::IsDefaultPropertyWritable(Property::Index index) const
211 bool GestureDetector::IsDefaultPropertyAnimatable(Property::Index index) const
216 bool GestureDetector::IsDefaultPropertyAConstraintInput( Property::Index index ) const
221 Property::Type GestureDetector::GetDefaultPropertyType(Property::Index index) const
223 return Property::NONE;
226 void GestureDetector::SetDefaultProperty( Property::Index index, const Property::Value& property )
228 // None of our properties should be settable from Public API
231 Property::Value GestureDetector::GetDefaultProperty(Property::Index index) const
233 return Property::Value();
236 const SceneGraph::PropertyOwner* GestureDetector::GetSceneObject() const
241 const SceneGraph::PropertyBase* GestureDetector::GetSceneObjectAnimatableProperty( Property::Index index ) const
246 const PropertyInputImpl* GestureDetector::GetSceneObjectInputProperty( Property::Index index ) const
251 } // namespace Internal