/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include <dali/public-api/object/type-registry.h>
#include <dali/internal/event/actors/layer-list.h>
#include <dali/internal/event/common/property-helper.h>
-#include <dali/internal/event/common/stage-impl.h>
+#include <dali/internal/event/common/scene-impl.h>
+#include <dali/internal/event/common/event-thread-services.h>
using Dali::Internal::SceneGraph::UpdateManager;
typedef Layer::Behavior Behavior;
-DALI_ENUM_TO_STRING_TABLE_BEGIN( Behavior )
-DALI_ENUM_TO_STRING_INSIDE_CLASS( Layer, LAYER_2D )
-DALI_ENUM_TO_STRING_INSIDE_CLASS( Layer, LAYER_3D )
-DALI_ENUM_TO_STRING_TABLE_END( Behavior )
+DALI_ENUM_TO_STRING_TABLE_BEGIN( BEHAVIOR )
+DALI_ENUM_TO_STRING_WITH_SCOPE( Layer, LAYER_UI )
+DALI_ENUM_TO_STRING_WITH_SCOPE( Layer, LAYER_3D )
+DALI_ENUM_TO_STRING_TABLE_END( BEHAVIOR )
} // namespace
DALI_PROPERTY_TABLE_BEGIN
DALI_PROPERTY( "clippingEnable", BOOLEAN, true, false, true, Dali::Layer::Property::CLIPPING_ENABLE )
DALI_PROPERTY( "clippingBox", RECTANGLE, true, false, true, Dali::Layer::Property::CLIPPING_BOX )
-DALI_PROPERTY( "behavior", STRING, true, false, false, Dali::Layer::Property::BEHAVIOR )
-DALI_PROPERTY_TABLE_END( DEFAULT_DERIVED_ACTOR_PROPERTY_START_INDEX )
+DALI_PROPERTY( "behavior", INTEGER, true, false, false, Dali::Layer::Property::BEHAVIOR )
+DALI_PROPERTY( "depth", INTEGER, false, false, false, Dali::Layer::Property::DEPTH )
+DALI_PROPERTY( "depthTest", BOOLEAN, true, false, false, Dali::Layer::Property::DEPTH_TEST )
+DALI_PROPERTY( "consumesTouch", BOOLEAN, true, false, false, Dali::Layer::Property::CONSUMES_TOUCH )
+DALI_PROPERTY( "consumesHover", BOOLEAN, true, false, false, Dali::Layer::Property::CONSUMES_HOVER )
+DALI_PROPERTY_TABLE_END( DEFAULT_DERIVED_ACTOR_PROPERTY_START_INDEX, LayerDefaultProperties )
// Actions
-const char* const ACTION_RAISE = "raise";
-const char* const ACTION_LOWER = "lower";
-const char* const ACTION_RAISE_TO_TOP = "raiseToTop";
-const char* const ACTION_LOWER_TO_BOTTOM = "lowerToBottom";
+static constexpr std::string_view ACTION_RAISE = "raise";
+static constexpr std::string_view ACTION_LOWER = "lower";
+static constexpr std::string_view ACTION_RAISE_TO_TOP = "raiseToTop";
+static constexpr std::string_view ACTION_LOWER_TO_BOTTOM = "lowerToBottom";
BaseHandle Create()
{
return Dali::Layer::New();
}
-TypeRegistration mType( typeid( Dali::Layer ), typeid( Dali::Actor ), Create );
+TypeRegistration mType( typeid( Dali::Layer ), typeid( Dali::Actor ), Create, LayerDefaultProperties );
-TypeAction a1( mType, ACTION_RAISE, &Layer::DoAction );
-TypeAction a2( mType, ACTION_LOWER, &Layer::DoAction );
-TypeAction a3( mType, ACTION_RAISE_TO_TOP, &Layer::DoAction );
-TypeAction a4( mType, ACTION_LOWER_TO_BOTTOM, &Layer::DoAction );
+TypeAction a1(mType, std::string(ACTION_RAISE), &Layer::DoAction);
+TypeAction a2(mType, std::string(ACTION_LOWER), &Layer::DoAction);
+TypeAction a3(mType, std::string(ACTION_RAISE_TO_TOP), &Layer::DoAction);
+TypeAction a4(mType, std::string(ACTION_LOWER_TO_BOTTOM), &Layer::DoAction);
} // unnamed namespace
LayerPtr Layer::New()
{
- LayerPtr layer( new Layer( Actor::LAYER ) );
+ // create node, nodes are owned by UpdateManager
+ SceneGraph::Layer* layerNode = SceneGraph::Layer::New();
+ OwnerPointer< SceneGraph::Node > transferOwnership( layerNode );
+ AddNodeMessage( EventThreadServices::Get().GetUpdateManager(), transferOwnership );
+ LayerPtr layer( new Layer( Actor::LAYER, *layerNode ) );
// Second-phase construction
layer->Initialize();
return layer;
}
-LayerPtr Layer::NewRoot( LayerList& layerList, UpdateManager& manager, bool systemLevel )
+LayerPtr Layer::NewRoot( LayerList& layerList )
{
- LayerPtr root( new Layer( Actor::ROOT_LAYER ) );
+ // create node, nodes are owned by UpdateManager
+ SceneGraph::Layer* rootLayer = SceneGraph::Layer::New();
+ OwnerPointer< SceneGraph::Layer > transferOwnership( rootLayer );
+ InstallRootMessage( EventThreadServices::Get().GetUpdateManager(), transferOwnership );
- // Second-phase construction
- SceneGraph::Layer* layer = static_cast<SceneGraph::Layer*>( root->CreateNode() );
- InstallRootMessage( manager, *layer, systemLevel ); // Transfer ownership to scene-graph
-
- // Keep a raw pointer to the layer node.
- root->mNode = layer;
+ LayerPtr root( new Layer( Actor::ROOT_LAYER, *rootLayer ) );
// root actor is immediately considered to be on-stage
- root->mIsOnStage = true;
+ root->mIsOnScene = true;
// The root actor will not emit a stage connection signal so set the signalled flag here as well
- root->mOnStageSignalled = true;
+ root->mOnSceneSignalled = true;
// layer-list must be set for the root layer
root->mLayerList = &layerList;
+ layerList.SetRootLayer( &(*root) );
layerList.RegisterLayer( *root );
return root;
}
-Layer::Layer( Actor::DerivedType type )
-: Actor( type ),
- mLayerList(NULL),
- mClippingBox(0,0,0,0),
- mSortFunction(Layer::ZValue),
- mBehavior(Dali::Layer::LAYER_2D),
- mIsClipping(false),
- mDepthTestDisabled(false),
- mTouchConsumed(false),
- mHoverConsumed(false)
+Layer::Layer( Actor::DerivedType type, const SceneGraph::Layer& layer )
+: Actor( type, layer ),
+ mLayerList( nullptr ),
+ mClippingBox( 0, 0, 0, 0 ),
+ mSortFunction( Layer::ZValue ),
+ mBehavior( Dali::Layer::LAYER_UI ),
+ mIsClipping( false ),
+ mDepthTestDisabled( true ),
+ mTouchConsumed( false ),
+ mHoverConsumed( false )
{
}
Layer::~Layer()
{
+ if ( mIsRoot )
+ {
+ // Guard to allow handle destruction after Core has been destroyed
+ if( EventThreadServices::IsCoreRunning() )
+ {
+ UninstallRootMessage( GetEventThreadServices().GetUpdateManager(), &GetSceneGraphLayer() );
+
+ GetEventThreadServices().UnregisterObject( this );
+ }
+ }
}
unsigned int Layer::GetDepth() const
void Layer::RaiseAbove( const Internal::Layer& target )
{
- // cannot raise above ourself, both have to be on stage
- if( ( this != &target ) && OnStage() && target.OnStage() )
+ // cannot raise above ourself, both have to be on the scene
+ if( ( this != &target ) && OnScene() && target.OnScene() )
{
// get parameters depth
- const unsigned int targetDepth = target.GetDepth();
+ const uint32_t targetDepth = target.GetDepth();
if( GetDepth() < targetDepth )
{
MoveAbove( target );
void Layer::LowerBelow( const Internal::Layer& target )
{
- // cannot lower below ourself, both have to be on stage
- if( ( this != &target ) && OnStage() && target.OnStage() )
+ // cannot lower below ourself, both have to be on the scene
+ if( ( this != &target ) && OnScene() && target.OnScene() )
{
// get parameters depth
- const unsigned int targetDepth = target.GetDepth();
+ const uint32_t targetDepth = target.GetDepth();
if( GetDepth() > targetDepth )
{
MoveBelow( target );
void Layer::MoveAbove( const Internal::Layer& target )
{
- // cannot raise above ourself, both have to be on stage
- if( ( this != &target ) && mLayerList && target.OnStage() )
+ // cannot raise above ourself, both have to be on the scene
+ if( ( this != &target ) && mLayerList && target.OnScene() )
{
mLayerList->MoveLayerAbove(*this, target );
}
void Layer::MoveBelow( const Internal::Layer& target )
{
- // cannot lower below ourself, both have to be on stage
- if( ( this != &target ) && mLayerList && target.OnStage() )
+ // cannot lower below ourself, both have to be on the scene
+ if( ( this != &target ) && mLayerList && target.OnScene() )
{
mLayerList->MoveLayerBelow(*this, target );
}
{
mBehavior = behavior;
- // notify update side object
- SetBehaviorMessage( GetEventThreadServices(), GetSceneLayerOnStage(), behavior );
+ // Notify update side object.
+ SetBehaviorMessage( GetEventThreadServices(), GetSceneGraphLayer(), behavior );
+ // By default, disable depth test for LAYER_UI, and enable for LAYER_3D.
+ SetDepthTestDisabled( mBehavior == Dali::Layer::LAYER_UI );
}
void Layer::SetClipping(bool enabled)
mIsClipping = enabled;
// layerNode is being used in a separate thread; queue a message to set the value
- SetClippingMessage( GetEventThreadServices(), GetSceneLayerOnStage(), mIsClipping );
+ SetClippingMessage( GetEventThreadServices(), GetSceneGraphLayer(), mIsClipping );
}
}
// Convert mClippingBox to GL based coordinates (from bottom-left)
ClippingBox clippingBox( mClippingBox );
- StagePtr stage = Stage::GetCurrent();
- if( stage )
+ if( mScene )
{
- clippingBox.y = stage->GetSize().height - clippingBox.y - clippingBox.height;
+ clippingBox.y = static_cast<int32_t>( mScene->GetSize().height ) - clippingBox.y - clippingBox.height;
// layerNode is being used in a separate thread; queue a message to set the value
- SetClippingBoxMessage( GetEventThreadServices(), GetSceneLayerOnStage(), clippingBox );
+ SetClippingBoxMessage( GetEventThreadServices(), GetSceneGraphLayer(), clippingBox );
}
}
}
{
mDepthTestDisabled = disable;
- // Send message .....
+ // Send message.
// layerNode is being used in a separate thread; queue a message to set the value
- SetDepthTestDisabledMessage( GetEventThreadServices(), GetSceneLayerOnStage(), mDepthTestDisabled );
+ SetDepthTestDisabledMessage( GetEventThreadServices(), GetSceneGraphLayer(), mDepthTestDisabled );
}
}
bool Layer::IsDepthTestDisabled() const
{
- return mDepthTestDisabled || (mBehavior == Dali::Layer::LAYER_2D);
+ return mDepthTestDisabled;
}
void Layer::SetSortFunction(Dali::Layer::SortFunctionType function)
mSortFunction = function;
// layerNode is being used in a separate thread; queue a message to set the value
- SetSortFunctionMessage( GetEventThreadServices(), GetSceneLayerOnStage(), mSortFunction );
+ SetSortFunctionMessage( GetEventThreadServices(), GetSceneGraphLayer(), mSortFunction );
}
}
return mHoverConsumed;
}
-SceneGraph::Node* Layer::CreateNode() const
-{
- return SceneGraph::Layer::New();
-}
-
-void Layer::OnStageConnectionInternal()
+void Layer::OnSceneConnectionInternal()
{
if ( !mIsRoot )
{
DALI_ASSERT_DEBUG( NULL == mLayerList );
// Find the ordered layer-list
- // This is different for Layers added via Integration::GetSystemOverlay()
- for ( Actor* parent = mParent; parent != NULL; parent = parent->GetParent() )
+ for ( Actor* parent = mParent; parent != nullptr; parent = parent->GetParent() )
{
if( parent->IsLayer() )
{
mLayerList->RegisterLayer( *this );
}
-void Layer::OnStageDisconnectionInternal()
+void Layer::OnSceneDisconnectionInternal()
{
mLayerList->UnregisterLayer(*this);
// mLayerList is only valid when on-stage
- mLayerList = NULL;
-}
-
-const SceneGraph::Layer& Layer::GetSceneLayerOnStage() const
-{
- DALI_ASSERT_DEBUG( mNode != NULL );
- return dynamic_cast< const SceneGraph::Layer& >( *mNode );
-}
-
-unsigned int Layer::GetDefaultPropertyCount() const
-{
- return Actor::GetDefaultPropertyCount() + DEFAULT_PROPERTY_COUNT;
-}
-
-void Layer::GetDefaultPropertyIndices( Property::IndexContainer& indices ) const
-{
- Actor::GetDefaultPropertyIndices( indices ); // Actor class properties
- indices.Reserve( indices.Size() + DEFAULT_PROPERTY_COUNT );
-
- int index = DEFAULT_DERIVED_ACTOR_PROPERTY_START_INDEX;
- for ( int i = 0; i < DEFAULT_PROPERTY_COUNT; ++i, ++index )
- {
- indices.PushBack( index );
- }
+ mLayerList = nullptr;
}
-bool Layer::IsDefaultPropertyWritable( Property::Index index ) const
+const SceneGraph::Layer& Layer::GetSceneGraphLayer() const
{
- if( index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT )
- {
- return Actor::IsDefaultPropertyWritable( index );
- }
-
- return DEFAULT_PROPERTY_DETAILS[ index - DEFAULT_DERIVED_ACTOR_PROPERTY_START_INDEX ].writable;
-}
-
-bool Layer::IsDefaultPropertyAnimatable( Property::Index index ) const
-{
- if( index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT )
- {
- return Actor::IsDefaultPropertyAnimatable( index );
- }
-
- return DEFAULT_PROPERTY_DETAILS[ index - DEFAULT_DERIVED_ACTOR_PROPERTY_START_INDEX ].animatable;
-}
-
-bool Layer::IsDefaultPropertyAConstraintInput( Property::Index index ) const
-{
- if( index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT )
- {
- return Actor::IsDefaultPropertyAConstraintInput( index );
- }
-
- return DEFAULT_PROPERTY_DETAILS[ index - DEFAULT_DERIVED_ACTOR_PROPERTY_START_INDEX ].constraintInput;
-}
-
-Property::Type Layer::GetDefaultPropertyType( Property::Index index ) const
-{
- if( index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT )
- {
- return Actor::GetDefaultPropertyType( index );
- }
-
- index -= DEFAULT_DERIVED_ACTOR_PROPERTY_START_INDEX;
-
- if ( ( index >= 0 ) && ( index < DEFAULT_PROPERTY_COUNT ) )
- {
- return DEFAULT_PROPERTY_DETAILS[index].type;
- }
-
- // index out-of-bounds
- return Property::NONE;
-}
-
-const char* Layer::GetDefaultPropertyName( Property::Index index ) const
-{
- if( index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT )
- {
- return Actor::GetDefaultPropertyName( index );
- }
-
- index -= DEFAULT_DERIVED_ACTOR_PROPERTY_START_INDEX;
- if ( ( index >= 0 ) && ( index < DEFAULT_PROPERTY_COUNT ) )
- {
- return DEFAULT_PROPERTY_DETAILS[index].name;
- }
-
- return NULL;
-}
-
-Property::Index Layer::GetDefaultPropertyIndex(const std::string& name) const
-{
- Property::Index index = Property::INVALID_INDEX;
-
- // Look for name in current class' default properties
- for( int i = 0; i < DEFAULT_PROPERTY_COUNT; ++i )
- {
- const Internal::PropertyDetails* property = &DEFAULT_PROPERTY_DETAILS[i];
- if( 0 == name.compare( property->name ) ) // dont want to convert rhs to string
- {
- index = i + DEFAULT_DERIVED_ACTOR_PROPERTY_START_INDEX;
- break;
- }
- }
- if( Property::INVALID_INDEX == index )
- {
- // If not found, check in base class
- index = Actor::GetDefaultPropertyIndex( name );
- }
-
- return index;
+ return static_cast< const SceneGraph::Layer& >( GetNode() ); // we know our node is a layer node
}
void Layer::SetDefaultProperty( Property::Index index, const Property::Value& propertyValue )
}
case Dali::Layer::Property::CLIPPING_BOX:
{
- Rect<int> clippingBox( propertyValue.Get<Rect<int> >() );
+ Rect<int32_t> clippingBox( propertyValue.Get<Rect<int32_t> >() );
SetClippingBox( clippingBox.x, clippingBox.y, clippingBox.width, clippingBox.height );
break;
}
case Dali::Layer::Property::BEHAVIOR:
{
- Behavior behavior(Dali::Layer::LAYER_2D);
- if( Scripting::GetEnumeration< Behavior >( propertyValue.Get< std::string >().c_str(), BehaviorTable, BehaviorTableCount, behavior ) )
+ Behavior behavior = mBehavior;
+
+ Property::Type type = propertyValue.GetType();
+ if( type == Property::STRING )
{
- SetBehavior( behavior );
+ if( Scripting::GetEnumeration< Behavior >( propertyValue.Get< std::string >().c_str(), BEHAVIOR_TABLE, BEHAVIOR_TABLE_COUNT, behavior ) )
+ {
+ SetBehavior( behavior );
+ }
}
+ else if ( type == Property::INTEGER )
+ {
+ SetBehavior( propertyValue.Get< Dali::Layer::Behavior >() );
+ }
+ break;
+ }
+ case Dali::Layer::Property::DEPTH_TEST:
+ {
+ SetDepthTestDisabled( !propertyValue.Get<bool>() );
+ break;
+ }
+ case Dali::Layer::Property::CONSUMES_TOUCH:
+ {
+ SetTouchConsumed( propertyValue.Get<bool>() );
+ break;
+ }
+ case Dali::Layer::Property::CONSUMES_HOVER:
+ {
+ SetHoverConsumed( propertyValue.Get<bool>() );
break;
}
default:
}
case Dali::Layer::Property::BEHAVIOR:
{
- ret = Scripting::GetLinearEnumerationName< Behavior >( GetBehavior(), BehaviorTable, BehaviorTableCount );
+ ret = mBehavior;
+ break;
+ }
+ case Dali::Layer::Property::DEPTH:
+ {
+ ret = static_cast<int>( GetDepth() );
+ break;
+ }
+ case Dali::Layer::Property::DEPTH_TEST:
+ {
+ ret = !mDepthTestDisabled;
+ break;
+ }
+ case Dali::Layer::Property::CONSUMES_TOUCH:
+ {
+ ret = mTouchConsumed;
+ break;
+ }
+ case Dali::Layer::Property::CONSUMES_HOVER:
+ {
+ ret = mHoverConsumed;
break;
}
default:
return ret;
}
+Property::Value Layer::GetDefaultPropertyCurrentValue( Property::Index index ) const
+{
+ Property::Value ret;
+ if( index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT )
+ {
+ ret = Actor::GetDefaultPropertyCurrentValue( index );
+ }
+ else
+ {
+ ret = GetDefaultProperty( index ); // Layer only has event-side properties
+ }
+
+ return ret;
+}
+
bool Layer::DoAction( BaseObject* object, const std::string& actionName, const Property::Map& /*attributes*/ )
{
bool done = false;
if( layer )
{
- if( 0 == actionName.compare( ACTION_RAISE ) )
+ std::string_view name(actionName);
+
+ if(name == ACTION_RAISE)
{
layer->Raise();
done = true;
}
- else if( 0 == actionName.compare( ACTION_LOWER ) )
+ else if(name == ACTION_LOWER)
{
layer->Lower();
done = true;
}
- else if( 0 == actionName.compare( ACTION_RAISE_TO_TOP ) )
+ else if(name == ACTION_RAISE_TO_TOP)
{
layer->RaiseToTop();
done = true;
}
- else if( 0 == actionName.compare( ACTION_LOWER_TO_BOTTOM ) )
+ else if(name == ACTION_LOWER_TO_BOTTOM)
{
layer->LowerToBottom();
done = true;