X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali%2Finternal%2Fevent%2Factors%2Factor-impl.cpp;h=2065436c1f8b373a69c55bd5040273fc8218c353;hb=bbbd986a3779df135740042b07321370deac2ba0;hp=d2b33c9fa471ef350d690d2dc4d845cf3d93e84a;hpb=14502a507909174b52e486a0ee7516cb26e6ad45;p=platform%2Fcore%2Fuifw%2Fdali-core.git diff --git a/dali/internal/event/actors/actor-impl.cpp b/dali/internal/event/actors/actor-impl.cpp index d2b33c9..2065436 100644 --- a/dali/internal/event/actors/actor-impl.cpp +++ b/dali/internal/event/actors/actor-impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018 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. @@ -42,6 +42,8 @@ #include #include #include +#include +#include #include #include #include @@ -412,7 +414,8 @@ const SceneGraph::Node* Actor::CreateNode() // create node. Nodes are owned by the update manager SceneGraph::Node* node = SceneGraph::Node::New(); OwnerPointer< SceneGraph::Node > transferOwnership( node ); - AddNodeMessage( Stage::GetCurrent()->GetUpdateManager(), transferOwnership ); + Internal::ThreadLocalStorage* tls = Internal::ThreadLocalStorage::GetInternal(); + AddNodeMessage( tls->GetUpdateManager(), transferOwnership ); return node; } @@ -792,20 +795,19 @@ const Vector3& Actor::GetCurrentWorldPosition() const const Vector2 Actor::GetCurrentScreenPosition() const { - StagePtr stage = Stage::GetCurrent(); - if( stage && OnStage() ) + if( mScene && OnStage() ) { Vector3 worldPosition = GetNode().GetWorldPosition( GetEventThreadServices().GetEventBufferIndex() ); - Vector3 cameraPosition = stage->GetDefaultCameraActor().GetNode().GetWorldPosition( GetEventThreadServices().GetEventBufferIndex() ); + Vector3 cameraPosition = mScene->GetDefaultCameraActor().GetNode().GetWorldPosition( GetEventThreadServices().GetEventBufferIndex() ); worldPosition -= cameraPosition; Vector3 actorSize = GetCurrentSize() * GetCurrentWorldScale(); - Vector2 halfStageSize( stage->GetSize() * 0.5f ); // World position origin is center of stage + Vector2 halfSceneSize( mScene->GetSize() * 0.5f ); // World position origin is center of scene Vector3 halfActorSize( actorSize * 0.5f ); Vector3 anchorPointOffSet = halfActorSize - actorSize * ( mPositionUsesAnchorPoint ? GetCurrentAnchorPoint() : AnchorPoint::TOP_LEFT ); - return Vector2( halfStageSize.width + worldPosition.x - anchorPointOffSet.x, - halfStageSize.height + worldPosition.y - anchorPointOffSet.y ); + return Vector2( halfSceneSize.width + worldPosition.x - anchorPointOffSet.x, + halfSceneSize.height + worldPosition.y - anchorPointOffSet.y ); } return Vector2::ZERO; @@ -1312,6 +1314,9 @@ void Actor::SetSizeScalePolicy( SizeScalePolicy::Type policy ) EnsureRelayoutData(); mRelayoutData->sizeSetPolicy = policy; + + // Trigger relayout on this control + RelayoutRequest(); } SizeScalePolicy::Type Actor::GetSizeScalePolicy() const @@ -1499,10 +1504,9 @@ DrawMode::Type Actor::GetDrawMode() const bool Actor::ScreenToLocal( float& localX, float& localY, float screenX, float screenY ) const { // only valid when on-stage - StagePtr stage = Stage::GetCurrent(); - if( stage && OnStage() ) + if( mScene && OnStage() ) { - const RenderTaskList& taskList = stage->GetRenderTaskList(); + const RenderTaskList& taskList = mScene->GetRenderTaskList(); Vector2 converted( screenX, screenY ); @@ -1778,7 +1782,7 @@ ActorGestureData& Actor::GetGestureData() return *mGestureData; } -bool Actor::IsGestureRequred( Gesture::Type type ) const +bool Actor::IsGestureRequred( DevelGesture::Type type ) const { return mGestureData && mGestureData->IsGestureRequred( type ); } @@ -2002,6 +2006,7 @@ bool Actor::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tra Actor::Actor( DerivedType derivedType, const SceneGraph::Node& node ) : Object( &node ), + mScene( nullptr ), mParent( NULL ), mChildren( NULL ), mRenderers( NULL ), @@ -2078,9 +2083,13 @@ Actor::~Actor() // Guard to allow handle destruction after Core has been destroyed if( EventThreadServices::IsCoreRunning() ) { - DestroyNodeMessage( GetEventThreadServices().GetUpdateManager(), GetNode() ); + // Root layer will destroy its node in its own destructor + if ( !mIsRoot ) + { + DestroyNodeMessage( GetEventThreadServices().GetUpdateManager(), GetNode() ); - GetEventThreadServices().UnregisterObject( this ); + GetEventThreadServices().UnregisterObject( this ); + } } // Cleanup optional gesture data @@ -2100,10 +2109,9 @@ void Actor::ConnectToStage( uint32_t parentDepth ) // It protects us when the Actor hierarchy is modified during OnStageConnectionExternal callbacks. ActorContainer connectionList; - StagePtr stage = Stage::GetCurrent(); - if( stage ) + if( mScene ) { - stage->RequestRebuildDepthTree(); + mScene->RequestRebuildDepthTree(); } // This stage is atomic i.e. not interrupted by user callbacks. @@ -2140,6 +2148,7 @@ void Actor::RecursiveConnectToStage( ActorContainer& connectionList, uint32_t de ActorConstIter endIter = mChildren->end(); for( ActorIter iter = mChildren->begin(); iter != endIter; ++iter ) { + (*iter)->SetScene( *mScene ); (*iter)->RecursiveConnectToStage( connectionList, depth + 1 ); } } @@ -2194,10 +2203,9 @@ void Actor::DisconnectFromStage() // It protects us when the Actor hierachy is modified during OnStageDisconnectionExternal callbacks. ActorContainer disconnectionList; - StagePtr stage = Stage::GetCurrent(); - if( stage ) + if( mScene ) { - stage->RequestRebuildDepthTree(); + mScene->RequestRebuildDepthTree(); } // This stage is atomic i.e. not interrupted by user callbacks @@ -2488,7 +2496,16 @@ void Actor::SetDefaultProperty( Property::Index index, const Property::Value& pr case Dali::Actor::Property::COLOR: { - SetColor( property.Get< Vector4 >() ); + Property::Type type = property.GetType(); + if( type == Property::VECTOR3 ) + { + Vector3 color = property.Get< Vector3 >(); + SetColor( Vector4( color.r, color.g, color.b, 1.0f ) ); + } + else if( type == Property::VECTOR4 ) + { + SetColor( property.Get< Vector4 >() ); + } break; } @@ -2913,6 +2930,19 @@ void Actor::OnNotifyDefaultPropertyAnimation( Animation& animation, Property::In { if( value.Get( mTargetSize ) ) { + if( mRelayoutData ) + { + if( GetResizePolicy( Dimension::WIDTH ) == ResizePolicy::FIXED ) + { + mRelayoutData->preferredSize.width = mTargetSize.width; + } + + if( GetResizePolicy( Dimension::HEIGHT ) == ResizePolicy::FIXED ) + { + mRelayoutData->preferredSize.height = mTargetSize.height; + } + } + // Notify deriving classes OnSizeAnimation( animation, mTargetSize ); } @@ -2923,6 +2953,11 @@ void Actor::OnNotifyDefaultPropertyAnimation( Animation& animation, Property::In { if( value.Get( mTargetSize.width ) ) { + if( mRelayoutData && GetResizePolicy( Dimension::WIDTH ) == ResizePolicy::FIXED ) + { + mRelayoutData->preferredSize.width = mTargetSize.width; + } + // Notify deriving classes OnSizeAnimation( animation, mTargetSize ); } @@ -2933,6 +2968,11 @@ void Actor::OnNotifyDefaultPropertyAnimation( Animation& animation, Property::In { if( value.Get( mTargetSize.height ) ) { + if( mRelayoutData && GetResizePolicy( Dimension::HEIGHT ) == ResizePolicy::FIXED ) + { + mRelayoutData->preferredSize.height = mTargetSize.height; + } + // Notify deriving classes OnSizeAnimation( animation, mTargetSize ); } @@ -3057,6 +3097,19 @@ void Actor::OnNotifyDefaultPropertyAnimation( Animation& animation, Property::In { if( AdjustValue< Vector3 >( mTargetSize, value ) ) { + if( mRelayoutData ) + { + if( GetResizePolicy( Dimension::WIDTH ) == ResizePolicy::FIXED ) + { + mRelayoutData->preferredSize.width = mTargetSize.width; + } + + if( GetResizePolicy( Dimension::HEIGHT ) == ResizePolicy::FIXED ) + { + mRelayoutData->preferredSize.height = mTargetSize.height; + } + } + // Notify deriving classes OnSizeAnimation( animation, mTargetSize ); } @@ -3067,6 +3120,11 @@ void Actor::OnNotifyDefaultPropertyAnimation( Animation& animation, Property::In { if( AdjustValue< float >( mTargetSize.width, value ) ) { + if( mRelayoutData && GetResizePolicy( Dimension::WIDTH ) == ResizePolicy::FIXED ) + { + mRelayoutData->preferredSize.width = mTargetSize.width; + } + // Notify deriving classes OnSizeAnimation( animation, mTargetSize ); } @@ -3077,6 +3135,11 @@ void Actor::OnNotifyDefaultPropertyAnimation( Animation& animation, Property::In { if( AdjustValue< float >( mTargetSize.height, value ) ) { + if( mRelayoutData && GetResizePolicy( Dimension::HEIGHT ) == ResizePolicy::FIXED ) + { + mRelayoutData->preferredSize.height = mTargetSize.height; + } + // Notify deriving classes OnSizeAnimation( animation, mTargetSize ); } @@ -3410,6 +3473,8 @@ void Actor::SetParent( Actor* parent ) mParent = parent; + mScene = parent->mScene; + if ( EventThreadServices::IsCoreRunning() && // Don't emit signals or send messages during Core destruction parent->OnStage() ) { @@ -3435,6 +3500,8 @@ void Actor::SetParent( Actor* parent ) // Instruct each actor to discard pointers to the scene-graph DisconnectFromStage(); } + + mScene = nullptr; } } @@ -3460,6 +3527,15 @@ bool Actor::DoAction( BaseObject* object, const std::string& actionName, const P return done; } +Rect<> Actor::CalculateScreenExtents( ) const +{ + auto screenPosition = GetCurrentScreenPosition(); + Vector3 size = GetCurrentSize() * GetCurrentWorldScale(); + Vector3 anchorPointOffSet = size * ( mPositionUsesAnchorPoint ? GetCurrentAnchorPoint() : AnchorPoint::TOP_LEFT ); + Vector2 position = Vector2( screenPosition.x - anchorPointOffSet.x, screenPosition.y - anchorPointOffSet.y ); + return { position.x, position.y, size.x, size.y }; +} + bool Actor::GetCachedPropertyValue( Property::Index index, Property::Value& value ) const { bool valueSet = true; @@ -4617,6 +4693,10 @@ void Actor::SetPreferredSize( const Vector2& size ) { EnsureRelayoutData(); + // If valid width or height, then set the resize policy to FIXED + // A 0 width or height may also be required so if the resize policy has not been changed, i.e. is still set to DEFAULT, + // then change to FIXED as well + if( size.width > 0.0f ) { SetResizePolicy( ResizePolicy::FIXED, Dimension::WIDTH ); @@ -4782,10 +4862,9 @@ void Actor::RequestRebuildDepthTree() { if( mIsOnStage ) { - StagePtr stage = Stage::GetCurrent(); - if( stage ) + if( mScene ) { - stage->RequestRebuildDepthTree(); + mScene->RequestRebuildDepthTree(); } } } @@ -4969,6 +5048,16 @@ void Actor::LowerBelow( Internal::Actor& target ) } } +void Actor::SetScene( Scene& scene ) +{ + mScene = &scene; +} + +Scene& Actor::GetScene() const +{ + return *mScene; +} + void Actor::SetInheritLayoutDirection( bool inherit ) { if( mInheritLayoutDirection != inherit )