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;
44 return Dali::Layer::New();
47 TypeRegistration mType( typeid(Dali::Layer), typeid(Dali::Actor), Create );
49 TypeAction a1(mType, Dali::Layer::ACTION_RAISE, &Layer::DoAction);
50 TypeAction a2(mType, Dali::Layer::ACTION_LOWER, &Layer::DoAction);
51 TypeAction a3(mType, Dali::Layer::ACTION_RAISE_TO_TOP, &Layer::DoAction);
52 TypeAction a4(mType, Dali::Layer::ACTION_LOWER_TO_BOTTOM, &Layer::DoAction);
54 const PropertyDetails DEFAULT_PROPERTY_DETAILS[] =
56 // Name Type writable animatable constraint-input
57 { "clipping-enable", Property::BOOLEAN, true, false, true }, // CLIPPING_ENABLE
58 { "clipping-box", Property::RECTANGLE, true, false, true }, // CLIPPING_BOX
60 const int DEFAULT_LAYER_PROPERTY_COUNT = sizeof( DEFAULT_PROPERTY_DETAILS ) / sizeof( DEFAULT_PROPERTY_DETAILS[0] );
62 } // unnamed namespace
66 LayerPtr layer( new Layer( Actor::LAYER ) );
68 // Second-phase construction
74 LayerPtr Layer::NewRoot( Stage& stage, LayerList& layerList, UpdateManager& manager, bool systemLevel )
76 LayerPtr root( new Layer( Actor::ROOT_LAYER ) );
78 // Second-phase construction
79 SceneGraph::Layer* layer = static_cast<SceneGraph::Layer*>( root->CreateNode() );
80 InstallRootMessage( manager, *layer, systemLevel ); // Transfer ownership to scene-graph
82 // Keep a raw pointer to the layer node.
85 // stage must be set for the root layer
86 root->mStage = &stage;
88 // root actor is immediately considered to be on-stage
89 root->mIsOnStage = true;
91 // The root actor will not emit a stage connection signal so set the signalled flag here as well
92 root->mOnStageSignalled = true;
94 // layer-list must be set for the root layer
95 root->mLayerList = &layerList;
96 layerList.RegisterLayer( *root );
101 Layer::Layer( Actor::DerivedType type )
104 mClippingBox(0,0,0,0),
105 mSortFunction(Dali::Layer::ZValue),
107 mDepthTestDisabled(false),
108 mTouchConsumed(false),
109 mHoverConsumed(false)
113 void Layer::OnInitialize()
121 unsigned int Layer::GetDepth() const
123 return mLayerList ? mLayerList->GetDepth( this ) : 0u;
130 mLayerList->RaiseLayer(*this);
138 mLayerList->LowerLayer(*this);
142 void Layer::RaiseAbove( const Internal::Layer& target )
144 // cannot raise above ourself, both have to be on stage
145 if( ( this != &target ) && OnStage() && target.OnStage() )
147 // get parameters depth
148 const unsigned int targetDepth = target.GetDepth();
149 if( GetDepth() < targetDepth )
156 void Layer::LowerBelow( const Internal::Layer& target )
158 // cannot lower below 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::RaiseToTop()
174 mLayerList->RaiseLayerToTop(*this);
178 void Layer::LowerToBottom()
182 mLayerList->LowerLayerToBottom(*this);
186 void Layer::MoveAbove( const Internal::Layer& target )
188 // cannot raise above ourself, both have to be on stage
189 if( ( this != &target ) && mLayerList && target.OnStage() )
191 mLayerList->MoveLayerAbove(*this, target );
195 void Layer::MoveBelow( const Internal::Layer& target )
197 // cannot lower below ourself, both have to be on stage
198 if( ( this != &target ) && mLayerList && target.OnStage() )
200 mLayerList->MoveLayerBelow(*this, target );
204 void Layer::SetClipping(bool enabled)
206 if (enabled != mIsClipping)
208 mIsClipping = enabled;
210 // layerNode is being used in a separate thread; queue a message to set the value
211 SetClippingMessage( mStage->GetUpdateInterface(), GetSceneLayerOnStage(), mIsClipping );
215 void Layer::SetClippingBox(int x, int y, int width, int height)
217 if( ( x != mClippingBox.x ) ||
218 ( y != mClippingBox.y ) ||
219 ( width != mClippingBox.width ) ||
220 ( height != mClippingBox.height ) )
222 // Clipping box is not animatable; this is the most up-to-date value
223 mClippingBox.Set(x, y, width, height);
225 // Convert mClippingBox to GL based coordinates (from bottom-left)
226 ClippingBox clippingBox( mClippingBox );
227 clippingBox.y = mStage->GetSize().height - clippingBox.y - clippingBox.height;
229 // layerNode is being used in a separate thread; queue a message to set the value
230 SetClippingBoxMessage( mStage->GetUpdateInterface(), GetSceneLayerOnStage(), clippingBox );
234 void Layer::SetDepthTestDisabled( bool disable )
236 if( disable != mDepthTestDisabled )
238 mDepthTestDisabled = disable;
240 // Send message .....
241 // layerNode is being used in a separate thread; queue a message to set the value
242 SetDepthTestDisabledMessage( mStage->GetUpdateInterface(), GetSceneLayerOnStage(), mDepthTestDisabled );
246 bool Layer::IsDepthTestDisabled() const
248 return mDepthTestDisabled;
251 void Layer::SetSortFunction(Dali::Layer::SortFunctionType function)
253 if( function != mSortFunction )
255 mSortFunction = function;
257 // layerNode is being used in a separate thread; queue a message to set the value
258 SetSortFunctionMessage( mStage->GetUpdateInterface(), GetSceneLayerOnStage(), mSortFunction );
262 void Layer::SetTouchConsumed( bool consume )
264 mTouchConsumed = consume;
267 bool Layer::IsTouchConsumed() const
269 return mTouchConsumed;
272 void Layer::SetHoverConsumed( bool consume )
274 mHoverConsumed = consume;
277 bool Layer::IsHoverConsumed() const
279 return mHoverConsumed;
282 SceneGraph::Node* Layer::CreateNode() const
284 return SceneGraph::Layer::New();
287 void Layer::OnStageConnectionInternal()
291 DALI_ASSERT_DEBUG( NULL == mLayerList );
293 // Find the ordered layer-list
294 // This is different for Layers added via Integration::GetSystemOverlay()
295 for ( Actor* parent = mParent; parent != NULL; parent = parent->GetParent() )
297 if( parent->IsLayer() )
299 Layer* parentLayer = static_cast< Layer* >( parent ); // cheaper than dynamic_cast
300 mLayerList = parentLayer->mLayerList;
305 DALI_ASSERT_DEBUG( NULL != mLayerList );
306 mLayerList->RegisterLayer( *this );
309 void Layer::OnStageDisconnectionInternal()
311 mLayerList->UnregisterLayer(*this);
313 // mLayerList is only valid when on-stage
317 const SceneGraph::Layer& Layer::GetSceneLayerOnStage() const
319 DALI_ASSERT_DEBUG( mNode != NULL );
320 return dynamic_cast< const SceneGraph::Layer& >( *mNode );
323 unsigned int Layer::GetDefaultPropertyCount() const
325 return Actor::GetDefaultPropertyCount() + DEFAULT_LAYER_PROPERTY_COUNT;
328 void Layer::GetDefaultPropertyIndices( Property::IndexContainer& indices ) const
330 Actor::GetDefaultPropertyIndices( indices ); // Actor class properties
331 indices.reserve( indices.size() + DEFAULT_LAYER_PROPERTY_COUNT );
333 int index = DEFAULT_ACTOR_PROPERTY_MAX_COUNT;
334 for ( int i = 0; i < DEFAULT_LAYER_PROPERTY_COUNT; ++i, ++index )
336 indices.push_back( index );
340 bool Layer::IsDefaultPropertyWritable( Property::Index index ) const
342 if(index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT)
344 return Actor::IsDefaultPropertyWritable(index);
348 return true; // all properties writable, no need to lookup the table
352 bool Layer::IsDefaultPropertyAnimatable( Property::Index index ) const
354 if(index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT)
356 return Actor::IsDefaultPropertyAnimatable(index);
360 return false; // all properties non animateable, no need to lookup the table
364 bool Layer::IsDefaultPropertyAConstraintInput( Property::Index index ) const
366 if(index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT)
368 return Actor::IsDefaultPropertyAConstraintInput(index);
370 return true; // our properties can be used as an input to a constraint, no need to lookup the table
373 Property::Type Layer::GetDefaultPropertyType( Property::Index index ) const
375 if(index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT)
377 return Actor::GetDefaultPropertyType(index);
381 index -= DEFAULT_ACTOR_PROPERTY_MAX_COUNT;
383 if ( ( index >= 0 ) && ( index < DEFAULT_LAYER_PROPERTY_COUNT ) )
385 return DEFAULT_PROPERTY_DETAILS[index].type;
389 // index out-of-bounds
390 return Property::NONE;
395 const char* Layer::GetDefaultPropertyName( Property::Index index ) const
397 if(index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT)
399 return Actor::GetDefaultPropertyName(index);
403 index -= DEFAULT_ACTOR_PROPERTY_MAX_COUNT;
405 if ( ( index >= 0 ) && ( index < DEFAULT_LAYER_PROPERTY_COUNT ) )
407 return DEFAULT_PROPERTY_DETAILS[index].name;
416 Property::Index Layer::GetDefaultPropertyIndex(const std::string& name) const
418 Property::Index index = Property::INVALID_INDEX;
420 // Look for name in current class' default properties
421 for( int i = 0; i < DEFAULT_LAYER_PROPERTY_COUNT; ++i )
423 const Internal::PropertyDetails* property = &DEFAULT_PROPERTY_DETAILS[ i ];
424 if( 0 == strcmp( name.c_str(), property->name ) ) // dont want to convert rhs to string
426 index = i + DEFAULT_ACTOR_PROPERTY_MAX_COUNT;
430 if( Property::INVALID_INDEX == index )
432 // If not found, check in base class
433 index = Actor::GetDefaultPropertyIndex( name );
439 void Layer::SetDefaultProperty( Property::Index index, const Property::Value& propertyValue )
441 if(index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT)
443 Actor::SetDefaultProperty(index, propertyValue);
449 case Dali::Layer::CLIPPING_ENABLE:
451 SetClipping( propertyValue.Get<bool>() );
454 case Dali::Layer::CLIPPING_BOX:
456 Rect<int> clippingBox( propertyValue.Get<Rect<int> >() );
457 SetClippingBox( clippingBox.x, clippingBox.y, clippingBox.width, clippingBox.height );
462 DALI_LOG_WARNING("Unknown property (%d)\n", index);
470 Property::Value Layer::GetDefaultProperty( Property::Index index ) const
473 if(index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT)
475 ret = Actor::GetDefaultProperty(index);
481 case Dali::Layer::CLIPPING_ENABLE:
486 case Dali::Layer::CLIPPING_BOX:
493 DALI_LOG_WARNING("Unknown property (%d)\n", index);
502 bool Layer::DoAction(BaseObject* object, const std::string& actionName, const std::vector<Property::Value>& attributes)
505 Layer* layer = dynamic_cast<Layer*>(object);
509 if(Dali::Layer::ACTION_RAISE == actionName)
514 else if(Dali::Layer::ACTION_LOWER == actionName)
519 else if(Dali::Layer::ACTION_RAISE_TO_TOP == actionName)
524 else if(Dali::Layer::ACTION_LOWER_TO_BOTTOM == actionName)
526 layer->LowerToBottom();
534 } // namespace Internal