From: Tom Robinson Date: Wed, 18 Nov 2015 10:33:03 +0000 (+0000) Subject: Control not always rendering background image depending on add order X-Git-Tag: dali_1.1.11~6 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=commitdiff_plain;h=421d28ac0c56bca53a4c187983de6c20b56957c5;hp=18644a10e91e667563734dfa9fa8be6b85ffdc51 Control not always rendering background image depending on add order Change-Id: Ie16a55fd59278d65f8665994972cb90708a4891e --- diff --git a/dali-toolkit/public-api/controls/control-impl.cpp b/dali-toolkit/public-api/controls/control-impl.cpp index b37b4fb..649946c 100644 --- a/dali-toolkit/public-api/controls/control-impl.cpp +++ b/dali-toolkit/public-api/controls/control-impl.cpp @@ -399,6 +399,23 @@ 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() ); @@ -411,13 +428,9 @@ void Control::SetBackgroundColor( const Vector4& color ) else { mImpl->mBackgroundRenderer = factory.GetControlRenderer( color ); - - if( self.OnStage() ) - { - mImpl->mBackgroundRenderer.SetDepthIndex( BACKGROUND_DEPTH_INDEX ); - mImpl->mBackgroundRenderer.SetOnStage( self ); - } } + + UpdateBackgroundState(); } Vector4 Control::GetBackgroundColor() const @@ -441,12 +454,7 @@ void Control::SetBackground(const Property::Map& map) Toolkit::RendererFactory factory = Toolkit::RendererFactory::Get(); mImpl->mBackgroundRenderer = factory.GetControlRenderer( map ); - // mBackgroundRenderer might be empty, if an invalid map is provided, no background. - if( self.OnStage() && mImpl->mBackgroundRenderer) - { - mImpl->mBackgroundRenderer.SetDepthIndex( BACKGROUND_DEPTH_INDEX ); - mImpl->mBackgroundRenderer.SetOnStage( self ); - } + UpdateBackgroundState(); } void Control::SetBackgroundImage( Image image ) @@ -461,13 +469,9 @@ void Control::SetBackgroundImage( Image image ) else { mImpl->mBackgroundRenderer = factory.GetControlRenderer( image ); - - if( self.OnStage() ) - { - mImpl->mBackgroundRenderer.SetDepthIndex( BACKGROUND_DEPTH_INDEX ); - mImpl->mBackgroundRenderer.SetOnStage( self ); - } } + + UpdateBackgroundState(); } void Control::ClearBackground() @@ -798,17 +802,16 @@ void Control::OnStageConnection( int depth ) { if( mImpl->mBackgroundRenderer) { - mImpl->mBackgroundRenderer.SetDepthIndex( BACKGROUND_DEPTH_INDEX ); - Actor self(Self()); + Actor self( Self() ); mImpl->mBackgroundRenderer.SetOnStage( self ); } } void Control::OnStageDisconnection() { - if( mImpl->mBackgroundRenderer) + if( mImpl->mBackgroundRenderer ) { - Actor self(Self()); + Actor self( Self() ); mImpl->mBackgroundRenderer.SetOffStage( self ); } } diff --git a/dali-toolkit/public-api/controls/control-impl.h b/dali-toolkit/public-api/controls/control-impl.h index aa86d6a..c6b3b5e 100644 --- a/dali-toolkit/public-api/controls/control-impl.h +++ b/dali-toolkit/public-api/controls/control-impl.h @@ -268,6 +268,15 @@ 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 /**