X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali%2Finternal%2Fevent%2Factors%2Flayer-impl.cpp;h=11f835a12cc4fe5fc4d1f597794df7e5042c7f0f;hb=e08e2992259823c5f9832ad959ffa510b0445a6c;hp=3550e74a2aed63ac30f2b05c348226d046b18cc5;hpb=7c51ca2f62b1fa560cb567080d858dbb357ef1b4;p=platform%2Fcore%2Fuifw%2Fdali-core.git diff --git a/dali/internal/event/actors/layer-impl.cpp b/dali/internal/event/actors/layer-impl.cpp index 3550e74..11f835a 100644 --- a/dali/internal/event/actors/layer-impl.cpp +++ b/dali/internal/event/actors/layer-impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Copyright (c) 2018 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. @@ -18,20 +18,32 @@ // CLASS HEADER #include +// EXTERNAL INCLUDES + // INTERNAL INCLUDES +#include #include #include -#include -#include #include +#include +#include using Dali::Internal::SceneGraph::UpdateManager; namespace Dali { -const Property::Index Layer::CLIPPING_ENABLE = Internal::DEFAULT_ACTOR_PROPERTY_MAX_COUNT; -const Property::Index Layer::CLIPPING_BOX = Internal::DEFAULT_ACTOR_PROPERTY_MAX_COUNT + 1; +namespace +{ + +typedef Layer::Behavior 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 namespace Internal { @@ -39,31 +51,44 @@ namespace Internal namespace { +// Properties + +// Name Type writable animatable constraint-input enum for index-checking +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, 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"; + 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, Dali::Layer::ACTION_RAISE, &Layer::DoAction); -TypeAction a2(mType, Dali::Layer::ACTION_LOWER, &Layer::DoAction); -TypeAction a3(mType, Dali::Layer::ACTION_RAISE_TO_TOP, &Layer::DoAction); -TypeAction a4(mType, Dali::Layer::ACTION_LOWER_TO_BOTTOM, &Layer::DoAction); - -const PropertyDetails DEFAULT_PROPERTY_DETAILS[] = -{ - // Name Type writable animatable constraint-input - { "clipping-enable", Property::BOOLEAN, true, false, true }, // CLIPPING_ENABLE - { "clipping-box", Property::RECTANGLE, true, false, true }, // CLIPPING_BOX -}; -const int DEFAULT_LAYER_PROPERTY_COUNT = sizeof( DEFAULT_PROPERTY_DETAILS ) / sizeof( DEFAULT_PROPERTY_DETAILS[0] ); +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 ); } // 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( Stage::GetCurrent()->GetUpdateManager(), transferOwnership ); + LayerPtr layer( new Layer( Actor::LAYER, *layerNode ) ); // Second-phase construction layer->Initialize(); @@ -71,19 +96,14 @@ LayerPtr Layer::New() return layer; } -LayerPtr Layer::NewRoot( Stage& stage, LayerList& layerList, UpdateManager& manager, bool systemLevel ) +LayerPtr Layer::NewRoot( LayerList& layerList, UpdateManager& manager ) { - 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( manager, transferOwnership ); - // Second-phase construction - SceneGraph::Layer* layer = static_cast( root->CreateNode() ); - InstallRootMessage( manager, *layer, systemLevel ); // Transfer ownership to scene-graph - - // Keep a raw pointer to the layer node. - root->mNode = layer; - - // stage must be set for the root layer - root->mStage = &stage; + LayerPtr root( new Layer( Actor::ROOT_LAYER, *rootLayer ) ); // root actor is immediately considered to be on-stage root->mIsOnStage = true; @@ -93,20 +113,22 @@ LayerPtr Layer::NewRoot( Stage& stage, LayerList& layerList, UpdateManager& mana // 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(Dali::Layer::ZValue), - mIsClipping(false), - mDepthTestDisabled(false), - mTouchConsumed(false), - mHoverConsumed(false) +Layer::Layer( Actor::DerivedType type, const SceneGraph::Layer& layer ) +: Actor( type, layer ), + mLayerList( NULL ), + mClippingBox( 0, 0, 0, 0 ), + mSortFunction( Layer::ZValue ), + mBehavior( Dali::Layer::LAYER_UI ), + mIsClipping( false ), + mDepthTestDisabled( true ), + mTouchConsumed( false ), + mHoverConsumed( false ) { } @@ -145,7 +167,7 @@ void Layer::RaiseAbove( const Internal::Layer& target ) if( ( this != &target ) && OnStage() && target.OnStage() ) { // get parameters depth - const unsigned int targetDepth = target.GetDepth(); + const uint32_t targetDepth = target.GetDepth(); if( GetDepth() < targetDepth ) { MoveAbove( target ); @@ -159,7 +181,7 @@ void Layer::LowerBelow( const Internal::Layer& target ) if( ( this != &target ) && OnStage() && target.OnStage() ) { // get parameters depth - const unsigned int targetDepth = target.GetDepth(); + const uint32_t targetDepth = target.GetDepth(); if( GetDepth() > targetDepth ) { MoveBelow( target ); @@ -201,6 +223,16 @@ void Layer::MoveBelow( const Internal::Layer& target ) } } +void Layer::SetBehavior( Dali::Layer::Behavior behavior ) +{ + mBehavior = behavior; + + // Notify update side object. + SetBehaviorMessage( GetEventThreadServices(), GetSceneLayerOnStage(), 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) { if (enabled != mIsClipping) @@ -208,7 +240,7 @@ void Layer::SetClipping(bool enabled) mIsClipping = enabled; // layerNode is being used in a separate thread; queue a message to set the value - SetClippingMessage( mStage->GetUpdateInterface(), GetSceneLayerOnStage(), mIsClipping ); + SetClippingMessage( GetEventThreadServices(), GetSceneLayerOnStage(), mIsClipping ); } } @@ -224,10 +256,15 @@ void Layer::SetClippingBox(int x, int y, int width, int height) // Convert mClippingBox to GL based coordinates (from bottom-left) ClippingBox clippingBox( mClippingBox ); - clippingBox.y = mStage->GetSize().height - clippingBox.y - clippingBox.height; - // layerNode is being used in a separate thread; queue a message to set the value - SetClippingBoxMessage( mStage->GetUpdateInterface(), GetSceneLayerOnStage(), clippingBox ); + StagePtr stage = Stage::GetCurrent(); + if( stage ) + { + clippingBox.y = static_cast( stage->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 ); + } } } @@ -237,9 +274,9 @@ void Layer::SetDepthTestDisabled( bool disable ) { mDepthTestDisabled = disable; - // Send message ..... + // Send message. // layerNode is being used in a separate thread; queue a message to set the value - SetDepthTestDisabledMessage( mStage->GetUpdateInterface(), GetSceneLayerOnStage(), mDepthTestDisabled ); + SetDepthTestDisabledMessage( GetEventThreadServices(), GetSceneLayerOnStage(), mDepthTestDisabled ); } } @@ -255,7 +292,7 @@ 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( mStage->GetUpdateInterface(), GetSceneLayerOnStage(), mSortFunction ); + SetSortFunctionMessage( GetEventThreadServices(), GetSceneLayerOnStage(), mSortFunction ); } } @@ -279,11 +316,6 @@ bool Layer::IsHoverConsumed() const return mHoverConsumed; } -SceneGraph::Node* Layer::CreateNode() const -{ - return SceneGraph::Layer::New(); -} - void Layer::OnStageConnectionInternal() { if ( !mIsRoot ) @@ -316,150 +348,42 @@ void Layer::OnStageDisconnectionInternal() 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_LAYER_PROPERTY_COUNT; -} - -void Layer::GetDefaultPropertyIndices( Property::IndexContainer& indices ) const -{ - Actor::GetDefaultPropertyIndices( indices ); // Actor class properties - indices.reserve( indices.size() + DEFAULT_LAYER_PROPERTY_COUNT ); - - int index = DEFAULT_ACTOR_PROPERTY_MAX_COUNT; - for ( int i = 0; i < DEFAULT_LAYER_PROPERTY_COUNT; ++i, ++index ) - { - indices.push_back( index ); - } -} - -bool Layer::IsDefaultPropertyWritable( Property::Index index ) const -{ - if(index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT) - { - return Actor::IsDefaultPropertyWritable(index); - } - else - { - return true; // all properties writable, no need to lookup the table - } -} - -bool Layer::IsDefaultPropertyAnimatable( Property::Index index ) const -{ - if(index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT) - { - return Actor::IsDefaultPropertyAnimatable(index); - } - else - { - return false; // all properties non animateable, no need to lookup the table - } -} - -bool Layer::IsDefaultPropertyAConstraintInput( Property::Index index ) const -{ - if(index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT) - { - return Actor::IsDefaultPropertyAConstraintInput(index); - } - return true; // our properties can be used as an input to a constraint, no need to lookup the table -} - -Property::Type Layer::GetDefaultPropertyType( Property::Index index ) const -{ - if(index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT) - { - return Actor::GetDefaultPropertyType(index); - } - else - { - index -= DEFAULT_ACTOR_PROPERTY_MAX_COUNT; - - if ( ( index >= 0 ) && ( index < DEFAULT_LAYER_PROPERTY_COUNT ) ) - { - return DEFAULT_PROPERTY_DETAILS[index].type; - } - else - { - // 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); - } - else - { - index -= DEFAULT_ACTOR_PROPERTY_MAX_COUNT; - - if ( ( index >= 0 ) && ( index < DEFAULT_LAYER_PROPERTY_COUNT ) ) - { - return DEFAULT_PROPERTY_DETAILS[index].name; - } - else - { - 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_LAYER_PROPERTY_COUNT; ++i ) - { - const Internal::PropertyDetails* property = &DEFAULT_PROPERTY_DETAILS[ i ]; - if( 0 == strcmp( name.c_str(), property->name ) ) // dont want to convert rhs to string - { - index = i + DEFAULT_ACTOR_PROPERTY_MAX_COUNT; - 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 ) { - if(index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT) + if( index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT ) { - Actor::SetDefaultProperty(index, propertyValue); + Actor::SetDefaultProperty( index, propertyValue ); } else { - switch(index) + switch( index ) { - case Dali::Layer::CLIPPING_ENABLE: + case Dali::Layer::Property::CLIPPING_ENABLE: { SetClipping( propertyValue.Get() ); break; } - case Dali::Layer::CLIPPING_BOX: + case Dali::Layer::Property::CLIPPING_BOX: { - Rect clippingBox( propertyValue.Get >() ); + Rect clippingBox( propertyValue.Get >() ); SetClippingBox( clippingBox.x, clippingBox.y, clippingBox.width, clippingBox.height ); break; } + case Dali::Layer::Property::BEHAVIOR: + { + Behavior behavior(Dali::Layer::LAYER_UI); + if( Scripting::GetEnumeration< Behavior >( propertyValue.Get< std::string >().c_str(), BEHAVIOR_TABLE, BEHAVIOR_TABLE_COUNT, behavior ) ) + { + SetBehavior( behavior ); + } + break; + } default: { - DALI_LOG_WARNING("Unknown property (%d)\n", index); + DALI_LOG_WARNING( "Unknown property (%d)\n", index ); break; } } // switch(index) @@ -470,27 +394,32 @@ void Layer::SetDefaultProperty( Property::Index index, const Property::Value& pr Property::Value Layer::GetDefaultProperty( Property::Index index ) const { Property::Value ret; - if(index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT) + if( index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT ) { - ret = Actor::GetDefaultProperty(index); + ret = Actor::GetDefaultProperty( index ); } else { - switch(index) + switch( index ) { - case Dali::Layer::CLIPPING_ENABLE: + case Dali::Layer::Property::CLIPPING_ENABLE: { ret = mIsClipping; break; } - case Dali::Layer::CLIPPING_BOX: + case Dali::Layer::Property::CLIPPING_BOX: { ret = mClippingBox; break; } + case Dali::Layer::Property::BEHAVIOR: + { + ret = Scripting::GetLinearEnumerationName< Behavior >( GetBehavior(), BEHAVIOR_TABLE, BEHAVIOR_TABLE_COUNT ); + break; + } default: { - DALI_LOG_WARNING("Unknown property (%d)\n", index); + DALI_LOG_WARNING( "Unknown property (%d)\n", index ); break; } } // switch(index) @@ -499,29 +428,44 @@ Property::Value Layer::GetDefaultProperty( Property::Index index ) const return ret; } -bool Layer::DoAction(BaseObject* object, const std::string& actionName, const std::vector& attributes) +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; - Layer* layer = dynamic_cast(object); + Layer* layer = dynamic_cast( object ); - if(layer) + if( layer ) { - if(Dali::Layer::ACTION_RAISE == actionName) + if( 0 == actionName.compare( ACTION_RAISE ) ) { layer->Raise(); done = true; } - else if(Dali::Layer::ACTION_LOWER == actionName) + else if( 0 == actionName.compare( ACTION_LOWER ) ) { layer->Lower(); done = true; } - else if(Dali::Layer::ACTION_RAISE_TO_TOP == actionName) + else if( 0 == actionName.compare( ACTION_RAISE_TO_TOP ) ) { layer->RaiseToTop(); done = true; } - else if(Dali::Layer::ACTION_LOWER_TO_BOTTOM == actionName) + else if( 0 == actionName.compare( ACTION_LOWER_TO_BOTTOM ) ) { layer->LowerToBottom(); done = true; @@ -534,4 +478,3 @@ bool Layer::DoAction(BaseObject* object, const std::string& actionName, const st } // namespace Internal } // namespace Dali -