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>
24 #include <dali/public-api/common/dali-common.h>
25 #include <dali/public-api/object/type-registry.h>
26 #include <dali/internal/event/actors/layer-list.h>
27 #include <dali/internal/event/common/property-helper.h>
28 #include <dali/internal/event/common/stage-impl.h>
30 using Dali::Internal::SceneGraph::UpdateManager;
43 // Name Type writable animatable constraint-input enum for index-checking
44 DALI_PROPERTY_TABLE_BEGIN
45 DALI_PROPERTY( "clipping-enable", BOOLEAN, true, false, true, Dali::Layer::Property::CLIPPING_ENABLE )
46 DALI_PROPERTY( "clipping-box", RECTANGLE, true, false, true, Dali::Layer::Property::CLIPPING_BOX )
47 DALI_PROPERTY_TABLE_END( DEFAULT_DERIVED_ACTOR_PROPERTY_START_INDEX )
51 const char* const ACTION_RAISE = "raise";
52 const char* const ACTION_LOWER = "lower";
53 const char* const ACTION_RAISE_TO_TOP = "raise-to-top";
54 const char* const ACTION_LOWER_TO_BOTTOM = "lower-to-bottom";
58 return Dali::Layer::New();
61 TypeRegistration mType( typeid( Dali::Layer ), typeid( Dali::Actor ), Create );
63 TypeAction a1( mType, ACTION_RAISE, &Layer::DoAction );
64 TypeAction a2( mType, ACTION_LOWER, &Layer::DoAction );
65 TypeAction a3( mType, ACTION_RAISE_TO_TOP, &Layer::DoAction );
66 TypeAction a4( mType, ACTION_LOWER_TO_BOTTOM, &Layer::DoAction );
68 } // unnamed namespace
72 LayerPtr layer( new Layer( Actor::LAYER ) );
74 // Second-phase construction
80 LayerPtr Layer::NewRoot( 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 // root actor is immediately considered to be on-stage
92 root->mIsOnStage = true;
94 // The root actor will not emit a stage connection signal so set the signalled flag here as well
95 root->mOnStageSignalled = true;
97 // layer-list must be set for the root layer
98 root->mLayerList = &layerList;
99 layerList.RegisterLayer( *root );
104 Layer::Layer( Actor::DerivedType type )
107 mClippingBox(0,0,0,0),
108 mSortFunction(Layer::ZValue),
110 mDepthTestDisabled(false),
111 mTouchConsumed(false),
112 mHoverConsumed(false)
116 void Layer::OnInitialize()
124 unsigned int Layer::GetDepth() const
126 return mLayerList ? mLayerList->GetDepth( this ) : 0u;
133 mLayerList->RaiseLayer(*this);
141 mLayerList->LowerLayer(*this);
145 void Layer::RaiseAbove( const Internal::Layer& target )
147 // cannot raise above ourself, both have to be on stage
148 if( ( this != &target ) && OnStage() && target.OnStage() )
150 // get parameters depth
151 const unsigned int targetDepth = target.GetDepth();
152 if( GetDepth() < targetDepth )
159 void Layer::LowerBelow( const Internal::Layer& target )
161 // cannot lower below ourself, both have to be on stage
162 if( ( this != &target ) && OnStage() && target.OnStage() )
164 // get parameters depth
165 const unsigned int targetDepth = target.GetDepth();
166 if( GetDepth() > targetDepth )
173 void Layer::RaiseToTop()
177 mLayerList->RaiseLayerToTop(*this);
181 void Layer::LowerToBottom()
185 mLayerList->LowerLayerToBottom(*this);
189 void Layer::MoveAbove( const Internal::Layer& target )
191 // cannot raise above ourself, both have to be on stage
192 if( ( this != &target ) && mLayerList && target.OnStage() )
194 mLayerList->MoveLayerAbove(*this, target );
198 void Layer::MoveBelow( const Internal::Layer& target )
200 // cannot lower below ourself, both have to be on stage
201 if( ( this != &target ) && mLayerList && target.OnStage() )
203 mLayerList->MoveLayerBelow(*this, target );
207 void Layer::SetClipping(bool enabled)
209 if (enabled != mIsClipping)
211 mIsClipping = enabled;
213 // layerNode is being used in a separate thread; queue a message to set the value
214 SetClippingMessage( GetEventThreadServices(), GetSceneLayerOnStage(), mIsClipping );
218 void Layer::SetClippingBox(int x, int y, int width, int height)
220 if( ( x != mClippingBox.x ) ||
221 ( y != mClippingBox.y ) ||
222 ( width != mClippingBox.width ) ||
223 ( height != mClippingBox.height ) )
225 // Clipping box is not animatable; this is the most up-to-date value
226 mClippingBox.Set(x, y, width, height);
228 // Convert mClippingBox to GL based coordinates (from bottom-left)
229 ClippingBox clippingBox( mClippingBox );
231 StagePtr stage = Stage::GetCurrent();
234 clippingBox.y = stage->GetSize().height - clippingBox.y - clippingBox.height;
236 // layerNode is being used in a separate thread; queue a message to set the value
237 SetClippingBoxMessage( GetEventThreadServices(), GetSceneLayerOnStage(), clippingBox );
242 void Layer::SetDepthTestDisabled( bool disable )
244 if( disable != mDepthTestDisabled )
246 mDepthTestDisabled = disable;
248 // Send message .....
249 // layerNode is being used in a separate thread; queue a message to set the value
250 SetDepthTestDisabledMessage( GetEventThreadServices(), GetSceneLayerOnStage(), mDepthTestDisabled );
254 bool Layer::IsDepthTestDisabled() const
256 return mDepthTestDisabled;
259 void Layer::SetSortFunction(Dali::Layer::SortFunctionType function)
261 if( function != mSortFunction )
263 mSortFunction = function;
265 // layerNode is being used in a separate thread; queue a message to set the value
266 SetSortFunctionMessage( GetEventThreadServices(), GetSceneLayerOnStage(), mSortFunction );
270 void Layer::SetTouchConsumed( bool consume )
272 mTouchConsumed = consume;
275 bool Layer::IsTouchConsumed() const
277 return mTouchConsumed;
280 void Layer::SetHoverConsumed( bool consume )
282 mHoverConsumed = consume;
285 bool Layer::IsHoverConsumed() const
287 return mHoverConsumed;
290 SceneGraph::Node* Layer::CreateNode() const
292 return SceneGraph::Layer::New();
295 void Layer::OnStageConnectionInternal()
299 DALI_ASSERT_DEBUG( NULL == mLayerList );
301 // Find the ordered layer-list
302 // This is different for Layers added via Integration::GetSystemOverlay()
303 for ( Actor* parent = mParent; parent != NULL; parent = parent->GetParent() )
305 if( parent->IsLayer() )
307 Layer* parentLayer = static_cast< Layer* >( parent ); // cheaper than dynamic_cast
308 mLayerList = parentLayer->mLayerList;
313 DALI_ASSERT_DEBUG( NULL != mLayerList );
314 mLayerList->RegisterLayer( *this );
317 void Layer::OnStageDisconnectionInternal()
319 mLayerList->UnregisterLayer(*this);
321 // mLayerList is only valid when on-stage
325 const SceneGraph::Layer& Layer::GetSceneLayerOnStage() const
327 DALI_ASSERT_DEBUG( mNode != NULL );
328 return dynamic_cast< const SceneGraph::Layer& >( *mNode );
331 unsigned int Layer::GetDefaultPropertyCount() const
333 return Actor::GetDefaultPropertyCount() + DEFAULT_PROPERTY_COUNT;
336 void Layer::GetDefaultPropertyIndices( Property::IndexContainer& indices ) const
338 Actor::GetDefaultPropertyIndices( indices ); // Actor class properties
339 indices.Reserve( indices.Size() + DEFAULT_PROPERTY_COUNT );
341 int index = DEFAULT_DERIVED_ACTOR_PROPERTY_START_INDEX;
342 for ( int i = 0; i < DEFAULT_PROPERTY_COUNT; ++i, ++index )
344 indices.PushBack( index );
348 bool Layer::IsDefaultPropertyWritable( Property::Index index ) const
350 if( index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT )
352 return Actor::IsDefaultPropertyWritable( index );
355 return DEFAULT_PROPERTY_DETAILS[ index - DEFAULT_DERIVED_ACTOR_PROPERTY_START_INDEX ].writable;
358 bool Layer::IsDefaultPropertyAnimatable( Property::Index index ) const
360 if( index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT )
362 return Actor::IsDefaultPropertyAnimatable( index );
365 return DEFAULT_PROPERTY_DETAILS[ index - DEFAULT_DERIVED_ACTOR_PROPERTY_START_INDEX ].animatable;
368 bool Layer::IsDefaultPropertyAConstraintInput( Property::Index index ) const
370 if( index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT )
372 return Actor::IsDefaultPropertyAConstraintInput( index );
375 return DEFAULT_PROPERTY_DETAILS[ index - DEFAULT_DERIVED_ACTOR_PROPERTY_START_INDEX ].constraintInput;
378 Property::Type Layer::GetDefaultPropertyType( Property::Index index ) const
380 if( index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT )
382 return Actor::GetDefaultPropertyType( index );
385 index -= DEFAULT_DERIVED_ACTOR_PROPERTY_START_INDEX;
387 if ( ( index >= 0 ) && ( index < DEFAULT_PROPERTY_COUNT ) )
389 return DEFAULT_PROPERTY_DETAILS[index].type;
392 // index out-of-bounds
393 return Property::NONE;
396 const char* Layer::GetDefaultPropertyName( Property::Index index ) const
398 if( index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT )
400 return Actor::GetDefaultPropertyName( index );
403 index -= DEFAULT_DERIVED_ACTOR_PROPERTY_START_INDEX;
404 if ( ( index >= 0 ) && ( index < DEFAULT_PROPERTY_COUNT ) )
406 return DEFAULT_PROPERTY_DETAILS[index].name;
412 Property::Index Layer::GetDefaultPropertyIndex(const std::string& name) const
414 Property::Index index = Property::INVALID_INDEX;
416 // Look for name in current class' default properties
417 for( int i = 0; i < DEFAULT_PROPERTY_COUNT; ++i )
419 const Internal::PropertyDetails* property = &DEFAULT_PROPERTY_DETAILS[i];
420 if( 0 == name.compare( property->name ) ) // dont want to convert rhs to string
422 index = i + DEFAULT_DERIVED_ACTOR_PROPERTY_START_INDEX;
426 if( Property::INVALID_INDEX == index )
428 // If not found, check in base class
429 index = Actor::GetDefaultPropertyIndex( name );
435 void Layer::SetDefaultProperty( Property::Index index, const Property::Value& propertyValue )
437 if( index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT )
439 Actor::SetDefaultProperty( index, propertyValue );
445 case Dali::Layer::Property::CLIPPING_ENABLE:
447 SetClipping( propertyValue.Get<bool>() );
450 case Dali::Layer::Property::CLIPPING_BOX:
452 Rect<int> clippingBox( propertyValue.Get<Rect<int> >() );
453 SetClippingBox( clippingBox.x, clippingBox.y, clippingBox.width, clippingBox.height );
458 DALI_LOG_WARNING( "Unknown property (%d)\n", index );
466 Property::Value Layer::GetDefaultProperty( Property::Index index ) const
469 if( index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT )
471 ret = Actor::GetDefaultProperty( index );
477 case Dali::Layer::Property::CLIPPING_ENABLE:
482 case Dali::Layer::Property::CLIPPING_BOX:
489 DALI_LOG_WARNING( "Unknown property (%d)\n", index );
498 bool Layer::DoAction( BaseObject* object, const std::string& actionName, const Property::Map& /*attributes*/ )
501 Layer* layer = dynamic_cast<Layer*>( object );
505 if( 0 == actionName.compare( ACTION_RAISE ) )
510 else if( 0 == actionName.compare( ACTION_LOWER ) )
515 else if( 0 == actionName.compare( ACTION_RAISE_TO_TOP ) )
520 else if( 0 == actionName.compare( ACTION_LOWER_TO_BOTTOM ) )
522 layer->LowerToBottom();
530 } // namespace Internal