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 <cstring> // for strcmp
25 #include <dali/public-api/common/dali-common.h>
26 #include <dali/public-api/object/type-registry.h>
27 #include <dali/internal/event/actors/layer-list.h>
28 #include <dali/internal/event/common/property-helper.h>
29 #include <dali/internal/event/common/stage-impl.h>
31 using Dali::Internal::SceneGraph::UpdateManager;
44 // Name Type writable animatable constraint-input enum for index-checking
45 DALI_PROPERTY_TABLE_BEGIN
46 DALI_PROPERTY( "clipping-enable", BOOLEAN, true, false, true, Dali::Layer::Property::CLIPPING_ENABLE )
47 DALI_PROPERTY( "clipping-box", RECTANGLE, true, false, true, Dali::Layer::Property::CLIPPING_BOX )
48 DALI_PROPERTY_TABLE_END( DEFAULT_DERIVED_ACTOR_PROPERTY_START_INDEX )
52 const char* const ACTION_RAISE = "raise";
53 const char* const ACTION_LOWER = "lower";
54 const char* const ACTION_RAISE_TO_TOP = "raise-to-top";
55 const char* const ACTION_LOWER_TO_BOTTOM = "lower-to-bottom";
59 return Dali::Layer::New();
62 TypeRegistration mType( typeid( Dali::Layer ), typeid( Dali::Actor ), Create );
64 TypeAction a1( mType, ACTION_RAISE, &Layer::DoAction );
65 TypeAction a2( mType, ACTION_LOWER, &Layer::DoAction );
66 TypeAction a3( mType, ACTION_RAISE_TO_TOP, &Layer::DoAction );
67 TypeAction a4( mType, ACTION_LOWER_TO_BOTTOM, &Layer::DoAction );
69 } // unnamed namespace
73 LayerPtr layer( new Layer( Actor::LAYER ) );
75 // Second-phase construction
81 LayerPtr Layer::NewRoot( LayerList& layerList, UpdateManager& manager, bool systemLevel )
83 LayerPtr root( new Layer( Actor::ROOT_LAYER ) );
85 // Second-phase construction
86 SceneGraph::Layer* layer = static_cast<SceneGraph::Layer*>( root->CreateNode() );
87 InstallRootMessage( manager, *layer, systemLevel ); // Transfer ownership to scene-graph
89 // Keep a raw pointer to the layer node.
92 // root actor is immediately considered to be on-stage
93 root->mIsOnStage = true;
95 // The root actor will not emit a stage connection signal so set the signalled flag here as well
96 root->mOnStageSignalled = true;
98 // layer-list must be set for the root layer
99 root->mLayerList = &layerList;
100 layerList.RegisterLayer( *root );
105 Layer::Layer( Actor::DerivedType type )
108 mClippingBox(0,0,0,0),
109 mSortFunction(Dali::Layer::ZValue),
111 mDepthTestDisabled(false),
112 mTouchConsumed(false),
113 mHoverConsumed(false)
117 void Layer::OnInitialize()
125 unsigned int Layer::GetDepth() const
127 return mLayerList ? mLayerList->GetDepth( this ) : 0u;
134 mLayerList->RaiseLayer(*this);
142 mLayerList->LowerLayer(*this);
146 void Layer::RaiseAbove( const Internal::Layer& target )
148 // cannot raise above ourself, both have to be on stage
149 if( ( this != &target ) && OnStage() && target.OnStage() )
151 // get parameters depth
152 const unsigned int targetDepth = target.GetDepth();
153 if( GetDepth() < targetDepth )
160 void Layer::LowerBelow( const Internal::Layer& target )
162 // cannot lower below ourself, both have to be on stage
163 if( ( this != &target ) && OnStage() && target.OnStage() )
165 // get parameters depth
166 const unsigned int targetDepth = target.GetDepth();
167 if( GetDepth() > targetDepth )
174 void Layer::RaiseToTop()
178 mLayerList->RaiseLayerToTop(*this);
182 void Layer::LowerToBottom()
186 mLayerList->LowerLayerToBottom(*this);
190 void Layer::MoveAbove( const Internal::Layer& target )
192 // cannot raise above ourself, both have to be on stage
193 if( ( this != &target ) && mLayerList && target.OnStage() )
195 mLayerList->MoveLayerAbove(*this, target );
199 void Layer::MoveBelow( const Internal::Layer& target )
201 // cannot lower below ourself, both have to be on stage
202 if( ( this != &target ) && mLayerList && target.OnStage() )
204 mLayerList->MoveLayerBelow(*this, target );
208 void Layer::SetClipping(bool enabled)
210 if (enabled != mIsClipping)
212 mIsClipping = enabled;
214 // layerNode is being used in a separate thread; queue a message to set the value
215 SetClippingMessage( GetEventThreadServices(), GetSceneLayerOnStage(), mIsClipping );
219 void Layer::SetClippingBox(int x, int y, int width, int height)
221 if( ( x != mClippingBox.x ) ||
222 ( y != mClippingBox.y ) ||
223 ( width != mClippingBox.width ) ||
224 ( height != mClippingBox.height ) )
226 // Clipping box is not animatable; this is the most up-to-date value
227 mClippingBox.Set(x, y, width, height);
229 // Convert mClippingBox to GL based coordinates (from bottom-left)
230 ClippingBox clippingBox( mClippingBox );
231 clippingBox.y = Stage::GetCurrent()->GetSize().height - clippingBox.y - clippingBox.height;
233 // layerNode is being used in a separate thread; queue a message to set the value
234 SetClippingBoxMessage( GetEventThreadServices(), GetSceneLayerOnStage(), clippingBox );
238 void Layer::SetDepthTestDisabled( bool disable )
240 if( disable != mDepthTestDisabled )
242 mDepthTestDisabled = disable;
244 // Send message .....
245 // layerNode is being used in a separate thread; queue a message to set the value
246 SetDepthTestDisabledMessage( GetEventThreadServices(), GetSceneLayerOnStage(), mDepthTestDisabled );
250 bool Layer::IsDepthTestDisabled() const
252 return mDepthTestDisabled;
255 void Layer::SetSortFunction(Dali::Layer::SortFunctionType function)
257 if( function != mSortFunction )
259 mSortFunction = function;
261 // layerNode is being used in a separate thread; queue a message to set the value
262 SetSortFunctionMessage( GetEventThreadServices(), GetSceneLayerOnStage(), mSortFunction );
266 void Layer::SetTouchConsumed( bool consume )
268 mTouchConsumed = consume;
271 bool Layer::IsTouchConsumed() const
273 return mTouchConsumed;
276 void Layer::SetHoverConsumed( bool consume )
278 mHoverConsumed = consume;
281 bool Layer::IsHoverConsumed() const
283 return mHoverConsumed;
286 SceneGraph::Node* Layer::CreateNode() const
288 return SceneGraph::Layer::New();
291 void Layer::OnStageConnectionInternal()
295 DALI_ASSERT_DEBUG( NULL == mLayerList );
297 // Find the ordered layer-list
298 // This is different for Layers added via Integration::GetSystemOverlay()
299 for ( Actor* parent = mParent; parent != NULL; parent = parent->GetParent() )
301 if( parent->IsLayer() )
303 Layer* parentLayer = static_cast< Layer* >( parent ); // cheaper than dynamic_cast
304 mLayerList = parentLayer->mLayerList;
309 DALI_ASSERT_DEBUG( NULL != mLayerList );
310 mLayerList->RegisterLayer( *this );
313 void Layer::OnStageDisconnectionInternal()
315 mLayerList->UnregisterLayer(*this);
317 // mLayerList is only valid when on-stage
321 const SceneGraph::Layer& Layer::GetSceneLayerOnStage() const
323 DALI_ASSERT_DEBUG( mNode != NULL );
324 return dynamic_cast< const SceneGraph::Layer& >( *mNode );
327 unsigned int Layer::GetDefaultPropertyCount() const
329 return Actor::GetDefaultPropertyCount() + DEFAULT_PROPERTY_COUNT;
332 void Layer::GetDefaultPropertyIndices( Property::IndexContainer& indices ) const
334 Actor::GetDefaultPropertyIndices( indices ); // Actor class properties
335 indices.reserve( indices.size() + DEFAULT_PROPERTY_COUNT );
337 int index = DEFAULT_DERIVED_ACTOR_PROPERTY_START_INDEX;
338 for ( int i = 0; i < DEFAULT_PROPERTY_COUNT; ++i, ++index )
340 indices.push_back( index );
344 bool Layer::IsDefaultPropertyWritable( Property::Index index ) const
346 if( index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT )
348 return Actor::IsDefaultPropertyWritable( index );
351 return DEFAULT_PROPERTY_DETAILS[ index - DEFAULT_DERIVED_ACTOR_PROPERTY_START_INDEX ].writable;
354 bool Layer::IsDefaultPropertyAnimatable( Property::Index index ) const
356 if( index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT )
358 return Actor::IsDefaultPropertyAnimatable( index );
361 return DEFAULT_PROPERTY_DETAILS[ index - DEFAULT_DERIVED_ACTOR_PROPERTY_START_INDEX ].animatable;
364 bool Layer::IsDefaultPropertyAConstraintInput( Property::Index index ) const
366 if( index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT )
368 return Actor::IsDefaultPropertyAConstraintInput( index );
371 return DEFAULT_PROPERTY_DETAILS[ index - DEFAULT_DERIVED_ACTOR_PROPERTY_START_INDEX ].constraintInput;
374 Property::Type Layer::GetDefaultPropertyType( Property::Index index ) const
376 if( index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT )
378 return Actor::GetDefaultPropertyType( index );
381 index -= DEFAULT_DERIVED_ACTOR_PROPERTY_START_INDEX;
383 if ( ( index >= 0 ) && ( index < DEFAULT_PROPERTY_COUNT ) )
385 return DEFAULT_PROPERTY_DETAILS[index].type;
388 // index out-of-bounds
389 return Property::NONE;
392 const char* Layer::GetDefaultPropertyName( Property::Index index ) const
394 if( index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT )
396 return Actor::GetDefaultPropertyName( index );
399 index -= DEFAULT_DERIVED_ACTOR_PROPERTY_START_INDEX;
400 if ( ( index >= 0 ) && ( index < DEFAULT_PROPERTY_COUNT ) )
402 return DEFAULT_PROPERTY_DETAILS[index].name;
408 Property::Index Layer::GetDefaultPropertyIndex(const std::string& name) const
410 Property::Index index = Property::INVALID_INDEX;
412 // Look for name in current class' default properties
413 for( int i = 0; i < DEFAULT_PROPERTY_COUNT; ++i )
415 const Internal::PropertyDetails* property = &DEFAULT_PROPERTY_DETAILS[i];
416 if( 0 == strcmp( name.c_str(), property->name ) ) // dont want to convert rhs to string
418 index = i + DEFAULT_DERIVED_ACTOR_PROPERTY_START_INDEX;
422 if( Property::INVALID_INDEX == index )
424 // If not found, check in base class
425 index = Actor::GetDefaultPropertyIndex( name );
431 void Layer::SetDefaultProperty( Property::Index index, const Property::Value& propertyValue )
433 if( index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT )
435 Actor::SetDefaultProperty( index, propertyValue );
441 case Dali::Layer::Property::CLIPPING_ENABLE:
443 SetClipping( propertyValue.Get<bool>() );
446 case Dali::Layer::Property::CLIPPING_BOX:
448 Rect<int> clippingBox( propertyValue.Get<Rect<int> >() );
449 SetClippingBox( clippingBox.x, clippingBox.y, clippingBox.width, clippingBox.height );
454 DALI_LOG_WARNING( "Unknown property (%d)\n", index );
462 Property::Value Layer::GetDefaultProperty( Property::Index index ) const
465 if( index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT )
467 ret = Actor::GetDefaultProperty( index );
473 case Dali::Layer::Property::CLIPPING_ENABLE:
478 case Dali::Layer::Property::CLIPPING_BOX:
485 DALI_LOG_WARNING( "Unknown property (%d)\n", index );
494 bool Layer::DoAction( BaseObject* object, const std::string& actionName, const std::vector<Property::Value>& attributes )
497 Layer* layer = dynamic_cast<Layer*>( object );
501 if( 0 == strcmp( actionName.c_str(), ACTION_RAISE ) )
506 else if( 0 == strcmp( actionName.c_str(), ACTION_LOWER ) )
511 else if( 0 == strcmp( actionName.c_str(), ACTION_RAISE_TO_TOP ) )
516 else if( 0 == strcmp( actionName.c_str(), ACTION_LOWER_TO_BOTTOM ) )
518 layer->LowerToBottom();
526 } // namespace Internal