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)
115 // Size negotiate disabled by default, so turn it on for this actor
116 SetRelayoutEnabled( true );
119 void Layer::OnInitialize()
127 unsigned int Layer::GetDepth() const
129 return mLayerList ? mLayerList->GetDepth( this ) : 0u;
136 mLayerList->RaiseLayer(*this);
144 mLayerList->LowerLayer(*this);
148 void Layer::RaiseAbove( const Internal::Layer& target )
150 // cannot raise above ourself, both have to be on stage
151 if( ( this != &target ) && OnStage() && target.OnStage() )
153 // get parameters depth
154 const unsigned int targetDepth = target.GetDepth();
155 if( GetDepth() < targetDepth )
162 void Layer::LowerBelow( const Internal::Layer& target )
164 // cannot lower below ourself, both have to be on stage
165 if( ( this != &target ) && OnStage() && target.OnStage() )
167 // get parameters depth
168 const unsigned int targetDepth = target.GetDepth();
169 if( GetDepth() > targetDepth )
176 void Layer::RaiseToTop()
180 mLayerList->RaiseLayerToTop(*this);
184 void Layer::LowerToBottom()
188 mLayerList->LowerLayerToBottom(*this);
192 void Layer::MoveAbove( const Internal::Layer& target )
194 // cannot raise above ourself, both have to be on stage
195 if( ( this != &target ) && mLayerList && target.OnStage() )
197 mLayerList->MoveLayerAbove(*this, target );
201 void Layer::MoveBelow( const Internal::Layer& target )
203 // cannot lower below ourself, both have to be on stage
204 if( ( this != &target ) && mLayerList && target.OnStage() )
206 mLayerList->MoveLayerBelow(*this, target );
210 void Layer::SetClipping(bool enabled)
212 if (enabled != mIsClipping)
214 mIsClipping = enabled;
216 // layerNode is being used in a separate thread; queue a message to set the value
217 SetClippingMessage( GetEventThreadServices(), GetSceneLayerOnStage(), mIsClipping );
221 void Layer::SetClippingBox(int x, int y, int width, int height)
223 if( ( x != mClippingBox.x ) ||
224 ( y != mClippingBox.y ) ||
225 ( width != mClippingBox.width ) ||
226 ( height != mClippingBox.height ) )
228 // Clipping box is not animatable; this is the most up-to-date value
229 mClippingBox.Set(x, y, width, height);
231 // Convert mClippingBox to GL based coordinates (from bottom-left)
232 ClippingBox clippingBox( mClippingBox );
233 clippingBox.y = Stage::GetCurrent()->GetSize().height - clippingBox.y - clippingBox.height;
235 // layerNode is being used in a separate thread; queue a message to set the value
236 SetClippingBoxMessage( GetEventThreadServices(), GetSceneLayerOnStage(), clippingBox );
240 void Layer::SetDepthTestDisabled( bool disable )
242 if( disable != mDepthTestDisabled )
244 mDepthTestDisabled = disable;
246 // Send message .....
247 // layerNode is being used in a separate thread; queue a message to set the value
248 SetDepthTestDisabledMessage( GetEventThreadServices(), GetSceneLayerOnStage(), mDepthTestDisabled );
252 bool Layer::IsDepthTestDisabled() const
254 return mDepthTestDisabled;
257 void Layer::SetSortFunction(Dali::Layer::SortFunctionType function)
259 if( function != mSortFunction )
261 mSortFunction = function;
263 // layerNode is being used in a separate thread; queue a message to set the value
264 SetSortFunctionMessage( GetEventThreadServices(), GetSceneLayerOnStage(), mSortFunction );
268 void Layer::SetTouchConsumed( bool consume )
270 mTouchConsumed = consume;
273 bool Layer::IsTouchConsumed() const
275 return mTouchConsumed;
278 void Layer::SetHoverConsumed( bool consume )
280 mHoverConsumed = consume;
283 bool Layer::IsHoverConsumed() const
285 return mHoverConsumed;
288 SceneGraph::Node* Layer::CreateNode() const
290 return SceneGraph::Layer::New();
293 void Layer::OnStageConnectionInternal()
297 DALI_ASSERT_DEBUG( NULL == mLayerList );
299 // Find the ordered layer-list
300 // This is different for Layers added via Integration::GetSystemOverlay()
301 for ( Actor* parent = mParent; parent != NULL; parent = parent->GetParent() )
303 if( parent->IsLayer() )
305 Layer* parentLayer = static_cast< Layer* >( parent ); // cheaper than dynamic_cast
306 mLayerList = parentLayer->mLayerList;
311 DALI_ASSERT_DEBUG( NULL != mLayerList );
312 mLayerList->RegisterLayer( *this );
315 void Layer::OnStageDisconnectionInternal()
317 mLayerList->UnregisterLayer(*this);
319 // mLayerList is only valid when on-stage
323 const SceneGraph::Layer& Layer::GetSceneLayerOnStage() const
325 DALI_ASSERT_DEBUG( mNode != NULL );
326 return dynamic_cast< const SceneGraph::Layer& >( *mNode );
329 unsigned int Layer::GetDefaultPropertyCount() const
331 return Actor::GetDefaultPropertyCount() + DEFAULT_PROPERTY_COUNT;
334 void Layer::GetDefaultPropertyIndices( Property::IndexContainer& indices ) const
336 Actor::GetDefaultPropertyIndices( indices ); // Actor class properties
337 indices.reserve( indices.size() + DEFAULT_PROPERTY_COUNT );
339 int index = DEFAULT_DERIVED_ACTOR_PROPERTY_START_INDEX;
340 for ( int i = 0; i < DEFAULT_PROPERTY_COUNT; ++i, ++index )
342 indices.push_back( index );
346 bool Layer::IsDefaultPropertyWritable( Property::Index index ) const
348 if( index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT )
350 return Actor::IsDefaultPropertyWritable( index );
353 return DEFAULT_PROPERTY_DETAILS[ index - DEFAULT_DERIVED_ACTOR_PROPERTY_START_INDEX ].writable;
356 bool Layer::IsDefaultPropertyAnimatable( Property::Index index ) const
358 if( index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT )
360 return Actor::IsDefaultPropertyAnimatable( index );
363 return DEFAULT_PROPERTY_DETAILS[ index - DEFAULT_DERIVED_ACTOR_PROPERTY_START_INDEX ].animatable;
366 bool Layer::IsDefaultPropertyAConstraintInput( Property::Index index ) const
368 if( index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT )
370 return Actor::IsDefaultPropertyAConstraintInput( index );
373 return DEFAULT_PROPERTY_DETAILS[ index - DEFAULT_DERIVED_ACTOR_PROPERTY_START_INDEX ].constraintInput;
376 Property::Type Layer::GetDefaultPropertyType( Property::Index index ) const
378 if( index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT )
380 return Actor::GetDefaultPropertyType( index );
383 index -= DEFAULT_DERIVED_ACTOR_PROPERTY_START_INDEX;
385 if ( ( index >= 0 ) && ( index < DEFAULT_PROPERTY_COUNT ) )
387 return DEFAULT_PROPERTY_DETAILS[index].type;
390 // index out-of-bounds
391 return Property::NONE;
394 const char* Layer::GetDefaultPropertyName( Property::Index index ) const
396 if( index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT )
398 return Actor::GetDefaultPropertyName( index );
401 index -= DEFAULT_DERIVED_ACTOR_PROPERTY_START_INDEX;
402 if ( ( index >= 0 ) && ( index < DEFAULT_PROPERTY_COUNT ) )
404 return DEFAULT_PROPERTY_DETAILS[index].name;
410 Property::Index Layer::GetDefaultPropertyIndex(const std::string& name) const
412 Property::Index index = Property::INVALID_INDEX;
414 // Look for name in current class' default properties
415 for( int i = 0; i < DEFAULT_PROPERTY_COUNT; ++i )
417 const Internal::PropertyDetails* property = &DEFAULT_PROPERTY_DETAILS[i];
418 if( 0 == strcmp( name.c_str(), property->name ) ) // dont want to convert rhs to string
420 index = i + DEFAULT_DERIVED_ACTOR_PROPERTY_START_INDEX;
424 if( Property::INVALID_INDEX == index )
426 // If not found, check in base class
427 index = Actor::GetDefaultPropertyIndex( name );
433 void Layer::SetDefaultProperty( Property::Index index, const Property::Value& propertyValue )
435 if( index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT )
437 Actor::SetDefaultProperty( index, propertyValue );
443 case Dali::Layer::Property::CLIPPING_ENABLE:
445 SetClipping( propertyValue.Get<bool>() );
448 case Dali::Layer::Property::CLIPPING_BOX:
450 Rect<int> clippingBox( propertyValue.Get<Rect<int> >() );
451 SetClippingBox( clippingBox.x, clippingBox.y, clippingBox.width, clippingBox.height );
456 DALI_LOG_WARNING( "Unknown property (%d)\n", index );
464 Property::Value Layer::GetDefaultProperty( Property::Index index ) const
467 if( index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT )
469 ret = Actor::GetDefaultProperty( index );
475 case Dali::Layer::Property::CLIPPING_ENABLE:
480 case Dali::Layer::Property::CLIPPING_BOX:
487 DALI_LOG_WARNING( "Unknown property (%d)\n", index );
496 bool Layer::DoAction( BaseObject* object, const std::string& actionName, const std::vector<Property::Value>& attributes )
499 Layer* layer = dynamic_cast<Layer*>( object );
503 if( 0 == strcmp( actionName.c_str(), ACTION_RAISE ) )
508 else if( 0 == strcmp( actionName.c_str(), ACTION_LOWER ) )
513 else if( 0 == strcmp( actionName.c_str(), ACTION_RAISE_TO_TOP ) )
518 else if( 0 == strcmp( actionName.c_str(), ACTION_LOWER_TO_BOTTOM ) )
520 layer->LowerToBottom();
528 } // namespace Internal