#include <dali/internal/event/common/stage-impl.h>
#include <dali/internal/event/common/type-info-impl.h>
#include <dali/internal/event/actor-attachments/actor-attachment-impl.h>
+#include <dali/internal/event/actor-attachments/renderer-attachment-impl.h>
#include <dali/internal/event/animation/constraint-impl.h>
#include <dali/internal/event/common/projection.h>
#include <dali/internal/event/size-negotiation/relayout-controller-impl.h>
#include <dali/internal/common/message.h>
#include <dali/integration-api/debug.h>
-#ifdef DYNAMICS_SUPPORT
+#ifdef DALI_DYNAMICS_SUPPORT
#include <dali/internal/event/dynamics/dynamics-body-config-impl.h>
#include <dali/internal/event/dynamics/dynamics-body-impl.h>
#include <dali/internal/event/dynamics/dynamics-joint-impl.h>
unsigned int Actor::mActorCounter = 0;
+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( Vector3::ONE ), preferredSize( Vector2::ZERO ), sizeSetPolicy( SizeScalePolicy::USE_SIZE_SET ), relayoutEnabled( false ), insideRelayout( false )
+ : sizeModeFactor( GetDefaultSizeModeFactor() ), preferredSize( GetDefaultPreferredSize() ), sizeSetPolicy( DEFAULT_SIZE_SCALE_POLICY ), relayoutEnabled( false ), insideRelayout( false )
{
// Set size negotiation defaults
for( unsigned int i = 0; i < Dimension::DIMENSION_COUNT; ++i )
dimensionNegotiated[ i ] = false;
dimensionDirty[ i ] = false;
dimensionDependencies[ i ] = Dimension::ALL_DIMENSIONS;
- dimensionPadding[ i ] = Vector2( 0.0f, 0.0f );
+ dimensionPadding[ i ] = GetDefaultDimensionPadding();
minimumSize[ i ] = 0.0f;
maximumSize[ i ] = FLT_MAX;
}
bool insideRelayout :1; ///< Locking flag to prevent recursive relayouts on size set
};
-#ifdef DYNAMICS_SUPPORT
+#ifdef DALI_DYNAMICS_SUPPORT
// Encapsulate actor related dynamics data
struct DynamicsData
SlotDelegate< Actor > slotDelegate;
};
-#endif // DYNAMICS_SUPPORT
+#endif // DALI_DYNAMICS_SUPPORT
namespace // unnamed namespace
{
{
return values.width;
}
-
case Dimension::HEIGHT:
{
return values.height;
}
-
default:
{
break;
}
}
-
return 0.0f;
}
return GetDimensionValue( values.GetVectorXY(), dimension );
}
+
} // unnamed namespace
ActorPtr Actor::New()
}
}
-void Actor::SetInitialVolume( const Vector3& volume )
-{
- if( NULL != mNode )
- {
- // mNode is being used in a separate thread; queue a message to set the value
- SetInitialVolumeMessage( GetEventThreadServices(), *mNode, volume );
- }
-}
-
-void Actor::SetTransmitGeometryScaling( bool transmitGeometryScaling )
-{
- if( NULL != mNode )
- {
- // mNode is being used in a separate thread; queue a message to set the value
- SetTransmitGeometryScalingMessage( GetEventThreadServices(), *mNode, transmitGeometryScaling );
- }
-}
-
-bool Actor::GetTransmitGeometryScaling() const
-{
- if( NULL != mNode )
- {
- // mNode is being used in a separate thread; copy the value from the previous update
- return mNode->GetTransmitGeometryScaling();
- }
-
- return false;
-}
-
-void Actor::ScaleBy( const Vector3& relativeScale )
+void Actor::ScaleBy(const Vector3& relativeScale)
{
if( NULL != mNode )
{
const Vector3& Actor::GetSizeModeFactor() const
{
- EnsureRelayoutData();
+ if ( mRelayoutData )
+ {
+ return mRelayoutData->sizeModeFactor;
+ }
- return mRelayoutData->sizeModeFactor;
+ return GetDefaultSizeModeFactor();
}
void Actor::SetColorMode( ColorMode colorMode )
ResizePolicy::Type Actor::GetResizePolicy( Dimension::Type dimension ) const
{
- EnsureRelayoutData();
-
- // If more than one dimension is requested, just return the first one found
- for( unsigned int i = 0; i < Dimension::DIMENSION_COUNT; ++i )
+ if ( mRelayoutData )
{
- if( ( dimension & ( 1 << i ) ) )
+ // If more than one dimension is requested, just return the first one found
+ for( unsigned int i = 0; i < Dimension::DIMENSION_COUNT; ++i )
{
- return mRelayoutData->resizePolicies[ i ];
+ if( ( dimension & ( 1 << i ) ) )
+ {
+ return mRelayoutData->resizePolicies[ i ];
+ }
}
}
SizeScalePolicy::Type Actor::GetSizeScalePolicy() const
{
- EnsureRelayoutData();
+ if ( mRelayoutData )
+ {
+ return mRelayoutData->sizeSetPolicy;
+ }
- return mRelayoutData->sizeSetPolicy;
+ return DEFAULT_SIZE_SCALE_POLICY;
}
void Actor::SetDimensionDependency( Dimension::Type dimension, Dimension::Type dependency )
Dimension::Type Actor::GetDimensionDependency( Dimension::Type dimension ) const
{
- EnsureRelayoutData();
-
- // If more than one dimension is requested, just return the first one found
- for( unsigned int i = 0; i < Dimension::DIMENSION_COUNT; ++i )
+ if ( mRelayoutData )
{
- if( ( dimension & ( 1 << i ) ) )
+ // If more than one dimension is requested, just return the first one found
+ for( unsigned int i = 0; i < Dimension::DIMENSION_COUNT; ++i )
{
- return mRelayoutData->dimensionDependencies[ i ];
+ if( ( dimension & ( 1 << i ) ) )
+ {
+ return mRelayoutData->dimensionDependencies[ i ];
+ }
}
}
bool Actor::IsLayoutDirty( Dimension::Type dimension ) const
{
- EnsureRelayoutData();
-
- for( unsigned int i = 0; i < Dimension::DIMENSION_COUNT; ++i )
+ if ( mRelayoutData )
{
- if( ( dimension & ( 1 << i ) ) && mRelayoutData->dimensionDirty[ i ] )
+ for( unsigned int i = 0; i < Dimension::DIMENSION_COUNT; ++i )
{
- return true;
+ if( ( dimension & ( 1 << i ) ) && mRelayoutData->dimensionDirty[ i ] )
+ {
+ return true;
+ }
}
}
bool Actor::RelayoutPossible( Dimension::Type dimension ) const
{
- EnsureRelayoutData();
-
- return mRelayoutData->relayoutEnabled && !IsLayoutDirty( dimension );
+ return mRelayoutData && mRelayoutData->relayoutEnabled && !IsLayoutDirty( dimension );
}
bool Actor::RelayoutRequired( Dimension::Type dimension ) const
{
- EnsureRelayoutData();
+ return mRelayoutData && mRelayoutData->relayoutEnabled && IsLayoutDirty( dimension );
+}
+
+unsigned int Actor::AddRenderer( Renderer& renderer )
+{
+ //TODO: MESH_REWORK : Add support for multiple renderers
+ if ( ! mAttachment )
+ {
+ mAttachment = RendererAttachment::New( GetEventThreadServices(), *mNode, renderer );
+ }
+
+ return 0;
+}
+
+unsigned int Actor::GetRendererCount() const
+{
+ //TODO: MESH_REWORK : Add support for multiple renderers
+ RendererAttachment* attachment = dynamic_cast<RendererAttachment*>(mAttachment.Get());
+ return attachment ? 1u : 0u;
+}
+
+Renderer& Actor::GetRendererAt( unsigned int index )
+{
+ //TODO: MESH_REWORK : Add support for multiple renderers
+ DALI_ASSERT_DEBUG( index == 0 && "Only one renderer is supported." );
+
+ //TODO: MESH_REWORK : Temporary code
+ RendererAttachment* attachment = dynamic_cast<RendererAttachment*>(mAttachment.Get());
+ DALI_ASSERT_ALWAYS( attachment && "Actor doesn't have a renderer" );
- return mRelayoutData->relayoutEnabled && IsLayoutDirty( dimension );
+ return attachment->GetRenderer();
+}
+
+void Actor::RemoveRenderer( Renderer& renderer )
+{
+ //TODO: MESH_REWORK : Add support for multiple renderers
+ mAttachment = NULL;
}
-#ifdef DYNAMICS_SUPPORT
+void Actor::RemoveRenderer( unsigned int index )
+{
+ //TODO: MESH_REWORK : Add support for multiple renderers
+ mAttachment = NULL;
+}
+
+
+#ifdef DALI_DYNAMICS_SUPPORT
//--------------- Dynamics ---------------
}
}
-#endif // DYNAMICS_SUPPORT
+#endif // DALI_DYNAMICS_SUPPORT
void Actor::SetOverlay( bool enable )
{
bool Actor::ScreenToLocal( float& localX, float& localY, float screenX, float screenY ) const
{
// only valid when on-stage
- if( OnStage() )
+ StagePtr stage = Stage::GetCurrent();
+ if( stage && OnStage() )
{
- const RenderTaskList& taskList = Stage::GetCurrent()->GetRenderTaskList();
+ const RenderTaskList& taskList = stage->GetRenderTaskList();
Vector2 converted( screenX, screenY );
mParentOrigin( NULL ),
mAnchorPoint( NULL ),
mRelayoutData( NULL ),
-#ifdef DYNAMICS_SUPPORT
+#ifdef DALI_DYNAMICS_SUPPORT
mDynamicsData( NULL ),
#endif
mGestureData( NULL ),
mTargetSize( 0.0f, 0.0f, 0.0f ),
mName(),
mId( ++mActorCounter ), // actor ID is initialised to start from 1, and 0 is reserved
+ mDepth( 0 ),
mIsRoot( ROOT_LAYER == derivedType ),
mIsRenderable( RENDERABLE == derivedType ),
mIsLayer( LAYER == derivedType || ROOT_LAYER == derivedType ),
GetEventThreadServices().UnregisterObject( this );
}
-#ifdef DYNAMICS_SUPPORT
+#ifdef DALI_DYNAMICS_SUPPORT
// Cleanup dynamics
delete mDynamicsData;
#endif
}
}
-void Actor::ConnectToStage( int index )
+void Actor::ConnectToStage( unsigned int parentDepth, int index )
{
// This container is used instead of walking the Actor hierachy.
// It protects us when the Actor hierachy is modified during OnStageConnectionExternal callbacks.
ActorContainer connectionList;
+
// This stage is atomic i.e. not interrupted by user callbacks
- RecursiveConnectToStage( connectionList, index );
+ RecursiveConnectToStage( connectionList, parentDepth+1, index );
// Notify applications about the newly connected actors.
const ActorIter endIter = connectionList.end();
RelayoutRequest();
}
-void Actor::RecursiveConnectToStage( ActorContainer& connectionList, int index )
+void Actor::RecursiveConnectToStage( ActorContainer& connectionList, unsigned int depth, int index )
{
DALI_ASSERT_ALWAYS( !OnStage() );
mIsOnStage = true;
+ mDepth = depth;
ConnectToSceneGraph( index );
for( ActorIter iter = mChildren->begin(); iter != endIter; ++iter )
{
Actor& actor = GetImplementation( *iter );
- actor.RecursiveConnectToStage( connectionList );
+ actor.RecursiveConnectToStage( connectionList, depth+1 );
}
}
}
mAttachment->Connect();
}
-#ifdef DYNAMICS_SUPPORT
+#ifdef DALI_DYNAMICS_SUPPORT
// Notify dynamics
if( NULL != mDynamicsData )
{
if( OnStage() && !mOnStageSignalled )
{
// Notification for external (CustomActor) derived classes
- OnStageConnectionExternal();
+ OnStageConnectionExternal( mDepth );
if( !mOnStageSignal.Empty() )
{
mAttachment->Disconnect();
}
-#ifdef DYNAMICS_SUPPORT
+#ifdef DALI_DYNAMICS_SUPPORT
// Notify dynamics
if( NULL != mDynamicsData )
{
case Dali::Actor::Property::WIDTH_RESIZE_POLICY:
{
- SetResizePolicy( Scripting::GetEnumeration< ResizePolicy::Type >( property.Get< std::string >().c_str(), ResizePolicy::TypeTable, ResizePolicy::TypeTableCount ), Dimension::WIDTH );
+ ResizePolicy::Type type;
+ if( Scripting::GetEnumeration< ResizePolicy::Type >( property.Get< std::string >().c_str(), ResizePolicy::TypeTable, ResizePolicy::TypeTableCount, type ) )
+ {
+ SetResizePolicy( type, Dimension::WIDTH );
+ }
break;
}
case Dali::Actor::Property::HEIGHT_RESIZE_POLICY:
{
- SetResizePolicy( Scripting::GetEnumeration< ResizePolicy::Type >( property.Get< std::string >().c_str(), ResizePolicy::TypeTable, ResizePolicy::TypeTableCount ), Dimension::HEIGHT );
+ ResizePolicy::Type type;
+ if( Scripting::GetEnumeration< ResizePolicy::Type >( property.Get< std::string >().c_str(), ResizePolicy::TypeTable, ResizePolicy::TypeTableCount, type ) )
+ {
+ SetResizePolicy( type, Dimension::HEIGHT );
+ }
break;
}
case Dali::Actor::Property::SIZE_SCALE_POLICY:
{
- SetSizeScalePolicy( Scripting::GetEnumeration< SizeScalePolicy::Type >( property.Get< std::string >().c_str(), SizeScalePolicy::TypeTable, SizeScalePolicy::TypeTableCount ) );
+ SizeScalePolicy::Type type;
+ if( Scripting::GetEnumeration< SizeScalePolicy::Type >( property.Get< std::string >().c_str(), SizeScalePolicy::TypeTable, SizeScalePolicy::TypeTableCount, type ) )
+ {
+ SetSizeScalePolicy( type );
+ }
break;
}
parent->OnStage() )
{
// Instruct each actor to create a corresponding node in the scene graph
- ConnectToStage( index );
+ ConnectToStage( parent->GetDepth(), index );
}
}
else // parent being set to NULL
return done;
}
-void Actor::EnsureRelayoutData() const
+void Actor::EnsureRelayoutData()
{
// Assign relayout data.
if( !mRelayoutData )
Vector2 Actor::GetPadding( Dimension::Type dimension ) const
{
- EnsureRelayoutData();
-
- // If more than one dimension is requested, just return the first one found
- for( unsigned int i = 0; i < Dimension::DIMENSION_COUNT; ++i )
+ if ( mRelayoutData )
{
- if( ( dimension & ( 1 << i ) ) )
+ // If more than one dimension is requested, just return the first one found
+ for( unsigned int i = 0; i < Dimension::DIMENSION_COUNT; ++i )
{
- return mRelayoutData->dimensionPadding[ i ];
+ if( ( dimension & ( 1 << i ) ) )
+ {
+ return mRelayoutData->dimensionPadding[ i ];
+ }
}
}
- return Vector2( 0.0f, 0.0f ); // Default
+ return GetDefaultDimensionPadding();
}
void Actor::SetLayoutNegotiated( bool negotiated, Dimension::Type dimension )
{
+ EnsureRelayoutData();
+
for( unsigned int i = 0; i < Dimension::DIMENSION_COUNT; ++i )
{
if( dimension & ( 1 << i ) )
bool Actor::IsLayoutNegotiated( Dimension::Type dimension ) const
{
- for( unsigned int i = 0; i < Dimension::DIMENSION_COUNT; ++i )
+ if ( mRelayoutData )
{
- if( ( dimension & ( 1 << i ) ) && mRelayoutData->dimensionNegotiated[ i ] )
+ for( unsigned int i = 0; i < Dimension::DIMENSION_COUNT; ++i )
{
- return true;
+ if( ( dimension & ( 1 << i ) ) && mRelayoutData->dimensionNegotiated[ i ] )
+ {
+ return true;
+ }
}
}
Vector2 Actor::GetPreferredSize() const
{
- EnsureRelayoutData();
+ if ( mRelayoutData )
+ {
+ return mRelayoutData->preferredSize;
+ }
- return mRelayoutData->preferredSize;
+ return GetDefaultPreferredSize();
}
void Actor::SetMinimumSize( float size, Dimension::Type dimension )
float Actor::GetMinimumSize( Dimension::Type dimension ) const
{
- EnsureRelayoutData();
-
- for( unsigned int i = 0; i < Dimension::DIMENSION_COUNT; ++i )
+ if ( mRelayoutData )
{
- if( dimension & ( 1 << i ) )
+ for( unsigned int i = 0; i < Dimension::DIMENSION_COUNT; ++i )
{
- return mRelayoutData->minimumSize[ i ];
+ if( dimension & ( 1 << i ) )
+ {
+ return mRelayoutData->minimumSize[ i ];
+ }
}
}
float Actor::GetMaximumSize( Dimension::Type dimension ) const
{
- EnsureRelayoutData();
-
- for( unsigned int i = 0; i < Dimension::DIMENSION_COUNT; ++i )
+ if ( mRelayoutData )
{
- if( dimension & ( 1 << i ) )
+ for( unsigned int i = 0; i < Dimension::DIMENSION_COUNT; ++i )
{
- return mRelayoutData->maximumSize[ i ];
+ if( dimension & ( 1 << i ) )
+ {
+ return mRelayoutData->maximumSize[ i ];
+ }
}
}
- return 0.0f; // Default
+ return FLT_MAX; // Default
}
} // namespace Internal