Add Control::GetBackgroudColor() implementation 11/54911/4
authorXiangyin Ma <x1.ma@samsung.com>
Fri, 18 Dec 2015 14:00:03 +0000 (14:00 +0000)
committerXiangyin Ma <x1.ma@samsung.com>
Fri, 18 Dec 2015 15:39:23 +0000 (15:39 +0000)
Change-Id: If6cce8812d0ff68c7ed263796ca098460c89b905

automated-tests/src/dali-toolkit/utc-Dali-Control.cpp
dali-toolkit/public-api/controls/control-impl.cpp
dali-toolkit/public-api/controls/control-impl.h
dali-toolkit/public-api/controls/control.h

index 9f220de..de50f8c 100644 (file)
@@ -400,6 +400,8 @@ int UtcDaliControlBackgroundColor(void)
   DALI_TEST_CHECK( resultMap->Find( "blendColor" ) );
   DALI_TEST_CHECK( resultMap->Find( "blendColor" )->Get<Vector4>() == Color::RED );
 
+  DALI_TEST_EQUALS( control.GetBackgroundColor(), Color::RED, TEST_LOCATION );
+
   control.SetBackgroundColor( Color::YELLOW );
 
   propValue = control.GetProperty( Control::Property::BACKGROUND );
@@ -407,6 +409,8 @@ int UtcDaliControlBackgroundColor(void)
   DALI_TEST_CHECK( resultMap->Find( "blendColor" ) );
   DALI_TEST_CHECK( resultMap->Find( "blendColor" )->Get<Vector4>() == Color::YELLOW );
 
+  DALI_TEST_EQUALS( control.GetBackgroundColor(), Color::YELLOW, TEST_LOCATION );
+
   END_TEST;
 }
 
index 649946c..b41b630 100644 (file)
@@ -40,7 +40,6 @@
 #include <dali-toolkit/devel-api/styling/style-manager.h>
 #include <dali-toolkit/internal/styling/style-manager-impl.h>
 #include <dali-toolkit/internal/controls/renderers/color/color-renderer.h>
-#include <dali-toolkit/internal/controls/renderers/image/image-renderer.h>
 
 namespace Dali
 {
@@ -165,6 +164,7 @@ TypeAction registerAction( typeRegistration, ACTION_ACCESSIBILITY_ACTIVATED, &Do
 DALI_TYPE_REGISTRATION_END()
 
 const char * const BACKGROUND_COLOR_NAME("color");
+const char * const COLOR_RENDERER_COLOR_NAME("blendColor");
 
 } // unnamed namespace
 
@@ -399,42 +399,28 @@ const std::string& Control::GetStyleName() const
   return mImpl->mStyleName;
 }
 
-void Control::UpdateBackgroundState()
-{
-  // Set the depth of the background renderer after creating/modifying it.
-  // We do this regardless of whether or not it is on stage as the index
-  // is relative and still valid if this control is re-parented.
-  if( mImpl->mBackgroundRenderer )
-  {
-    mImpl->mBackgroundRenderer.SetDepthIndex( BACKGROUND_DEPTH_INDEX );
-
-    Actor self( Self() );
-    if( self.OnStage() )
-    {
-      mImpl->mBackgroundRenderer.SetOnStage( self );
-    }
-  }
-}
-
 void Control::SetBackgroundColor( const Vector4& color )
 {
   Actor self( Self() );
   Toolkit::RendererFactory factory = Toolkit::RendererFactory::Get();
-
-  if( mImpl->mBackgroundRenderer )
-  {
-    factory.ResetRenderer( mImpl->mBackgroundRenderer, self, color );
-  }
-  else
-  {
-    mImpl->mBackgroundRenderer = factory.GetControlRenderer( color );
-  }
-
-  UpdateBackgroundState();
+  factory.ResetRenderer( mImpl->mBackgroundRenderer, self, color );
+  mImpl->mBackgroundRenderer.SetDepthIndex( BACKGROUND_DEPTH_INDEX );
 }
 
 Vector4 Control::GetBackgroundColor() const
 {
+  if( mImpl->mBackgroundRenderer && ( &typeid( GetImplementation(mImpl->mBackgroundRenderer) ) == &typeid( ColorRenderer ) ) )
+  {
+     Property::Map map;
+     mImpl->mBackgroundRenderer.CreatePropertyMap( map );
+     const Property::Value* colorValue = map.Find( COLOR_RENDERER_COLOR_NAME );
+     Vector4 color;
+     if( colorValue && colorValue->Get(color))
+     {
+       return color;
+     }
+  }
+
   return Color::TRANSPARENT;
 }
 
@@ -450,28 +436,21 @@ void Control::SetBackground(const Property::Map& map)
 
   Actor self( Self() );
   mImpl->mBackgroundRenderer.RemoveAndReset( self );
-
   Toolkit::RendererFactory factory = Toolkit::RendererFactory::Get();
   mImpl->mBackgroundRenderer = factory.GetControlRenderer( map );
-
-  UpdateBackgroundState();
+  if( mImpl->mBackgroundRenderer  && self.OnStage() ) // Request control renderer with a property map might return an empty handle
+  {
+    mImpl->mBackgroundRenderer.SetDepthIndex( BACKGROUND_DEPTH_INDEX );
+    mImpl->mBackgroundRenderer.SetOnStage( self );
+  }
 }
 
 void Control::SetBackgroundImage( Image image )
 {
   Actor self( Self() );
   Toolkit::RendererFactory factory = Toolkit::RendererFactory::Get();
-
-  if(  mImpl->mBackgroundRenderer  )
-  {
-    factory.ResetRenderer( mImpl->mBackgroundRenderer, self, image );
-  }
-  else
-  {
-    mImpl->mBackgroundRenderer = factory.GetControlRenderer( image );
-  }
-
-  UpdateBackgroundState();
+  factory.ResetRenderer( mImpl->mBackgroundRenderer, self, image );
+  mImpl->mBackgroundRenderer.SetDepthIndex( BACKGROUND_DEPTH_INDEX );
 }
 
 void Control::ClearBackground()
index c6b3b5e..aa86d6a 100644 (file)
@@ -268,15 +268,6 @@ public:
    */
   DALI_INTERNAL bool EmitKeyEventSignal( const KeyEvent& event );
 
-private:
-
-  /**
-   * Sets up the background image/color based on the current state.
-   * This will set the depth index (always), and add to stage if the control is on stage.
-   *
-   */
-  void UpdateBackgroundState();
-
 protected: // For derived classes to call
 
   /**
index 9afebab..6d6ca11 100644 (file)
@@ -261,6 +261,8 @@ public:
   /**
    * @brief Sets the background color of the control.
    *
+   * @note if SetBackgroundImage is called later, this background color is removed.
+   *
    * @param[in] color The required background color of the control
    *
    * @note The background color fully blends with the actor color.