Add property SHADOW to Control
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / public-api / controls / control-impl.cpp
index df78b15..46f24d8 100755 (executable)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017 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.
@@ -129,46 +129,6 @@ void CreateClippingRenderer( Control& controlImpl )
   }
 }
 
-/**
- * @brief Sets Control::Property::BACKGROUND visual
- * @param[in] controlImpl The control implementation
- * @param[in] visual The control background visual
- * @param[in] size The current size
- */
-void SetBackgroundVisual( Control::Impl& controlImpl, Toolkit::Visual::Base& visual, const Vector2& size )
-{
-  Property::Map transformMap = Property::Map();
-
-  Vector2 newSize( 0.f, 0.f );
-  newSize.width = size.width + ( controlImpl.mPadding.start + controlImpl.mPadding.end );
-  newSize.height = size.height + ( controlImpl.mPadding.top + controlImpl.mPadding.bottom );
-
-  if( ( controlImpl.mMargin.start != 0 ) ||
-      ( controlImpl.mMargin.end != 0 ) ||
-      ( controlImpl.mMargin.top != 0 ) ||
-      ( controlImpl.mMargin.bottom != 0 ) )
-  {
-    transformMap.Add( Toolkit::Visual::Transform::Property::SIZE, newSize )
-                .Add( Toolkit::Visual::Transform::Property::SIZE_POLICY, Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ) )
-                .Add( Toolkit::Visual::Transform::Property::OFFSET, Vector2( controlImpl.mMargin.start, controlImpl.mMargin.top ) )
-                .Add( Toolkit::Visual::Transform::Property::OFFSET_POLICY, Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ) )
-                .Add( Toolkit::Visual::Transform::Property::ORIGIN, Toolkit::Align::TOP_BEGIN )
-                .Add( Toolkit::Visual::Transform::Property::ANCHOR_POINT, Toolkit::Align::TOP_BEGIN );
-  }
-  else if( ( controlImpl.mPadding.start != 0 ) ||
-           ( controlImpl.mPadding.end != 0 ) ||
-           ( controlImpl.mPadding.top != 0 ) ||
-           ( controlImpl.mPadding.bottom != 0 ) )
-  {
-    transformMap.Add( Toolkit::Visual::Transform::Property::SIZE, newSize )
-                .Add( Toolkit::Visual::Transform::Property::SIZE_POLICY, Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ) )
-                .Add( Toolkit::Visual::Transform::Property::ORIGIN, Toolkit::Align::TOP_BEGIN )
-                .Add( Toolkit::Visual::Transform::Property::ANCHOR_POINT, Toolkit::Align::TOP_BEGIN );
-  }
-
-  visual.SetTransformAndSize( transformMap, newSize ); // Send an empty map as we do not want to modify the visual's set transform
-}
-
 } // unnamed namespace
 
 
@@ -225,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 );
@@ -243,24 +198,37 @@ void Control::SetBackground( const Property::Map& map )
   }
 }
 
-void Control::SetBackgroundImage( Image image )
+void Control::ClearBackground()
+{
+   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( image );
+  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 )
@@ -613,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();
@@ -659,8 +631,7 @@ void Control::OnSizeSet(const Vector3& targetSize)
   if( visual )
   {
     Vector2 size( targetSize );
-    SetBackgroundVisual( *mImpl, visual, size );
-
+    visual.SetTransformAndSize( Property::Map(), size ); // Send an empty map as we do not want to modify the visual's set transform
   }
 }
 
@@ -721,14 +692,13 @@ void Control::OnRelayout( const Vector2& size, RelayoutContainer& container )
 
       child.SetPosition( childOffset.x, childOffset.y );
     }
-
     container.Add( child, newChildSize );
   }
 
   Toolkit::Visual::Base visual = mImpl->GetVisual( Toolkit::Control::Property::BACKGROUND );
   if( visual )
   {
-    SetBackgroundVisual( *mImpl, visual, size );
+    visual.SetTransformAndSize( Property::Map(), size ); // Send an empty map as we do not want to modify the visual's set transform
   }
 }
 
@@ -738,6 +708,7 @@ void Control::OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dime
 
 Vector3 Control::GetNaturalSize()
 {
+  DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::GetNaturalSize for %s\n", Self().GetName().c_str() );
   Toolkit::Visual::Base visual = mImpl->GetVisual( Toolkit::Control::Property::BACKGROUND );
   if( visual )
   {