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/actors/layer-impl.h>
22 #include <dali/public-api/common/dali-common.h>
23 #include <dali/public-api/object/type-registry.h>
24 #include <dali/internal/event/common/property-index-ranges.h>
25 #include <dali/internal/event/common/stage-impl.h>
26 #include <dali/internal/event/actors/layer-list.h>
28 using Dali::Internal::SceneGraph::UpdateManager;
33 const Property::Index Layer::CLIPPING_ENABLE = Internal::DEFAULT_ACTOR_PROPERTY_MAX_COUNT;
34 const Property::Index Layer::CLIPPING_BOX = Internal::DEFAULT_ACTOR_PROPERTY_MAX_COUNT + 1;
38 bool Layer::mFirstInstance = true;
39 Actor::DefaultPropertyLookup* Layer::mDefaultLayerPropertyLookup = NULL;
46 return Dali::Layer::New();
49 TypeRegistration mType( typeid(Dali::Layer), typeid(Dali::Actor), Create );
51 TypeAction a1(mType, Dali::Layer::ACTION_RAISE, &Layer::DoAction);
52 TypeAction a2(mType, Dali::Layer::ACTION_LOWER, &Layer::DoAction);
53 TypeAction a3(mType, Dali::Layer::ACTION_RAISE_TO_TOP, &Layer::DoAction);
54 TypeAction a4(mType, Dali::Layer::ACTION_LOWER_TO_BOTTOM, &Layer::DoAction);
56 const std::string DEFAULT_LAYER_PROPERTY_NAMES[] =
61 const int DEFAULT_LAYER_PROPERTY_COUNT = sizeof( DEFAULT_LAYER_PROPERTY_NAMES ) / sizeof( std::string );
63 const Property::Type DEFAULT_LAYER_PROPERTY_TYPES[DEFAULT_LAYER_PROPERTY_COUNT] =
65 Property::BOOLEAN, // "clipping-enable",
66 Property::RECTANGLE, // "clipping-box",
69 } // unnamed namespace
73 LayerPtr layer( new Layer( Actor::LAYER ) );
75 // Second-phase construction
81 LayerPtr Layer::NewRoot( Stage& stage, LayerList& layerList, UpdateManager& manager, bool systemLevel )
83 LayerPtr root( new Layer( Actor::ROOT_LAYER ) );
85 // Second-phase construction
86 SceneGraph::Layer* layer = static_cast<SceneGraph::Layer*>( root->CreateNode() );
87 InstallRootMessage( manager, *layer, systemLevel ); // Transfer ownership to scene-graph
89 // Keep a raw pointer to the layer node.
92 // stage must be set for the root layer
93 root->mStage = &stage;
95 // root actor is immediately considered to be on-stage
96 root->mIsOnStage = true;
98 // The root actor will not emit a stage connection signal so set the signalled flag here as well
99 root->mOnStageSignalled = true;
101 // layer-list must be set for the root layer
102 root->mLayerList = &layerList;
103 layerList.RegisterLayer( *root );
108 Layer::Layer( Actor::DerivedType type )
111 mClippingBox(0,0,0,0),
112 mSortFunction(Dali::Layer::ZValue),
114 mDepthTestDisabled(false),
115 mTouchConsumed(false)
119 void Layer::OnInitialize()
121 if(Layer::mFirstInstance)
123 mDefaultLayerPropertyLookup = new DefaultPropertyLookup();
124 const int start = DEFAULT_ACTOR_PROPERTY_MAX_COUNT;
125 for ( int i = 0; i < DEFAULT_LAYER_PROPERTY_COUNT; ++i )
127 (*mDefaultLayerPropertyLookup)[DEFAULT_LAYER_PROPERTY_NAMES[i]] = i + start;
129 Layer::mFirstInstance = false;
137 unsigned int Layer::GetDepth() const
139 return mLayerList ? mLayerList->GetDepth( this ) : 0u;
146 mLayerList->RaiseLayer(*this);
154 mLayerList->LowerLayer(*this);
158 void Layer::RaiseAbove( const Internal::Layer& target )
160 // cannot raise above ourself, both have to be on stage
161 if( ( this != &target ) && OnStage() && target.OnStage() )
163 // get parameters depth
164 const unsigned int targetDepth = target.GetDepth();
165 if( GetDepth() < targetDepth )
172 void Layer::LowerBelow( const Internal::Layer& target )
174 // cannot lower below ourself, both have to be on stage
175 if( ( this != &target ) && OnStage() && target.OnStage() )
177 // get parameters depth
178 const unsigned int targetDepth = target.GetDepth();
179 if( GetDepth() > targetDepth )
186 void Layer::RaiseToTop()
190 mLayerList->RaiseLayerToTop(*this);
194 void Layer::LowerToBottom()
198 mLayerList->LowerLayerToBottom(*this);
202 void Layer::MoveAbove( const Internal::Layer& target )
204 // cannot raise above ourself, both have to be on stage
205 if( ( this != &target ) && mLayerList && target.OnStage() )
207 mLayerList->MoveLayerAbove(*this, target );
211 void Layer::MoveBelow( const Internal::Layer& target )
213 // cannot lower below ourself, both have to be on stage
214 if( ( this != &target ) && mLayerList && target.OnStage() )
216 mLayerList->MoveLayerBelow(*this, target );
220 void Layer::SetClipping(bool enabled)
222 if (enabled != mIsClipping)
224 mIsClipping = enabled;
226 // layerNode is being used in a separate thread; queue a message to set the value
227 SetClippingMessage( mStage->GetUpdateInterface(), GetSceneLayerOnStage(), mIsClipping );
231 void Layer::SetClippingBox(int x, int y, int width, int height)
233 if( ( x != mClippingBox.x ) ||
234 ( y != mClippingBox.y ) ||
235 ( width != mClippingBox.width ) ||
236 ( height != mClippingBox.height ) )
238 // Clipping box is not animatable; this is the most up-to-date value
239 mClippingBox.Set(x, y, width, height);
241 // layerNode is being used in a separate thread; queue a message to set the value
242 SetClippingBoxMessage( mStage->GetUpdateInterface(), GetSceneLayerOnStage(), mClippingBox );
246 void Layer::SetDepthTestDisabled( bool disable )
248 if( disable != mDepthTestDisabled )
250 mDepthTestDisabled = disable;
252 // Send message .....
253 // layerNode is being used in a separate thread; queue a message to set the value
254 SetDepthTestDisabledMessage( mStage->GetUpdateInterface(), GetSceneLayerOnStage(), mDepthTestDisabled );
258 bool Layer::IsDepthTestDisabled() const
260 return mDepthTestDisabled;
263 void Layer::SetSortFunction(Dali::Layer::SortFunctionType function)
265 if( function != mSortFunction )
267 mSortFunction = function;
269 // layerNode is being used in a separate thread; queue a message to set the value
270 SetSortFunctionMessage( mStage->GetUpdateInterface(), GetSceneLayerOnStage(), mSortFunction );
274 void Layer::SetTouchConsumed( bool consume )
276 mTouchConsumed = consume;
279 bool Layer::IsTouchConsumed() const
281 return mTouchConsumed;
284 SceneGraph::Node* Layer::CreateNode() const
286 return SceneGraph::Layer::New();
289 void Layer::OnStageConnectionInternal()
293 DALI_ASSERT_DEBUG( NULL == mLayerList );
295 // Find the ordered layer-list
296 // This is different for Layers added via Integration::GetSystemOverlay()
297 for ( Actor* parent = mParent; parent != NULL; parent = parent->GetParent() )
299 if( parent->IsLayer() )
301 Layer* parentLayer = static_cast< Layer* >( parent ); // cheaper than dynamic_cast
302 mLayerList = parentLayer->mLayerList;
307 DALI_ASSERT_DEBUG( NULL != mLayerList );
308 mLayerList->RegisterLayer( *this );
311 void Layer::OnStageDisconnectionInternal()
313 mLayerList->UnregisterLayer(*this);
315 // mLayerList is only valid when on-stage
319 const SceneGraph::Layer& Layer::GetSceneLayerOnStage() const
321 DALI_ASSERT_DEBUG( mNode != NULL );
322 return dynamic_cast< const SceneGraph::Layer& >( *mNode );
325 unsigned int Layer::GetDefaultPropertyCount() const
327 return Actor::GetDefaultPropertyCount() + DEFAULT_LAYER_PROPERTY_COUNT;
330 void Layer::GetDefaultPropertyIndices( Property::IndexContainer& indices ) const
332 Actor::GetDefaultPropertyIndices( indices ); // Actor class properties
333 indices.reserve( indices.size() + DEFAULT_LAYER_PROPERTY_COUNT );
335 int index = DEFAULT_ACTOR_PROPERTY_MAX_COUNT;
336 for ( int i = 0; i < DEFAULT_LAYER_PROPERTY_COUNT; ++i, ++index )
338 indices.push_back( index );
342 bool Layer::IsDefaultPropertyWritable( Property::Index index ) const
344 if(index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT)
346 return Actor::IsDefaultPropertyWritable(index);
354 bool Layer::IsDefaultPropertyAnimatable( Property::Index index ) const
356 if(index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT)
358 return Actor::IsDefaultPropertyAnimatable(index);
366 bool Layer::IsDefaultPropertyAConstraintInput( Property::Index index ) const
368 if(index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT)
370 return Actor::IsDefaultPropertyAConstraintInput(index);
372 return true; // our properties can be used as an input to a constraint
375 Property::Type Layer::GetDefaultPropertyType( Property::Index index ) const
377 if(index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT)
379 return Actor::GetDefaultPropertyType(index);
383 index -= DEFAULT_ACTOR_PROPERTY_MAX_COUNT;
385 if ( ( index >= 0 ) && ( index < DEFAULT_LAYER_PROPERTY_COUNT ) )
387 return DEFAULT_LAYER_PROPERTY_TYPES[index];
391 // index out-of-bounds
392 return Property::NONE;
398 const std::string& Layer::GetDefaultPropertyName( Property::Index index ) const
400 if(index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT)
402 return Actor::GetDefaultPropertyName(index);
406 index -= DEFAULT_ACTOR_PROPERTY_MAX_COUNT;
408 if ( ( index >= 0 ) && ( index < DEFAULT_LAYER_PROPERTY_COUNT ) )
410 return DEFAULT_LAYER_PROPERTY_NAMES[index];
414 // index out-of-bounds
415 static const std::string INVALID_PROPERTY_NAME;
416 return INVALID_PROPERTY_NAME;
421 Property::Index Layer::GetDefaultPropertyIndex(const std::string& name) const
423 Property::Index index = Property::INVALID_INDEX;
425 DALI_ASSERT_DEBUG( NULL != mDefaultLayerPropertyLookup );
427 // Look for name in current class' default properties
428 DefaultPropertyLookup::const_iterator result = mDefaultLayerPropertyLookup->find( name );
429 if ( mDefaultLayerPropertyLookup->end() != result )
431 index = result->second;
435 // If not found, check in base class
436 index = Actor::GetDefaultPropertyIndex( name );
442 void Layer::SetDefaultProperty( Property::Index index, const Property::Value& propertyValue )
444 if(index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT)
446 Actor::SetDefaultProperty(index, propertyValue);
452 case Dali::Layer::CLIPPING_ENABLE:
454 SetClipping( propertyValue.Get<bool>() );
457 case Dali::Layer::CLIPPING_BOX:
459 Rect<int> clippingBox( propertyValue.Get<Rect<int> >() );
460 SetClippingBox( clippingBox.x, clippingBox.y, clippingBox.width, clippingBox.height );
465 DALI_LOG_WARNING("Unknown property (%d)\n", index);
473 Property::Value Layer::GetDefaultProperty( Property::Index index ) const
476 if(index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT)
478 ret = Actor::GetDefaultProperty(index);
484 case Dali::Layer::CLIPPING_ENABLE:
489 case Dali::Layer::CLIPPING_BOX:
496 DALI_LOG_WARNING("Unknown property (%d)\n", index);
505 bool Layer::DoAction(BaseObject* object, const std::string& actionName, const std::vector<Property::Value>& attributes)
508 Layer* layer = dynamic_cast<Layer*>(object);
512 if(Dali::Layer::ACTION_RAISE == actionName)
517 else if(Dali::Layer::ACTION_LOWER == actionName)
522 else if(Dali::Layer::ACTION_RAISE_TO_TOP == actionName)
527 else if(Dali::Layer::ACTION_LOWER_TO_BOTTOM == actionName)
529 layer->LowerToBottom();
537 } // namespace Internal