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 = DEFAULT_ACTOR_PROPERTY_MAX_COUNT;
33 const Property::Index Layer::CLIPPING_BOX = 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),
112 mRenderOffscreen(false),
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 Property::Type Layer::GetDefaultPropertyType( Property::Index index ) const
357 if(index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT)
359 return Actor::GetDefaultPropertyType(index);
363 index -= DEFAULT_ACTOR_PROPERTY_MAX_COUNT;
365 if ( ( index >= 0 ) && ( index < DEFAULT_LAYER_PROPERTY_COUNT ) )
367 return DEFAULT_LAYER_PROPERTY_TYPES[index];
371 // index out-of-bounds
372 return Property::NONE;
378 const std::string& Layer::GetDefaultPropertyName( Property::Index index ) const
380 if(index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT)
382 return Actor::GetDefaultPropertyName(index);
386 index -= DEFAULT_ACTOR_PROPERTY_MAX_COUNT;
388 if ( ( index >= 0 ) && ( index < DEFAULT_LAYER_PROPERTY_COUNT ) )
390 return DEFAULT_LAYER_PROPERTY_NAMES[index];
394 // index out-of-bounds
395 static const std::string INVALID_PROPERTY_NAME;
396 return INVALID_PROPERTY_NAME;
401 Property::Index Layer::GetDefaultPropertyIndex(const std::string& name) const
403 Property::Index index = Property::INVALID_INDEX;
405 DALI_ASSERT_DEBUG( NULL != mDefaultLayerPropertyLookup );
407 // Look for name in current class' default properties
408 DefaultPropertyLookup::const_iterator result = mDefaultLayerPropertyLookup->find( name );
409 if ( mDefaultLayerPropertyLookup->end() != result )
411 index = result->second;
415 // If not found, check in base class
416 index = Actor::GetDefaultPropertyIndex( name );
422 void Layer::SetDefaultProperty( Property::Index index, const Property::Value& propertyValue )
424 if(index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT)
426 Actor::SetDefaultProperty(index, propertyValue);
432 case Dali::Layer::CLIPPING_ENABLE:
434 mIsClipping = propertyValue.Get<bool>();
437 case Dali::Layer::CLIPPING_BOX:
439 mClippingBox = propertyValue.Get<Rect<int> >();
444 DALI_LOG_WARNING("Unknown property (%d)\n", index);
452 Property::Value Layer::GetDefaultProperty( Property::Index index ) const
455 if(index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT)
457 ret = Actor::GetDefaultProperty(index);
463 case Dali::Layer::CLIPPING_ENABLE:
468 case Dali::Layer::CLIPPING_BOX:
475 DALI_LOG_WARNING("Unknown property (%d)\n", index);
484 bool Layer::DoAction(BaseObject* object, const std::string& actionName, const std::vector<Property::Value>& attributes)
487 Layer* layer = dynamic_cast<Layer*>(object);
491 if(Dali::Layer::ACTION_RAISE == actionName)
496 else if(Dali::Layer::ACTION_LOWER == actionName)
501 else if(Dali::Layer::ACTION_RAISE_TO_TOP == actionName)
506 else if(Dali::Layer::ACTION_LOWER_TO_BOTTOM == actionName)
508 layer->LowerToBottom();
516 } // namespace Internal