X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali%2Finternal%2Fevent%2Factors%2Factor-impl.cpp;h=eccc527fa47505b0a5f63c4a616afe2f94c2d53a;hb=refs%2Ftags%2Faccepted%2Ftizen%2F6.0%2Funified%2F20201111.064916;hp=b387d334e4575ff8cb0df6319124b7d71cc6c9b4;hpb=910059be77e79b5f788c04ff7b9eb066a712ee26;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 old mode 100644 new mode 100755 index b387d33..eccc527 --- a/dali/internal/event/actors/actor-impl.cpp +++ b/dali/internal/event/actors/actor-impl.cpp @@ -27,14 +27,13 @@ #include #include #include -#include #include #include #include #include #include -#include -#include +#include +#include #include #include #include @@ -44,15 +43,10 @@ #include #include #include -#include #include #include -#include #include -#include -#include #include -#include #include using Dali::Internal::SceneGraph::Node; @@ -70,78 +64,6 @@ namespace Dali namespace Internal { -namespace -{ -/// Using a function because of library initialisation order. Vector3::ONE may not have been initialised yet. -inline const Vector3& GetDefaultSizeModeFactor() -{ - return Vector3::ONE; -} - -/// Using a function because of library initialisation order. Vector2::ZERO may not have been initialised yet. -inline const Vector2& GetDefaultPreferredSize() -{ - return Vector2::ZERO; -} - -/// Using a function because of library initialisation order. Vector2::ZERO may not have been initialised yet. -inline const Vector2& GetDefaultDimensionPadding() -{ - return Vector2::ZERO; -} - -const SizeScalePolicy::Type DEFAULT_SIZE_SCALE_POLICY = SizeScalePolicy::USE_SIZE_SET; - -} // unnamed namespace - -/** - * Struct to collect relayout variables - */ -struct Actor::RelayoutData -{ - RelayoutData() - : sizeModeFactor( GetDefaultSizeModeFactor() ), preferredSize( GetDefaultPreferredSize() ), sizeSetPolicy( DEFAULT_SIZE_SCALE_POLICY ), relayoutEnabled( false ), insideRelayout( false ) - { - // Set size negotiation defaults - for( uint32_t i = 0; i < Dimension::DIMENSION_COUNT; ++i ) - { - resizePolicies[ i ] = ResizePolicy::DEFAULT; - useAssignedSize[ i ] = false; - negotiatedDimensions[ i ] = 0.0f; - dimensionNegotiated[ i ] = false; - dimensionDirty[ i ] = false; - dimensionDependencies[ i ] = Dimension::ALL_DIMENSIONS; - dimensionPadding[ i ] = GetDefaultDimensionPadding(); - minimumSize[ i ] = 0.0f; - maximumSize[ i ] = FLT_MAX; - } - } - - ResizePolicy::Type resizePolicies[ Dimension::DIMENSION_COUNT ]; ///< Resize policies - bool useAssignedSize[ Dimension::DIMENSION_COUNT ]; ///< The flag to specify whether the size should be assigned to the actor - - Dimension::Type dimensionDependencies[ Dimension::DIMENSION_COUNT ]; ///< A list of dimension dependencies - - Vector2 dimensionPadding[ Dimension::DIMENSION_COUNT ]; ///< Padding for each dimension. X = start (e.g. left, bottom), y = end (e.g. right, top) - - float negotiatedDimensions[ Dimension::DIMENSION_COUNT ]; ///< Storage for when a dimension is negotiated but before set on actor - - float minimumSize[ Dimension::DIMENSION_COUNT ]; ///< The minimum size an actor can be - float maximumSize[ Dimension::DIMENSION_COUNT ]; ///< The maximum size an actor can be - - bool dimensionNegotiated[ Dimension::DIMENSION_COUNT ]; ///< Has the dimension been negotiated - bool dimensionDirty[ Dimension::DIMENSION_COUNT ]; ///< Flags indicating whether the layout dimension is dirty or not - - Vector3 sizeModeFactor; ///< Factor of size used for certain SizeModes - - Vector2 preferredSize; ///< The preferred size of the actor - - SizeScalePolicy::Type sizeSetPolicy :3; ///< Policy to apply when setting size. Enough room for the enum - - bool relayoutEnabled :1; ///< Flag to specify if this actor should be included in size negotiation or not (defaults to true) - bool insideRelayout :1; ///< Locking flag to prevent recursive relayouts on size set -}; - namespace // unnamed namespace { @@ -219,17 +141,19 @@ DALI_PROPERTY( "isLayer", BOOLEAN, false, false, false, Dali: DALI_PROPERTY( "connectedToScene", BOOLEAN, false, false, false, Dali::Actor::Property::CONNECTED_TO_SCENE ) DALI_PROPERTY( "keyboardFocusable", BOOLEAN, true, false, false, Dali::Actor::Property::KEYBOARD_FOCUSABLE ) DALI_PROPERTY( "siblingOrder", INTEGER, true, false, false, Dali::DevelActor::Property::SIBLING_ORDER ) +DALI_PROPERTY( "updateSizeHint", VECTOR2, true, false, false, Dali::DevelActor::Property::UPDATE_SIZE_HINT ) +DALI_PROPERTY( "captureAllTouchAfterStart", BOOLEAN, true, false, false, Dali::DevelActor::Property::CAPTURE_ALL_TOUCH_AFTER_START ) +DALI_PROPERTY( "touchArea", VECTOR2, true, false, false, Dali::DevelActor::Property::TOUCH_AREA ) DALI_PROPERTY_TABLE_END( DEFAULT_ACTOR_PROPERTY_START_INDEX, ActorDefaultProperties ) // Signals -const char* const SIGNAL_TOUCHED = "touched"; const char* const SIGNAL_HOVERED = "hovered"; const char* const SIGNAL_WHEEL_EVENT = "wheelEvent"; -const char* const SIGNAL_ON_STAGE = "onStage"; -const char* const SIGNAL_OFF_STAGE = "offStage"; +const char* const SIGNAL_ON_SCENE = "onScene"; +const char* const SIGNAL_OFF_SCENE = "offScene"; const char* const SIGNAL_ON_RELAYOUT = "onRelayout"; -const char* const SIGNAL_TOUCH = "touch"; +const char* const SIGNAL_TOUCHED = "touched"; const char* const SIGNAL_VISIBILITY_CHANGED = "visibilityChanged"; const char* const SIGNAL_LAYOUT_DIRECTION_CHANGED = "layoutDirectionChanged"; const char* const SIGNAL_CHILD_ADDED = "childAdded"; @@ -247,13 +171,12 @@ BaseHandle CreateActor() TypeRegistration mType( typeid(Dali::Actor), typeid(Dali::Handle), CreateActor, ActorDefaultProperties ); -SignalConnectorType signalConnector1( mType, SIGNAL_TOUCHED, &Actor::DoConnectSignal ); SignalConnectorType signalConnector2( mType, SIGNAL_HOVERED, &Actor::DoConnectSignal ); SignalConnectorType signalConnector3( mType, SIGNAL_WHEEL_EVENT, &Actor::DoConnectSignal ); -SignalConnectorType signalConnector4( mType, SIGNAL_ON_STAGE, &Actor::DoConnectSignal ); -SignalConnectorType signalConnector5( mType, SIGNAL_OFF_STAGE, &Actor::DoConnectSignal ); +SignalConnectorType signalConnector4( mType, SIGNAL_ON_SCENE, &Actor::DoConnectSignal ); +SignalConnectorType signalConnector5( mType, SIGNAL_OFF_SCENE, &Actor::DoConnectSignal ); SignalConnectorType signalConnector6( mType, SIGNAL_ON_RELAYOUT, &Actor::DoConnectSignal ); -SignalConnectorType signalConnector7( mType, SIGNAL_TOUCH, &Actor::DoConnectSignal ); +SignalConnectorType signalConnector7( mType, SIGNAL_TOUCHED, &Actor::DoConnectSignal ); SignalConnectorType signalConnector8( mType, SIGNAL_VISIBILITY_CHANGED, &Actor::DoConnectSignal ); SignalConnectorType signalConnector9( mType, SIGNAL_LAYOUT_DIRECTION_CHANGED, &Actor::DoConnectSignal ); SignalConnectorType signalConnector10( mType, SIGNAL_CHILD_ADDED, &Actor::DoConnectSignal ); @@ -262,83 +185,6 @@ SignalConnectorType signalConnector11( mType, SIGNAL_CHILD_REMOVED, &Actor::DoCo TypeAction a1( mType, ACTION_SHOW, &Actor::DoAction ); TypeAction a2( mType, ACTION_HIDE, &Actor::DoAction ); -struct AnchorValue -{ - const char* name; - const Vector3& value; -}; - -DALI_ENUM_TO_STRING_TABLE_BEGIN_WITH_TYPE( AnchorValue, ANCHOR_CONSTANT ) -DALI_ENUM_TO_STRING_WITH_SCOPE( AnchorPoint, TOP_LEFT ) -DALI_ENUM_TO_STRING_WITH_SCOPE( AnchorPoint, TOP_CENTER ) -DALI_ENUM_TO_STRING_WITH_SCOPE( AnchorPoint, TOP_RIGHT ) -DALI_ENUM_TO_STRING_WITH_SCOPE( AnchorPoint, CENTER_LEFT ) -DALI_ENUM_TO_STRING_WITH_SCOPE( AnchorPoint, CENTER ) -DALI_ENUM_TO_STRING_WITH_SCOPE( AnchorPoint, CENTER_RIGHT ) -DALI_ENUM_TO_STRING_WITH_SCOPE( AnchorPoint, BOTTOM_LEFT ) -DALI_ENUM_TO_STRING_WITH_SCOPE( AnchorPoint, BOTTOM_CENTER ) -DALI_ENUM_TO_STRING_WITH_SCOPE( AnchorPoint, BOTTOM_RIGHT ) -DALI_ENUM_TO_STRING_TABLE_END( ANCHOR_CONSTANT ) - -DALI_ENUM_TO_STRING_TABLE_BEGIN( COLOR_MODE ) -DALI_ENUM_TO_STRING( USE_OWN_COLOR ) -DALI_ENUM_TO_STRING( USE_PARENT_COLOR ) -DALI_ENUM_TO_STRING( USE_OWN_MULTIPLY_PARENT_COLOR ) -DALI_ENUM_TO_STRING( USE_OWN_MULTIPLY_PARENT_ALPHA ) -DALI_ENUM_TO_STRING_TABLE_END( COLOR_MODE ) - -DALI_ENUM_TO_STRING_TABLE_BEGIN( DRAW_MODE ) -DALI_ENUM_TO_STRING_WITH_SCOPE( DrawMode, NORMAL ) -DALI_ENUM_TO_STRING_WITH_SCOPE( DrawMode, OVERLAY_2D ) -DALI_ENUM_TO_STRING_TABLE_END( DRAW_MODE ) - -DALI_ENUM_TO_STRING_TABLE_BEGIN( RESIZE_POLICY ) -DALI_ENUM_TO_STRING_WITH_SCOPE( ResizePolicy, FIXED ) -DALI_ENUM_TO_STRING_WITH_SCOPE( ResizePolicy, USE_NATURAL_SIZE ) -DALI_ENUM_TO_STRING_WITH_SCOPE( ResizePolicy, FILL_TO_PARENT ) -DALI_ENUM_TO_STRING_WITH_SCOPE( ResizePolicy, SIZE_RELATIVE_TO_PARENT ) -DALI_ENUM_TO_STRING_WITH_SCOPE( ResizePolicy, SIZE_FIXED_OFFSET_FROM_PARENT ) -DALI_ENUM_TO_STRING_WITH_SCOPE( ResizePolicy, FIT_TO_CHILDREN ) -DALI_ENUM_TO_STRING_WITH_SCOPE( ResizePolicy, DIMENSION_DEPENDENCY ) -DALI_ENUM_TO_STRING_WITH_SCOPE( ResizePolicy, USE_ASSIGNED_SIZE ) -DALI_ENUM_TO_STRING_TABLE_END( RESIZE_POLICY ) - -DALI_ENUM_TO_STRING_TABLE_BEGIN( SIZE_SCALE_POLICY ) -DALI_ENUM_TO_STRING_WITH_SCOPE( SizeScalePolicy, USE_SIZE_SET ) -DALI_ENUM_TO_STRING_WITH_SCOPE( SizeScalePolicy, FIT_WITH_ASPECT_RATIO ) -DALI_ENUM_TO_STRING_WITH_SCOPE( SizeScalePolicy, FILL_WITH_ASPECT_RATIO ) -DALI_ENUM_TO_STRING_TABLE_END( SIZE_SCALE_POLICY ) - -DALI_ENUM_TO_STRING_TABLE_BEGIN( CLIPPING_MODE ) -DALI_ENUM_TO_STRING_WITH_SCOPE( ClippingMode, DISABLED ) -DALI_ENUM_TO_STRING_WITH_SCOPE( ClippingMode, CLIP_CHILDREN ) -DALI_ENUM_TO_STRING_TABLE_END( CLIPPING_MODE ) - -DALI_ENUM_TO_STRING_TABLE_BEGIN( LAYOUT_DIRECTION ) -DALI_ENUM_TO_STRING_WITH_SCOPE( LayoutDirection, LEFT_TO_RIGHT ) -DALI_ENUM_TO_STRING_WITH_SCOPE( LayoutDirection, RIGHT_TO_LEFT ) -DALI_ENUM_TO_STRING_TABLE_END( LAYOUT_DIRECTION ) - -bool GetAnchorPointConstant( const std::string& value, Vector3& anchor ) -{ - for( uint32_t i = 0; i < ANCHOR_CONSTANT_TABLE_COUNT; ++i ) - { - uint32_t sizeIgnored = 0; - if( CompareTokens( value.c_str(), ANCHOR_CONSTANT_TABLE[ i ].name, sizeIgnored ) ) - { - anchor = ANCHOR_CONSTANT_TABLE[ i ].value; - return true; - } - } - return false; -} - -inline bool GetParentOriginConstant( const std::string& value, Vector3& parentOrigin ) -{ - // Values are the same so just use the same table as anchor-point - return GetAnchorPointConstant( value, parentOrigin ); -} - /** * @brief Extract a given dimension from a Vector2 * @@ -346,7 +192,7 @@ inline bool GetParentOriginConstant( const std::string& value, Vector3& parentOr * @param[in] dimension The dimension to extract * @return Return the value for the dimension */ -float GetDimensionValue( const Vector2& values, Dimension::Type dimension ) +constexpr float GetDimensionValue( const Vector2& values, Dimension::Type dimension ) { switch( dimension ) { @@ -392,15 +238,94 @@ void EmitVisibilityChangedSignalRecursively( ActorPtr actor, bool visible, Devel if( actor->GetChildCount() > 0 ) { - ActorContainer& children = actor->GetChildrenInternal(); - for( ActorIter iter = children.begin(), endIter = children.end(); iter != endIter; ++iter ) + for( auto& child : actor->GetChildrenInternal() ) { - EmitVisibilityChangedSignalRecursively( *iter, visible, DevelActor::VisibilityChange::PARENT ); + EmitVisibilityChangedSignalRecursively( child, visible, DevelActor::VisibilityChange::PARENT ); } } } } +/// Helper for emitting a signal +template +bool EmitConsumingSignal( Actor& actor, Signal& signal, const Event& event ) +{ + bool consumed = false; + + if( !signal.Empty() ) + { + Dali::Actor handle( &actor ); + consumed = signal.Emit( handle, event ); + } + + return consumed; +} + +/// Helper for emitting signals with multiple parameters +template +void EmitSignal( Actor& actor, Signal& signal, Param... params) +{ + if( !signal.Empty() ) + { + Dali::Actor handle( &actor ); + signal.Emit( handle, params... ); + } +} + +bool ScreenToLocalInternal( + const Matrix& viewMatrix, + const Matrix& projectionMatrix, + const Matrix& worldMatrix, + const Viewport& viewport, + const Vector3& currentSize, + float& localX, + float& localY, + float screenX, + float screenY ) +{ + // Get the ModelView matrix + Matrix modelView; + Matrix::Multiply( modelView, worldMatrix, viewMatrix ); + + // Calculate the inverted ModelViewProjection matrix; this will be used for 2 unprojects + Matrix invertedMvp( false/*don't init*/); + Matrix::Multiply( invertedMvp, modelView, projectionMatrix ); + bool success = invertedMvp.Invert(); + + // Convert to GL coordinates + Vector4 screenPos( screenX - static_cast( viewport.x ), static_cast( viewport.height ) - screenY - static_cast( viewport.y ), 0.f, 1.f ); + + Vector4 nearPos; + if( success ) + { + success = Unproject( screenPos, invertedMvp, static_cast( viewport.width ), static_cast( viewport.height ), nearPos ); + } + + Vector4 farPos; + if( success ) + { + screenPos.z = 1.0f; + success = Unproject( screenPos, invertedMvp, static_cast( viewport.width ), static_cast( viewport.height ), farPos ); + } + + if( success ) + { + Vector4 local; + if( XyPlaneIntersect( nearPos, farPos, local ) ) + { + Vector3 size = currentSize; + localX = local.x + size.x * 0.5f; + localY = local.y + size.y * 0.5f; + } + else + { + success = false; + } + } + + return success; +} + } // unnamed namespace ActorPtr Actor::New() @@ -428,11 +353,6 @@ const SceneGraph::Node* Actor::CreateNode() return node; } -const std::string& Actor::GetName() const -{ - return mName; -} - void Actor::SetName( const std::string& name ) { mName = name; @@ -446,11 +366,6 @@ uint32_t Actor::GetId() const return GetNode().GetId(); } -bool Actor::OnStage() const -{ - return mIsOnStage; -} - Dali::Layer Actor::GetLayer() { Dali::Layer layer; @@ -462,7 +377,7 @@ Dali::Layer Actor::GetLayer() } // Find the immediate Layer parent - for( Actor* parent = mParent; !layer && parent != NULL; parent = parent->GetParent() ) + for( Actor* parent = mParent; !layer && parent != nullptr; parent = parent->GetParent() ) { if( parent->IsLayer() ) { @@ -549,7 +464,7 @@ void Actor::Remove( Actor& child ) mChildren->erase( iter ); DALI_ASSERT_DEBUG( actor->GetParent() == this ); - actor->SetParent( NULL ); + actor->SetParent( nullptr ); break; } @@ -582,7 +497,7 @@ void Actor::Unparent() uint32_t Actor::GetChildCount() const { - return ( NULL != mChildren ) ? static_cast( mChildren->size() ) : 0; // only 4,294,967,295 children per actor + return ( nullptr != mChildren ) ? static_cast( mChildren->size() ) : 0; // only 4,294,967,295 children per actor } ActorPtr Actor::GetChildAt( uint32_t index ) const @@ -594,17 +509,16 @@ ActorPtr Actor::GetChildAt( uint32_t index ) const ActorPtr Actor::FindChildByName( const std::string& actorName ) { - ActorPtr child = 0; + ActorPtr child = nullptr; if( actorName == mName ) { child = this; } else if( mChildren ) { - ActorIter end = mChildren->end(); - for( ActorIter iter = mChildren->begin(); iter != end; ++iter ) + for( const auto& actor : *mChildren ) { - child = (*iter)->FindChildByName( actorName ); + child = actor->FindChildByName( actorName ); if( child ) { @@ -617,17 +531,16 @@ ActorPtr Actor::FindChildByName( const std::string& actorName ) ActorPtr Actor::FindChildById( const uint32_t id ) { - ActorPtr child = 0; + ActorPtr child = nullptr; if( id == GetId() ) { child = this; } else if( mChildren ) { - ActorIter end = mChildren->end(); - for( ActorIter iter = mChildren->begin(); iter != end; ++iter ) + for( const auto& actor : *mChildren ) { - child = (*iter)->FindChildById( id ); + child = actor->FindChildById( id ); if( child ) { @@ -659,27 +572,6 @@ void Actor::SetParentOrigin( const Vector3& origin ) } } -void Actor::SetParentOriginX( float x ) -{ - const Vector3& current = GetCurrentParentOrigin(); - - SetParentOrigin( Vector3( x, current.y, current.z ) ); -} - -void Actor::SetParentOriginY( float y ) -{ - const Vector3& current = GetCurrentParentOrigin(); - - SetParentOrigin( Vector3( current.x, y, current.z ) ); -} - -void Actor::SetParentOriginZ( float z ) -{ - const Vector3& current = GetCurrentParentOrigin(); - - SetParentOrigin( Vector3( current.x, current.y, z ) ); -} - const Vector3& Actor::GetCurrentParentOrigin() const { // Cached for event-thread access @@ -707,27 +599,6 @@ void Actor::SetAnchorPoint( const Vector3& anchor ) } } -void Actor::SetAnchorPointX( float x ) -{ - const Vector3& current = GetCurrentAnchorPoint(); - - SetAnchorPoint( Vector3( x, current.y, current.z ) ); -} - -void Actor::SetAnchorPointY( float y ) -{ - const Vector3& current = GetCurrentAnchorPoint(); - - SetAnchorPoint( Vector3( current.x, y, current.z ) ); -} - -void Actor::SetAnchorPointZ( float z ) -{ - const Vector3& current = GetCurrentAnchorPoint(); - - SetAnchorPoint( Vector3( current.x, current.y, z ) ); -} - const Vector3& Actor::GetCurrentAnchorPoint() const { // Cached for event-thread access @@ -790,11 +661,6 @@ const Vector3& Actor::GetCurrentPosition() const return GetNode().GetPosition(GetEventThreadServices().GetEventBufferIndex()); } -const Vector3& Actor::GetTargetPosition() const -{ - return mTargetPosition; -} - const Vector3& Actor::GetCurrentWorldPosition() const { // node is being used in a separate thread; copy the value from the previous update @@ -803,7 +669,7 @@ const Vector3& Actor::GetCurrentWorldPosition() const const Vector2 Actor::GetCurrentScreenPosition() const { - if( mScene && OnStage() ) + if( mScene && OnScene() ) { Vector3 worldPosition = GetNode().GetWorldPosition( GetEventThreadServices().GetEventBufferIndex() ); Vector3 cameraPosition = mScene->GetDefaultCameraActor().GetNode().GetWorldPosition( GetEventThreadServices().GetEventBufferIndex() ); @@ -831,11 +697,6 @@ void Actor::SetInheritPosition( bool inherit ) } } -bool Actor::IsPositionInherited() const -{ - return mInheritPosition; -} - void Actor::SetOrientation( const Radian& angle, const Vector3& axis ) { Vector3 normalizedAxis( axis.x, axis.y, axis.z ); @@ -952,11 +813,6 @@ void Actor::SetInheritScale( bool inherit ) } } -bool Actor::IsScaleInherited() const -{ - return mInheritScale; -} - Matrix Actor::GetCurrentWorldMatrix() const { return GetNode().GetWorldMatrix(0); @@ -987,16 +843,6 @@ float Actor::GetCurrentOpacity() const return GetNode().GetOpacity(GetEventThreadServices().GetEventBufferIndex()); } -ClippingMode::Type Actor::GetClippingMode() const -{ - return mClippingMode; -} - -uint32_t Actor::GetSortingDepth() -{ - return mSortedDepth; -} - const Vector4& Actor::GetCurrentWorldColor() const { return GetNode().GetWorldColor( GetEventThreadServices().GetEventBufferIndex() ); @@ -1051,14 +897,9 @@ void Actor::SetInheritOrientation( bool inherit ) } } -bool Actor::IsOrientationInherited() const -{ - return mInheritOrientation; -} - void Actor::SetSizeModeFactor( const Vector3& factor ) { - EnsureRelayoutData(); + EnsureRelayouter(); mRelayoutData->sizeModeFactor = factor; } @@ -1070,7 +911,7 @@ const Vector3& Actor::GetSizeModeFactor() const return mRelayoutData->sizeModeFactor; } - return GetDefaultSizeModeFactor(); + return Relayouter::DEFAULT_SIZE_MODE_FACTOR; } void Actor::SetColorMode( ColorMode colorMode ) @@ -1081,12 +922,6 @@ void Actor::SetColorMode( ColorMode colorMode ) SetColorModeMessage( GetEventThreadServices(), GetNode(), colorMode ); } -ColorMode Actor::GetColorMode() const -{ - // we have cached copy - return mColorMode; -} - void Actor::SetSize( float width, float height ) { SetSize( Vector2( width, height ) ); @@ -1249,70 +1084,7 @@ Vector3 Actor::GetNaturalSize() const void Actor::SetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension ) { - EnsureRelayoutData(); - - ResizePolicy::Type originalWidthPolicy = GetResizePolicy(Dimension::WIDTH); - ResizePolicy::Type originalHeightPolicy = GetResizePolicy(Dimension::HEIGHT); - - for( uint32_t i = 0; i < Dimension::DIMENSION_COUNT; ++i ) - { - if( dimension & ( 1 << i ) ) - { - if ( policy == ResizePolicy::USE_ASSIGNED_SIZE ) - { - mRelayoutData->useAssignedSize[ i ] = true; - } - else - { - mRelayoutData->resizePolicies[ i ] = policy; - mRelayoutData->useAssignedSize[ i ] = false; - } - } - } - - if( policy == ResizePolicy::DIMENSION_DEPENDENCY ) - { - if( dimension & Dimension::WIDTH ) - { - SetDimensionDependency( Dimension::WIDTH, Dimension::HEIGHT ); - } - - if( dimension & Dimension::HEIGHT ) - { - SetDimensionDependency( Dimension::HEIGHT, Dimension::WIDTH ); - } - } - - // If calling SetResizePolicy, assume we want relayout enabled - SetRelayoutEnabled( true ); - - // If the resize policy is set to be FIXED, the preferred size - // should be overrided by the target size. Otherwise the target - // size should be overrided by the preferred size. - - if( dimension & Dimension::WIDTH ) - { - if( originalWidthPolicy != ResizePolicy::FIXED && policy == ResizePolicy::FIXED ) - { - mRelayoutData->preferredSize.width = mTargetSize.width; - } - else if( originalWidthPolicy == ResizePolicy::FIXED && policy != ResizePolicy::FIXED ) - { - mTargetSize.width = mRelayoutData->preferredSize.width; - } - } - - if( dimension & Dimension::HEIGHT ) - { - if( originalHeightPolicy != ResizePolicy::FIXED && policy == ResizePolicy::FIXED ) - { - mRelayoutData->preferredSize.height = mTargetSize.height; - } - else if( originalHeightPolicy == ResizePolicy::FIXED && policy != ResizePolicy::FIXED ) - { - mTargetSize.height = mRelayoutData->preferredSize.height; - } - } + EnsureRelayouter().SetResizePolicy(policy, dimension, mTargetSize); OnSetResizePolicy( policy, dimension ); @@ -1324,21 +1096,7 @@ ResizePolicy::Type Actor::GetResizePolicy( Dimension::Type dimension ) const { if ( mRelayoutData ) { - // If more than one dimension is requested, just return the first one found - for( uint32_t i = 0; i < Dimension::DIMENSION_COUNT; ++i ) - { - if( ( dimension & ( 1 << i ) ) ) - { - if( mRelayoutData->useAssignedSize[ i ] ) - { - return ResizePolicy::USE_ASSIGNED_SIZE; - } - else - { - return mRelayoutData->resizePolicies[ i ]; - } - } - } + return mRelayoutData->GetResizePolicy(dimension); } return ResizePolicy::DEFAULT; @@ -1346,7 +1104,7 @@ ResizePolicy::Type Actor::GetResizePolicy( Dimension::Type dimension ) const void Actor::SetSizeScalePolicy( SizeScalePolicy::Type policy ) { - EnsureRelayoutData(); + EnsureRelayouter(); mRelayoutData->sizeSetPolicy = policy; @@ -1361,34 +1119,19 @@ SizeScalePolicy::Type Actor::GetSizeScalePolicy() const return mRelayoutData->sizeSetPolicy; } - return DEFAULT_SIZE_SCALE_POLICY; + return Relayouter::DEFAULT_SIZE_SCALE_POLICY; } void Actor::SetDimensionDependency( Dimension::Type dimension, Dimension::Type dependency ) { - EnsureRelayoutData(); - - for( uint32_t i = 0; i < Dimension::DIMENSION_COUNT; ++i ) - { - if( dimension & ( 1 << i ) ) - { - mRelayoutData->dimensionDependencies[ i ] = dependency; - } - } + EnsureRelayouter().SetDimensionDependency(dimension, dependency); } Dimension::Type Actor::GetDimensionDependency( Dimension::Type dimension ) const { if ( mRelayoutData ) { - // If more than one dimension is requested, just return the first one found - for( uint32_t i = 0; i < Dimension::DIMENSION_COUNT; ++i ) - { - if( ( dimension & ( 1 << i ) ) ) - { - return mRelayoutData->dimensionDependencies[ i ]; - } - } + return mRelayoutData->GetDimensionDependency(dimension); } return Dimension::ALL_DIMENSIONS; // Default @@ -1400,7 +1143,7 @@ void Actor::SetRelayoutEnabled( bool relayoutEnabled ) // to disable it, do nothing if( mRelayoutData || relayoutEnabled ) { - EnsureRelayoutData(); + EnsureRelayouter(); DALI_ASSERT_DEBUG( mRelayoutData && "mRelayoutData not created" ); @@ -1417,31 +1160,12 @@ bool Actor::IsRelayoutEnabled() const void Actor::SetLayoutDirty( bool dirty, Dimension::Type dimension ) { - EnsureRelayoutData(); - - for( uint32_t i = 0; i < Dimension::DIMENSION_COUNT; ++i ) - { - if( dimension & ( 1 << i ) ) - { - mRelayoutData->dimensionDirty[ i ] = dirty; - } - } + EnsureRelayouter().SetLayoutDirty(dirty, dimension); } bool Actor::IsLayoutDirty( Dimension::Type dimension ) const { - if ( mRelayoutData ) - { - for( uint32_t i = 0; i < Dimension::DIMENSION_COUNT; ++i ) - { - if( ( dimension & ( 1 << i ) ) && mRelayoutData->dimensionDirty[ i ] ) - { - return true; - } - } - } - - return false; + return mRelayoutData && mRelayoutData->IsLayoutDirty(dimension); } bool Actor::RelayoutPossible( Dimension::Type dimension ) const @@ -1517,11 +1241,6 @@ void Actor::RemoveRenderer( uint32_t index ) } } -bool Actor::IsOverlay() const -{ - return ( DrawMode::OVERLAY_2D == mDrawMode ); -} - void Actor::SetDrawMode( DrawMode::Type drawMode ) { // this flag is not animatable so keep the value @@ -1531,15 +1250,10 @@ void Actor::SetDrawMode( DrawMode::Type drawMode ) SetDrawModeMessage( GetEventThreadServices(), GetNode(), drawMode ); } -DrawMode::Type Actor::GetDrawMode() const -{ - return mDrawMode; -} - bool Actor::ScreenToLocal( float& localX, float& localY, float screenX, float screenY ) const { // only valid when on-stage - if( mScene && OnStage() ) + if( mScene && OnScene() ) { const RenderTaskList& taskList = mScene->GetRenderTaskList(); @@ -1564,7 +1278,7 @@ bool Actor::ScreenToLocal( const RenderTask& renderTask, float& localX, float& l { bool retval = false; // only valid when on-stage - if( OnStage() ) + if( OnScene() ) { CameraActor* camera = renderTask.GetCameraActor(); if( camera ) @@ -1585,400 +1299,63 @@ bool Actor::ScreenToLocal( const RenderTask& renderTask, float& localX, float& l bool Actor::ScreenToLocal( const Matrix& viewMatrix, const Matrix& projectionMatrix, const Viewport& viewport, float& localX, float& localY, float screenX, float screenY ) const { - // Early-out if not on stage - if( !OnStage() ) + return OnScene() && ScreenToLocalInternal(viewMatrix, projectionMatrix, GetNode().GetWorldMatrix(0), viewport, GetCurrentSize(), localX, localY, screenX, screenY); +} + +ActorGestureData& Actor::GetGestureData() +{ + // Likely scenario is that once gesture-data is created for this actor, the actor will require + // that gesture for its entire life-time so no need to destroy it until the actor is destroyed + if( nullptr == mGestureData ) { - return false; + mGestureData = new ActorGestureData; } + return *mGestureData; +} - // Get the ModelView matrix - Matrix modelView; - Matrix::Multiply( modelView, GetNode().GetWorldMatrix(0), viewMatrix ); +bool Actor::IsGestureRequired( GestureType::Value type ) const +{ + return mGestureData && mGestureData->IsGestureRequired( type ); +} - // Calculate the inverted ModelViewProjection matrix; this will be used for 2 unprojects - Matrix invertedMvp( false/*don't init*/); - Matrix::Multiply( invertedMvp, modelView, projectionMatrix ); - bool success = invertedMvp.Invert(); - - // Convert to GL coordinates - Vector4 screenPos( screenX - static_cast( viewport.x ), static_cast( viewport.height ) - screenY - static_cast( viewport.y ), 0.f, 1.f ); - - Vector4 nearPos; - if( success ) - { - success = Unproject( screenPos, invertedMvp, static_cast( viewport.width ), static_cast( viewport.height ), nearPos ); - } - - Vector4 farPos; - if( success ) - { - screenPos.z = 1.0f; - success = Unproject( screenPos, invertedMvp, static_cast( viewport.width ), static_cast( viewport.height ), farPos ); - } - - if( success ) - { - Vector4 local; - if( XyPlaneIntersect( nearPos, farPos, local ) ) - { - Vector3 size = GetCurrentSize(); - localX = local.x + size.x * 0.5f; - localY = local.y + size.y * 0.5f; - } - else - { - success = false; - } - } - - return success; -} - -bool Actor::RaySphereTest( const Vector4& rayOrigin, const Vector4& rayDir ) const -{ - /* - http://wiki.cgsociety.org/index.php/Ray_Sphere_Intersection - - Mathematical Formulation - - Given the above mentioned sphere, a point 'p' lies on the surface of the sphere if - - ( p - c ) dot ( p - c ) = r^2 - - Given a ray with a point of origin 'o', and a direction vector 'd': - - ray(t) = o + td, t >= 0 - - we can find the t at which the ray intersects the sphere by setting ray(t) equal to 'p' - - (o + td - c ) dot ( o + td - c ) = r^2 - - To solve for t we first expand the above into a more recognisable quadratic equation form - - ( d dot d )t^2 + 2( o - c ) dot dt + ( o - c ) dot ( o - c ) - r^2 = 0 - - or - - At2 + Bt + C = 0 - - where - - A = d dot d - B = 2( o - c ) dot d - C = ( o - c ) dot ( o - c ) - r^2 - - which can be solved using a standard quadratic formula. - - Note that in the absence of positive, real, roots, the ray does not intersect the sphere. - - Practical Simplification - - In a renderer, we often differentiate between world space and object space. In the object space - of a sphere it is centred at origin, meaning that if we first transform the ray from world space - into object space, the mathematical solution presented above can be simplified significantly. - - If a sphere is centred at origin, a point 'p' lies on a sphere of radius r2 if - - p dot p = r^2 - - and we can find the t at which the (transformed) ray intersects the sphere by - - ( o + td ) dot ( o + td ) = r^2 - - According to the reasoning above, we expand the above quadratic equation into the general form - - At2 + Bt + C = 0 - - which now has coefficients: - - A = d dot d - B = 2( d dot o ) - C = o dot o - r^2 - */ - - // Early-out if not on stage - if( !OnStage() ) - { - return false; - } - - BufferIndex bufferIndex( GetEventThreadServices().GetEventBufferIndex() ); - - // Transforms the ray to the local reference system. As the test is against a sphere, only the translation and scale are needed. - const Vector3& translation( GetNode().GetWorldPosition( bufferIndex ) ); - Vector3 rayOriginLocal( rayOrigin.x - translation.x, rayOrigin.y - translation.y, rayOrigin.z - translation.z ); - - // Compute the radius is not needed, square radius it's enough. - const Vector3& size( GetNode().GetSize( bufferIndex ) ); - - // Scale the sphere. - const Vector3& scale( GetNode().GetWorldScale( bufferIndex ) ); - - const float width = size.width * scale.width; - const float height = size.height * scale.height; - - float squareSphereRadius = 0.5f * ( width * width + height * height ); - - float a = rayDir.Dot( rayDir ); // a - float b2 = rayDir.Dot( rayOriginLocal ); // b/2 - float c = rayOriginLocal.Dot( rayOriginLocal ) - squareSphereRadius; // c - - return ( b2 * b2 - a * c ) >= 0.f; -} - -bool Actor::RayActorTest( const Vector4& rayOrigin, const Vector4& rayDir, Vector2& hitPointLocal, float& distance ) const -{ - bool hit = false; - - if( OnStage() ) - { - // Transforms the ray to the local reference system. - // Calculate the inverse of Model matrix - Matrix invModelMatrix( false/*don't init*/); - - BufferIndex bufferIndex( GetEventThreadServices().GetEventBufferIndex() ); - invModelMatrix = GetNode().GetWorldMatrix(0); - invModelMatrix.Invert(); - - Vector4 rayOriginLocal( invModelMatrix * rayOrigin ); - Vector4 rayDirLocal( invModelMatrix * rayDir - invModelMatrix.GetTranslation() ); - - // Test with the actor's XY plane (Normal = 0 0 1 1). - - float a = -rayOriginLocal.z; - float b = rayDirLocal.z; - - if( fabsf( b ) > Math::MACHINE_EPSILON_1 ) - { - // Ray travels distance * rayDirLocal to intersect with plane. - distance = a / b; - - const Vector3& size = GetNode().GetSize( bufferIndex ); - - hitPointLocal.x = rayOriginLocal.x + rayDirLocal.x * distance + size.x * 0.5f; - hitPointLocal.y = rayOriginLocal.y + rayDirLocal.y * distance + size.y * 0.5f; - - // Test with the actor's geometry. - hit = ( hitPointLocal.x >= 0.f ) && ( hitPointLocal.x <= size.x ) && ( hitPointLocal.y >= 0.f ) && ( hitPointLocal.y <= size.y ); - } - } - - return hit; -} - -void Actor::SetLeaveRequired( bool required ) -{ - mLeaveRequired = required; -} - -bool Actor::GetLeaveRequired() const -{ - return mLeaveRequired; -} - -void Actor::SetKeyboardFocusable( bool focusable ) +bool Actor::EmitInterceptTouchEventSignal( const Dali::TouchEvent& touch ) { - mKeyboardFocusable = focusable; + return EmitConsumingSignal( *this, mInterceptTouchedSignal, touch ); } -bool Actor::IsKeyboardFocusable() const +bool Actor::EmitTouchEventSignal( const Dali::TouchEvent& touch ) { - return mKeyboardFocusable; -} - -bool Actor::GetTouchRequired() const -{ - return !mTouchedSignal.Empty() || !mTouchSignal.Empty() || mDerivedRequiresTouch; -} - -bool Actor::GetHoverRequired() const -{ - return !mHoveredSignal.Empty() || mDerivedRequiresHover; -} - -bool Actor::GetWheelEventRequired() const -{ - return !mWheelEventSignal.Empty() || mDerivedRequiresWheelEvent; -} - -bool Actor::IsHittable() const -{ - return IsSensitive() && IsVisible() && ( GetCurrentWorldColor().a > FULLY_TRANSPARENT ) && IsNodeConnected(); -} - -ActorGestureData& Actor::GetGestureData() -{ - // Likely scenario is that once gesture-data is created for this actor, the actor will require - // that gesture for its entire life-time so no need to destroy it until the actor is destroyed - if( NULL == mGestureData ) - { - mGestureData = new ActorGestureData; - } - return *mGestureData; -} - -bool Actor::IsGestureRequred( DevelGesture::Type type ) const -{ - return mGestureData && mGestureData->IsGestureRequred( type ); -} - -bool Actor::EmitTouchEventSignal( const TouchEvent& event, const Dali::TouchData& touch ) -{ - bool consumed = false; - - if( !mTouchSignal.Empty() ) - { - Dali::Actor handle( this ); - consumed = mTouchSignal.Emit( handle, touch ); - } - - if( !mTouchedSignal.Empty() ) - { - Dali::Actor handle( this ); - consumed |= mTouchedSignal.Emit( handle, event ); - } - - if( !consumed ) - { - // Notification for derived classes - consumed = OnTouchEvent( event ); // TODO - } - - return consumed; + return EmitConsumingSignal( *this, mTouchedSignal, touch ); } -bool Actor::EmitHoverEventSignal( const HoverEvent& event ) +bool Actor::EmitHoverEventSignal( const Dali::HoverEvent& event ) { - bool consumed = false; - - if( !mHoveredSignal.Empty() ) - { - Dali::Actor handle( this ); - consumed = mHoveredSignal.Emit( handle, event ); - } - - if( !consumed ) - { - // Notification for derived classes - consumed = OnHoverEvent( event ); - } - - return consumed; + return EmitConsumingSignal( *this, mHoveredSignal, event ); } -bool Actor::EmitWheelEventSignal( const WheelEvent& event ) +bool Actor::EmitWheelEventSignal( const Dali::WheelEvent& event ) { - bool consumed = false; - - if( !mWheelEventSignal.Empty() ) - { - Dali::Actor handle( this ); - consumed = mWheelEventSignal.Emit( handle, event ); - } - - if( !consumed ) - { - // Notification for derived classes - consumed = OnWheelEvent( event ); - } - - return consumed; + return EmitConsumingSignal( *this, mWheelEventSignal, event ); } void Actor::EmitVisibilityChangedSignal( bool visible, DevelActor::VisibilityChange::Type type ) { - if( ! mVisibilityChangedSignal.Empty() ) - { - Dali::Actor handle( this ); - mVisibilityChangedSignal.Emit( handle, visible, type ); - } + EmitSignal( *this, mVisibilityChangedSignal, visible, type ); } void Actor::EmitLayoutDirectionChangedSignal( LayoutDirection::Type type ) { - if( ! mLayoutDirectionChangedSignal.Empty() ) - { - Dali::Actor handle( this ); - mLayoutDirectionChangedSignal.Emit( handle, type ); - } + EmitSignal( *this, mLayoutDirectionChangedSignal, type ); } void Actor::EmitChildAddedSignal( Actor& child ) { - if( ! mChildAddedSignal.Empty() ) - { - Dali::Actor handle( &child ); - mChildAddedSignal.Emit( handle ); - } + EmitSignal( child, mChildAddedSignal ); } void Actor::EmitChildRemovedSignal( Actor& child ) { - if( ! mChildRemovedSignal.Empty() ) - { - Dali::Actor handle( &child ); - mChildRemovedSignal.Emit( handle ); - } -} - -Dali::Actor::TouchSignalType& Actor::TouchedSignal() -{ - return mTouchedSignal; -} - -Dali::Actor::TouchDataSignalType& Actor::TouchSignal() -{ - return mTouchSignal; -} - -Dali::Actor::HoverSignalType& Actor::HoveredSignal() -{ - return mHoveredSignal; -} - -Dali::Actor::WheelEventSignalType& Actor::WheelEventSignal() -{ - return mWheelEventSignal; -} - -Dali::Actor::OnStageSignalType& Actor::OnStageSignal() -{ - return mOnStageSignal; -} - -Dali::Actor::OffStageSignalType& Actor::OffStageSignal() -{ - return mOffStageSignal; -} - -Dali::Actor::OnRelayoutSignalType& Actor::OnRelayoutSignal() -{ - return mOnRelayoutSignal; -} - -DevelActor::VisibilityChangedSignalType& Actor::VisibilityChangedSignal() -{ - return mVisibilityChangedSignal; -} - -Dali::Actor::LayoutDirectionChangedSignalType& Actor::LayoutDirectionChangedSignal() -{ - return mLayoutDirectionChangedSignal; -} - -DevelActor::ChildChangedSignalType& Actor::ChildAddedSignal() -{ - return mChildAddedSignal; -} - -DevelActor::ChildChangedSignalType& Actor::ChildRemovedSignal() -{ - return mChildRemovedSignal; -} - -DevelActor::ChildOrderChangedSignalType& Actor::ChildOrderChangedSignal() -{ - return mChildOrderChangedSignal; + EmitSignal( child, mChildRemovedSignal ); } bool Actor::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor ) @@ -1986,11 +1363,7 @@ bool Actor::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tra bool connected( true ); Actor* actor = static_cast< Actor* >( object ); // TypeRegistry guarantees that this is the correct type. - if( 0 == signalName.compare( SIGNAL_TOUCHED ) ) - { - actor->TouchedSignal().Connect( tracker, functor ); - } - else if( 0 == signalName.compare( SIGNAL_HOVERED ) ) + if( 0 == signalName.compare( SIGNAL_HOVERED ) ) { actor->HoveredSignal().Connect( tracker, functor ); } @@ -1998,21 +1371,21 @@ bool Actor::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tra { actor->WheelEventSignal().Connect( tracker, functor ); } - else if( 0 == signalName.compare( SIGNAL_ON_STAGE ) ) + else if( 0 == signalName.compare( SIGNAL_ON_SCENE ) ) { - actor->OnStageSignal().Connect( tracker, functor ); + actor->OnSceneSignal().Connect( tracker, functor ); } - else if( 0 == signalName.compare( SIGNAL_OFF_STAGE ) ) + else if( 0 == signalName.compare( SIGNAL_OFF_SCENE ) ) { - actor->OffStageSignal().Connect( tracker, functor ); + actor->OffSceneSignal().Connect( tracker, functor ); } else if( 0 == signalName.compare( SIGNAL_ON_RELAYOUT ) ) { actor->OnRelayoutSignal().Connect( tracker, functor ); } - else if( 0 == signalName.compare( SIGNAL_TOUCH ) ) + else if( 0 == signalName.compare( SIGNAL_TOUCHED ) ) { - actor->TouchSignal().Connect( tracker, functor ); + actor->TouchedSignal().Connect( tracker, functor ); } else if( 0 == signalName.compare( SIGNAL_VISIBILITY_CHANGED ) ) { @@ -2042,19 +1415,19 @@ 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 ), - mParentOrigin( NULL ), - mAnchorPoint( NULL ), - mRelayoutData( NULL ), - mGestureData( NULL ), + mParent( nullptr ), + mChildren( nullptr ), + mRenderers( nullptr ), + mParentOrigin( nullptr ), + mAnchorPoint( nullptr ), + mRelayoutData( nullptr ), + mGestureData( nullptr ), + mInterceptTouchedSignal(), mTouchedSignal(), - mTouchSignal(), mHoveredSignal(), mWheelEventSignal(), - mOnStageSignal(), - mOffStageSignal(), + mOnSceneSignal(), + mOffSceneSignal(), mOnRelayoutSignal(), mVisibilityChangedSignal(), mLayoutDirectionChangedSignal(), @@ -2067,20 +1440,18 @@ Actor::Actor( DerivedType derivedType, const SceneGraph::Node& node ) mTargetPosition( Vector3::ZERO ), mTargetScale( Vector3::ONE ), mAnimatedSize( Vector3::ZERO ), + mTouchArea( Vector2::ZERO ), mName(), mSortedDepth( 0u ), mDepth( 0u ), mUseAnimatedSize( AnimatedSizeFlag::CLEAR ), mIsRoot( ROOT_LAYER == derivedType ), mIsLayer( LAYER == derivedType || ROOT_LAYER == derivedType ), - mIsOnStage( false ), + mIsOnScene( false ), mSensitive( true ), mLeaveRequired( false ), mKeyboardFocusable( false ), - mDerivedRequiresTouch( false ), - mDerivedRequiresHover( false ), - mDerivedRequiresWheelEvent( false ), - mOnStageSignalled( false ), + mOnSceneSignalled( false ), mInsideOnSizeSet( false ), mInheritPosition( true ), mInheritOrientation( true ), @@ -2088,6 +1459,7 @@ Actor::Actor( DerivedType derivedType, const SceneGraph::Node& node ) mPositionUsesAnchorPoint( true ), mVisible( true ), mInheritLayoutDirection( true ), + mCaptureAllTouchAfterStart( false ), mLayoutDirection( LayoutDirection::LEFT_TO_RIGHT ), mDrawMode( DrawMode::NORMAL ), mColorMode( Node::DEFAULT_COLOR_MODE ), @@ -2108,10 +1480,9 @@ Actor::~Actor() // to guard against GetParent() & Unparent() calls from CustomActor destructors. if( mChildren ) { - ActorConstIter endIter = mChildren->end(); - for( ActorIter iter = mChildren->begin(); iter != endIter; ++iter ) + for( const auto& actor : *mChildren ) { - (*iter)->SetParent( NULL ); + actor->SetParent( nullptr ); } } delete mChildren; @@ -2140,10 +1511,10 @@ Actor::~Actor() delete mRelayoutData; } -void Actor::ConnectToStage( uint32_t parentDepth ) +void Actor::ConnectToScene( uint32_t parentDepth ) { // This container is used instead of walking the Actor hierarchy. - // It protects us when the Actor hierarchy is modified during OnStageConnectionExternal callbacks. + // It protects us when the Actor hierarchy is modified during OnSceneConnectionExternal callbacks. ActorContainer connectionList; if( mScene ) @@ -2152,29 +1523,28 @@ void Actor::ConnectToStage( uint32_t parentDepth ) } // This stage is atomic i.e. not interrupted by user callbacks. - RecursiveConnectToStage( connectionList, parentDepth + 1 ); + RecursiveConnectToScene( connectionList, parentDepth + 1 ); // Notify applications about the newly connected actors. - const ActorIter endIter = connectionList.end(); - for( ActorIter iter = connectionList.begin(); iter != endIter; ++iter ) + for( const auto& actor : connectionList ) { - (*iter)->NotifyStageConnection(); + actor->NotifyStageConnection(); } RelayoutRequest(); } -void Actor::RecursiveConnectToStage( ActorContainer& connectionList, uint32_t depth ) +void Actor::RecursiveConnectToScene( ActorContainer& connectionList, uint32_t depth ) { - DALI_ASSERT_ALWAYS( !OnStage() ); + DALI_ASSERT_ALWAYS( !OnScene() ); - mIsOnStage = true; + mIsOnScene = true; mDepth = static_cast< uint16_t >( depth ); // overflow ignored, not expected in practice ConnectToSceneGraph(); // Notification for internal derived classes - OnStageConnectionInternal(); + OnSceneConnectionInternal(); // This stage is atomic; avoid emitting callbacks until all Actors are connected connectionList.push_back( ActorPtr( this ) ); @@ -2182,11 +1552,10 @@ void Actor::RecursiveConnectToStage( ActorContainer& connectionList, uint32_t de // Recursively connect children if( mChildren ) { - ActorConstIter endIter = mChildren->end(); - for( ActorIter iter = mChildren->begin(); iter != endIter; ++iter ) + for( const auto& actor : *mChildren ) { - (*iter)->SetScene( *mScene ); - (*iter)->RecursiveConnectToStage( connectionList, depth + 1 ); + actor->SetScene( *mScene ); + actor->RecursiveConnectToScene( connectionList, depth + 1 ); } } } @@ -2195,7 +1564,7 @@ void Actor::RecursiveConnectToStage( ActorContainer& connectionList, uint32_t de * This method is called when the Actor is connected to the Stage. * The parent must have added its Node to the scene-graph. * The child must connect its Node to the parent's Node. - * This is recursive; the child calls ConnectToStage() for its children. + * This is recursive; the child calls ConnectToScene() for its children. */ void Actor::ConnectToSceneGraph() { @@ -2214,22 +1583,22 @@ void Actor::ConnectToSceneGraph() void Actor::NotifyStageConnection() { // Actors can be removed (in a callback), before the on-stage stage is reported. - // The actor may also have been reparented, in which case mOnStageSignalled will be true. - if( OnStage() && !mOnStageSignalled ) + // The actor may also have been reparented, in which case mOnSceneSignalled will be true. + if( OnScene() && !mOnSceneSignalled ) { // Notification for external (CustomActor) derived classes - OnStageConnectionExternal( mDepth ); + OnSceneConnectionExternal( mDepth ); - if( !mOnStageSignal.Empty() ) + if( !mOnSceneSignal.Empty() ) { Dali::Actor handle( this ); - mOnStageSignal.Emit( handle ); + mOnSceneSignal.Emit( handle ); } // Guard against Remove during callbacks - if( OnStage() ) + if( OnScene() ) { - mOnStageSignalled = true; // signal required next time Actor is removed + mOnSceneSignalled = true; // signal required next time Actor is removed } } } @@ -2237,7 +1606,7 @@ void Actor::NotifyStageConnection() void Actor::DisconnectFromStage() { // This container is used instead of walking the Actor hierachy. - // It protects us when the Actor hierachy is modified during OnStageDisconnectionExternal callbacks. + // It protects us when the Actor hierachy is modified during OnSceneDisconnectionExternal callbacks. ActorContainer disconnectionList; if( mScene ) @@ -2249,25 +1618,23 @@ void Actor::DisconnectFromStage() RecursiveDisconnectFromStage( disconnectionList ); // Notify applications about the newly disconnected actors. - const ActorIter endIter = disconnectionList.end(); - for( ActorIter iter = disconnectionList.begin(); iter != endIter; ++iter ) + for( const auto& actor : disconnectionList ) { - (*iter)->NotifyStageDisconnection(); + actor->NotifyStageDisconnection(); } } void Actor::RecursiveDisconnectFromStage( ActorContainer& disconnectionList ) { - // need to change state first so that internals relying on IsOnStage() inside OnStageDisconnectionInternal() get the correct value - mIsOnStage = false; + // need to change state first so that internals relying on IsOnScene() inside OnSceneDisconnectionInternal() get the correct value + mIsOnScene = false; // Recursively disconnect children if( mChildren ) { - ActorConstIter endIter = mChildren->end(); - for( ActorIter iter = mChildren->begin(); iter != endIter; ++iter ) + for( const auto& child : *mChildren ) { - (*iter)->RecursiveDisconnectFromStage( disconnectionList ); + child->RecursiveDisconnectFromStage( disconnectionList ); } } @@ -2275,7 +1642,7 @@ void Actor::RecursiveDisconnectFromStage( ActorContainer& disconnectionList ) disconnectionList.push_back( ActorPtr( this ) ); // Notification for internal derived classes - OnStageDisconnectionInternal(); + OnSceneDisconnectionInternal(); DisconnectFromSceneGraph(); } @@ -2293,23 +1660,23 @@ void Actor::DisconnectFromSceneGraph() void Actor::NotifyStageDisconnection() { // Actors can be added (in a callback), before the off-stage state is reported. - // Also if the actor was added & removed before mOnStageSignalled was set, then we don't notify here. + // Also if the actor was added & removed before mOnSceneSignalled was set, then we don't notify here. // only do this step if there is a stage, i.e. Core is not being shut down - if ( EventThreadServices::IsCoreRunning() && !OnStage() && mOnStageSignalled ) + if ( EventThreadServices::IsCoreRunning() && !OnScene() && mOnSceneSignalled ) { // Notification for external (CustomeActor) derived classes - OnStageDisconnectionExternal(); + OnSceneDisconnectionExternal(); - if( !mOffStageSignal.Empty() ) + if( !mOffSceneSignal.Empty() ) { Dali::Actor handle( this ); - mOffStageSignal.Emit( handle ); + mOffSceneSignal.Emit( handle ); } // Guard against Add during callbacks - if( !OnStage() ) + if( !OnScene() ) { - mOnStageSignalled = false; // signal required next time Actor is added + mOnSceneSignalled = false; // signal required next time Actor is added } } } @@ -2318,7 +1685,7 @@ bool Actor::IsNodeConnected() const { bool connected( false ); - if( OnStage() ) + if( OnScene() ) { if( IsRoot() || GetNode().GetParent() ) { @@ -2358,9 +1725,9 @@ void Actor::DepthTraverseActorTree( OwnerPointer& sceneG // Create/add to children of this node if( mChildren ) { - for( ActorContainer::iterator it = mChildren->begin(); it != mChildren->end(); ++it ) + for( const auto& child : *mChildren ) { - Actor* childActor = (*it).Get(); + Actor* childActor = child.Get(); ++depthIndex; childActor->DepthTraverseActorTree( sceneGraphNodeDepths, depthIndex ); } @@ -2369,1773 +1736,173 @@ void Actor::DepthTraverseActorTree( OwnerPointer& sceneG void Actor::SetDefaultProperty( Property::Index index, const Property::Value& property ) { - switch( index ) - { - case Dali::Actor::Property::PARENT_ORIGIN: - { - Property::Type type = property.GetType(); - if( type == Property::VECTOR3 ) - { - SetParentOrigin( property.Get< Vector3 >() ); - } - else if ( type == Property::STRING ) - { - std::string parentOriginString; - property.Get( parentOriginString ); - Vector3 parentOrigin; - if( GetParentOriginConstant( parentOriginString, parentOrigin ) ) - { - SetParentOrigin( parentOrigin ); - } - } - break; - } + PropertyHandler::SetDefaultProperty(*this, index, property); +} - case Dali::Actor::Property::PARENT_ORIGIN_X: - { - SetParentOriginX( property.Get< float >() ); - break; - } +// TODO: This method needs to be removed +void Actor::SetSceneGraphProperty( Property::Index index, const PropertyMetadata& entry, const Property::Value& value ) +{ + PropertyHandler::SetSceneGraphProperty(index, entry, value, GetEventThreadServices(), GetNode()); +} - case Dali::Actor::Property::PARENT_ORIGIN_Y: - { - SetParentOriginY( property.Get< float >() ); - break; - } +Property::Value Actor::GetDefaultProperty( Property::Index index ) const +{ + Property::Value value; - case Dali::Actor::Property::PARENT_ORIGIN_Z: - { - SetParentOriginZ( property.Get< float >() ); - break; - } + if( ! GetCachedPropertyValue( index, value ) ) + { + // If property value is not stored in the event-side, then it must be a scene-graph only property + GetCurrentPropertyValue( index, value ); + } - case Dali::Actor::Property::ANCHOR_POINT: - { - Property::Type type = property.GetType(); - if( type == Property::VECTOR3 ) - { - SetAnchorPoint( property.Get< Vector3 >() ); - } - else if ( type == Property::STRING ) - { - std::string anchorPointString; - property.Get( anchorPointString ); - Vector3 anchor; - if( GetAnchorPointConstant( anchorPointString, anchor ) ) - { - SetAnchorPoint( anchor ); - } - } - break; - } + return value; +} - case Dali::Actor::Property::ANCHOR_POINT_X: - { - SetAnchorPointX( property.Get< float >() ); - break; - } - - case Dali::Actor::Property::ANCHOR_POINT_Y: - { - SetAnchorPointY( property.Get< float >() ); - break; - } - - case Dali::Actor::Property::ANCHOR_POINT_Z: - { - SetAnchorPointZ( property.Get< float >() ); - break; - } - - case Dali::Actor::Property::SIZE: - { - Property::Type type = property.GetType(); - if( type == Property::VECTOR2 ) - { - SetSize( property.Get< Vector2 >() ); - } - else if ( type == Property::VECTOR3 ) - { - SetSize( property.Get< Vector3 >() ); - } - break; - } - - case Dali::Actor::Property::SIZE_WIDTH: - { - SetWidth( property.Get< float >() ); - break; - } - - case Dali::Actor::Property::SIZE_HEIGHT: - { - SetHeight( property.Get< float >() ); - break; - } - - case Dali::Actor::Property::SIZE_DEPTH: - { - SetDepth( property.Get< float >() ); - break; - } - - case Dali::Actor::Property::POSITION: - { - Property::Type type = property.GetType(); - if( type == Property::VECTOR2 ) - { - Vector2 position = property.Get< Vector2 >(); - SetPosition( Vector3( position.x, position.y, 0.0f ) ); - } - else if ( type == Property::VECTOR3 ) - { - SetPosition( property.Get< Vector3 >() ); - } - break; - } - - case Dali::Actor::Property::POSITION_X: - { - SetX( property.Get< float >() ); - break; - } - - case Dali::Actor::Property::POSITION_Y: - { - SetY( property.Get< float >() ); - break; - } - - case Dali::Actor::Property::POSITION_Z: - { - SetZ( property.Get< float >() ); - break; - } - - case Dali::Actor::Property::ORIENTATION: - { - SetOrientation( property.Get< Quaternion >() ); - break; - } - - case Dali::Actor::Property::SCALE: - { - Property::Type type = property.GetType(); - if( type == Property::FLOAT ) - { - float scale = property.Get< float >(); - SetScale( scale, scale, scale ); - } - else if ( type == Property::VECTOR3 ) - { - SetScale( property.Get< Vector3 >() ); - } - break; - } - - case Dali::Actor::Property::SCALE_X: - { - SetScaleX( property.Get< float >() ); - break; - } - - case Dali::Actor::Property::SCALE_Y: - { - SetScaleY( property.Get< float >() ); - break; - } - - case Dali::Actor::Property::SCALE_Z: - { - SetScaleZ( property.Get< float >() ); - break; - } - - case Dali::Actor::Property::VISIBLE: - { - SetVisible( property.Get< bool >() ); - break; - } - - case Dali::Actor::Property::COLOR: - { - 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; - } - - case Dali::Actor::Property::COLOR_RED: - { - SetColorRed( property.Get< float >() ); - break; - } - - case Dali::Actor::Property::COLOR_GREEN: - { - SetColorGreen( property.Get< float >() ); - break; - } - - case Dali::Actor::Property::COLOR_BLUE: - { - SetColorBlue( property.Get< float >() ); - break; - } - - case Dali::Actor::Property::COLOR_ALPHA: - case Dali::Actor::Property::OPACITY: - { - float value; - if( property.Get( value ) ) - { - SetOpacity( value ); - } - break; - } - - case Dali::Actor::Property::NAME: - { - SetName( property.Get< std::string >() ); - break; - } - - case Dali::Actor::Property::SENSITIVE: - { - SetSensitive( property.Get< bool >() ); - break; - } - - case Dali::Actor::Property::LEAVE_REQUIRED: - { - SetLeaveRequired( property.Get< bool >() ); - break; - } - - case Dali::Actor::Property::INHERIT_POSITION: - { - SetInheritPosition( property.Get< bool >() ); - break; - } - - case Dali::Actor::Property::INHERIT_ORIENTATION: - { - SetInheritOrientation( property.Get< bool >() ); - break; - } - - case Dali::Actor::Property::INHERIT_SCALE: - { - SetInheritScale( property.Get< bool >() ); - break; - } - - case Dali::Actor::Property::COLOR_MODE: - { - ColorMode mode = mColorMode; - if ( Scripting::GetEnumerationProperty< ColorMode >( property, COLOR_MODE_TABLE, COLOR_MODE_TABLE_COUNT, mode ) ) - { - SetColorMode( mode ); - } - break; - } - - case Dali::Actor::Property::DRAW_MODE: - { - DrawMode::Type mode = mDrawMode; - if( Scripting::GetEnumerationProperty< DrawMode::Type >( property, DRAW_MODE_TABLE, DRAW_MODE_TABLE_COUNT, mode ) ) - { - SetDrawMode( mode ); - } - break; - } - - case Dali::Actor::Property::SIZE_MODE_FACTOR: - { - SetSizeModeFactor( property.Get< Vector3 >() ); - break; - } - - case Dali::Actor::Property::WIDTH_RESIZE_POLICY: - { - ResizePolicy::Type type = GetResizePolicy( Dimension::WIDTH ); - if( Scripting::GetEnumerationProperty< ResizePolicy::Type >( property, RESIZE_POLICY_TABLE, RESIZE_POLICY_TABLE_COUNT, type ) ) - { - SetResizePolicy( type, Dimension::WIDTH ); - } - break; - } - - case Dali::Actor::Property::HEIGHT_RESIZE_POLICY: - { - ResizePolicy::Type type = GetResizePolicy( Dimension::HEIGHT ); - if( Scripting::GetEnumerationProperty< ResizePolicy::Type >( property, RESIZE_POLICY_TABLE, RESIZE_POLICY_TABLE_COUNT, type ) ) - { - SetResizePolicy( type, Dimension::HEIGHT ); - } - break; - } - - case Dali::Actor::Property::SIZE_SCALE_POLICY: - { - SizeScalePolicy::Type type = GetSizeScalePolicy(); - if( Scripting::GetEnumerationProperty< SizeScalePolicy::Type >( property, SIZE_SCALE_POLICY_TABLE, SIZE_SCALE_POLICY_TABLE_COUNT, type ) ) - { - SetSizeScalePolicy( type ); - } - break; - } - - case Dali::Actor::Property::WIDTH_FOR_HEIGHT: - { - if( property.Get< bool >() ) - { - SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::WIDTH ); - } - break; - } - - case Dali::Actor::Property::HEIGHT_FOR_WIDTH: - { - if( property.Get< bool >() ) - { - SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT ); - } - break; - } - - case Dali::Actor::Property::PADDING: - { - Vector4 padding = property.Get< Vector4 >(); - SetPadding( Vector2( padding.x, padding.y ), Dimension::WIDTH ); - SetPadding( Vector2( padding.z, padding.w ), Dimension::HEIGHT ); - break; - } - - case Dali::Actor::Property::MINIMUM_SIZE: - { - Vector2 size = property.Get< Vector2 >(); - SetMinimumSize( size.x, Dimension::WIDTH ); - SetMinimumSize( size.y, Dimension::HEIGHT ); - break; - } - - case Dali::Actor::Property::MAXIMUM_SIZE: - { - Vector2 size = property.Get< Vector2 >(); - SetMaximumSize( size.x, Dimension::WIDTH ); - SetMaximumSize( size.y, Dimension::HEIGHT ); - break; - } - - case Dali::DevelActor::Property::SIBLING_ORDER: - { - int value; - - if( property.Get( value ) ) - { - SetSiblingOrder( value ); - } - break; - } - - case Dali::Actor::Property::CLIPPING_MODE: - { - ClippingMode::Type convertedValue = mClippingMode; - if( Scripting::GetEnumerationProperty< ClippingMode::Type >( property, CLIPPING_MODE_TABLE, CLIPPING_MODE_TABLE_COUNT, convertedValue ) ) - { - mClippingMode = convertedValue; - SetClippingModeMessage( GetEventThreadServices(), GetNode(), mClippingMode ); - } - break; - } - - case Dali::Actor::Property::POSITION_USES_ANCHOR_POINT: - { - bool value = false; - if( property.Get( value ) && value != mPositionUsesAnchorPoint ) - { - mPositionUsesAnchorPoint = value; - SetPositionUsesAnchorPointMessage( GetEventThreadServices(), GetNode(), mPositionUsesAnchorPoint ); - } - break; - } - - case Dali::Actor::Property::LAYOUT_DIRECTION: - { - Dali::LayoutDirection::Type direction = mLayoutDirection; - mInheritLayoutDirection = false; - - if( Scripting::GetEnumerationProperty< LayoutDirection::Type >( property, LAYOUT_DIRECTION_TABLE, LAYOUT_DIRECTION_TABLE_COUNT, direction ) ) - { - InheritLayoutDirectionRecursively( this, direction, true ); - } - break; - } - - case Dali::Actor::Property::INHERIT_LAYOUT_DIRECTION: - { - bool value = false; - if( property.Get( value ) ) - { - SetInheritLayoutDirection( value ); - } - break; - } - - case Dali::Actor::Property::KEYBOARD_FOCUSABLE: - { - bool value = false; - if( property.Get( value ) ) - { - SetKeyboardFocusable( value ); - } - break; - } - - default: - { - // this can happen in the case of a non-animatable default property so just do nothing - break; - } - } -} - -// TODO: This method needs to be removed -void Actor::SetSceneGraphProperty( Property::Index index, const PropertyMetadata& entry, const Property::Value& value ) -{ - switch( entry.GetType() ) - { - case Property::BOOLEAN: - { - const AnimatableProperty< bool >* property = dynamic_cast< const AnimatableProperty< bool >* >( entry.GetSceneGraphProperty() ); - DALI_ASSERT_DEBUG( NULL != property ); - - // property is being used in a separate thread; queue a message to set the property - SceneGraph::NodePropertyMessage::Send( GetEventThreadServices(), &GetNode(), property, &AnimatableProperty::Bake, value.Get() ); - - break; - } - - case Property::INTEGER: - { - const AnimatableProperty< int >* property = dynamic_cast< const AnimatableProperty< int >* >( entry.GetSceneGraphProperty() ); - DALI_ASSERT_DEBUG( NULL != property ); - - // property is being used in a separate thread; queue a message to set the property - SceneGraph::NodePropertyMessage::Send( GetEventThreadServices(), &GetNode(), property, &AnimatableProperty::Bake, value.Get() ); - - break; - } - - case Property::FLOAT: - { - const AnimatableProperty< float >* property = dynamic_cast< const AnimatableProperty< float >* >( entry.GetSceneGraphProperty() ); - DALI_ASSERT_DEBUG( NULL != property ); - - // property is being used in a separate thread; queue a message to set the property - SceneGraph::NodePropertyMessage::Send( GetEventThreadServices(), &GetNode(), property, &AnimatableProperty::Bake, value.Get() ); - - break; - } - - case Property::VECTOR2: - { - const AnimatableProperty< Vector2 >* property = dynamic_cast< const AnimatableProperty< Vector2 >* >( entry.GetSceneGraphProperty() ); - DALI_ASSERT_DEBUG( NULL != property ); - - // property is being used in a separate thread; queue a message to set the property - if(entry.componentIndex == 0) - { - SceneGraph::NodePropertyComponentMessage::Send( GetEventThreadServices(), &GetNode(), property, &AnimatableProperty::BakeX, value.Get() ); - } - else if(entry.componentIndex == 1) - { - SceneGraph::NodePropertyComponentMessage::Send( GetEventThreadServices(), &GetNode(), property, &AnimatableProperty::BakeY, value.Get() ); - } - else - { - SceneGraph::NodePropertyMessage::Send( GetEventThreadServices(), &GetNode(), property, &AnimatableProperty::Bake, value.Get() ); - } - - break; - } - - case Property::VECTOR3: - { - const AnimatableProperty< Vector3 >* property = dynamic_cast< const AnimatableProperty< Vector3 >* >( entry.GetSceneGraphProperty() ); - DALI_ASSERT_DEBUG( NULL != property ); - - // property is being used in a separate thread; queue a message to set the property - if(entry.componentIndex == 0) - { - SceneGraph::NodePropertyComponentMessage::Send( GetEventThreadServices(), &GetNode(), property, &AnimatableProperty::BakeX, value.Get() ); - } - else if(entry.componentIndex == 1) - { - SceneGraph::NodePropertyComponentMessage::Send( GetEventThreadServices(), &GetNode(), property, &AnimatableProperty::BakeY, value.Get() ); - } - else if(entry.componentIndex == 2) - { - SceneGraph::NodePropertyComponentMessage::Send( GetEventThreadServices(), &GetNode(), property, &AnimatableProperty::BakeZ, value.Get() ); - } - else - { - SceneGraph::NodePropertyMessage::Send( GetEventThreadServices(), &GetNode(), property, &AnimatableProperty::Bake, value.Get() ); - } - - break; - } - - case Property::VECTOR4: - { - const AnimatableProperty< Vector4 >* property = dynamic_cast< const AnimatableProperty< Vector4 >* >( entry.GetSceneGraphProperty() ); - DALI_ASSERT_DEBUG( NULL != property ); - - // property is being used in a separate thread; queue a message to set the property - if(entry.componentIndex == 0) - { - SceneGraph::NodePropertyComponentMessage::Send( GetEventThreadServices(), &GetNode(), property, &AnimatableProperty::BakeX, value.Get() ); - } - else if(entry.componentIndex == 1) - { - SceneGraph::NodePropertyComponentMessage::Send( GetEventThreadServices(), &GetNode(), property, &AnimatableProperty::BakeY, value.Get() ); - } - else if(entry.componentIndex == 2) - { - SceneGraph::NodePropertyComponentMessage::Send( GetEventThreadServices(), &GetNode(), property, &AnimatableProperty::BakeZ, value.Get() ); - } - else if(entry.componentIndex == 3) - { - SceneGraph::NodePropertyComponentMessage::Send( GetEventThreadServices(), &GetNode(), property, &AnimatableProperty::BakeW, value.Get() ); - } - else - { - SceneGraph::NodePropertyMessage::Send( GetEventThreadServices(), &GetNode(), property, &AnimatableProperty::Bake, value.Get() ); - } - - break; - } - - case Property::ROTATION: - { - const AnimatableProperty< Quaternion >* property = dynamic_cast< const AnimatableProperty< Quaternion >* >( entry.GetSceneGraphProperty() ); - DALI_ASSERT_DEBUG( NULL != property ); - - // property is being used in a separate thread; queue a message to set the property - SceneGraph::NodePropertyMessage::Send( GetEventThreadServices(), &GetNode(), property,&AnimatableProperty::Bake, value.Get() ); - - break; - } - - case Property::MATRIX: - { - const AnimatableProperty< Matrix >* property = dynamic_cast< const AnimatableProperty< Matrix >* >( entry.GetSceneGraphProperty() ); - DALI_ASSERT_DEBUG( NULL != property ); - - // property is being used in a separate thread; queue a message to set the property - SceneGraph::NodePropertyMessage::Send( GetEventThreadServices(), &GetNode(), property,&AnimatableProperty::Bake, value.Get() ); - - break; - } - - case Property::MATRIX3: - { - const AnimatableProperty< Matrix3 >* property = dynamic_cast< const AnimatableProperty< Matrix3 >* >( entry.GetSceneGraphProperty() ); - DALI_ASSERT_DEBUG( NULL != property ); - - // property is being used in a separate thread; queue a message to set the property - SceneGraph::NodePropertyMessage::Send( GetEventThreadServices(), &GetNode(), property,&AnimatableProperty::Bake, value.Get() ); - - break; - } - - default: - { - // nothing to do for other types - } - } // entry.GetType -} - -Property::Value Actor::GetDefaultProperty( Property::Index index ) const -{ - Property::Value value; - - if( ! GetCachedPropertyValue( index, value ) ) - { - // If property value is not stored in the event-side, then it must be a scene-graph only property - GetCurrentPropertyValue( index, value ); - } - - return value; -} - -Property::Value Actor::GetDefaultPropertyCurrentValue( Property::Index index ) const -{ - Property::Value value; - - if( ! GetCurrentPropertyValue( index, value ) ) - { - // If unable to retrieve scene-graph property value, then it must be an event-side only property - GetCachedPropertyValue( index, value ); - } - - return value; -} - -void Actor::OnNotifyDefaultPropertyAnimation( Animation& animation, Property::Index index, const Property::Value& value, Animation::Type animationType ) -{ - switch( animationType ) - { - case Animation::TO: - case Animation::BETWEEN: - { - switch( index ) - { - case Dali::Actor::Property::SIZE: - { - if( value.Get( mTargetSize ) ) - { - mAnimatedSize = mTargetSize; - mUseAnimatedSize = AnimatedSizeFlag::WIDTH | AnimatedSizeFlag::HEIGHT | AnimatedSizeFlag::DEPTH; - - // Notify deriving classes - OnSizeAnimation( animation, mTargetSize ); - } - break; - } - - case Dali::Actor::Property::SIZE_WIDTH: - { - if( value.Get( mTargetSize.width ) ) - { - mAnimatedSize.width = mTargetSize.width; - mUseAnimatedSize |= AnimatedSizeFlag::WIDTH; - - // Notify deriving classes - OnSizeAnimation( animation, mTargetSize ); - } - break; - } - - case Dali::Actor::Property::SIZE_HEIGHT: - { - if( value.Get( mTargetSize.height ) ) - { - mAnimatedSize.height = mTargetSize.height; - mUseAnimatedSize |= AnimatedSizeFlag::HEIGHT; - - // Notify deriving classes - OnSizeAnimation( animation, mTargetSize ); - } - break; - } - - case Dali::Actor::Property::SIZE_DEPTH: - { - if( value.Get( mTargetSize.depth ) ) - { - mAnimatedSize.depth = mTargetSize.depth; - mUseAnimatedSize |= AnimatedSizeFlag::DEPTH; - - // Notify deriving classes - OnSizeAnimation( animation, mTargetSize ); - } - break; - } - - case Dali::Actor::Property::POSITION: - { - value.Get( mTargetPosition ); - break; - } - - case Dali::Actor::Property::POSITION_X: - { - value.Get( mTargetPosition.x ); - break; - } - - case Dali::Actor::Property::POSITION_Y: - { - value.Get( mTargetPosition.y ); - break; - } - - case Dali::Actor::Property::POSITION_Z: - { - value.Get( mTargetPosition.z ); - break; - } - - case Dali::Actor::Property::ORIENTATION: - { - value.Get( mTargetOrientation ); - break; - } - - case Dali::Actor::Property::SCALE: - { - value.Get( mTargetScale ); - break; - } - - case Dali::Actor::Property::SCALE_X: - { - value.Get( mTargetScale.x ); - break; - } - - case Dali::Actor::Property::SCALE_Y: - { - value.Get( mTargetScale.y ); - break; - } - - case Dali::Actor::Property::SCALE_Z: - { - value.Get( mTargetScale.z ); - break; - } - - case Dali::Actor::Property::VISIBLE: - { - SetVisibleInternal( value.Get< bool >(), SendMessage::FALSE ); - break; - } - - case Dali::Actor::Property::COLOR: - { - value.Get( mTargetColor ); - break; - } - - case Dali::Actor::Property::COLOR_RED: - { - value.Get( mTargetColor.r ); - break; - } - - case Dali::Actor::Property::COLOR_GREEN: - { - value.Get( mTargetColor.g ); - break; - } - - case Dali::Actor::Property::COLOR_BLUE: - { - value.Get( mTargetColor.b ); - break; - } - - case Dali::Actor::Property::COLOR_ALPHA: - case Dali::Actor::Property::OPACITY: - { - value.Get( mTargetColor.a ); - break; - } - - default: - { - // Not an animatable property. Do nothing. - break; - } - } - break; - } - - case Animation::BY: - { - switch( index ) - { - case Dali::Actor::Property::SIZE: - { - if( AdjustValue< Vector3 >( mTargetSize, value ) ) - { - mAnimatedSize = mTargetSize; - mUseAnimatedSize = AnimatedSizeFlag::WIDTH | AnimatedSizeFlag::HEIGHT | AnimatedSizeFlag::DEPTH; - - // Notify deriving classes - OnSizeAnimation( animation, mTargetSize ); - } - break; - } - - case Dali::Actor::Property::SIZE_WIDTH: - { - if( AdjustValue< float >( mTargetSize.width, value ) ) - { - mAnimatedSize.width = mTargetSize.width; - mUseAnimatedSize |= AnimatedSizeFlag::WIDTH; - - // Notify deriving classes - OnSizeAnimation( animation, mTargetSize ); - } - break; - } - - case Dali::Actor::Property::SIZE_HEIGHT: - { - if( AdjustValue< float >( mTargetSize.height, value ) ) - { - mAnimatedSize.height = mTargetSize.height; - mUseAnimatedSize |= AnimatedSizeFlag::HEIGHT; - - // Notify deriving classes - OnSizeAnimation( animation, mTargetSize ); - } - break; - } - - case Dali::Actor::Property::SIZE_DEPTH: - { - if( AdjustValue< float >( mTargetSize.depth, value ) ) - { - mAnimatedSize.depth = mTargetSize.depth; - mUseAnimatedSize |= AnimatedSizeFlag::DEPTH; - - // Notify deriving classes - OnSizeAnimation( animation, mTargetSize ); - } - break; - } - - case Dali::Actor::Property::POSITION: - { - AdjustValue< Vector3 >( mTargetPosition, value ); - break; - } - - case Dali::Actor::Property::POSITION_X: - { - AdjustValue< float >( mTargetPosition.x, value ); - break; - } - - case Dali::Actor::Property::POSITION_Y: - { - AdjustValue< float >( mTargetPosition.y, value ); - break; - } - - case Dali::Actor::Property::POSITION_Z: - { - AdjustValue< float >( mTargetPosition.z, value ); - break; - } - - case Dali::Actor::Property::ORIENTATION: - { - Quaternion relativeValue; - if( value.Get( relativeValue ) ) - { - mTargetOrientation *= relativeValue; - } - break; - } - - case Dali::Actor::Property::SCALE: - { - AdjustValue< Vector3 >( mTargetScale, value ); - break; - } - - case Dali::Actor::Property::SCALE_X: - { - AdjustValue< float >( mTargetScale.x, value ); - break; - } - - case Dali::Actor::Property::SCALE_Y: - { - AdjustValue< float >( mTargetScale.y, value ); - break; - } - - case Dali::Actor::Property::SCALE_Z: - { - AdjustValue< float >( mTargetScale.z, value ); - break; - } - - case Dali::Actor::Property::VISIBLE: - { - bool relativeValue = false; - if( value.Get( relativeValue ) ) - { - bool visible = mVisible || relativeValue; - SetVisibleInternal( visible, SendMessage::FALSE ); - } - break; - } - - case Dali::Actor::Property::COLOR: - { - AdjustValue< Vector4 >( mTargetColor, value ); - break; - } - - case Dali::Actor::Property::COLOR_RED: - { - AdjustValue< float >( mTargetColor.r, value ); - break; - } - - case Dali::Actor::Property::COLOR_GREEN: - { - AdjustValue< float >( mTargetColor.g, value ); - break; - } - - case Dali::Actor::Property::COLOR_BLUE: - { - AdjustValue< float >( mTargetColor.b, value ); - break; - } - - case Dali::Actor::Property::COLOR_ALPHA: - case Dali::Actor::Property::OPACITY: - { - AdjustValue< float >( mTargetColor.a, value ); - break; - } - - default: - { - // Not an animatable property. Do nothing. - break; - } - } - break; - } - } -} - -const PropertyBase* Actor::GetSceneObjectAnimatableProperty( Property::Index index ) const -{ - const PropertyBase* property( NULL ); - - switch( index ) - { - case Dali::Actor::Property::SIZE: // FALLTHROUGH - case Dali::Actor::Property::SIZE_WIDTH: // FALLTHROUGH - case Dali::Actor::Property::SIZE_HEIGHT: // FALLTHROUGH - case Dali::Actor::Property::SIZE_DEPTH: - { - property = &GetNode().mSize; - break; - } - case Dali::Actor::Property::POSITION: // FALLTHROUGH - case Dali::Actor::Property::POSITION_X: // FALLTHROUGH - case Dali::Actor::Property::POSITION_Y: // FALLTHROUGH - case Dali::Actor::Property::POSITION_Z: - { - property = &GetNode().mPosition; - break; - } - case Dali::Actor::Property::ORIENTATION: - { - property = &GetNode().mOrientation; - break; - } - case Dali::Actor::Property::SCALE: // FALLTHROUGH - case Dali::Actor::Property::SCALE_X: // FALLTHROUGH - case Dali::Actor::Property::SCALE_Y: // FALLTHROUGH - case Dali::Actor::Property::SCALE_Z: - { - property = &GetNode().mScale; - break; - } - case Dali::Actor::Property::VISIBLE: - { - property = &GetNode().mVisible; - break; - } - case Dali::Actor::Property::COLOR: // FALLTHROUGH - case Dali::Actor::Property::COLOR_RED: // FALLTHROUGH - case Dali::Actor::Property::COLOR_GREEN: // FALLTHROUGH - case Dali::Actor::Property::COLOR_BLUE: // FALLTHROUGH - case Dali::Actor::Property::COLOR_ALPHA: // FALLTHROUGH - case Dali::Actor::Property::OPACITY: - { - property = &GetNode().mColor; - break; - } - default: - { - break; - } - } - if( !property ) - { - // not our property, ask base - property = Object::GetSceneObjectAnimatableProperty( index ); - } - - return property; -} - -const PropertyInputImpl* Actor::GetSceneObjectInputProperty( Property::Index index ) const -{ - const PropertyInputImpl* property( NULL ); - - switch( index ) - { - case Dali::Actor::Property::PARENT_ORIGIN: // FALLTHROUGH - case Dali::Actor::Property::PARENT_ORIGIN_X: // FALLTHROUGH - case Dali::Actor::Property::PARENT_ORIGIN_Y: // FALLTHROUGH - case Dali::Actor::Property::PARENT_ORIGIN_Z: - { - property = &GetNode().mParentOrigin; - break; - } - case Dali::Actor::Property::ANCHOR_POINT: // FALLTHROUGH - case Dali::Actor::Property::ANCHOR_POINT_X: // FALLTHROUGH - case Dali::Actor::Property::ANCHOR_POINT_Y: // FALLTHROUGH - case Dali::Actor::Property::ANCHOR_POINT_Z: - { - property = &GetNode().mAnchorPoint; - break; - } - case Dali::Actor::Property::WORLD_POSITION: // FALLTHROUGH - case Dali::Actor::Property::WORLD_POSITION_X: // FALLTHROUGH - case Dali::Actor::Property::WORLD_POSITION_Y: // FALLTHROUGH - case Dali::Actor::Property::WORLD_POSITION_Z: - { - property = &GetNode().mWorldPosition; - break; - } - case Dali::Actor::Property::WORLD_ORIENTATION: - { - property = &GetNode().mWorldOrientation; - break; - } - case Dali::Actor::Property::WORLD_SCALE: - { - property = &GetNode().mWorldScale; - break; - } - case Dali::Actor::Property::WORLD_COLOR: - { - property = &GetNode().mWorldColor; - break; - } - case Dali::Actor::Property::WORLD_MATRIX: - { - property = &GetNode().mWorldMatrix; - break; - } - case Dali::Actor::Property::CULLED: - { - property = &GetNode().mCulled; - break; - } - default: - { - break; - } - } - if( !property ) - { - // reuse animatable property getter as animatable properties are inputs as well - // animatable property chains back to Object::GetSceneObjectInputProperty() so all properties get covered - property = GetSceneObjectAnimatableProperty( index ); - } - - return property; -} - -int32_t Actor::GetPropertyComponentIndex( Property::Index index ) const -{ - int32_t componentIndex = Property::INVALID_COMPONENT_INDEX; - - switch( index ) - { - case Dali::Actor::Property::PARENT_ORIGIN_X: - case Dali::Actor::Property::ANCHOR_POINT_X: - case Dali::Actor::Property::SIZE_WIDTH: - case Dali::Actor::Property::POSITION_X: - case Dali::Actor::Property::WORLD_POSITION_X: - case Dali::Actor::Property::SCALE_X: - case Dali::Actor::Property::COLOR_RED: - { - componentIndex = 0; - break; - } - - case Dali::Actor::Property::PARENT_ORIGIN_Y: - case Dali::Actor::Property::ANCHOR_POINT_Y: - case Dali::Actor::Property::SIZE_HEIGHT: - case Dali::Actor::Property::POSITION_Y: - case Dali::Actor::Property::WORLD_POSITION_Y: - case Dali::Actor::Property::SCALE_Y: - case Dali::Actor::Property::COLOR_GREEN: - { - componentIndex = 1; - break; - } - - case Dali::Actor::Property::PARENT_ORIGIN_Z: - case Dali::Actor::Property::ANCHOR_POINT_Z: - case Dali::Actor::Property::SIZE_DEPTH: - case Dali::Actor::Property::POSITION_Z: - case Dali::Actor::Property::WORLD_POSITION_Z: - case Dali::Actor::Property::SCALE_Z: - case Dali::Actor::Property::COLOR_BLUE: - { - componentIndex = 2; - break; - } - - case Dali::Actor::Property::COLOR_ALPHA: - case Dali::Actor::Property::OPACITY: - { - componentIndex = 3; - break; - } - - default: - { - // Do nothing - break; - } - } - if( Property::INVALID_COMPONENT_INDEX == componentIndex ) - { - // ask base - componentIndex = Object::GetPropertyComponentIndex( index ); - } - - return componentIndex; -} - -void Actor::SetParent( Actor* parent ) -{ - if( parent ) - { - DALI_ASSERT_ALWAYS( !mParent && "Actor cannot have 2 parents" ); - - mParent = parent; - - mScene = parent->mScene; - - if ( EventThreadServices::IsCoreRunning() && // Don't emit signals or send messages during Core destruction - parent->OnStage() ) - { - // Instruct each actor to create a corresponding node in the scene graph - ConnectToStage( parent->GetHierarchyDepth() ); - } - - // Resolve the name and index for the child properties if any - ResolveChildProperties(); - } - else // parent being set to NULL - { - DALI_ASSERT_ALWAYS( mParent != NULL && "Actor should have a parent" ); - - mParent = NULL; - - if ( EventThreadServices::IsCoreRunning() && // Don't emit signals or send messages during Core destruction - OnStage() ) - { - // Disconnect the Node & its children from the scene-graph. - DisconnectNodeMessage( GetEventThreadServices().GetUpdateManager(), GetNode() ); - - // Instruct each actor to discard pointers to the scene-graph - DisconnectFromStage(); - } - - mScene = nullptr; - } -} - -bool Actor::DoAction( BaseObject* object, const std::string& actionName, const Property::Map& /* attributes */ ) -{ - bool done = false; - Actor* actor = dynamic_cast< Actor* >( object ); - - if( actor ) - { - if( 0 == actionName.compare( ACTION_SHOW ) ) - { - actor->SetVisible( true ); - done = true; - } - else if( 0 == actionName.compare( ACTION_HIDE ) ) - { - actor->SetVisible( false ); - done = true; - } - } - - 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; - - switch( index ) - { - case Dali::Actor::Property::PARENT_ORIGIN: - { - value = GetCurrentParentOrigin(); - break; - } - - case Dali::Actor::Property::PARENT_ORIGIN_X: - { - value = GetCurrentParentOrigin().x; - break; - } - - case Dali::Actor::Property::PARENT_ORIGIN_Y: - { - value = GetCurrentParentOrigin().y; - break; - } - - case Dali::Actor::Property::PARENT_ORIGIN_Z: - { - value = GetCurrentParentOrigin().z; - break; - } - - case Dali::Actor::Property::ANCHOR_POINT: - { - value = GetCurrentAnchorPoint(); - break; - } - - case Dali::Actor::Property::ANCHOR_POINT_X: - { - value = GetCurrentAnchorPoint().x; - break; - } - - case Dali::Actor::Property::ANCHOR_POINT_Y: - { - value = GetCurrentAnchorPoint().y; - break; - } - - case Dali::Actor::Property::ANCHOR_POINT_Z: - { - value = GetCurrentAnchorPoint().z; - break; - } - - case Dali::Actor::Property::SIZE: - { - value = GetTargetSize(); - break; - } - - case Dali::Actor::Property::SIZE_WIDTH: - { - value = GetTargetSize().width; - break; - } - - case Dali::Actor::Property::SIZE_HEIGHT: - { - value = GetTargetSize().height; - break; - } - - case Dali::Actor::Property::SIZE_DEPTH: - { - value = GetTargetSize().depth; - break; - } - - case Dali::Actor::Property::POSITION: - { - value = GetTargetPosition(); - break; - } - - case Dali::Actor::Property::POSITION_X: - { - value = GetTargetPosition().x; - break; - } - - case Dali::Actor::Property::POSITION_Y: - { - value = GetTargetPosition().y; - break; - } - - case Dali::Actor::Property::POSITION_Z: - { - value = GetTargetPosition().z; - break; - } - - case Dali::Actor::Property::ORIENTATION: - { - value = mTargetOrientation; - break; - } - - case Dali::Actor::Property::SCALE: - { - value = mTargetScale; - break; - } - - case Dali::Actor::Property::SCALE_X: - { - value = mTargetScale.x; - break; - } - - case Dali::Actor::Property::SCALE_Y: - { - value = mTargetScale.y; - break; - } - - case Dali::Actor::Property::SCALE_Z: - { - value = mTargetScale.z; - break; - } - - case Dali::Actor::Property::VISIBLE: - { - value = mVisible; - break; - } - - case Dali::Actor::Property::COLOR: - { - value = mTargetColor; - break; - } - - case Dali::Actor::Property::COLOR_RED: - { - value = mTargetColor.r; - break; - } - - case Dali::Actor::Property::COLOR_GREEN: - { - value = mTargetColor.g; - break; - } - - case Dali::Actor::Property::COLOR_BLUE: - { - value = mTargetColor.b; - break; - } - - case Dali::Actor::Property::COLOR_ALPHA: - case Dali::Actor::Property::OPACITY: - { - value = mTargetColor.a; - break; - } - - case Dali::Actor::Property::NAME: - { - value = GetName(); - break; - } - - case Dali::Actor::Property::SENSITIVE: - { - value = IsSensitive(); - break; - } - - case Dali::Actor::Property::LEAVE_REQUIRED: - { - value = GetLeaveRequired(); - break; - } - - case Dali::Actor::Property::INHERIT_POSITION: - { - value = IsPositionInherited(); - break; - } - - case Dali::Actor::Property::INHERIT_ORIENTATION: - { - value = IsOrientationInherited(); - break; - } - - case Dali::Actor::Property::INHERIT_SCALE: - { - value = IsScaleInherited(); - break; - } - - case Dali::Actor::Property::COLOR_MODE: - { - value = GetColorMode(); - break; - } - - case Dali::Actor::Property::DRAW_MODE: - { - value = GetDrawMode(); - break; - } - - case Dali::Actor::Property::SIZE_MODE_FACTOR: - { - value = GetSizeModeFactor(); - break; - } - - case Dali::Actor::Property::WIDTH_RESIZE_POLICY: - { - value = Scripting::GetLinearEnumerationName< ResizePolicy::Type >( GetResizePolicy( Dimension::WIDTH ), RESIZE_POLICY_TABLE, RESIZE_POLICY_TABLE_COUNT ); - break; - } - - case Dali::Actor::Property::HEIGHT_RESIZE_POLICY: - { - value = Scripting::GetLinearEnumerationName< ResizePolicy::Type >( GetResizePolicy( Dimension::HEIGHT ), RESIZE_POLICY_TABLE, RESIZE_POLICY_TABLE_COUNT ); - break; - } - - case Dali::Actor::Property::SIZE_SCALE_POLICY: - { - value = GetSizeScalePolicy(); - break; - } - - case Dali::Actor::Property::WIDTH_FOR_HEIGHT: - { - value = ( GetResizePolicy( Dimension::WIDTH ) == ResizePolicy::DIMENSION_DEPENDENCY ) && ( GetDimensionDependency( Dimension::WIDTH ) == Dimension::HEIGHT ); - break; - } - - case Dali::Actor::Property::HEIGHT_FOR_WIDTH: - { - value = ( GetResizePolicy( Dimension::HEIGHT ) == ResizePolicy::DIMENSION_DEPENDENCY ) && ( GetDimensionDependency( Dimension::HEIGHT ) == Dimension::WIDTH ); - break; - } - - case Dali::Actor::Property::PADDING: - { - Vector2 widthPadding = GetPadding( Dimension::WIDTH ); - Vector2 heightPadding = GetPadding( Dimension::HEIGHT ); - value = Vector4( widthPadding.x, widthPadding.y, heightPadding.x, heightPadding.y ); - break; - } - - case Dali::Actor::Property::MINIMUM_SIZE: - { - value = Vector2( GetMinimumSize( Dimension::WIDTH ), GetMinimumSize( Dimension::HEIGHT ) ); - break; - } - - case Dali::Actor::Property::MAXIMUM_SIZE: - { - value = Vector2( GetMaximumSize( Dimension::WIDTH ), GetMaximumSize( Dimension::HEIGHT ) ); - break; - } - - case Dali::Actor::Property::CLIPPING_MODE: - { - value = mClippingMode; - break; - } - - case Dali::DevelActor::Property::SIBLING_ORDER: - { - value = static_cast( GetSiblingOrder() ); - break; - } - - case Dali::Actor::Property::SCREEN_POSITION: - { - value = GetCurrentScreenPosition(); - break; - } - - case Dali::Actor::Property::POSITION_USES_ANCHOR_POINT: - { - value = mPositionUsesAnchorPoint; - break; - } - - case Dali::Actor::Property::LAYOUT_DIRECTION: - { - value = mLayoutDirection; - break; - } - - case Dali::Actor::Property::INHERIT_LAYOUT_DIRECTION: - { - value = IsLayoutDirectionInherited(); - break; - } - - case Dali::Actor::Property::ID: - { - value = static_cast( GetId() ); - break; - } - - case Dali::Actor::Property::HIERARCHY_DEPTH: - { - value = GetHierarchyDepth(); - break; - } - - case Dali::Actor::Property::IS_ROOT: - { - value = IsRoot(); - break; - } - - case Dali::Actor::Property::IS_LAYER: - { - value = IsLayer(); - break; - } - - case Dali::Actor::Property::CONNECTED_TO_SCENE: - { - value = OnStage(); - break; - } - - case Dali::Actor::Property::KEYBOARD_FOCUSABLE: - { - value = IsKeyboardFocusable(); - break; - } +Property::Value Actor::GetDefaultPropertyCurrentValue( Property::Index index ) const +{ + Property::Value value; - default: - { - // Must be a scene-graph only property - valueSet = false; - break; - } + if( ! GetCurrentPropertyValue( index, value ) ) + { + // If unable to retrieve scene-graph property value, then it must be an event-side only property + GetCachedPropertyValue( index, value ); } - return valueSet; + return value; } -bool Actor::GetCurrentPropertyValue( Property::Index index, Property::Value& value ) const +void Actor::OnNotifyDefaultPropertyAnimation( Animation& animation, Property::Index index, const Property::Value& value, Animation::Type animationType ) { - bool valueSet = true; + PropertyHandler::OnNotifyDefaultPropertyAnimation(*this, animation, index, value, animationType); +} - switch( index ) +const PropertyBase* Actor::GetSceneObjectAnimatableProperty( Property::Index index ) const +{ + const PropertyBase* property = PropertyHandler::GetSceneObjectAnimatableProperty(index, GetNode()); + if( !property ) { - case Dali::Actor::Property::SIZE: - { - value = GetCurrentSize(); - break; - } - - case Dali::Actor::Property::SIZE_WIDTH: - { - value = GetCurrentSize().width; - break; - } - - case Dali::Actor::Property::SIZE_HEIGHT: - { - value = GetCurrentSize().height; - break; - } - - case Dali::Actor::Property::SIZE_DEPTH: - { - value = GetCurrentSize().depth; - break; - } - - case Dali::Actor::Property::POSITION: - { - value = GetCurrentPosition(); - break; - } - - case Dali::Actor::Property::POSITION_X: - { - value = GetCurrentPosition().x; - break; - } - - case Dali::Actor::Property::POSITION_Y: - { - value = GetCurrentPosition().y; - break; - } - - case Dali::Actor::Property::POSITION_Z: - { - value = GetCurrentPosition().z; - break; - } - - case Dali::Actor::Property::WORLD_POSITION: - { - value = GetCurrentWorldPosition(); - break; - } + // not our property, ask base + property = Object::GetSceneObjectAnimatableProperty( index ); + } - case Dali::Actor::Property::WORLD_POSITION_X: - { - value = GetCurrentWorldPosition().x; - break; - } + return property; +} - case Dali::Actor::Property::WORLD_POSITION_Y: - { - value = GetCurrentWorldPosition().y; - break; - } +const PropertyInputImpl* Actor::GetSceneObjectInputProperty( Property::Index index ) const +{ + const PropertyInputImpl* property = PropertyHandler::GetSceneObjectInputProperty(index, GetNode()); + if( !property ) + { + // reuse animatable property getter as animatable properties are inputs as well + // animatable property chains back to Object::GetSceneObjectInputProperty() so all properties get covered + property = GetSceneObjectAnimatableProperty( index ); + } - case Dali::Actor::Property::WORLD_POSITION_Z: - { - value = GetCurrentWorldPosition().z; - break; - } + return property; +} - case Dali::Actor::Property::ORIENTATION: - { - value = GetCurrentOrientation(); - break; - } +int32_t Actor::GetPropertyComponentIndex( Property::Index index ) const +{ + int32_t componentIndex = PropertyHandler::GetPropertyComponentIndex(index); + if( Property::INVALID_COMPONENT_INDEX == componentIndex ) + { + // ask base + componentIndex = Object::GetPropertyComponentIndex( index ); + } - case Dali::Actor::Property::WORLD_ORIENTATION: - { - value = GetCurrentWorldOrientation(); - break; - } + return componentIndex; +} - case Dali::Actor::Property::SCALE: - { - value = GetCurrentScale(); - break; - } +void Actor::SetParent( Actor* parent ) +{ + if( parent ) + { + DALI_ASSERT_ALWAYS( !mParent && "Actor cannot have 2 parents" ); - case Dali::Actor::Property::SCALE_X: - { - value = GetCurrentScale().x; - break; - } + mParent = parent; - case Dali::Actor::Property::SCALE_Y: - { - value = GetCurrentScale().y; - break; - } + mScene = parent->mScene; - case Dali::Actor::Property::SCALE_Z: + if ( EventThreadServices::IsCoreRunning() && // Don't emit signals or send messages during Core destruction + parent->OnScene() ) { - value = GetCurrentScale().z; - break; + // Instruct each actor to create a corresponding node in the scene graph + ConnectToScene( parent->GetHierarchyDepth() ); } - case Dali::Actor::Property::WORLD_SCALE: - { - value = GetCurrentWorldScale(); - break; - } + // Resolve the name and index for the child properties if any + ResolveChildProperties(); + } + else // parent being set to NULL + { + DALI_ASSERT_ALWAYS( mParent != nullptr && "Actor should have a parent" ); - case Dali::Actor::Property::COLOR: - { - value = GetCurrentColor(); - break; - } + mParent = nullptr; - case Dali::Actor::Property::COLOR_RED: + if ( EventThreadServices::IsCoreRunning() && // Don't emit signals or send messages during Core destruction + OnScene() ) { - value = GetCurrentColor().r; - break; - } + // Disconnect the Node & its children from the scene-graph. + DisconnectNodeMessage( GetEventThreadServices().GetUpdateManager(), GetNode() ); - case Dali::Actor::Property::COLOR_GREEN: - { - value = GetCurrentColor().g; - break; + // Instruct each actor to discard pointers to the scene-graph + DisconnectFromStage(); } - case Dali::Actor::Property::COLOR_BLUE: - { - value = GetCurrentColor().b; - break; - } + mScene = nullptr; + } +} - case Dali::Actor::Property::COLOR_ALPHA: - case Dali::Actor::Property::OPACITY: - { - value = GetCurrentColor().a; - break; - } +bool Actor::DoAction( BaseObject* object, const std::string& actionName, const Property::Map& /* attributes */ ) +{ + bool done = false; + Actor* actor = dynamic_cast< Actor* >( object ); - case Dali::Actor::Property::WORLD_COLOR: + if( actor ) + { + if( 0 == actionName.compare( ACTION_SHOW ) ) { - value = GetCurrentWorldColor(); - break; + actor->SetVisible( true ); + done = true; } - - case Dali::Actor::Property::WORLD_MATRIX: + else if( 0 == actionName.compare( ACTION_HIDE ) ) { - value = GetCurrentWorldMatrix(); - break; + actor->SetVisible( false ); + done = true; } + } - case Dali::Actor::Property::VISIBLE: - { - value = IsVisible(); - break; - } + return done; +} - case Dali::Actor::Property::CULLED: - { - value = GetNode().IsCulled( GetEventThreadServices().GetEventBufferIndex() ); - break; - } +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 }; +} - default: - { - // Must be an event-side only property - valueSet = false; - break; - } - } +bool Actor::GetCachedPropertyValue( Property::Index index, Property::Value& value ) const +{ + return PropertyHandler::GetCachedPropertyValue(*this, index, value); +} - return valueSet; +bool Actor::GetCurrentPropertyValue( Property::Index index, Property::Value& value ) const +{ + return PropertyHandler::GetCurrentPropertyValue(*this, index, value); } -void Actor::EnsureRelayoutData() +Actor::Relayouter& Actor::EnsureRelayouter() { - // Assign relayout data. + // Assign relayouter if( !mRelayoutData ) { - mRelayoutData = new RelayoutData(); + mRelayoutData = new Relayouter(); } + + return *mRelayoutData; } bool Actor::RelayoutDependentOnParent( Dimension::Type dimension ) @@ -4229,15 +1996,7 @@ float Actor::GetNegotiatedDimension( Dimension::Type dimension ) const void Actor::SetPadding( const Vector2& padding, Dimension::Type dimension ) { - EnsureRelayoutData(); - - for( uint32_t i = 0; i < Dimension::DIMENSION_COUNT; ++i ) - { - if( dimension & ( 1 << i ) ) - { - mRelayoutData->dimensionPadding[ i ] = padding; - } - } + EnsureRelayouter().SetPadding( padding, dimension ); } Vector2 Actor::GetPadding( Dimension::Type dimension ) const @@ -4254,36 +2013,17 @@ Vector2 Actor::GetPadding( Dimension::Type dimension ) const } } - return GetDefaultDimensionPadding(); + return Relayouter::DEFAULT_DIMENSION_PADDING; } void Actor::SetLayoutNegotiated( bool negotiated, Dimension::Type dimension ) { - EnsureRelayoutData(); - - for( uint32_t i = 0; i < Dimension::DIMENSION_COUNT; ++i ) - { - if( dimension & ( 1 << i ) ) - { - mRelayoutData->dimensionNegotiated[ i ] = negotiated; - } - } + EnsureRelayouter().SetLayoutNegotiated(negotiated, dimension); } bool Actor::IsLayoutNegotiated( Dimension::Type dimension ) const { - if ( mRelayoutData ) - { - for( uint32_t i = 0; i < Dimension::DIMENSION_COUNT; ++i ) - { - if( ( dimension & ( 1 << i ) ) && mRelayoutData->dimensionNegotiated[ i ] ) - { - return true; - } - } - } - - return false; + return mRelayoutData && mRelayoutData->IsLayoutNegotiated(dimension); } float Actor::GetHeightForWidthBase( float width ) @@ -4478,14 +2218,6 @@ float Actor::CalculateSize( Dimension::Type dimension, const Vector2& maximumSiz return 0.0f; // Default } -float Actor::ClampDimension( float size, Dimension::Type dimension ) -{ - const float minSize = GetMinimumSize( dimension ); - const float maxSize = GetMaximumSize( dimension ); - - return std::max( minSize, std::min( size, maxSize ) ); -} - void Actor::NegotiateDimension( Dimension::Type dimension, const Vector2& allocatedSize, ActorDimensionStack& recursionStack ) { // Check if it needs to be negotiated @@ -4494,9 +2226,9 @@ void Actor::NegotiateDimension( Dimension::Type dimension, const Vector2& alloca // Check that we havn't gotten into an infinite loop ActorDimensionPair searchActor = ActorDimensionPair( this, dimension ); bool recursionFound = false; - for( ActorDimensionStack::iterator it = recursionStack.begin(), itEnd = recursionStack.end(); it != itEnd; ++it ) + for( auto& element : recursionStack ) { - if( *it == searchActor ) + if( element == searchActor ) { recursionFound = true; break; @@ -4545,7 +2277,7 @@ void Actor::NegotiateDimension( Dimension::Type dimension, const Vector2& alloca OnCalculateRelayoutSize( dimension ); // All dependencies checked, calculate the size and set negotiated flag - const float newSize = ClampDimension( CalculateSize( dimension, allocatedSize ), dimension ); + const float newSize = Relayouter::ClampDimension( *this, CalculateSize( dimension, allocatedSize ), dimension ); SetNegotiatedDimension( newSize, dimension ); SetLayoutNegotiated( true, dimension ); @@ -4580,71 +2312,7 @@ void Actor::NegotiateDimensions( const Vector2& allocatedSize ) Vector2 Actor::ApplySizeSetPolicy( const Vector2& size ) { - switch( mRelayoutData->sizeSetPolicy ) - { - case SizeScalePolicy::USE_SIZE_SET: - { - return size; - } - - case SizeScalePolicy::FIT_WITH_ASPECT_RATIO: - { - // Scale size to fit within the original size bounds, keeping the natural size aspect ratio - const Vector3 naturalSize = GetNaturalSize(); - if( naturalSize.width > 0.0f && naturalSize.height > 0.0f && size.width > 0.0f && size.height > 0.0f ) - { - const float sizeRatio = size.width / size.height; - const float naturalSizeRatio = naturalSize.width / naturalSize.height; - - if( naturalSizeRatio < sizeRatio ) - { - return Vector2( naturalSizeRatio * size.height, size.height ); - } - else if( naturalSizeRatio > sizeRatio ) - { - return Vector2( size.width, size.width / naturalSizeRatio ); - } - else - { - return size; - } - } - - break; - } - - case SizeScalePolicy::FILL_WITH_ASPECT_RATIO: - { - // Scale size to fill the original size bounds, keeping the natural size aspect ratio. Potentially exceeding the original bounds. - const Vector3 naturalSize = GetNaturalSize(); - if( naturalSize.width > 0.0f && naturalSize.height > 0.0f && size.width > 0.0f && size.height > 0.0f ) - { - const float sizeRatio = size.width / size.height; - const float naturalSizeRatio = naturalSize.width / naturalSize.height; - - if( naturalSizeRatio < sizeRatio ) - { - return Vector2( size.width, size.width / naturalSizeRatio ); - } - else if( naturalSizeRatio > sizeRatio ) - { - return Vector2( naturalSizeRatio * size.height, size.height ); - } - else - { - return size; - } - } - break; - } - - default: - { - break; - } - } - - return size; + return mRelayoutData->ApplySizeSetPolicy(*this, size); } void Actor::SetNegotiatedSize( RelayoutContainer& container ) @@ -4731,31 +2399,13 @@ void Actor::SetUseAssignedSize( bool use, Dimension::Type dimension ) { if( mRelayoutData ) { - for( uint32_t i = 0; i < Dimension::DIMENSION_COUNT; ++i ) - { - if( dimension & ( 1 << i ) ) - { - mRelayoutData->useAssignedSize[ i ] = use; - } - } + mRelayoutData->SetUseAssignedSize(use, dimension); } } bool Actor::GetUseAssignedSize( Dimension::Type dimension ) const { - if ( mRelayoutData ) - { - // If more than one dimension is requested, just return the first one found - for( uint32_t i = 0; i < Dimension::DIMENSION_COUNT; ++i ) - { - if( dimension & ( 1 << i ) ) - { - return mRelayoutData->useAssignedSize[ i ]; - } - } - } - - return false; + return mRelayoutData && mRelayoutData->GetUseAssignedSize(dimension); } void Actor::RelayoutRequest( Dimension::Type dimension ) @@ -4768,17 +2418,9 @@ void Actor::RelayoutRequest( Dimension::Type dimension ) } } -void Actor::OnCalculateRelayoutSize( Dimension::Type dimension ) -{ -} - -void Actor::OnLayoutNegotiated( float size, Dimension::Type dimension ) -{ -} - void Actor::SetPreferredSize( const Vector2& size ) { - EnsureRelayoutData(); + EnsureRelayouter(); // 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, @@ -4808,21 +2450,12 @@ Vector2 Actor::GetPreferredSize() const return Vector2( mRelayoutData->preferredSize ); } - return GetDefaultPreferredSize(); + return Relayouter::DEFAULT_PREFERRED_SIZE; } void Actor::SetMinimumSize( float size, Dimension::Type dimension ) { - EnsureRelayoutData(); - - for( uint32_t i = 0; i < Dimension::DIMENSION_COUNT; ++i ) - { - if( dimension & ( 1 << i ) ) - { - mRelayoutData->minimumSize[ i ] = size; - } - } - + EnsureRelayouter().SetMinimumSize(size, dimension); RelayoutRequest(); } @@ -4830,13 +2463,7 @@ float Actor::GetMinimumSize( Dimension::Type dimension ) const { if ( mRelayoutData ) { - for( uint32_t i = 0; i < Dimension::DIMENSION_COUNT; ++i ) - { - if( dimension & ( 1 << i ) ) - { - return mRelayoutData->minimumSize[ i ]; - } - } + return mRelayoutData->GetMinimumSize(dimension); } return 0.0f; // Default @@ -4844,16 +2471,7 @@ float Actor::GetMinimumSize( Dimension::Type dimension ) const void Actor::SetMaximumSize( float size, Dimension::Type dimension ) { - EnsureRelayoutData(); - - for( uint32_t i = 0; i < Dimension::DIMENSION_COUNT; ++i ) - { - if( dimension & ( 1 << i ) ) - { - mRelayoutData->maximumSize[ i ] = size; - } - } - + EnsureRelayouter().SetMaximumSize(size, dimension); RelayoutRequest(); } @@ -4861,23 +2479,12 @@ float Actor::GetMaximumSize( Dimension::Type dimension ) const { if ( mRelayoutData ) { - for( uint32_t i = 0; i < Dimension::DIMENSION_COUNT; ++i ) - { - if( dimension & ( 1 << i ) ) - { - return mRelayoutData->maximumSize[ i ]; - } - } + return mRelayoutData->GetMaximumSize(dimension); } return FLT_MAX; // Default } -Object* Actor::GetParentObject() const -{ - return mParent; -} - void Actor::SetVisibleInternal( bool visible, SendMessage::Type sendMessage ) { if( mVisible != visible ) @@ -4949,7 +2556,7 @@ uint32_t Actor::GetSiblingOrder() const void Actor::RequestRebuildDepthTree() { - if( mIsOnStage ) + if( mIsOnScene ) { if( mScene ) { @@ -5027,7 +2634,7 @@ void Actor::RaiseToTop() ActorContainer& siblings = *(mParent->mChildren); if( siblings.back() != this ) // If not already at end { - ActorContainer::iterator iter = std::find( siblings.begin(), siblings.end(), this ); + auto iter = std::find( siblings.begin(), siblings.end(), this ); if( iter != siblings.end() ) { siblings.erase(iter); @@ -5055,7 +2662,7 @@ void Actor::LowerToBottom() { ActorPtr thisPtr(this); // ensure this actor remains referenced. - ActorContainer::iterator iter = std::find( siblings.begin(), siblings.end(), this ); + auto iter = std::find( siblings.begin(), siblings.end(), this ); if( iter != siblings.end() ) { siblings.erase(iter); @@ -5083,8 +2690,8 @@ void Actor::RaiseAbove( Internal::Actor& target ) { ActorPtr thisPtr(this); // ensure this actor remains referenced. - ActorContainer::iterator targetIter = std::find( siblings.begin(), siblings.end(), &target ); - ActorContainer::iterator thisIter = std::find( siblings.begin(), siblings.end(), this ); + auto targetIter = std::find( siblings.begin(), siblings.end(), &target ); + auto thisIter = std::find( siblings.begin(), siblings.end(), this ); if( thisIter < targetIter ) { siblings.erase(thisIter); @@ -5116,8 +2723,8 @@ void Actor::LowerBelow( Internal::Actor& target ) { ActorPtr thisPtr(this); // ensure this actor remains referenced. - ActorContainer::iterator targetIter = std::find( siblings.begin(), siblings.end(), &target ); - ActorContainer::iterator thisIter = std::find( siblings.begin(), siblings.end(), this ); + auto targetIter = std::find( siblings.begin(), siblings.end(), &target ); + auto thisIter = std::find( siblings.begin(), siblings.end(), this ); if( thisIter > targetIter ) { @@ -5137,16 +2744,6 @@ 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 ) @@ -5160,11 +2757,6 @@ void Actor::SetInheritLayoutDirection( bool inherit ) } } -bool Actor::IsLayoutDirectionInherited() const -{ - return mInheritLayoutDirection; -} - void Actor::InheritLayoutDirectionRecursively( ActorPtr actor, Dali::LayoutDirection::Type direction, bool set ) { if( actor && ( actor->mInheritLayoutDirection || set ) ) @@ -5178,15 +2770,20 @@ void Actor::InheritLayoutDirectionRecursively( ActorPtr actor, Dali::LayoutDirec if( actor->GetChildCount() > 0 ) { - ActorContainer& children = actor->GetChildrenInternal(); - for( ActorIter iter = children.begin(), endIter = children.end(); iter != endIter; ++iter ) + for( const auto& child : actor->GetChildrenInternal() ) { - InheritLayoutDirectionRecursively( *iter, direction ); + InheritLayoutDirectionRecursively( child, direction ); } } } } +void Actor::SetUpdateSizeHint( const Vector2& updateSizeHint ) +{ + // node is being used in a separate thread; queue a message to set the value & base value + SceneGraph::NodePropertyMessage::Send( GetEventThreadServices(), &GetNode(), &GetNode().mUpdateSizeHint, &AnimatableProperty::Bake, Vector3(updateSizeHint.width, updateSizeHint.height, 0.f ) ); +} + } // namespace Internal } // namespace Dali