From: Xiangyin Ma Date: Fri, 18 Dec 2015 14:00:03 +0000 (+0000) Subject: Add Control::GetBackgroudColor() implementation X-Git-Tag: dali_1.1.15~1 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=commitdiff_plain;h=12ba8f6537fee9e4ad8c4fc11bbbea01691833b2;ds=sidebyside Add Control::GetBackgroudColor() implementation Change-Id: If6cce8812d0ff68c7ed263796ca098460c89b905 --- diff --git a/automated-tests/src/dali-toolkit/utc-Dali-Control.cpp b/automated-tests/src/dali-toolkit/utc-Dali-Control.cpp index 9f220de..de50f8c 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-Control.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-Control.cpp @@ -400,6 +400,8 @@ int UtcDaliControlBackgroundColor(void) DALI_TEST_CHECK( resultMap->Find( "blendColor" ) ); DALI_TEST_CHECK( resultMap->Find( "blendColor" )->Get() == 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() == Color::YELLOW ); + DALI_TEST_EQUALS( control.GetBackgroundColor(), Color::YELLOW, TEST_LOCATION ); + END_TEST; } diff --git a/dali-toolkit/public-api/controls/control-impl.cpp b/dali-toolkit/public-api/controls/control-impl.cpp index 649946c..b41b630 100644 --- a/dali-toolkit/public-api/controls/control-impl.cpp +++ b/dali-toolkit/public-api/controls/control-impl.cpp @@ -40,7 +40,6 @@ #include #include #include -#include 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() diff --git a/dali-toolkit/public-api/controls/control-impl.h b/dali-toolkit/public-api/controls/control-impl.h index c6b3b5e..aa86d6a 100644 --- a/dali-toolkit/public-api/controls/control-impl.h +++ b/dali-toolkit/public-api/controls/control-impl.h @@ -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 /** diff --git a/dali-toolkit/public-api/controls/control.h b/dali-toolkit/public-api/controls/control.h index 9afebab..6d6ca11 100644 --- a/dali-toolkit/public-api/controls/control.h +++ b/dali-toolkit/public-api/controls/control.h @@ -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.