Merge "Clean up the code to build successfully on macOS" into devel/master
[platform/core/uifw/dali-core.git] / dali / internal / event / actors / actor-impl.cpp
old mode 100644 (file)
new mode 100755 (executable)
index 321b111..b6960ed
@@ -31,6 +31,7 @@
 #include <dali/public-api/math/vector3.h>
 #include <dali/public-api/math/radian.h>
 #include <dali/public-api/object/type-registry.h>
+#include <dali/devel-api/common/capabilities.h>
 #include <dali/devel-api/actors/actor-devel.h>
 #include <dali/internal/event/actors/actor-property-handler.h>
 #include <dali/internal/event/actors/actor-relayouter.h>
@@ -143,25 +144,27 @@ DALI_PROPERTY( "keyboardFocusable",         BOOLEAN,  true,  false, false, Dali:
 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( "blendEquation",             INTEGER,  true,  false, false, Dali::DevelActor::Property::BLEND_EQUATION )
 DALI_PROPERTY_TABLE_END( DEFAULT_ACTOR_PROPERTY_START_INDEX, ActorDefaultProperties )
 
 // Signals
 
-const char* const SIGNAL_HOVERED = "hovered";
-const char* const SIGNAL_WHEEL_EVENT = "wheelEvent";
-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_TOUCHED = "touched";
-const char* const SIGNAL_VISIBILITY_CHANGED = "visibilityChanged";
-const char* const SIGNAL_LAYOUT_DIRECTION_CHANGED = "layoutDirectionChanged";
-const char* const SIGNAL_CHILD_ADDED = "childAdded";
-const char* const SIGNAL_CHILD_REMOVED = "childRemoved";
+static constexpr std::string_view SIGNAL_HOVERED                  = "hovered";
+static constexpr std::string_view SIGNAL_WHEEL_EVENT              = "wheelEvent";
+static constexpr std::string_view SIGNAL_ON_SCENE                 = "onScene";
+static constexpr std::string_view SIGNAL_OFF_SCENE                = "offScene";
+static constexpr std::string_view SIGNAL_ON_RELAYOUT              = "onRelayout";
+static constexpr std::string_view SIGNAL_TOUCHED                  = "touched";
+static constexpr std::string_view SIGNAL_VISIBILITY_CHANGED       = "visibilityChanged";
+static constexpr std::string_view SIGNAL_LAYOUT_DIRECTION_CHANGED = "layoutDirectionChanged";
+static constexpr std::string_view SIGNAL_CHILD_ADDED              = "childAdded";
+static constexpr std::string_view SIGNAL_CHILD_REMOVED            = "childRemoved";
 
 // Actions
 
-const char* const ACTION_SHOW = "show";
-const char* const ACTION_HIDE = "hide";
+static constexpr std::string_view ACTION_SHOW = "show";
+static constexpr std::string_view ACTION_HIDE = "hide";
 
 BaseHandle CreateActor()
 {
@@ -170,19 +173,19 @@ BaseHandle CreateActor()
 
 TypeRegistration mType( typeid(Dali::Actor), typeid(Dali::Handle), CreateActor, ActorDefaultProperties );
 
-SignalConnectorType signalConnector2( mType, SIGNAL_HOVERED, &Actor::DoConnectSignal );
-SignalConnectorType signalConnector3( mType, SIGNAL_WHEEL_EVENT, &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_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 );
-SignalConnectorType signalConnector11( mType, SIGNAL_CHILD_REMOVED, &Actor::DoConnectSignal );
+SignalConnectorType signalConnector2(mType, std::string(SIGNAL_HOVERED), &Actor::DoConnectSignal);
+SignalConnectorType signalConnector3(mType, std::string(SIGNAL_WHEEL_EVENT), &Actor::DoConnectSignal);
+SignalConnectorType signalConnector4(mType, std::string(SIGNAL_ON_SCENE), &Actor::DoConnectSignal);
+SignalConnectorType signalConnector5(mType, std::string(SIGNAL_OFF_SCENE), &Actor::DoConnectSignal);
+SignalConnectorType signalConnector6(mType, std::string(SIGNAL_ON_RELAYOUT), &Actor::DoConnectSignal);
+SignalConnectorType signalConnector7(mType, std::string(SIGNAL_TOUCHED), &Actor::DoConnectSignal);
+SignalConnectorType signalConnector8(mType, std::string(SIGNAL_VISIBILITY_CHANGED), &Actor::DoConnectSignal);
+SignalConnectorType signalConnector9(mType, std::string(SIGNAL_LAYOUT_DIRECTION_CHANGED), &Actor::DoConnectSignal);
+SignalConnectorType signalConnector10(mType, std::string(SIGNAL_CHILD_ADDED), &Actor::DoConnectSignal);
+SignalConnectorType signalConnector11(mType, std::string(SIGNAL_CHILD_REMOVED), &Actor::DoConnectSignal);
 
-TypeAction a1( mType, ACTION_SHOW, &Actor::DoAction );
-TypeAction a2( mType, ACTION_HIDE, &Actor::DoAction );
+TypeAction a1(mType, std::string(ACTION_SHOW), &Actor::DoAction);
+TypeAction a2(mType, std::string(ACTION_HIDE), &Actor::DoAction);
 
 /**
  * @brief Extract a given dimension from a Vector2
@@ -237,7 +240,7 @@ void EmitVisibilityChangedSignalRecursively( ActorPtr actor, bool visible, Devel
 
     if( actor->GetChildCount() > 0 )
     {
-      for( ActorPtr& child : actor->GetChildrenInternal() )
+      for( auto& child : actor->GetChildrenInternal() )
       {
         EmitVisibilityChangedSignalRecursively( child, visible, DevelActor::VisibilityChange::PARENT );
       }
@@ -515,10 +518,9 @@ ActorPtr Actor::FindChildByName( const std::string& actorName )
   }
   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 )
       {
@@ -538,10 +540,9 @@ ActorPtr Actor::FindChildById( const uint32_t id )
   }
   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 )
       {
@@ -836,6 +837,8 @@ void Actor::SetOpacity( float opacity )
 
   // node is being used in a separate thread; queue a message to set the value & base value
   SceneGraph::NodePropertyComponentMessage<Vector4>::Send( GetEventThreadServices(), &GetNode(), &GetNode().mColor, &AnimatableProperty<Vector4>::BakeW, opacity );
+
+  RequestRenderingMessage( GetEventThreadServices().GetUpdateManager() );
 }
 
 float Actor::GetCurrentOpacity() const
@@ -855,6 +858,8 @@ void Actor::SetColor( const Vector4& color )
 
   // node is being used in a separate thread; queue a message to set the value & base value
   SceneGraph::NodePropertyMessage<Vector4>::Send( GetEventThreadServices(), &GetNode(), &GetNode().mColor, &AnimatableProperty<Vector4>::Bake, color );
+
+  RequestRenderingMessage( GetEventThreadServices().GetUpdateManager() );
 }
 
 void Actor::SetColorRed( float red )
@@ -863,6 +868,8 @@ void Actor::SetColorRed( float red )
 
   // node is being used in a separate thread; queue a message to set the value & base value
   SceneGraph::NodePropertyComponentMessage<Vector4>::Send( GetEventThreadServices(), &GetNode(), &GetNode().mColor, &AnimatableProperty<Vector4>::BakeX, red );
+
+  RequestRenderingMessage( GetEventThreadServices().GetUpdateManager() );
 }
 
 void Actor::SetColorGreen( float green )
@@ -871,6 +878,8 @@ void Actor::SetColorGreen( float green )
 
   // node is being used in a separate thread; queue a message to set the value & base value
   SceneGraph::NodePropertyComponentMessage<Vector4>::Send( GetEventThreadServices(), &GetNode(), &GetNode().mColor, &AnimatableProperty<Vector4>::BakeY, green );
+
+  RequestRenderingMessage( GetEventThreadServices().GetUpdateManager() );
 }
 
 void Actor::SetColorBlue( float blue )
@@ -879,6 +888,8 @@ void Actor::SetColorBlue( float blue )
 
   // node is being used in a separate thread; queue a message to set the value & base value
   SceneGraph::NodePropertyComponentMessage<Vector4>::Send( GetEventThreadServices(), &GetNode(), &GetNode().mColor, &AnimatableProperty<Vector4>::BakeZ, blue );
+
+  RequestRenderingMessage( GetEventThreadServices().GetUpdateManager() );
 }
 
 const Vector4& Actor::GetCurrentColor() const
@@ -1186,6 +1197,12 @@ uint32_t Actor::AddRenderer( Renderer& renderer )
     mRenderers = new RendererContainer;
   }
 
+  if(mIsBlendEquationSet)
+  {
+    renderer.SetBlendMode(Dali::BlendMode::ON);
+    renderer.SetBlendEquation(static_cast<DevelBlendEquation::Type>(mBlendEquation));
+  }
+
   uint32_t index = static_cast<uint32_t>( mRenderers->size() ); //  4,294,967,295 renderers per actor
   RendererPtr rendererPtr = RendererPtr( &renderer );
   mRenderers->push_back( rendererPtr );
@@ -1242,6 +1259,34 @@ void Actor::RemoveRenderer( uint32_t index )
   }
 }
 
+void Actor::SetBlendEquation(DevelBlendEquation::Type blendEquation)
+{
+  if(Dali::Capabilities::IsBlendEquationSupported(blendEquation))
+  {
+    if(mBlendEquation != blendEquation)
+    {
+      mBlendEquation         = blendEquation;
+      uint32_t rendererCount = GetRendererCount();
+      for(uint32_t i = 0; i < rendererCount; ++i)
+      {
+        RendererPtr renderer = GetRendererAt(i);
+        renderer->SetBlendMode(Dali::BlendMode::ON);
+        renderer->SetBlendEquation(static_cast<DevelBlendEquation::Type>(blendEquation));
+      }
+    }
+    mIsBlendEquationSet = true;
+  }
+  else
+  {
+    DALI_LOG_ERROR("Invalid blend equation is entered.\n");
+  }
+}
+
+DevelBlendEquation::Type Actor::GetBlendEquation() const
+{
+  return mBlendEquation;
+}
+
 void Actor::SetDrawMode( DrawMode::Type drawMode )
 {
   // this flag is not animatable so keep the value
@@ -1319,6 +1364,11 @@ bool Actor::IsGestureRequired( GestureType::Value type ) const
   return mGestureData && mGestureData->IsGestureRequired( type );
 }
 
+bool Actor::EmitInterceptTouchEventSignal( const Dali::TouchEvent& touch )
+{
+  return EmitConsumingSignal( *this, mInterceptTouchedSignal, touch );
+}
+
 bool Actor::EmitTouchEventSignal( const Dali::TouchEvent& touch )
 {
   return EmitConsumingSignal( *this, mTouchedSignal, touch );
@@ -1359,43 +1409,45 @@ 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_HOVERED ) )
+  std::string_view name(signalName);
+
+  if(name == SIGNAL_HOVERED)
   {
     actor->HoveredSignal().Connect( tracker, functor );
   }
-  else if( 0 == signalName.compare( SIGNAL_WHEEL_EVENT ) )
+  else if(signalName == SIGNAL_WHEEL_EVENT)
   {
     actor->WheelEventSignal().Connect( tracker, functor );
   }
-  else if( 0 == signalName.compare( SIGNAL_ON_SCENE ) )
+  else if(name == SIGNAL_ON_SCENE)
   {
     actor->OnSceneSignal().Connect( tracker, functor );
   }
-  else if( 0 == signalName.compare( SIGNAL_OFF_SCENE ) )
+  else if(name == SIGNAL_OFF_SCENE)
   {
     actor->OffSceneSignal().Connect( tracker, functor );
   }
-  else if( 0 == signalName.compare( SIGNAL_ON_RELAYOUT ) )
+  else if(name == SIGNAL_ON_RELAYOUT)
   {
     actor->OnRelayoutSignal().Connect( tracker, functor );
   }
-  else if( 0 == signalName.compare( SIGNAL_TOUCHED ) )
+  else if(name == SIGNAL_TOUCHED)
   {
     actor->TouchedSignal().Connect( tracker, functor );
   }
-  else if( 0 == signalName.compare( SIGNAL_VISIBILITY_CHANGED ) )
+  else if(name == SIGNAL_VISIBILITY_CHANGED)
   {
     actor->VisibilityChangedSignal().Connect( tracker, functor );
   }
-  else if( 0 == signalName.compare( SIGNAL_LAYOUT_DIRECTION_CHANGED ) )
+  else if(name == SIGNAL_LAYOUT_DIRECTION_CHANGED)
   {
     actor->LayoutDirectionChangedSignal().Connect( tracker, functor );
   }
-  else if( 0 == signalName.compare( SIGNAL_CHILD_ADDED ) )
+  else if(name == SIGNAL_CHILD_ADDED)
   {
     actor->ChildAddedSignal().Connect( tracker, functor );
   }
-  else if( 0 == signalName.compare( SIGNAL_CHILD_REMOVED ) )
+  else if(name == SIGNAL_CHILD_REMOVED)
   {
     actor->ChildRemovedSignal().Connect( tracker, functor );
   }
@@ -1418,6 +1470,7 @@ Actor::Actor( DerivedType derivedType, const SceneGraph::Node& node )
   mAnchorPoint( nullptr ),
   mRelayoutData( nullptr ),
   mGestureData( nullptr ),
+  mInterceptTouchedSignal(),
   mTouchedSignal(),
   mHoveredSignal(),
   mWheelEventSignal(),
@@ -1435,6 +1488,7 @@ 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 ),
@@ -1457,7 +1511,9 @@ Actor::Actor( DerivedType derivedType, const SceneGraph::Node& node )
   mLayoutDirection( LayoutDirection::LEFT_TO_RIGHT ),
   mDrawMode( DrawMode::NORMAL ),
   mColorMode( Node::DEFAULT_COLOR_MODE ),
-  mClippingMode( ClippingMode::DISABLED )
+  mClippingMode( ClippingMode::DISABLED ),
+  mBlendEquation( DevelBlendEquation::ADD ),
+  mIsBlendEquationSet( false )
 {
 }
 
@@ -1474,10 +1530,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( nullptr );
+      actor->SetParent( nullptr );
     }
   }
   delete mChildren;
@@ -1521,10 +1576,9 @@ void Actor::ConnectToScene( uint32_t parentDepth )
   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();
@@ -1548,11 +1602,10 @@ void Actor::RecursiveConnectToScene( 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)->RecursiveConnectToScene( connectionList, depth + 1 );
+      actor->SetScene( *mScene );
+      actor->RecursiveConnectToScene( connectionList, depth + 1 );
     }
   }
 }
@@ -1615,10 +1668,9 @@ 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();
   }
 }
 
@@ -1630,10 +1682,9 @@ void Actor::RecursiveDisconnectFromStage( ActorContainer& disconnectionList )
   // 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 );
     }
   }
 
@@ -1724,9 +1775,9 @@ void Actor::DepthTraverseActorTree( OwnerPointer<SceneGraph::NodeDepths>& 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 );
     }
@@ -1859,12 +1910,13 @@ bool Actor::DoAction( BaseObject* object, const std::string& actionName, const P
 
   if( actor )
   {
-    if( 0 == actionName.compare( ACTION_SHOW ) )
+    std::string_view name(actionName);
+    if(name == ACTION_SHOW)
     {
       actor->SetVisible( true );
       done = true;
     }
-    else if( 0 == actionName.compare( ACTION_HIDE ) )
+    else if(name == ACTION_HIDE)
     {
       actor->SetVisible( false );
       done = true;
@@ -2225,9 +2277,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;
@@ -2492,6 +2544,8 @@ void Actor::SetVisibleInternal( bool visible, SendMessage::Type sendMessage )
     {
       // node is being used in a separate thread; queue a message to set the value & base value
       SceneGraph::NodePropertyMessage<bool>::Send( GetEventThreadServices(), &GetNode(), &GetNode().mVisible, &AnimatableProperty<bool>::Bake, visible );
+
+      RequestRenderingMessage( GetEventThreadServices().GetUpdateManager() );
     }
 
     mVisible = visible;
@@ -2633,7 +2687,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);
@@ -2661,7 +2715,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);
@@ -2689,8 +2743,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);
@@ -2722,8 +2776,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 )
       {
@@ -2769,7 +2823,7 @@ void Actor::InheritLayoutDirectionRecursively( ActorPtr actor, Dali::LayoutDirec
 
     if( actor->GetChildCount() > 0 )
     {
-      for( ActorPtr& child : actor->GetChildrenInternal() )
+      for( const auto& child : actor->GetChildrenInternal() )
       {
         InheritLayoutDirectionRecursively( child, direction );
       }