Add property SHADOW to Control
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / public-api / controls / control-impl.cpp
index 8f862f5..46f24d8 100755 (executable)
@@ -1,5 +1,5 @@
 /*
- * 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.
@@ -185,11 +185,6 @@ void Control::SetBackgroundColor( const Vector4& color )
   SetBackground( map );
 }
 
-Vector4 Control::GetBackgroundColor() const
-{
-  return mImpl->mBackgroundColor;
-}
-
 void Control::SetBackground( const Property::Map& map )
 {
   Toolkit::Visual::Base visual = Toolkit::VisualFactory::Get().CreateVisual( map );
@@ -203,24 +198,37 @@ void Control::SetBackground( const Property::Map& map )
   }
 }
 
-void Control::SetBackgroundImage( Image image )
+void Control::ClearBackground()
 {
-  Toolkit::Visual::Base visual = Toolkit::VisualFactory::Get().CreateVisual( image );
+   mImpl->UnregisterVisual( Toolkit::Control::Property::BACKGROUND );
+   mImpl->mBackgroundColor = Color::TRANSPARENT;
+
+   // Trigger a size negotiation request that may be needed when unregistering a visual.
+   RelayoutRequest();
+}
+
+void Control::SetShadow( const Property::Map& map )
+{
+  Toolkit::Visual::Base visual = Toolkit::VisualFactory::Get().CreateVisual( map );
+  visual.SetName("shadow");
+
   if( visual )
   {
-    mImpl->RegisterVisual( Toolkit::Control::Property::BACKGROUND, visual, DepthIndex::BACKGROUND );
+    mImpl->RegisterVisual( Toolkit::DevelControl::Property::SHADOW, visual, DepthIndex::BACKGROUND_EFFECT );
+
+    RelayoutRequest();
   }
 }
 
-void Control::ClearBackground()
+void Control::ClearShadow()
 {
-   mImpl->UnregisterVisual( Toolkit::Control::Property::BACKGROUND );
-   mImpl->mBackgroundColor = Color::TRANSPARENT;
+   mImpl->UnregisterVisual( Toolkit::DevelControl::Property::SHADOW );
 
    // Trigger a size negotiation request that may be needed when unregistering a visual.
    RelayoutRequest();
 }
 
+
 void Control::EnableGestureDetection(Gesture::Type type)
 {
   if ( (type & Gesture::Pinch) && !mImpl->mPinchGestureDetector )
@@ -573,8 +581,12 @@ void Control::OnStageConnection( int depth )
 
   // The clipping renderer is only created if required.
   CreateClippingRenderer( *this );
+
+  // Request to be laid out when the control is connected to the Stage.
+  // Signal that a Relayout may be needed
 }
 
+
 void Control::OnStageDisconnection()
 {
   mImpl->OnStageDisconnection();
@@ -655,44 +667,32 @@ void Control::OnRelayout( const Vector2& size, RelayoutContainer& container )
     Actor child = Self().GetChildAt( i );
     Vector2 newChildSize( size );
 
-    // When setting the padding or margin on the control child should be resized and repositioned for legacy reasons.
+    // When set the padding or margin on the control, child should be resized and repositioned.
     if( ( mImpl->mPadding.start != 0 ) || ( mImpl->mPadding.end != 0 ) || ( mImpl->mPadding.top != 0 ) || ( mImpl->mPadding.bottom != 0 ) ||
         ( mImpl->mMargin.start != 0 ) || ( mImpl->mMargin.end != 0 ) || ( mImpl->mMargin.top != 0 ) || ( mImpl->mMargin.bottom != 0 ) )
     {
-      // Cannot use childs Position property as it can already have margin applied on it,
-      // so we end up cumulatively applying them over and over again.
-      Toolkit::Control childControl = Toolkit::Control::DownCast( child );
-
-      // If control not a LayoutItem layout then must be the old Relayout algorithm hence account
-      // for margins and padding.
-      // Padding is incorrect but may have to keep this functionality for compatibility.
-      if ( childControl && ! Toolkit::DevelControl::GetLayout( childControl ) )
-      {
-        Extents padding = mImpl->mPadding;
+      Extents padding = mImpl->mPadding;
 
-        Dali::CustomActor ownerActor(GetOwner());
-        Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( ownerActor.GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
+      Dali::CustomActor ownerActor(GetOwner());
+      Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( ownerActor.GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
 
-        if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection )
-        {
-          std::swap( padding.start, padding.end );
-        }
+      if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection )
+      {
+        std::swap( padding.start, padding.end );
+      }
 
-        // Child size should include padding, this is the wrong use of padding but kept for compatibility.
-        newChildSize.width = size.width - ( padding.start + padding.end );
-        newChildSize.height = size.height - ( padding.top + padding.bottom );
+      newChildSize.width = size.width - ( padding.start + padding.end );
+      newChildSize.height = size.height - ( padding.top + padding.bottom );
 
-        // Cannot use childs Position property as it can already have padding and margin applied on it,
-        // so we end up cumulatively applying them over and over again.
-        Vector2 childOffset( 0.f, 0.f );
-        childOffset.x += ( mImpl->mMargin.start + padding.start );
-        childOffset.y += ( mImpl->mMargin.top + padding.top );
+      // Cannot use childs Position property as it can already have padding and margin applied on it,
+      // so we end up cumulatively applying them over and over again.
+      Vector2 childOffset( 0.f, 0.f );
+      childOffset.x += ( mImpl->mMargin.start + padding.start );
+      childOffset.y += ( mImpl->mMargin.top + padding.top );
 
-        child.SetPosition( childOffset.x, childOffset.y );
-      }
+      child.SetPosition( childOffset.x, childOffset.y );
     }
-
-    container.Add( child, size );
+    container.Add( child, newChildSize );
   }
 
   Toolkit::Visual::Base visual = mImpl->GetVisual( Toolkit::Control::Property::BACKGROUND );