/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include <dali/internal/event/common/property-helper.h>
#include <dali/internal/event/common/stage-impl.h>
#include <dali/internal/event/common/type-info-impl.h>
+#include <dali/internal/event/common/scene-impl.h>
+#include <dali/internal/event/common/thread-local-storage.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>
// create node. Nodes are owned by the update manager
SceneGraph::Node* node = SceneGraph::Node::New();
OwnerPointer< SceneGraph::Node > transferOwnership( node );
- AddNodeMessage( Stage::GetCurrent()->GetUpdateManager(), transferOwnership );
+ Internal::ThreadLocalStorage* tls = Internal::ThreadLocalStorage::GetInternal();
+ AddNodeMessage( tls->GetUpdateManager(), transferOwnership );
return node;
}
const Vector2 Actor::GetCurrentScreenPosition() const
{
- StagePtr stage = Stage::GetCurrent();
- if( stage && OnStage() )
+ if( mScene && OnStage() )
{
Vector3 worldPosition = GetNode().GetWorldPosition( GetEventThreadServices().GetEventBufferIndex() );
- Vector3 cameraPosition = stage->GetDefaultCameraActor().GetNode().GetWorldPosition( GetEventThreadServices().GetEventBufferIndex() );
+ Vector3 cameraPosition = mScene->GetDefaultCameraActor().GetNode().GetWorldPosition( GetEventThreadServices().GetEventBufferIndex() );
worldPosition -= cameraPosition;
Vector3 actorSize = GetCurrentSize() * GetCurrentWorldScale();
- Vector2 halfStageSize( stage->GetSize() * 0.5f ); // World position origin is center of stage
+ Vector2 halfSceneSize( mScene->GetSize() * 0.5f ); // World position origin is center of scene
Vector3 halfActorSize( actorSize * 0.5f );
Vector3 anchorPointOffSet = halfActorSize - actorSize * ( mPositionUsesAnchorPoint ? GetCurrentAnchorPoint() : AnchorPoint::TOP_LEFT );
- return Vector2( halfStageSize.width + worldPosition.x - anchorPointOffSet.x,
- halfStageSize.height + worldPosition.y - anchorPointOffSet.y );
+ return Vector2( halfSceneSize.width + worldPosition.x - anchorPointOffSet.x,
+ halfSceneSize.height + worldPosition.y - anchorPointOffSet.y );
}
return Vector2::ZERO;
EnsureRelayoutData();
mRelayoutData->sizeSetPolicy = policy;
+
+ // Trigger relayout on this control
+ RelayoutRequest();
}
SizeScalePolicy::Type Actor::GetSizeScalePolicy() const
bool Actor::ScreenToLocal( float& localX, float& localY, float screenX, float screenY ) const
{
// only valid when on-stage
- StagePtr stage = Stage::GetCurrent();
- if( stage && OnStage() )
+ if( mScene && OnStage() )
{
- const RenderTaskList& taskList = stage->GetRenderTaskList();
+ const RenderTaskList& taskList = mScene->GetRenderTaskList();
Vector2 converted( screenX, screenY );
return *mGestureData;
}
-bool Actor::IsGestureRequred( Gesture::Type type ) const
+bool Actor::IsGestureRequred( DevelGesture::Type type ) const
{
return mGestureData && mGestureData->IsGestureRequred( type );
}
Actor::Actor( DerivedType derivedType, const SceneGraph::Node& node )
: Object( &node ),
+ mScene( nullptr ),
mParent( NULL ),
mChildren( NULL ),
mRenderers( NULL ),
// Guard to allow handle destruction after Core has been destroyed
if( EventThreadServices::IsCoreRunning() )
{
- DestroyNodeMessage( GetEventThreadServices().GetUpdateManager(), GetNode() );
+ // Root layer will destroy its node in its own destructor
+ if ( !mIsRoot )
+ {
+ DestroyNodeMessage( GetEventThreadServices().GetUpdateManager(), GetNode() );
- GetEventThreadServices().UnregisterObject( this );
+ GetEventThreadServices().UnregisterObject( this );
+ }
}
// Cleanup optional gesture data
// It protects us when the Actor hierarchy is modified during OnStageConnectionExternal callbacks.
ActorContainer connectionList;
- StagePtr stage = Stage::GetCurrent();
- if( stage )
+ if( mScene )
{
- stage->RequestRebuildDepthTree();
+ mScene->RequestRebuildDepthTree();
}
// This stage is atomic i.e. not interrupted by user callbacks.
ActorConstIter endIter = mChildren->end();
for( ActorIter iter = mChildren->begin(); iter != endIter; ++iter )
{
+ (*iter)->SetScene( *mScene );
(*iter)->RecursiveConnectToStage( connectionList, depth + 1 );
}
}
// It protects us when the Actor hierachy is modified during OnStageDisconnectionExternal callbacks.
ActorContainer disconnectionList;
- StagePtr stage = Stage::GetCurrent();
- if( stage )
+ if( mScene )
{
- stage->RequestRebuildDepthTree();
+ mScene->RequestRebuildDepthTree();
}
// This stage is atomic i.e. not interrupted by user callbacks
mParent = parent;
+ mScene = parent->mScene;
+
if ( EventThreadServices::IsCoreRunning() && // Don't emit signals or send messages during Core destruction
parent->OnStage() )
{
// Instruct each actor to discard pointers to the scene-graph
DisconnectFromStage();
}
+
+ mScene = nullptr;
}
}
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;
{
if( mIsOnStage )
{
- StagePtr stage = Stage::GetCurrent();
- if( stage )
+ if( mScene )
{
- stage->RequestRebuildDepthTree();
+ mScene->RequestRebuildDepthTree();
}
}
}
}
}
+void Actor::SetScene( Scene& scene )
+{
+ mScene = &scene;
+}
+
+Scene& Actor::GetScene() const
+{
+ return *mScene;
+}
+
void Actor::SetInheritLayoutDirection( bool inherit )
{
if( mInheritLayoutDirection != inherit )