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 );
230 clippingBox.y = Stage::GetCurrent()->GetSize().height - clippingBox.y - clippingBox.height;
232 // layerNode is being used in a separate thread; queue a message to set the value
233 SetClippingBoxMessage( GetEventThreadServices(), GetSceneLayerOnStage(), clippingBox );
237 void Layer::SetDepthTestDisabled( bool disable )
239 if( disable != mDepthTestDisabled )
241 mDepthTestDisabled = disable;
243 // Send message .....
244 // layerNode is being used in a separate thread; queue a message to set the value
245 SetDepthTestDisabledMessage( GetEventThreadServices(), GetSceneLayerOnStage(), mDepthTestDisabled );
249 bool Layer::IsDepthTestDisabled() const
251 return mDepthTestDisabled;
254 void Layer::SetSortFunction(Dali::Layer::SortFunctionType function)
256 if( function != mSortFunction )
258 mSortFunction = function;
260 // layerNode is being used in a separate thread; queue a message to set the value
261 SetSortFunctionMessage( GetEventThreadServices(), GetSceneLayerOnStage(), mSortFunction );
265 void Layer::SetTouchConsumed( bool consume )
267 mTouchConsumed = consume;
270 bool Layer::IsTouchConsumed() const
272 return mTouchConsumed;
275 void Layer::SetHoverConsumed( bool consume )
277 mHoverConsumed = consume;
280 bool Layer::IsHoverConsumed() const
282 return mHoverConsumed;
285 SceneGraph::Node* Layer::CreateNode() const
287 return SceneGraph::Layer::New();
290 void Layer::OnStageConnectionInternal()
294 DALI_ASSERT_DEBUG( NULL == mLayerList );
296 // Find the ordered layer-list
297 // This is different for Layers added via Integration::GetSystemOverlay()
298 for ( Actor* parent = mParent; parent != NULL; parent = parent->GetParent() )
300 if( parent->IsLayer() )
302 Layer* parentLayer = static_cast< Layer* >( parent ); // cheaper than dynamic_cast
303 mLayerList = parentLayer->mLayerList;
308 DALI_ASSERT_DEBUG( NULL != mLayerList );
309 mLayerList->RegisterLayer( *this );
312 void Layer::OnStageDisconnectionInternal()
314 mLayerList->UnregisterLayer(*this);
316 // mLayerList is only valid when on-stage
320 const SceneGraph::Layer& Layer::GetSceneLayerOnStage() const
322 DALI_ASSERT_DEBUG( mNode != NULL );
323 return dynamic_cast< const SceneGraph::Layer& >( *mNode );
326 unsigned int Layer::GetDefaultPropertyCount() const
328 return Actor::GetDefaultPropertyCount() + DEFAULT_PROPERTY_COUNT;
331 void Layer::GetDefaultPropertyIndices( Property::IndexContainer& indices ) const
333 Actor::GetDefaultPropertyIndices( indices ); // Actor class properties
334 indices.Reserve( indices.Size() + DEFAULT_PROPERTY_COUNT );
336 int index = DEFAULT_DERIVED_ACTOR_PROPERTY_START_INDEX;
337 for ( int i = 0; i < DEFAULT_PROPERTY_COUNT; ++i, ++index )
339 indices.PushBack( index );
343 bool Layer::IsDefaultPropertyWritable( Property::Index index ) const
345 if( index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT )
347 return Actor::IsDefaultPropertyWritable( index );
350 return DEFAULT_PROPERTY_DETAILS[ index - DEFAULT_DERIVED_ACTOR_PROPERTY_START_INDEX ].writable;
353 bool Layer::IsDefaultPropertyAnimatable( Property::Index index ) const
355 if( index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT )
357 return Actor::IsDefaultPropertyAnimatable( index );
360 return DEFAULT_PROPERTY_DETAILS[ index - DEFAULT_DERIVED_ACTOR_PROPERTY_START_INDEX ].animatable;
363 bool Layer::IsDefaultPropertyAConstraintInput( Property::Index index ) const
365 if( index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT )
367 return Actor::IsDefaultPropertyAConstraintInput( index );
370 return DEFAULT_PROPERTY_DETAILS[ index - DEFAULT_DERIVED_ACTOR_PROPERTY_START_INDEX ].constraintInput;
373 Property::Type Layer::GetDefaultPropertyType( Property::Index index ) const
375 if( index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT )
377 return Actor::GetDefaultPropertyType( index );
380 index -= DEFAULT_DERIVED_ACTOR_PROPERTY_START_INDEX;
382 if ( ( index >= 0 ) && ( index < DEFAULT_PROPERTY_COUNT ) )
384 return DEFAULT_PROPERTY_DETAILS[index].type;
387 // index out-of-bounds
388 return Property::NONE;
391 const char* Layer::GetDefaultPropertyName( Property::Index index ) const
393 if( index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT )
395 return Actor::GetDefaultPropertyName( index );
398 index -= DEFAULT_DERIVED_ACTOR_PROPERTY_START_INDEX;
399 if ( ( index >= 0 ) && ( index < DEFAULT_PROPERTY_COUNT ) )
401 return DEFAULT_PROPERTY_DETAILS[index].name;
407 Property::Index Layer::GetDefaultPropertyIndex(const std::string& name) const
409 Property::Index index = Property::INVALID_INDEX;
411 // Look for name in current class' default properties
412 for( int i = 0; i < DEFAULT_PROPERTY_COUNT; ++i )
414 const Internal::PropertyDetails* property = &DEFAULT_PROPERTY_DETAILS[i];
415 if( 0 == name.compare( property->name ) ) // dont want to convert rhs to string
417 index = i + DEFAULT_DERIVED_ACTOR_PROPERTY_START_INDEX;
421 if( Property::INVALID_INDEX == index )
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::Property::CLIPPING_ENABLE:
442 SetClipping( propertyValue.Get<bool>() );
445 case Dali::Layer::Property::CLIPPING_BOX:
447 Rect<int> clippingBox( propertyValue.Get<Rect<int> >() );
448 SetClippingBox( clippingBox.x, clippingBox.y, clippingBox.width, clippingBox.height );
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::Property::CLIPPING_ENABLE:
477 case Dali::Layer::Property::CLIPPING_BOX:
484 DALI_LOG_WARNING( "Unknown property (%d)\n", index );
493 bool Layer::DoAction( BaseObject* object, const std::string& actionName, const Property::Map& /*attributes*/ )
496 Layer* layer = dynamic_cast<Layer*>( object );
500 if( 0 == actionName.compare( ACTION_RAISE ) )
505 else if( 0 == actionName.compare( ACTION_LOWER ) )
510 else if( 0 == actionName.compare( ACTION_RAISE_TO_TOP ) )
515 else if( 0 == actionName.compare( ACTION_LOWER_TO_BOTTOM ) )
517 layer->LowerToBottom();
525 } // namespace Internal