X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali%2Finternal%2Fevent%2Factors%2Factor-impl.cpp;h=d9a67fefa687e376c0f78ead9696b896c2ff385a;hb=62a036e95cc8447bba0ef068948c8feb15de76b2;hp=cdb81051a1992d7d7f5235bbb4a1e67f69d88f7c;hpb=52d998719683ba91c5f7fbd2c9da544f51317891;p=platform%2Fcore%2Fuifw%2Fdali-core.git diff --git a/dali/internal/event/actors/actor-impl.cpp b/dali/internal/event/actors/actor-impl.cpp index cdb8105..d9a67fe 100644 --- a/dali/internal/event/actors/actor-impl.cpp +++ b/dali/internal/event/actors/actor-impl.cpp @@ -42,7 +42,6 @@ #include #include #include -#include #include #include #include @@ -61,8 +60,6 @@ using Dali::Internal::SceneGraph::Node; using Dali::Internal::SceneGraph::AnimatableProperty; using Dali::Internal::SceneGraph::PropertyBase; -using namespace std; - namespace Dali { @@ -209,17 +206,16 @@ BaseHandle CreateActor() TypeRegistration mType( typeid(Dali::Actor), typeid(Dali::Handle), CreateActor ); SignalConnectorType signalConnector1(mType, Dali::Actor::SIGNAL_TOUCHED, &Actor::DoConnectSignal); -SignalConnectorType signalConnector2(mType, Dali::Actor::SIGNAL_SET_SIZE, &Actor::DoConnectSignal); -SignalConnectorType signalConnector3(mType, Dali::Actor::SIGNAL_ON_STAGE, &Actor::DoConnectSignal); -SignalConnectorType signalConnector4(mType, Dali::Actor::SIGNAL_OFF_STAGE, &Actor::DoConnectSignal); +SignalConnectorType signalConnector2(mType, Dali::Actor::SIGNAL_HOVERED, &Actor::DoConnectSignal); +SignalConnectorType signalConnector3(mType, Dali::Actor::SIGNAL_SET_SIZE, &Actor::DoConnectSignal); +SignalConnectorType signalConnector4(mType, Dali::Actor::SIGNAL_ON_STAGE, &Actor::DoConnectSignal); +SignalConnectorType signalConnector5(mType, Dali::Actor::SIGNAL_OFF_STAGE, &Actor::DoConnectSignal); TypeAction a1(mType, Dali::Actor::ACTION_SHOW, &Actor::DoAction); TypeAction a2(mType, Dali::Actor::ACTION_HIDE, &Actor::DoAction); } -Actor::DefaultPropertyLookup* Actor::mDefaultPropertyLookup = NULL; - ActorPtr Actor::New() { ActorPtr actor( new Actor( BASIC ) ); @@ -331,6 +327,46 @@ void Actor::Add(Actor& child) } } +void Actor::Insert(unsigned int index, Actor& child) +{ + DALI_ASSERT_ALWAYS( this != &child && "Cannot add actor to itself" ); + DALI_ASSERT_ALWAYS( !child.IsRoot() && "Cannot add root actor" ); + + if( !mChildren ) + { + mChildren = new ActorContainer; + } + + Actor* const oldParent( child.mParent ); + + // since an explicit position has been given, always insert, even if already a child + if( oldParent ) + { + oldParent->Remove( child ); // This causes OnChildRemove callback + } + + // Guard against Add() during previous OnChildRemove callback + if ( !child.mParent ) + { + // Do this first, since user callbacks from within SetParent() may need to remove child + if (index < GetChildCount()) + { + ActorIter it = mChildren->begin(); + std::advance(it, index); + mChildren->insert(it, Dali::Actor(&child)); + } + else + { + mChildren->push_back(Dali::Actor(&child)); + } + // SetParent asserts that child can be added + child.SetParent(this, index); + + // Notification for derived classes + OnChildAdd(child); + } +} + void Actor::Remove(Actor& child) { DALI_ASSERT_ALWAYS( this != &child && "Cannot remove actor from itself" ); @@ -1051,31 +1087,44 @@ void Actor::SetSize(float width, float height, float depth) void Actor::SetSize(const Vector2& size) { - Vector3 volume( size ); - volume.z = std::min( size.width, size.height ); - SetSize( volume ); + SetSize( Vector3( size.width, size.height, CalculateSizeZ( size ) ) ); +} + +float Actor::CalculateSizeZ( const Vector2& size ) const +{ + return std::min( size.width, size.height ); } void Actor::SetSize(const Vector3& size) { if( NULL != mNode ) { + mSize = size; + // mNode is being used in a separate thread; queue a message to set the value & base value - SceneGraph::NodePropertyMessage::Send( mStage->GetUpdateManager(), mNode, &mNode->mSize, &AnimatableProperty::Bake, size ); + SceneGraph::NodePropertyMessage::Send( mStage->GetUpdateManager(), mNode, &mNode->mSize, &AnimatableProperty::Bake, mSize ); // Notification for derived classes - OnSizeSet(size); + OnSizeSet( mSize ); // Emit signal for application developer if( !mSetSizeSignalV2.Empty() ) { Dali::Actor handle( this ); - mSetSizeSignalV2.Emit( handle, size ); + mSetSizeSignalV2.Emit( handle, mSize ); } } } +void Actor::NotifySizeAnimation(Animation& animation, const Vector3& targetSize) +{ + mSize = targetSize; + + // Notify deriving classes + OnSizeAnimation( animation, targetSize ); +} + void Actor::SetWidth( float width ) { if( NULL != mNode ) @@ -1103,6 +1152,11 @@ void Actor::SetDepth( float depth ) } } +const Vector3& Actor::GetSize() const +{ + return mSize; +} + const Vector3& Actor::GetCurrentSize() const { if( NULL != mNode ) @@ -1114,6 +1168,13 @@ const Vector3& Actor::GetCurrentSize() const return Vector3::ZERO; } +Vector3 Actor::GetNaturalSize() const +{ + // It is up to deriving classes to return the appropriate natural size + return Vector3( 0.0f, 0.0f, 0.0f ); +} + + #ifdef DYNAMICS_SUPPORT //--------------- Dynamics --------------- @@ -1798,6 +1859,11 @@ bool Actor::GetTouchRequired() const return !mTouchedSignalV2.Empty() || mDerivedRequiresTouch; } +bool Actor::GetHoverRequired() const +{ + return !mHoveredSignalV2.Empty() || mDerivedRequiresHover; +} + bool Actor::GetMouseWheelEventRequired() const { return !mMouseWheelEventSignalV2.Empty() || mDerivedRequiresMouseWheelEvent; @@ -1846,6 +1912,25 @@ bool Actor::EmitTouchEventSignal(const TouchEvent& event) return consumed; } +bool Actor::EmitHoverEventSignal(const HoverEvent& event) +{ + bool consumed = false; + + if ( !mHoveredSignalV2.Empty() ) + { + Dali::Actor handle( this ); + consumed = mHoveredSignalV2.Emit( handle, event ); + } + + if (!consumed) + { + // Notification for derived classes + consumed = OnHoverEvent( event ); + } + + return consumed; +} + bool Actor::EmitMouseWheelEventSignal(const MouseWheelEvent& event) { bool consumed = false; @@ -1870,6 +1955,11 @@ Dali::Actor::TouchSignalV2& Actor::TouchedSignal() return mTouchedSignalV2; } +Dali::Actor::HoverSignalV2& Actor::HoveredSignal() +{ + return mHoveredSignalV2; +} + Dali::Actor::MouseWheelEventSignalV2& Actor::MouseWheelEventSignal() { return mMouseWheelEventSignalV2; @@ -1899,6 +1989,10 @@ bool Actor::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tra { actor->TouchedSignal().Connect( tracker, functor ); } + else if(Dali::Actor::SIGNAL_HOVERED == signalName) + { + actor->HoveredSignal().Connect( tracker, functor ); + } else if(Dali::Actor::SIGNAL_MOUSE_WHEEL_EVENT == signalName) { actor->MouseWheelEventSignal().Connect( tracker, functor ); @@ -1936,6 +2030,7 @@ Actor::Actor( DerivedType derivedType ) #endif mGestureData( NULL ), mAttachment(), + mSize( 0.0f, 0.0f, 0.0f ), mName(), mId( ++mActorCounter ), // actor ID is initialised to start from 1, and 0 is reserved mIsRoot( ROOT_LAYER == derivedType ), @@ -1947,6 +2042,7 @@ Actor::Actor( DerivedType derivedType ) mLeaveRequired( false ), mKeyboardFocusable( false ), mDerivedRequiresTouch( false ), + mDerivedRequiresHover( false ), mDerivedRequiresMouseWheelEvent( false ), mOnStageSignalled( false ), mInheritRotation( true ), @@ -1967,16 +2063,6 @@ void Actor::Initialize() AddNodeMessage( mStage->GetUpdateManager(), *node ); // Pass ownership to scene-graph mNode = node; // Keep raw-pointer to Node - if(!mDefaultPropertyLookup) - { - mDefaultPropertyLookup = new DefaultPropertyLookup(); - - for (int i=0; iGetUpdateManager(), *(mParent->mNode), *mNode ); + ConnectNodeMessage( mStage->GetUpdateManager(), *(mParent->mNode), *mNode, index ); } // Notify attachment @@ -2233,11 +2319,6 @@ bool Actor::IsNodeConnected() const return connected; } -bool Actor::IsSceneObjectRemovable() const -{ - return false; -} - unsigned int Actor::GetDefaultPropertyCount() const { return DEFAULT_PROPERTY_COUNT; @@ -2253,7 +2334,7 @@ void Actor::GetDefaultPropertyIndices( Property::IndexContainer& indices ) const } } -const std::string& Actor::GetDefaultPropertyName( Property::Index index ) const +const char* Actor::GetDefaultPropertyName( Property::Index index ) const { if( index < DEFAULT_PROPERTY_COUNT ) { @@ -2261,8 +2342,7 @@ const std::string& Actor::GetDefaultPropertyName( Property::Index index ) const } else { - // index out of range..return empty string - return String::EMPTY; + return NULL; } } @@ -2270,13 +2350,15 @@ Property::Index Actor::GetDefaultPropertyIndex(const std::string& name) const { Property::Index index = Property::INVALID_INDEX; - DALI_ASSERT_DEBUG( NULL != mDefaultPropertyLookup ); - // Look for name in default properties - DefaultPropertyLookup::const_iterator result = mDefaultPropertyLookup->find( name ); - if ( mDefaultPropertyLookup->end() != result ) + for( int i = 0; i < DEFAULT_PROPERTY_COUNT; ++i ) { - index = result->second; + const Internal::PropertyDetails* property = &DEFAULT_PROPERTY_DETAILS[ i ]; + if( 0 == strcmp( name.c_str(), property->name ) ) // dont want to convert rhs to string + { + index = i; + break; + } } return index; @@ -2547,105 +2629,122 @@ void Actor::SetDefaultProperty( Property::Index index, const Property::Value& pr default: { - DALI_ASSERT_ALWAYS(false && "Actor::Property is out of bounds"); // should not come here + // this can happen in the case of a non-animatable default property so just do nothing break; } } } -void Actor::SetCustomProperty( Property::Index index, const CustomProperty& entry, const Property::Value& value ) +// TODO: This method needs to be removed +void Actor::SetSceneGraphProperty( Property::Index index, const CustomProperty& entry, const Property::Value& value ) { - // TODO: This should be deprecated OnPropertySet(index, value); - if(entry.IsAnimatable()) + switch ( entry.type ) { - // TODO: ADD MATRIX & MATRIX3 types + case Property::BOOLEAN: + { + const AnimatableProperty* property = dynamic_cast< const AnimatableProperty* >( 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( mStage->GetUpdateManager(), mNode, property, &AnimatableProperty::Bake, value.Get() ); - switch ( entry.type ) + break; + } + + case Property::FLOAT: { - case Property::BOOLEAN: - { - AnimatableProperty* property = dynamic_cast< AnimatableProperty* >( entry.GetSceneGraphProperty() ); - DALI_ASSERT_DEBUG( NULL != property ); + const AnimatableProperty* property = dynamic_cast< const AnimatableProperty* >( 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( mStage->GetUpdateManager(), mNode, property, &AnimatableProperty::Bake, value.Get() ); + // property is being used in a separate thread; queue a message to set the property + SceneGraph::NodePropertyMessage::Send( mStage->GetUpdateManager(), mNode, property, &AnimatableProperty::Bake, value.Get() ); - break; - } + break; + } - case Property::FLOAT: - { - AnimatableProperty* property = dynamic_cast< AnimatableProperty* >( entry.GetSceneGraphProperty() ); - DALI_ASSERT_DEBUG( NULL != property ); + case Property::INTEGER: + { + const AnimatableProperty* property = dynamic_cast< const AnimatableProperty* >( 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( mStage->GetUpdateManager(), mNode, property, &AnimatableProperty::Bake, value.Get() ); + // property is being used in a separate thread; queue a message to set the property + SceneGraph::NodePropertyMessage::Send( mStage->GetUpdateManager(), mNode, property, &AnimatableProperty::Bake, value.Get() ); - break; - } + break; + } - case Property::INTEGER: - { - AnimatableProperty* property = dynamic_cast< AnimatableProperty* >( entry.GetSceneGraphProperty() ); - DALI_ASSERT_DEBUG( NULL != property ); + case Property::VECTOR2: + { + const AnimatableProperty* property = dynamic_cast< const AnimatableProperty* >( 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( mStage->GetUpdateManager(), mNode, property, &AnimatableProperty::Bake, value.Get() ); + // property is being used in a separate thread; queue a message to set the property + SceneGraph::NodePropertyMessage::Send( mStage->GetUpdateManager(), mNode, property, &AnimatableProperty::Bake, value.Get() ); - break; - } + break; + } - case Property::VECTOR2: - { - AnimatableProperty* property = dynamic_cast< AnimatableProperty* >( entry.GetSceneGraphProperty() ); - DALI_ASSERT_DEBUG( NULL != property ); + case Property::VECTOR3: + { + const AnimatableProperty* property = dynamic_cast< const AnimatableProperty* >( 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( mStage->GetUpdateManager(), mNode, property, &AnimatableProperty::Bake, value.Get() ); + // property is being used in a separate thread; queue a message to set the property + SceneGraph::NodePropertyMessage::Send( mStage->GetUpdateManager(), mNode, property, &AnimatableProperty::Bake, value.Get() ); - break; - } + break; + } - case Property::VECTOR3: - { - AnimatableProperty* property = dynamic_cast< AnimatableProperty* >( entry.GetSceneGraphProperty() ); - DALI_ASSERT_DEBUG( NULL != property ); + case Property::VECTOR4: + { + const AnimatableProperty* property = dynamic_cast< const AnimatableProperty* >( 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( mStage->GetUpdateManager(), mNode, property, &AnimatableProperty::Bake, value.Get() ); + // property is being used in a separate thread; queue a message to set the property + SceneGraph::NodePropertyMessage::Send( mStage->GetUpdateManager(), mNode, property, &AnimatableProperty::Bake, value.Get() ); - break; - } + break; + } - case Property::VECTOR4: - { - AnimatableProperty* property = dynamic_cast< AnimatableProperty* >( entry.GetSceneGraphProperty() ); - DALI_ASSERT_DEBUG( NULL != property ); + case Property::ROTATION: + { + const AnimatableProperty* property = dynamic_cast< const AnimatableProperty* >( 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( mStage->GetUpdateManager(), mNode, property, &AnimatableProperty::Bake, value.Get() ); + // property is being used in a separate thread; queue a message to set the property + SceneGraph::NodePropertyMessage::Send( mStage->GetUpdateManager(), mNode, property,&AnimatableProperty::Bake, value.Get() ); - break; - } + break; + } - case Property::ROTATION: - { - AnimatableProperty* property = dynamic_cast< AnimatableProperty* >( entry.GetSceneGraphProperty() ); - DALI_ASSERT_DEBUG( NULL != property ); + case Property::MATRIX: + { + const AnimatableProperty* property = dynamic_cast< const AnimatableProperty* >( 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( mStage->GetUpdateManager(), mNode, property,&AnimatableProperty::Bake, value.Get() ); + // property is being used in a separate thread; queue a message to set the property + SceneGraph::NodePropertyMessage::Send( mStage->GetUpdateManager(), mNode, property,&AnimatableProperty::Bake, value.Get() ); - break; - } + break; + } - default: - { - DALI_ASSERT_ALWAYS( false && "Property type enumeration out of bounds" ); // should not come here - break; - } + case Property::MATRIX3: + { + const AnimatableProperty* property = dynamic_cast< const AnimatableProperty* >( 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( mStage->GetUpdateManager(), mNode, property,&AnimatableProperty::Bake, value.Get() ); + + break; + } + + default: + { + DALI_ASSERT_ALWAYS( false && "Property type enumeration out of bounds" ); // should not come here + break; } } } @@ -2924,13 +3023,9 @@ Property::Value Actor::GetDefaultProperty(Property::Index index) const return value; } -void Actor::InstallSceneObjectProperty( PropertyBase& newProperty, const std::string& name, unsigned int index ) +const SceneGraph::PropertyOwner* Actor::GetPropertyOwner() const { - if( NULL != mNode ) - { - // mNode is being used in a separate thread; queue a message to add the property - InstallCustomPropertyMessage( mStage->GetUpdateInterface(), *mNode, newProperty ); // Message takes ownership - } + return mNode; } const SceneGraph::PropertyOwner* Actor::GetSceneObject() const @@ -2953,11 +3048,10 @@ const PropertyBase* Actor::GetSceneObjectAnimatableProperty( Property::Index ind if ( static_cast(index) >= DEFAULT_PROPERTY_MAX_COUNT ) { - CustomPropertyLookup::const_iterator entry = GetCustomPropertyLookup().find( index ); - - DALI_ASSERT_ALWAYS( GetCustomPropertyLookup().end() != entry && "index is invalid" ); + CustomProperty* custom = FindCustomProperty( index ); + DALI_ASSERT_ALWAYS( custom && "Property index is invalid" ); - property = dynamic_cast( entry->second.GetSceneGraphProperty() ); + property = custom->GetSceneGraphProperty(); } else if( NULL != mNode ) { @@ -3059,11 +3153,9 @@ const PropertyInputImpl* Actor::GetSceneObjectInputProperty( Property::Index ind if ( index >= DEFAULT_PROPERTY_MAX_COUNT ) { - CustomPropertyLookup::const_iterator entry = GetCustomPropertyLookup().find( index ); - - DALI_ASSERT_ALWAYS( GetCustomPropertyLookup().end() != entry && "property index is invalid" ); - - property = entry->second.GetSceneGraphProperty(); + CustomProperty* custom = FindCustomProperty( index ); + DALI_ASSERT_ALWAYS( custom && "Property index is invalid" ); + property = custom->GetSceneGraphProperty(); } else if( NULL != mNode ) { @@ -3275,7 +3367,7 @@ int Actor::GetPropertyComponentIndex( Property::Index index ) const return componentIndex; } -void Actor::SetParent(Actor* parent) +void Actor::SetParent(Actor* parent, int index) { if( parent ) { @@ -3289,7 +3381,7 @@ void Actor::SetParent(Actor* parent) StagePtr stage = parent->mStage; // Instruct each actor to create a corresponding node in the scene graph - ConnectToStage(*stage); + ConnectToStage(*stage, index); } } else // parent being set to NULL