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)
118 void Layer::OnInitialize()
120 if(Layer::mFirstInstance)
122 mDefaultLayerPropertyLookup = new DefaultPropertyLookup();
123 const int start = DEFAULT_ACTOR_PROPERTY_MAX_COUNT;
124 for ( int i = 0; i < DEFAULT_LAYER_PROPERTY_COUNT; ++i )
126 (*mDefaultLayerPropertyLookup)[DEFAULT_LAYER_PROPERTY_NAMES[i]] = i + start;
128 Layer::mFirstInstance = false;
136 unsigned int Layer::GetDepth() const
138 return mLayerList ? mLayerList->GetDepth( this ) : 0u;
145 mLayerList->RaiseLayer(*this);
153 mLayerList->LowerLayer(*this);
157 void Layer::RaiseAbove( const Internal::Layer& target )
159 // cannot raise above ourself, both have to be on stage
160 if( ( this != &target ) && OnStage() && target.OnStage() )
162 // get parameters depth
163 const unsigned int targetDepth = target.GetDepth();
164 if( GetDepth() < targetDepth )
171 void Layer::LowerBelow( const Internal::Layer& target )
173 // cannot lower below ourself, both have to be on stage
174 if( ( this != &target ) && OnStage() && target.OnStage() )
176 // get parameters depth
177 const unsigned int targetDepth = target.GetDepth();
178 if( GetDepth() > targetDepth )
185 void Layer::RaiseToTop()
189 mLayerList->RaiseLayerToTop(*this);
193 void Layer::LowerToBottom()
197 mLayerList->LowerLayerToBottom(*this);
201 void Layer::MoveAbove( const Internal::Layer& target )
203 // cannot raise above ourself, both have to be on stage
204 if( ( this != &target ) && mLayerList && target.OnStage() )
206 mLayerList->MoveLayerAbove(*this, target );
210 void Layer::MoveBelow( const Internal::Layer& target )
212 // cannot lower below ourself, both have to be on stage
213 if( ( this != &target ) && mLayerList && target.OnStage() )
215 mLayerList->MoveLayerBelow(*this, target );
219 void Layer::SetClipping(bool enabled)
221 if (enabled != mIsClipping)
223 mIsClipping = enabled;
225 // layerNode is being used in a separate thread; queue a message to set the value
226 SetClippingMessage( mStage->GetUpdateInterface(), GetSceneLayerOnStage(), mIsClipping );
230 void Layer::SetClippingBox(int x, int y, int width, int height)
232 if( ( x != mClippingBox.x ) ||
233 ( y != mClippingBox.y ) ||
234 ( width != mClippingBox.width ) ||
235 ( height != mClippingBox.height ) )
237 // Clipping box is not animatable; this is the most up-to-date value
238 mClippingBox.Set(x, y, width, height);
240 // layerNode is being used in a separate thread; queue a message to set the value
241 SetClippingBoxMessage( mStage->GetUpdateInterface(), GetSceneLayerOnStage(), mClippingBox );
245 void Layer::SetDepthTestDisabled( bool disable )
247 if( disable != mDepthTestDisabled )
249 mDepthTestDisabled = disable;
251 // Send message .....
252 // layerNode is being used in a separate thread; queue a message to set the value
253 SetDepthTestDisabledMessage( mStage->GetUpdateInterface(), GetSceneLayerOnStage(), mDepthTestDisabled );
257 bool Layer::IsDepthTestDisabled() const
259 return mDepthTestDisabled;
262 void Layer::SetSortFunction(Dali::Layer::SortFunctionType function)
264 if( function != mSortFunction )
266 mSortFunction = function;
268 // layerNode is being used in a separate thread; queue a message to set the value
269 SetSortFunctionMessage( mStage->GetUpdateInterface(), GetSceneLayerOnStage(), mSortFunction );
273 SceneGraph::Node* Layer::CreateNode() const
275 return SceneGraph::Layer::New();
278 void Layer::OnStageConnectionInternal()
282 DALI_ASSERT_DEBUG( NULL == mLayerList );
284 // Find the ordered layer-list
285 // This is different for Layers added via Integration::GetSystemOverlay()
286 for ( Actor* parent = mParent; parent != NULL; parent = parent->GetParent() )
288 if( parent->IsLayer() )
290 Layer* parentLayer = static_cast< Layer* >( parent ); // cheaper than dynamic_cast
291 mLayerList = parentLayer->mLayerList;
296 DALI_ASSERT_DEBUG( NULL != mLayerList );
297 mLayerList->RegisterLayer( *this );
300 void Layer::OnStageDisconnectionInternal()
302 mLayerList->UnregisterLayer(*this);
304 // mLayerList is only valid when on-stage
308 const SceneGraph::Layer& Layer::GetSceneLayerOnStage() const
310 DALI_ASSERT_DEBUG( mNode != NULL );
311 return dynamic_cast< const SceneGraph::Layer& >( *mNode );
314 unsigned int Layer::GetDefaultPropertyCount() const
316 return Actor::GetDefaultPropertyCount() + DEFAULT_LAYER_PROPERTY_COUNT;
319 void Layer::GetDefaultPropertyIndices( Property::IndexContainer& indices ) const
321 Actor::GetDefaultPropertyIndices( indices ); // Actor class properties
322 indices.reserve( indices.size() + DEFAULT_LAYER_PROPERTY_COUNT );
324 int index = DEFAULT_ACTOR_PROPERTY_MAX_COUNT;
325 for ( int i = 0; i < DEFAULT_LAYER_PROPERTY_COUNT; ++i, ++index )
327 indices.push_back( index );
331 bool Layer::IsDefaultPropertyWritable( Property::Index index ) const
333 if(index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT)
335 return Actor::IsDefaultPropertyWritable(index);
343 bool Layer::IsDefaultPropertyAnimatable( Property::Index index ) const
345 if(index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT)
347 return Actor::IsDefaultPropertyAnimatable(index);
355 bool Layer::IsDefaultPropertyAConstraintInput( Property::Index index ) const
357 if(index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT)
359 return Actor::IsDefaultPropertyAConstraintInput(index);
361 return true; // our properties can be used as an input to a constraint
364 Property::Type Layer::GetDefaultPropertyType( Property::Index index ) const
366 if(index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT)
368 return Actor::GetDefaultPropertyType(index);
372 index -= DEFAULT_ACTOR_PROPERTY_MAX_COUNT;
374 if ( ( index >= 0 ) && ( index < DEFAULT_LAYER_PROPERTY_COUNT ) )
376 return DEFAULT_LAYER_PROPERTY_TYPES[index];
380 // index out-of-bounds
381 return Property::NONE;
387 const std::string& Layer::GetDefaultPropertyName( Property::Index index ) const
389 if(index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT)
391 return Actor::GetDefaultPropertyName(index);
395 index -= DEFAULT_ACTOR_PROPERTY_MAX_COUNT;
397 if ( ( index >= 0 ) && ( index < DEFAULT_LAYER_PROPERTY_COUNT ) )
399 return DEFAULT_LAYER_PROPERTY_NAMES[index];
403 // index out-of-bounds
404 static const std::string INVALID_PROPERTY_NAME;
405 return INVALID_PROPERTY_NAME;
410 Property::Index Layer::GetDefaultPropertyIndex(const std::string& name) const
412 Property::Index index = Property::INVALID_INDEX;
414 DALI_ASSERT_DEBUG( NULL != mDefaultLayerPropertyLookup );
416 // Look for name in current class' default properties
417 DefaultPropertyLookup::const_iterator result = mDefaultLayerPropertyLookup->find( name );
418 if ( mDefaultLayerPropertyLookup->end() != result )
420 index = result->second;
424 // If not found, check in base class
425 index = Actor::GetDefaultPropertyIndex( name );
431 void Layer::SetDefaultProperty( Property::Index index, const Property::Value& propertyValue )
433 if(index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT)
435 Actor::SetDefaultProperty(index, propertyValue);
441 case Dali::Layer::CLIPPING_ENABLE:
443 mIsClipping = propertyValue.Get<bool>();
446 case Dali::Layer::CLIPPING_BOX:
448 mClippingBox = propertyValue.Get<Rect<int> >();
453 DALI_LOG_WARNING("Unknown property (%d)\n", index);
461 Property::Value Layer::GetDefaultProperty( Property::Index index ) const
464 if(index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT)
466 ret = Actor::GetDefaultProperty(index);
472 case Dali::Layer::CLIPPING_ENABLE:
477 case Dali::Layer::CLIPPING_BOX:
484 DALI_LOG_WARNING("Unknown property (%d)\n", index);
493 bool Layer::DoAction(BaseObject* object, const std::string& actionName, const std::vector<Property::Value>& attributes)
496 Layer* layer = dynamic_cast<Layer*>(object);
500 if(Dali::Layer::ACTION_RAISE == actionName)
505 else if(Dali::Layer::ACTION_LOWER == actionName)
510 else if(Dali::Layer::ACTION_RAISE_TO_TOP == actionName)
515 else if(Dali::Layer::ACTION_LOWER_TO_BOTTOM == actionName)
517 layer->LowerToBottom();
525 } // namespace Internal