2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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.
18 #include <dali/internal/event/actors/layer-impl.h>
21 #include <dali/public-api/common/dali-common.h>
22 #include <dali/public-api/object/type-registry.h>
23 #include <dali/internal/event/common/property-index-ranges.h>
24 #include <dali/internal/event/common/stage-impl.h>
25 #include <dali/internal/event/actors/layer-list.h>
27 using Dali::Internal::SceneGraph::UpdateManager;
32 const Property::Index Layer::CLIPPING_ENABLE = Internal::DEFAULT_ACTOR_PROPERTY_MAX_COUNT;
33 const Property::Index Layer::CLIPPING_BOX = Internal::DEFAULT_ACTOR_PROPERTY_MAX_COUNT + 1;
37 bool Layer::mFirstInstance = true;
38 Actor::DefaultPropertyLookup* Layer::mDefaultLayerPropertyLookup = NULL;
45 return Dali::Layer::New();
48 TypeRegistration mType( typeid(Dali::Layer), typeid(Dali::Actor), Create );
50 TypeAction a1(mType, Dali::Layer::ACTION_RAISE, &Layer::DoAction);
51 TypeAction a2(mType, Dali::Layer::ACTION_LOWER, &Layer::DoAction);
52 TypeAction a3(mType, Dali::Layer::ACTION_RAISE_TO_TOP, &Layer::DoAction);
53 TypeAction a4(mType, Dali::Layer::ACTION_LOWER_TO_BOTTOM, &Layer::DoAction);
55 const std::string DEFAULT_LAYER_PROPERTY_NAMES[] =
60 const int DEFAULT_LAYER_PROPERTY_COUNT = sizeof( DEFAULT_LAYER_PROPERTY_NAMES ) / sizeof( std::string );
62 const Property::Type DEFAULT_LAYER_PROPERTY_TYPES[DEFAULT_LAYER_PROPERTY_COUNT] =
64 Property::BOOLEAN, // "clipping-enable",
65 Property::RECTANGLE, // "clipping-box",
68 } // unnamed namespace
72 LayerPtr layer( new Layer( Actor::LAYER ) );
74 // Second-phase construction
80 LayerPtr Layer::NewRoot( Stage& stage, LayerList& layerList, UpdateManager& manager, bool systemLevel )
82 LayerPtr root( new Layer( Actor::ROOT_LAYER ) );
84 // Second-phase construction
85 SceneGraph::Layer* layer = static_cast<SceneGraph::Layer*>( root->CreateNode() );
86 InstallRootMessage( manager, *layer, systemLevel ); // Transfer ownership to scene-graph
88 // Keep a raw pointer to the layer node.
91 // stage must be set for the root layer
92 root->mStage = &stage;
94 // root actor is immediately considered to be on-stage
95 root->mIsOnStage = true;
97 // The root actor will not emit a stage connection signal so set the signalled flag here as well
98 root->mOnStageSignalled = true;
100 // layer-list must be set for the root layer
101 root->mLayerList = &layerList;
102 layerList.RegisterLayer( *root );
107 Layer::Layer( Actor::DerivedType type )
110 mClippingBox(0,0,0,0),
111 mSortFunction(Dali::Layer::ZValue),
113 mDepthTestDisabled(false)
117 void Layer::OnInitialize()
119 if(Layer::mFirstInstance)
121 mDefaultLayerPropertyLookup = new DefaultPropertyLookup();
122 const int start = DEFAULT_ACTOR_PROPERTY_MAX_COUNT;
123 for ( int i = 0; i < DEFAULT_LAYER_PROPERTY_COUNT; ++i )
125 (*mDefaultLayerPropertyLookup)[DEFAULT_LAYER_PROPERTY_NAMES[i]] = i + start;
127 Layer::mFirstInstance = false;
135 unsigned int Layer::GetDepth() const
137 return mLayerList ? mLayerList->GetDepth( this ) : 0u;
144 mLayerList->RaiseLayer(*this);
152 mLayerList->LowerLayer(*this);
156 void Layer::RaiseAbove( const Internal::Layer& target )
158 // cannot raise above ourself, both have to be on stage
159 if( ( this != &target ) && OnStage() && target.OnStage() )
161 // get parameters depth
162 const unsigned int targetDepth = target.GetDepth();
163 if( GetDepth() < targetDepth )
170 void Layer::LowerBelow( const Internal::Layer& target )
172 // cannot lower below ourself, both have to be on stage
173 if( ( this != &target ) && OnStage() && target.OnStage() )
175 // get parameters depth
176 const unsigned int targetDepth = target.GetDepth();
177 if( GetDepth() > targetDepth )
184 void Layer::RaiseToTop()
188 mLayerList->RaiseLayerToTop(*this);
192 void Layer::LowerToBottom()
196 mLayerList->LowerLayerToBottom(*this);
200 void Layer::MoveAbove( const Internal::Layer& target )
202 // cannot raise above ourself, both have to be on stage
203 if( ( this != &target ) && mLayerList && target.OnStage() )
205 mLayerList->MoveLayerAbove(*this, target );
209 void Layer::MoveBelow( const Internal::Layer& target )
211 // cannot lower below ourself, both have to be on stage
212 if( ( this != &target ) && mLayerList && target.OnStage() )
214 mLayerList->MoveLayerBelow(*this, target );
218 void Layer::SetClipping(bool enabled)
220 if (enabled != mIsClipping)
222 mIsClipping = enabled;
224 // layerNode is being used in a separate thread; queue a message to set the value
225 SetClippingMessage( mStage->GetUpdateInterface(), GetSceneLayerOnStage(), mIsClipping );
229 void Layer::SetClippingBox(int x, int y, int width, int height)
231 if( ( x != mClippingBox.x ) ||
232 ( y != mClippingBox.y ) ||
233 ( width != mClippingBox.width ) ||
234 ( height != mClippingBox.height ) )
236 // Clipping box is not animatable; this is the most up-to-date value
237 mClippingBox.Set(x, y, width, height);
239 // layerNode is being used in a separate thread; queue a message to set the value
240 SetClippingBoxMessage( mStage->GetUpdateInterface(), GetSceneLayerOnStage(), mClippingBox );
244 void Layer::SetDepthTestDisabled( bool disable )
246 if( disable != mDepthTestDisabled )
248 mDepthTestDisabled = disable;
250 // Send message .....
251 // layerNode is being used in a separate thread; queue a message to set the value
252 SetDepthTestDisabledMessage( mStage->GetUpdateInterface(), GetSceneLayerOnStage(), mDepthTestDisabled );
256 bool Layer::IsDepthTestDisabled() const
258 return mDepthTestDisabled;
261 void Layer::SetSortFunction(Dali::Layer::SortFunctionType function)
263 if( function != mSortFunction )
265 mSortFunction = function;
267 // layerNode is being used in a separate thread; queue a message to set the value
268 SetSortFunctionMessage( mStage->GetUpdateInterface(), GetSceneLayerOnStage(), mSortFunction );
272 SceneGraph::Node* Layer::CreateNode() const
274 return SceneGraph::Layer::New();
277 void Layer::OnStageConnectionInternal()
281 DALI_ASSERT_DEBUG( NULL == mLayerList );
283 // Find the ordered layer-list
284 // This is different for Layers added via Integration::GetSystemOverlay()
285 for ( Actor* parent = mParent; parent != NULL; parent = parent->GetParent() )
287 if( parent->IsLayer() )
289 Layer* parentLayer = static_cast< Layer* >( parent ); // cheaper than dynamic_cast
290 mLayerList = parentLayer->mLayerList;
295 DALI_ASSERT_DEBUG( NULL != mLayerList );
296 mLayerList->RegisterLayer( *this );
299 void Layer::OnStageDisconnectionInternal()
301 mLayerList->UnregisterLayer(*this);
303 // mLayerList is only valid when on-stage
307 const SceneGraph::Layer& Layer::GetSceneLayerOnStage() const
309 DALI_ASSERT_DEBUG( mNode != NULL );
310 return dynamic_cast< const SceneGraph::Layer& >( *mNode );
313 unsigned int Layer::GetDefaultPropertyCount() const
315 return Actor::GetDefaultPropertyCount() + DEFAULT_LAYER_PROPERTY_COUNT;
318 void Layer::GetDefaultPropertyIndices( Property::IndexContainer& indices ) const
320 Actor::GetDefaultPropertyIndices( indices ); // Actor class properties
321 indices.reserve( indices.size() + DEFAULT_LAYER_PROPERTY_COUNT );
323 int index = DEFAULT_ACTOR_PROPERTY_MAX_COUNT;
324 for ( int i = 0; i < DEFAULT_LAYER_PROPERTY_COUNT; ++i, ++index )
326 indices.push_back( index );
330 bool Layer::IsDefaultPropertyWritable( Property::Index index ) const
332 if(index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT)
334 return Actor::IsDefaultPropertyWritable(index);
342 bool Layer::IsDefaultPropertyAnimatable( Property::Index index ) const
344 if(index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT)
346 return Actor::IsDefaultPropertyAnimatable(index);
354 bool Layer::IsDefaultPropertyAConstraintInput( Property::Index index ) const
356 if(index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT)
358 return Actor::IsDefaultPropertyAConstraintInput(index);
360 return true; // our properties can be used as an input to a constraint
363 Property::Type Layer::GetDefaultPropertyType( Property::Index index ) const
365 if(index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT)
367 return Actor::GetDefaultPropertyType(index);
371 index -= DEFAULT_ACTOR_PROPERTY_MAX_COUNT;
373 if ( ( index >= 0 ) && ( index < DEFAULT_LAYER_PROPERTY_COUNT ) )
375 return DEFAULT_LAYER_PROPERTY_TYPES[index];
379 // index out-of-bounds
380 return Property::NONE;
386 const std::string& Layer::GetDefaultPropertyName( Property::Index index ) const
388 if(index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT)
390 return Actor::GetDefaultPropertyName(index);
394 index -= DEFAULT_ACTOR_PROPERTY_MAX_COUNT;
396 if ( ( index >= 0 ) && ( index < DEFAULT_LAYER_PROPERTY_COUNT ) )
398 return DEFAULT_LAYER_PROPERTY_NAMES[index];
402 // index out-of-bounds
403 static const std::string INVALID_PROPERTY_NAME;
404 return INVALID_PROPERTY_NAME;
409 Property::Index Layer::GetDefaultPropertyIndex(const std::string& name) const
411 Property::Index index = Property::INVALID_INDEX;
413 DALI_ASSERT_DEBUG( NULL != mDefaultLayerPropertyLookup );
415 // Look for name in current class' default properties
416 DefaultPropertyLookup::const_iterator result = mDefaultLayerPropertyLookup->find( name );
417 if ( mDefaultLayerPropertyLookup->end() != result )
419 index = result->second;
423 // If not found, check in base class
424 index = Actor::GetDefaultPropertyIndex( name );
430 void Layer::SetDefaultProperty( Property::Index index, const Property::Value& propertyValue )
432 if(index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT)
434 Actor::SetDefaultProperty(index, propertyValue);
440 case Dali::Layer::CLIPPING_ENABLE:
442 mIsClipping = propertyValue.Get<bool>();
445 case Dali::Layer::CLIPPING_BOX:
447 mClippingBox = propertyValue.Get<Rect<int> >();
452 DALI_LOG_WARNING("Unknown property (%d)\n", index);
460 Property::Value Layer::GetDefaultProperty( Property::Index index ) const
463 if(index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT)
465 ret = Actor::GetDefaultProperty(index);
471 case Dali::Layer::CLIPPING_ENABLE:
476 case Dali::Layer::CLIPPING_BOX:
483 DALI_LOG_WARNING("Unknown property (%d)\n", index);
492 bool Layer::DoAction(BaseObject* object, const std::string& actionName, const std::vector<Property::Value>& attributes)
495 Layer* layer = dynamic_cast<Layer*>(object);
499 if(Dali::Layer::ACTION_RAISE == actionName)
504 else if(Dali::Layer::ACTION_LOWER == actionName)
509 else if(Dali::Layer::ACTION_RAISE_TO_TOP == actionName)
514 else if(Dali::Layer::ACTION_LOWER_TO_BOTTOM == actionName)
516 layer->LowerToBottom();
524 } // namespace Internal