From: Adeel Kazmi Date: Fri, 5 Nov 2021 09:57:57 +0000 (+0000) Subject: Merge "Move ModelUpdating method outside of Text::Controller::Impl class to reduce... X-Git-Tag: dali_2.0.52~7 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=commitdiff_plain;h=4bade9d33a0c2ddd5904356b780ea92385b3fe0b;hp=416cce959ca385d6fbc014ffa169c35b82cac85f Merge "Move ModelUpdating method outside of Text::Controller::Impl class to reduce LOC" into devel/master --- diff --git a/dali-toolkit/internal/visuals/text/text-visual.cpp b/dali-toolkit/internal/visuals/text/text-visual.cpp index 19ecb5c..a4903c5 100644 --- a/dali-toolkit/internal/visuals/text/text-visual.cpp +++ b/dali-toolkit/internal/visuals/text/text-visual.cpp @@ -23,7 +23,6 @@ #include #include #include -#include #include // INTERNAL HEADER @@ -240,6 +239,7 @@ TextVisual::TextVisual(VisualFactoryCache& factoryCache) mController(Text::Controller::New()), mTypesetter(Text::Typesetter::New(mController->GetTextModel())), mAnimatableTextColorPropertyIndex(Property::INVALID_INDEX), + mTextColorAnimatableIndex(Property::INVALID_INDEX), mRendererUpdateNeeded(false) { } @@ -291,23 +291,36 @@ void TextVisual::DoSetOnScene(Actor& actor) // Enable the pre-multiplied alpha to improve the text quality EnablePreMultipliedAlpha(true); - const Vector4& defaultColor = mController->GetTextModel()->GetDefaultColor(); - Dali::Property::Index shaderTextColorIndex = mImpl->mRenderer.RegisterProperty("uTextColorAnimatable", defaultColor); + const Vector4& defaultColor = mController->GetTextModel()->GetDefaultColor(); + if(mTextColorAnimatableIndex == Property::INVALID_INDEX) + { + mTextColorAnimatableIndex = mImpl->mRenderer.RegisterProperty("uTextColorAnimatable", defaultColor); + } + else + { + mImpl->mRenderer.SetProperty(mTextColorAnimatableIndex, defaultColor); + } if(mAnimatableTextColorPropertyIndex != Property::INVALID_INDEX) { // Create constraint for the animatable text's color Property with uTextColorAnimatable in the renderer. - if(shaderTextColorIndex != Property::INVALID_INDEX) + if(mTextColorAnimatableIndex != Property::INVALID_INDEX) { - Constraint colorConstraint = Constraint::New(mImpl->mRenderer, shaderTextColorIndex, TextColorConstraint); - colorConstraint.AddSource(Source(actor, mAnimatableTextColorPropertyIndex)); - colorConstraint.Apply(); - - // Make zero if the alpha value of text color is zero to skip rendering text - Constraint opacityConstraint = Constraint::New(mImpl->mRenderer, Dali::DevelRenderer::Property::OPACITY, OpacityConstraint); - opacityConstraint.AddSource(Source(actor, mAnimatableTextColorPropertyIndex)); - opacityConstraint.Apply(); + if(!mColorConstraint) + { + mColorConstraint = Constraint::New(mImpl->mRenderer, mTextColorAnimatableIndex, TextColorConstraint); + mColorConstraint.AddSource(Source(actor, mAnimatableTextColorPropertyIndex)); + } + mColorConstraint.Apply(); } + + // Make zero if the alpha value of text color is zero to skip rendering text + if(!mOpacityConstraint) + { + mOpacityConstraint = Constraint::New(mImpl->mRenderer, Dali::DevelRenderer::Property::OPACITY, OpacityConstraint); + mOpacityConstraint.AddSource(Source(actor, mAnimatableTextColorPropertyIndex)); + } + mOpacityConstraint.Apply(); } // Renderer needs textures and to be added to control @@ -335,6 +348,15 @@ void TextVisual::RemoveRenderer(Actor& actor) void TextVisual::DoSetOffScene(Actor& actor) { + if(mColorConstraint) + { + mColorConstraint.Remove(); + } + if(mOpacityConstraint) + { + mOpacityConstraint.Remove(); + } + RemoveRenderer(actor); // Resets the control handle. diff --git a/dali-toolkit/internal/visuals/text/text-visual.h b/dali-toolkit/internal/visuals/text/text-visual.h index 7ae5e4e..f9d6c79 100644 --- a/dali-toolkit/internal/visuals/text/text-visual.h +++ b/dali-toolkit/internal/visuals/text/text-visual.h @@ -19,6 +19,7 @@ */ // EXTERNAL INCLUDES +#include #include #include @@ -332,7 +333,10 @@ private: Text::ControllerPtr mController; ///< The text's controller. Text::TypesetterPtr mTypesetter; ///< The text's typesetter. WeakHandle mControl; ///< The control where the renderer is added. + Constraint mColorConstraint{}; ///< Color constraint + Constraint mOpacityConstraint{}; ///< Opacity constraint Property::Index mAnimatableTextColorPropertyIndex; ///< The index of animatable text color property registered by the control. + Property::Index mTextColorAnimatableIndex; ///< The index of uTextColorAnimatable property. bool mRendererUpdateNeeded : 1; ///< The flag to indicate whether the renderer needs to be updated. RendererContainer mRendererList; };