From a705c754f9d19640969ed75213884756e764a465 Mon Sep 17 00:00:00 2001 From: Victor Cebollada Date: Tue, 30 Jun 2015 11:22:04 +0100 Subject: [PATCH] Stop doing unparent and reset in text decorator. * Fixes the text's popup performance issue. * Lays out the highlight text behind the text. * Fixes the highlight color. Change-Id: I65a1d5509117f33b6e77bcb2fa2517bb1cd42ff3 Signed-off-by: Victor Cebollada --- .../src/dali-toolkit/utc-Dali-TextField.cpp | 2 +- .../text-controls/text-selection-popup.cpp | 5 + .../controls/text-controls/text-selection-popup.h | 7 + .../text-controls/text-selection-toolbar.cpp | 5 + .../text-controls/text-selection-toolbar.h | 7 + .../controls/text-controls/text-field-impl.cpp | 36 ++- .../controls/text-controls/text-field-impl.h | 1 - .../controls/text-controls/text-label-impl.cpp | 11 +- .../controls/text-controls/text-label-impl.h | 1 - .../text-controls/text-selection-popup-impl.cpp | 29 ++- .../text-controls/text-selection-popup-impl.h | 10 + .../text-controls/text-selection-toolbar-impl.cpp | 50 +++- .../text-controls/text-selection-toolbar-impl.h | 30 ++- .../internal/text/decorator/text-decorator.cpp | 259 +++++++++++++-------- .../internal/text/decorator/text-decorator.h | 7 + .../text/rendering/atlas/text-atlas-renderer.cpp | 13 +- .../text/rendering/atlas/text-atlas-renderer.h | 2 +- .../internal/text/rendering/text-renderer.h | 2 +- 18 files changed, 334 insertions(+), 143 deletions(-) diff --git a/automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp b/automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp index 8597e4b..7e6b21e 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp @@ -75,7 +75,7 @@ const char* const PROPERTY_NAME_INPUT_METHOD_SETTINGS = "input-me const unsigned int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND; const Vector4 PLACEHOLDER_TEXT_COLOR( 0.8f, 0.8f, 0.8f, 0.8f ); -const Dali::Vector4 LIGHT_BLUE( (0xb2 / 255.0f), (0xeb / 255.0f), (0xf2 / 255.0f), 0.5f ); // The text highlight color. +const Dali::Vector4 LIGHT_BLUE( 0.75f, 0.96f, 1.f, 1.f ); // The text highlight color. const unsigned int CURSOR_BLINK_INTERVAL = 500u; // Cursor blink interval const float TO_MILLISECONDS = 1000.f; diff --git a/dali-toolkit/devel-api/controls/text-controls/text-selection-popup.cpp b/dali-toolkit/devel-api/controls/text-controls/text-selection-popup.cpp index 5b85fac..ec3ad65 100644 --- a/dali-toolkit/devel-api/controls/text-controls/text-selection-popup.cpp +++ b/dali-toolkit/devel-api/controls/text-controls/text-selection-popup.cpp @@ -63,6 +63,11 @@ TextSelectionPopup TextSelectionPopup::DownCast( BaseHandle handle ) return Control::DownCast(handle); } +void TextSelectionPopup::RaiseAbove( Layer target ) +{ + GetImpl(*this).RaiseAbove( target ); +} + TextSelectionPopup::TextSelectionPopup( Internal::TextSelectionPopup& implementation ) : Control(implementation) { diff --git a/dali-toolkit/devel-api/controls/text-controls/text-selection-popup.h b/dali-toolkit/devel-api/controls/text-controls/text-selection-popup.h index 3d6d5d0..8608891 100644 --- a/dali-toolkit/devel-api/controls/text-controls/text-selection-popup.h +++ b/dali-toolkit/devel-api/controls/text-controls/text-selection-popup.h @@ -136,6 +136,13 @@ public: */ static TextSelectionPopup DownCast( BaseHandle handle ); + /** + * @brief Raises the toolbar's layer above the given @e target layer. + * + * @param[in] target The layer to get above of. + */ + void RaiseAbove( Layer target ); + public: // Not intended for application developers /** diff --git a/dali-toolkit/devel-api/controls/text-controls/text-selection-toolbar.cpp b/dali-toolkit/devel-api/controls/text-controls/text-selection-toolbar.cpp index 453b12d..df103cf 100644 --- a/dali-toolkit/devel-api/controls/text-controls/text-selection-toolbar.cpp +++ b/dali-toolkit/devel-api/controls/text-controls/text-selection-toolbar.cpp @@ -72,6 +72,11 @@ void TextSelectionToolbar::ResizeDividers( Size& size ) GetImpl(*this).ResizeDividers( size ); } +void TextSelectionToolbar::RaiseAbove( Layer target ) +{ + GetImpl(*this).RaiseAbove( target ); +} + TextSelectionToolbar TextSelectionToolbar::DownCast( BaseHandle handle ) { return Control::DownCast(handle); diff --git a/dali-toolkit/devel-api/controls/text-controls/text-selection-toolbar.h b/dali-toolkit/devel-api/controls/text-controls/text-selection-toolbar.h index 31fca5c..d0c5976 100644 --- a/dali-toolkit/devel-api/controls/text-controls/text-selection-toolbar.h +++ b/dali-toolkit/devel-api/controls/text-controls/text-selection-toolbar.h @@ -119,6 +119,13 @@ public: void ResizeDividers( Size& size ); /** + * @brief Raises the layer above the given @e target layer. + * + * @param[in] target The layer to get above of. + */ + void RaiseAbove( Layer target ); + + /** * @brief Downcast a handle to TextSelectionToolbar. * * If the BaseHandle points is a TextSelectionToolbar the downcast returns a valid handle. diff --git a/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp b/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp index 991848b..598edb0 100644 --- a/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp @@ -938,10 +938,11 @@ void TextField::OnRelayout( const Vector2& size, RelayoutContainer& container ) void TextField::RenderText() { + Actor self = Self(); Actor renderableActor; if( mRenderer ) { - renderableActor = mRenderer->Render( mController->GetView(), mDepth ); + renderableActor = mRenderer->Render( mController->GetView(), self.GetHierarchyDepth() ); } if( renderableActor != mRenderableActor ) @@ -956,14 +957,10 @@ void TextField::RenderText() mRenderableActor.SetPosition( offset.x, offset.y ); - // Make sure the actor is parented correctly with/without clipping + Actor clipRootActor; if( mClipper ) { - mClipper->GetRootActor().Add( mRenderableActor ); - } - else - { - Self().Add( mRenderableActor ); + clipRootActor = mClipper->GetRootActor(); } for( std::vector::const_iterator it = mClippingDecorationActors.begin(), @@ -973,16 +970,26 @@ void TextField::RenderText() { Actor actor = *it; - if( mClipper ) + if( clipRootActor ) { - mClipper->GetRootActor().Add( actor ); + clipRootActor.Add( actor ); } else { - Self().Add( actor ); + self.Add( actor ); } } mClippingDecorationActors.clear(); + + // Make sure the actor is parented correctly with/without clipping + if( clipRootActor ) + { + clipRootActor.Add( mRenderableActor ); + } + else + { + self.Add( mRenderableActor ); + } } } @@ -1187,7 +1194,13 @@ void TextField::KeyboardStatusChanged(bool keyboardShown) void TextField::OnStageConnection( int depth ) { - mDepth = depth; + // Call the Control::OnStageConnection() to set the depth of the background. + Control::OnStageConnection( depth ); + + // Sets the depth to the renderers inside the text's decorator. + mDecorator->SetTextDepth( depth ); + + // The depth of the text renderer is set in the RenderText() called from OnRelayout(). } bool TextField::OnTouched( Actor actor, const TouchEvent& event ) @@ -1199,7 +1212,6 @@ TextField::TextField() : Control( ControlBehaviour( REQUIRES_STYLE_CHANGE_SIGNALS ) ), mRenderingBackend( DEFAULT_RENDERING_BACKEND ), mExceedPolicy( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP ), - mDepth( 0 ), mHasBeenStaged( false ) { } diff --git a/dali-toolkit/internal/controls/text-controls/text-field-impl.h b/dali-toolkit/internal/controls/text-controls/text-field-impl.h index b1150ff..e275980 100644 --- a/dali-toolkit/internal/controls/text-controls/text-field-impl.h +++ b/dali-toolkit/internal/controls/text-controls/text-field-impl.h @@ -248,7 +248,6 @@ private: // Data int mRenderingBackend; int mExceedPolicy; - unsigned int mDepth; bool mHasBeenStaged:1; }; diff --git a/dali-toolkit/internal/controls/text-controls/text-label-impl.cpp b/dali-toolkit/internal/controls/text-controls/text-label-impl.cpp index 065d0f9..aff8134 100644 --- a/dali-toolkit/internal/controls/text-controls/text-label-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-label-impl.cpp @@ -491,10 +491,11 @@ void TextLabel::RequestTextRelayout() void TextLabel::RenderText() { + Actor self = Self(); Actor renderableActor; if( mRenderer ) { - renderableActor = mRenderer->Render( mController->GetView(), mDepth ); + renderableActor = mRenderer->Render( mController->GetView(), self.GetHierarchyDepth() ); } if( renderableActor != mRenderableActor ) @@ -506,7 +507,7 @@ void TextLabel::RenderText() const Vector2& alignmentOffset = mController->GetAlignmentOffset(); renderableActor.SetPosition( alignmentOffset.x, alignmentOffset.y ); - Self().Add( renderableActor ); + self.Add( renderableActor ); } mRenderableActor = renderableActor; } @@ -531,7 +532,10 @@ void TextLabel::AddDecoration( Actor& actor, bool needsClipping ) void TextLabel::OnStageConnection( int depth ) { - mDepth = depth; + // Call the Control::OnStageConnection() to set the depth of the background. + Control::OnStageConnection( depth ); + + // The depth of the text renderer is set in the RenderText() called from OnRelayout(). } void TextLabel::TextChanged() @@ -547,7 +551,6 @@ void TextLabel::MaxLengthReached() TextLabel::TextLabel() : Control( ControlBehaviour( REQUIRES_STYLE_CHANGE_SIGNALS ) ), mRenderingBackend( DEFAULT_RENDERING_BACKEND ), - mDepth( 0 ), mHasBeenStaged( false ) { } diff --git a/dali-toolkit/internal/controls/text-controls/text-label-impl.h b/dali-toolkit/internal/controls/text-controls/text-label-impl.h index c099bdf..ae88beb 100644 --- a/dali-toolkit/internal/controls/text-controls/text-label-impl.h +++ b/dali-toolkit/internal/controls/text-controls/text-label-impl.h @@ -149,7 +149,6 @@ private: // Data Text::RendererPtr mRenderer; Actor mRenderableActor; int mRenderingBackend; - unsigned int mDepth; bool mHasBeenStaged:1; }; diff --git a/dali-toolkit/internal/controls/text-controls/text-selection-popup-impl.cpp b/dali-toolkit/internal/controls/text-controls/text-selection-popup-impl.cpp index 59507cd..199c8ef 100644 --- a/dali-toolkit/internal/controls/text-controls/text-selection-popup-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-selection-popup-impl.cpp @@ -298,11 +298,27 @@ Property::Value TextSelectionPopup::GetProperty( BaseObject* object, Property::I return value; } +void TextSelectionPopup::RaiseAbove( Layer target ) +{ + if( mToolbar ) + { + mToolbar.RaiseAbove( target ); + } +} + void TextSelectionPopup::OnInitialize() { CreatePopup(); } +void TextSelectionPopup::OnStageConnection( int depth ) +{ + // Call the Control::OnStageConnection() to set the depth of the background. + Control::OnStageConnection( depth ); + + // TextSelectionToolbar::OnStageConnection() will set the depths of all the popup's components. +} + bool TextSelectionPopup::OnCutButtonPressed( Toolkit::Button button ) { if( mCallbackInterface ) @@ -526,6 +542,7 @@ Dali::Image TextSelectionPopup::GetButtonImage( Toolkit::TextSelectionPopup::But void TextSelectionPopup::CreateOrderedListOfPopupOptions() { mOrderListOfButtons.clear(); + mOrderListOfButtons.reserve( 8u ); // Create button for each possible option using Option priority if ( !mCutIconImage ) @@ -568,7 +585,6 @@ Dali::Image TextSelectionPopup::GetButtonImage( Toolkit::TextSelectionPopup::But void TextSelectionPopup::AddOption( const ButtonRequirement& button, bool showDivider, bool showIcons, bool showCaption ) { - const std::string& name = button.name; const std::string& caption = button.caption; Image iconImage = button.icon; @@ -613,13 +629,14 @@ Dali::Image TextSelectionPopup::GetButtonImage( Toolkit::TextSelectionPopup::But optionPressedContainer.AddChild( pressedCaptionTextLabel, Toolkit::TableView::CellPosition(( showIcons&showCaption)?1:0, 0 ) ); } + int depth = Self().GetHierarchyDepth(); // 3. Create the icons if ( showIcons ) { ImageActor pressedIcon = ImageActor::New( iconImage ); ImageActor icon = ImageActor::New( iconImage ); - icon.SetSortModifier( DECORATION_DEPTH_INDEX - 1 ); - pressedIcon.SetSortModifier( DECORATION_DEPTH_INDEX - 1 ); + icon.SetSortModifier( DECORATION_DEPTH_INDEX + depth - 1 ); + pressedIcon.SetSortModifier( DECORATION_DEPTH_INDEX + depth - 1 ); icon.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); pressedIcon.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); @@ -700,9 +717,13 @@ Dali::Image TextSelectionPopup::GetButtonImage( Toolkit::TextSelectionPopup::But const Size size( mOptionDividerSize.width, 0.0f ); // Height FILL_TO_PARENT ImageActor divider = Toolkit::CreateSolidColorActor( Color::WHITE ); +#ifdef DECORATOR_DEBUG + divider.SetName("Text's popup divider"); +#endif divider.SetSize( size ); divider.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT ); divider.SetColor( mDividerColor ); + divider.SetSortModifier( DECORATION_DEPTH_INDEX + depth ); mToolbar.AddDivider( divider ); } } @@ -745,7 +766,7 @@ Dali::Image TextSelectionPopup::GetButtonImage( Toolkit::TextSelectionPopup::But self.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS ); SetBackgroundImage( NinePatchImage::New( DEFAULT_POPUP_BACKGROUND_IMAGE ) ); - if ( !mToolbar ) + if( !mToolbar ) { mToolbar = Toolkit::TextSelectionToolbar::New(); mToolbar.SetParentOrigin( ParentOrigin::CENTER ); diff --git a/dali-toolkit/internal/controls/text-controls/text-selection-popup-impl.h b/dali-toolkit/internal/controls/text-controls/text-selection-popup-impl.h index 9882764..3bb8b71 100644 --- a/dali-toolkit/internal/controls/text-controls/text-selection-popup-impl.h +++ b/dali-toolkit/internal/controls/text-controls/text-selection-popup-impl.h @@ -124,6 +124,11 @@ public: */ static Property::Value GetProperty( BaseObject* object, Property::Index index ); + /** + * @copydoc Toolkit::TextSelectionPopup::RaiseAbove() + */ + void RaiseAbove( Layer target ); + private: // From Control /** @@ -131,6 +136,11 @@ private: // From Control */ virtual void OnInitialize(); + /** + * @copydoc Control::OnStageConnection() + */ + virtual void OnStageConnection( int depth ); + private: // Implementation /** diff --git a/dali-toolkit/internal/controls/text-controls/text-selection-toolbar-impl.cpp b/dali-toolkit/internal/controls/text-controls/text-selection-toolbar-impl.cpp index cb1e205..756c44d 100644 --- a/dali-toolkit/internal/controls/text-controls/text-selection-toolbar-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-selection-toolbar-impl.cpp @@ -19,6 +19,7 @@ #include // INTERNAL INCLUDES +#include #include // EXTERNAL INCLUDES @@ -125,6 +126,31 @@ void TextSelectionToolbar::OnRelayout( const Vector2& size, RelayoutContainer& c mScrollView.SetRulerX( mRulerX ); } +void TextSelectionToolbar::OnStageConnection( int depth ) +{ + // Call the Control::OnStageConnection() to set the depth of the background. + Control::OnStageConnection( depth ); + + // Traverse the dividers and set the depth. + for( unsigned int i = 0; i < mDividerIndexes.Count(); ++i ) + { + Actor divider = mTableOfButtons.GetChildAt( Toolkit::TableView::CellPosition( 0, mDividerIndexes[ i ] ) ); + + ImageActor dividerImageActor = ImageActor::DownCast( divider ); + if( dividerImageActor ) + { + dividerImageActor.SetSortModifier( DECORATION_DEPTH_INDEX + depth ); + } + else + { + // TODO at the moment divider are image actors. + } + } + + // Texts are controls, they have their own OnStageConnection() implementation. + // Icons are inside a TableView. It has it's own OnStageConnection() implementation. +} + void TextSelectionToolbar::SetPopupMaxSize( const Size& maxSize ) { mMaxSize = maxSize; @@ -160,10 +186,10 @@ void TextSelectionToolbar::SetUp() self.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS ); // Create Layer and Stencil. Layer enable's clipping when content exceed maximum defined width. - Layer stencilLayer = Layer::New(); - stencilLayer.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS ); - stencilLayer.SetParentOrigin( ParentOrigin::CENTER ); - stencilLayer.SetMaximumSize( mMaxSize ); + mStencilLayer = Layer::New(); + mStencilLayer.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS ); + mStencilLayer.SetParentOrigin( ParentOrigin::CENTER ); + mStencilLayer.SetMaximumSize( mMaxSize ); ImageActor stencil = CreateSolidColorActor( Color::RED ); stencil.SetDrawMode( DrawMode::STENCIL ); @@ -181,12 +207,10 @@ void TextSelectionToolbar::SetUp() mTableOfButtons.SetAnchorPoint( AnchorPoint::CENTER_LEFT ); - stencilLayer.Add( stencil ); - stencilLayer.Add( mScrollView ); + mStencilLayer.Add( stencil ); + mStencilLayer.Add( mScrollView ); mScrollView.Add( mTableOfButtons ); - self.Add( stencilLayer ); - - stencilLayer.RaiseToTop(); + self.Add( mStencilLayer ); } void TextSelectionToolbar::OnScrollStarted( const Vector2& position ) @@ -209,7 +233,7 @@ void TextSelectionToolbar::AddOption( Actor& option ) void TextSelectionToolbar::AddDivider( Actor& divider ) { AddOption( divider ); - mDividerIndexes.PushBack( mIndexInTable ); + mDividerIndexes.PushBack( mIndexInTable - 1u ); } void TextSelectionToolbar::ResizeDividers( Size& size ) @@ -222,6 +246,11 @@ void TextSelectionToolbar::ResizeDividers( Size& size ) RelayoutRequest(); } +void TextSelectionToolbar::RaiseAbove( Layer target ) +{ + mStencilLayer.RaiseAbove( target ); +} + TextSelectionToolbar::TextSelectionToolbar() : Control( ControlBehaviour( ControlBehaviour( ACTOR_BEHAVIOUR_NONE ) ) ), mMaxSize ( DEFAULT_MAX_SIZE ), @@ -235,7 +264,6 @@ TextSelectionToolbar::~TextSelectionToolbar() mRulerX.Reset(); } - } // namespace Internal } // namespace Toolkit diff --git a/dali-toolkit/internal/controls/text-controls/text-selection-toolbar-impl.h b/dali-toolkit/internal/controls/text-controls/text-selection-toolbar-impl.h index 3593e79..7309781 100644 --- a/dali-toolkit/internal/controls/text-controls/text-selection-toolbar-impl.h +++ b/dali-toolkit/internal/controls/text-controls/text-selection-toolbar-impl.h @@ -70,20 +70,25 @@ public: static Property::Value GetProperty( BaseObject* object, Property::Index index ); /** - * @copydoc TextSelectionToolbar::AddOption + * @copydoc Toolkit::TextSelectionToolbar::AddOption() */ void AddOption( Actor& option ); /** - * @copydoc TextSelectionToolbar::AddDivider + * @copydoc Toolkit::TextSelectionToolbar::AddDivider() */ void AddDivider( Actor& divider ); /** - * @copydoc ResizeDividers + * @copydoc Toolkit::TextSelectionToolbar::ResizeDividers() */ void ResizeDividers( Size& size ); + /** + * @copydoc Toolkit::TextSelectionToolbar::RaiseAbove() + */ + void RaiseAbove( Layer target ); + private: // From Control /** @@ -95,6 +100,12 @@ private: // From Control * @copydoc Control::OnRelayout() */ virtual void OnRelayout( const Vector2& size, RelayoutContainer& container ); + + /** + * @copydoc Control::OnStageConnection() + */ + virtual void OnStageConnection( int depth ); + /** * @brief Set max size of Popup * @param[in] maxSize Size (Vector2) @@ -150,12 +161,13 @@ private: private: // Data - Toolkit::TableView mTableOfButtons; // Actor which holds all the buttons, sensitivity can be set on buttons via this actor - Toolkit::ScrollView mScrollView; // Provides scrolling of Toolbar when content does not fit. - RulerPtr mRulerX; // Ruler to clamp horizontal scrolling. Updates on Relayout - Size mMaxSize; // Max size of the Toolbar - unsigned int mIndexInTable; // Index in table to add option - Dali::Vector< unsigned int > mDividerIndexes; // Vector of indexes in the Toolbar that contain dividers. + Layer mStencilLayer; ///< The stencil layer + Toolkit::TableView mTableOfButtons; ///< Actor which holds all the buttons, sensitivity can be set on buttons via this actor + Toolkit::ScrollView mScrollView; ///< Provides scrolling of Toolbar when content does not fit. + RulerPtr mRulerX; ///< Ruler to clamp horizontal scrolling. Updates on Relayout + Size mMaxSize; ///< Max size of the Toolbar + unsigned int mIndexInTable; ///< Index in table to add option + Dali::Vector< unsigned int > mDividerIndexes; ///< Vector of indexes in the Toolbar that contain dividers. }; diff --git a/dali-toolkit/internal/text/decorator/text-decorator.cpp b/dali-toolkit/internal/text/decorator/text-decorator.cpp index 9a1b7cd..43867b4 100644 --- a/dali-toolkit/internal/text/decorator/text-decorator.cpp +++ b/dali-toolkit/internal/text/decorator/text-decorator.cpp @@ -113,7 +113,7 @@ const int DEFAULT_POPUP_OFFSET( -100.0f ); // Vertical offset of Popup from curs const Dali::Vector3 DEFAULT_GRAB_HANDLE_RELATIVE_SIZE( 1.25f, 1.5f, 1.0f ); const Dali::Vector3 DEFAULT_SELECTION_HANDLE_RELATIVE_SIZE( 1.25f, 1.5f, 1.0f ); -const Dali::Vector4 LIGHT_BLUE( (0xb2 / 255.0f), (0xeb / 255.0f), (0xf2 / 255.0f), 0.5f ); // The text highlight color. +const Dali::Vector4 LIGHT_BLUE( 0.75f, 0.96f, 1.f, 1.f ); // The text highlight color. TODO: due some problems, maybe with the blending function in the text clipping, the color is fully opaque. const Dali::Vector4 HANDLE_COLOR( 0.0f, (183.0f / 255.0f), (229.0f / 255.0f), 1.0f ); @@ -121,8 +121,6 @@ const unsigned int CURSOR_BLINK_INTERVAL = 500u; // Cursor blink interval const float TO_MILLISECONDS = 1000.f; const float TO_SECONDS = 1.f / TO_MILLISECONDS; -const float DISPLAYED_HIGHLIGHT_Z_OFFSET( -0.05f ); - const unsigned int SCROLL_TICK_INTERVAL = 50u; const float SCROLL_THRESHOLD = 10.f; @@ -346,7 +344,7 @@ struct Decorator::Impl : public ConnectionTracker } else if( grabHandle.actor ) { - UnparentAndReset( grabHandle.actor ); + grabHandle.actor.Unparent(); } // Show or hide the selection handles/highlight @@ -381,40 +379,40 @@ struct Decorator::Impl : public ConnectionTracker primary.actor.SetVisible( isPrimaryVisible ); secondary.actor.SetVisible( isSecondaryVisible ); - // Shouldn't be needed...... - UnparentAndReset( mHighlightActor ); - CreateHighlight(); UpdateHighlight(); } else { - UnparentAndReset( primary.actor ); - UnparentAndReset( secondary.actor ); - UnparentAndReset( mHighlightActor ); + if( primary.actor ) + { + primary.actor.Unparent(); + } + if( secondary.actor ) + { + secondary.actor.Unparent(); + } + if( mHighlightActor ) + { + mHighlightActor.Unparent(); + } } - if ( mActiveCopyPastePopup ) + if( mActiveCopyPastePopup ) { - // todo Swap UnparentAndReset for DeterminePositionPopup() if mCopyPastePopup.actor valid Once the issue with the labels disappearing is fixed. - UnparentAndReset( mCopyPastePopup.actor ); - if ( !mCopyPastePopup.actor ) + if( !mCopyPastePopup.actor.GetParent() ) { - mCopyPastePopup.actor = TextSelectionPopup::New( mEnabledPopupButtons, &mTextSelectionPopupCallbackInterface ); -#ifdef DECORATOR_DEBUG - mCopyPastePopup.actor.SetName("mCopyPastePopup"); -#endif - mCopyPastePopup.actor.SetAnchorPoint( AnchorPoint::CENTER ); - mCopyPastePopup.actor.OnRelayoutSignal().Connect( this, &Decorator::Impl::PopupRelayoutComplete ); // Position popup after size negotiation - mActiveLayer.Add ( mCopyPastePopup.actor ); + mActiveLayer.Add( mCopyPastePopup.actor ); } + + mCopyPastePopup.actor.RaiseAbove( mActiveLayer ); } else { - if ( mCopyPastePopup.actor ) - { - UnparentAndReset( mCopyPastePopup.actor ); - } + if( mCopyPastePopup.actor ) + { + mCopyPastePopup.actor.Unparent(); + } } } @@ -426,6 +424,7 @@ struct Decorator::Impl : public ConnectionTracker mHandle[ LEFT_SELECTION_HANDLE ].position += scrollOffset; mHandle[ RIGHT_SELECTION_HANDLE ].position += scrollOffset; mHighlightPosition += scrollOffset; + DeterminePositionPopup(); } void DeterminePositionPopup() @@ -480,8 +479,14 @@ struct Decorator::Impl : public ConnectionTracker { if( mActiveCursor == ACTIVE_CURSOR_NONE ) { - UnparentAndReset( mPrimaryCursor ); - UnparentAndReset( mSecondaryCursor ); + if( mPrimaryCursor ) + { + mPrimaryCursor.Unparent(); + } + if( mSecondaryCursor ) + { + mSecondaryCursor.Unparent(); + } } else { @@ -495,6 +500,10 @@ struct Decorator::Impl : public ConnectionTracker #ifdef DECORATOR_DEBUG mPrimaryCursor.SetName( "PrimaryCursorActor" ); #endif + } + + if( !mPrimaryCursor.GetParent() ) + { mActiveLayer.Add( mPrimaryCursor ); } } @@ -507,12 +516,19 @@ struct Decorator::Impl : public ConnectionTracker #ifdef DECORATOR_DEBUG mSecondaryCursor.SetName( "SecondaryCursorActor" ); #endif + } + + if( !mSecondaryCursor.GetParent() ) + { mActiveLayer.Add( mSecondaryCursor ); } } else { - UnparentAndReset( mSecondaryCursor ); + if( mSecondaryCursor ) + { + mSecondaryCursor.Unparent(); + } } } } @@ -612,6 +628,11 @@ struct Decorator::Impl : public ConnectionTracker mActiveLayer.Add( grabHandle.actor ); } + + if( !grabHandle.actor.GetParent() ) + { + mActiveLayer.Add( grabHandle.actor ); + } } void CreateSelectionHandles() @@ -647,6 +668,10 @@ struct Decorator::Impl : public ConnectionTracker primary.grabArea.TouchedSignal().Connect( this, &Decorator::Impl::OnHandleOneTouched ); primary.actor.Add( primary.grabArea ); + } + + if( !primary.actor.GetParent() ) + { mActiveLayer.Add( primary.actor ); } @@ -681,13 +706,17 @@ struct Decorator::Impl : public ConnectionTracker secondary.grabArea.TouchedSignal().Connect( this, &Decorator::Impl::OnHandleTwoTouched ); secondary.actor.Add( secondary.grabArea ); + } + + if( !secondary.actor.GetParent() ) + { mActiveLayer.Add( secondary.actor ); } } void CreateHighlight() { - if ( !mHighlightActor ) + if( !mHighlightActor ) { mHighlightActor = Actor::New(); @@ -695,84 +724,104 @@ struct Decorator::Impl : public ConnectionTracker mHighlightActor.SetName( "HighlightActor" ); #endif mHighlightActor.SetAnchorPoint( AnchorPoint::TOP_LEFT ); - mHighlightActor.SetPosition( 0.0f, 0.0f, DISPLAYED_HIGHLIGHT_Z_OFFSET ); mHighlightActor.SetSize( 1.0f, 1.0f ); mHighlightActor.SetColor( mHighlightColor ); mHighlightActor.SetColorMode( USE_OWN_COLOR ); - - // Add the highlight box telling the controller it needs clipping. - mController.AddDecoration( mHighlightActor, true ); } + + // Add the highlight box telling the controller it needs clipping. + mController.AddDecoration( mHighlightActor, true ); } void UpdateHighlight() { - - if ( mHighlightActor && !mHighlightQuadList.empty() ) + if ( mHighlightActor ) { - Vector< Vector2 > vertices; - Vector< unsigned int> indices; - Vector2 vertex; + if( !mHighlightQuadList.empty() ) + { + Vector< Vector2 > vertices; + Vector< unsigned int> indices; + Vector2 vertex; - std::vector::iterator iter = mHighlightQuadList.begin(); - std::vector::iterator endIter = mHighlightQuadList.end(); + std::vector::iterator iter = mHighlightQuadList.begin(); + std::vector::iterator endIter = mHighlightQuadList.end(); - for(std::size_t v = 0; iter != endIter; ++iter,v+=4 ) - { + for( std::size_t v = 0; iter != endIter; ++iter,v+=4 ) + { + + QuadCoordinates& quad = *iter; + + // top-left (v+0) + vertex.x = quad.min.x; + vertex.y = quad.min.y; + vertices.PushBack( vertex ); + + // top-right (v+1) + vertex.x = quad.max.x; + vertex.y = quad.min.y; + vertices.PushBack( vertex ); + + // bottom-left (v+2) + vertex.x = quad.min.x; + vertex.y = quad.max.y; + vertices.PushBack( vertex ); + + // bottom-right (v+3) + vertex.x = quad.max.x; + vertex.y = quad.max.y; + vertices.PushBack( vertex ); + + // triangle A (3, 1, 0) + indices.PushBack( v + 3 ); + indices.PushBack( v + 1 ); + indices.PushBack( v ); + + // triangle B (0, 2, 3) + indices.PushBack( v ); + indices.PushBack( v + 2 ); + indices.PushBack( v + 3 ); + } + + if( mQuadVertices ) + { + mQuadVertices.SetSize( vertices.Size() ); + } + else + { + mQuadVertices = PropertyBuffer::New( mQuadVertexFormat, vertices.Size() ); + } + + if( mQuadIndices ) + { + mQuadIndices.SetSize( indices.Size() ); + } + else + { + mQuadIndices = PropertyBuffer::New( mQuadIndexFormat, indices.Size() ); + } + + mQuadVertices.SetData( &vertices[ 0 ] ); + mQuadIndices.SetData( &indices[ 0 ] ); + + mQuadGeometry = Geometry::New(); + mQuadGeometry.AddVertexBuffer( mQuadVertices ); + mQuadGeometry.SetIndexBuffer( mQuadIndices ); + + if( mHighlightRenderer ) + { + mHighlightRenderer.SetGeometry( mQuadGeometry ); + } + else + { + mHighlightRenderer = Dali::Renderer::New( mQuadGeometry, mHighlightMaterial ); + mHighlightActor.AddRenderer( mHighlightRenderer ); + } - QuadCoordinates& quad = *iter; - - // top-left (v+0) - vertex.x = quad.min.x; - vertex.y = quad.min.y; - vertices.PushBack( vertex ); - - // top-right (v+1) - vertex.x = quad.max.x; - vertex.y = quad.min.y; - vertices.PushBack( vertex ); - - // bottom-left (v+2) - vertex.x = quad.min.x; - vertex.y = quad.max.y; - vertices.PushBack( vertex ); - - // bottom-right (v+3) - vertex.x = quad.max.x; - vertex.y = quad.max.y; - vertices.PushBack( vertex ); - - // triangle A (3, 1, 0) - indices.PushBack( v + 3 ); - indices.PushBack( v + 1 ); - indices.PushBack( v ); - - // triangle B (0, 2, 3) - indices.PushBack( v ); - indices.PushBack( v + 2 ); - indices.PushBack( v + 3 ); + mHighlightActor.SetPosition( mHighlightPosition.x, + mHighlightPosition.y ); } - PropertyBuffer quadVertices = PropertyBuffer::New( mQuadVertexFormat, vertices.Size() ); - PropertyBuffer quadIndices = PropertyBuffer::New( mQuadIndexFormat, indices.Size() ); - - quadVertices.SetData( &vertices[ 0 ] ); - quadIndices.SetData( &indices[ 0 ] ); - - Geometry quadGeometry = Geometry::New(); - quadGeometry.AddVertexBuffer( quadVertices ); - quadGeometry.SetIndexBuffer( quadIndices ); - - // if ( mHighlightRenderer ) - // { - // mHighlightRenderer.SetGeometry( quadGeometry ); - // } - // else - // { - mHighlightRenderer = Dali::Renderer::New( quadGeometry, mHighlightMaterial ); - mHighlightRenderer.SetDepthIndex( DECORATION_DEPTH_INDEX - 1 ); - // } - mHighlightActor.AddRenderer( mHighlightRenderer ); + mHighlightRenderer.SetDepthIndex( mTextDepth - 2u ); // text is rendered at mTextDepth and text's shadow at mTextDepth -1u. } } @@ -1204,6 +1253,10 @@ struct Decorator::Impl : public ConnectionTracker CursorImpl mCursor[CURSOR_COUNT]; HandleImpl mHandle[HANDLE_TYPE_COUNT]; + + PropertyBuffer mQuadVertices; + PropertyBuffer mQuadIndices; + Geometry mQuadGeometry; QuadContainer mHighlightQuadList; ///< Sub-selections that combine to create the complete selection highlight Rect mBoundingBox; @@ -1218,6 +1271,7 @@ struct Decorator::Impl : public ConnectionTracker float mScrollThreshold; ///< Defines a square area inside the control, close to the edge. A cursor entering this area will trigger scroll events. float mScrollSpeed; ///< The scroll speed in pixels per second. float mScrollDistance; ///< Distance the text scrolls during a scroll interval. + int mTextDepth; ///< The depth used to render the text. bool mActiveCopyPastePopup : 1; bool mCursorBlinkStatus : 1; ///< Flag to switch between blink on and blink off. @@ -1440,6 +1494,11 @@ const Vector4& Decorator::GetHighlightColor() const return mImpl->mHighlightColor; } +void Decorator::SetTextDepth( int textDepth ) +{ + mImpl->mTextDepth = textDepth; +} + void Decorator::SetPopupActive( bool active ) { mImpl->mActiveCopyPastePopup = active; @@ -1453,6 +1512,20 @@ bool Decorator::IsPopupActive() const void Decorator::SetEnabledPopupButtons( TextSelectionPopup::Buttons& enabledButtonsBitMask ) { mImpl->mEnabledPopupButtons = enabledButtonsBitMask; + + UnparentAndReset( mImpl->mCopyPastePopup.actor ); + mImpl->mCopyPastePopup.actor = TextSelectionPopup::New( mImpl->mEnabledPopupButtons, + &mImpl->mTextSelectionPopupCallbackInterface ); +#ifdef DECORATOR_DEBUG + mImpl->mCopyPastePopup.actor.SetName("mCopyPastePopup"); +#endif + mImpl->mCopyPastePopup.actor.SetAnchorPoint( AnchorPoint::CENTER ); + mImpl->mCopyPastePopup.actor.OnRelayoutSignal().Connect( mImpl, &Decorator::Impl::PopupRelayoutComplete ); // Position popup after size negotiation + + if( mImpl->mActiveLayer ) + { + mImpl->mActiveLayer.Add( mImpl->mCopyPastePopup.actor ); + } } TextSelectionPopup::Buttons& Decorator::GetEnabledPopupButtons() diff --git a/dali-toolkit/internal/text/decorator/text-decorator.h b/dali-toolkit/internal/text/decorator/text-decorator.h index 927fb83..4a1fc5f 100644 --- a/dali-toolkit/internal/text/decorator/text-decorator.h +++ b/dali-toolkit/internal/text/decorator/text-decorator.h @@ -423,6 +423,13 @@ public: const Vector4& GetHighlightColor() const; /** + * @brief Sets into the decorator the depth used to render the text. + * + * @param[in] depth The text's depth. + */ + void SetTextDepth( int textDepth ); + + /** * @brief Set the Selection Popup to show or hide via the active flaf * @param[in] active true to show, false to hide */ diff --git a/dali-toolkit/internal/text/rendering/atlas/text-atlas-renderer.cpp b/dali-toolkit/internal/text/rendering/atlas/text-atlas-renderer.cpp index 457959f..a2faebc 100644 --- a/dali-toolkit/internal/text/rendering/atlas/text-atlas-renderer.cpp +++ b/dali-toolkit/internal/text/rendering/atlas/text-atlas-renderer.cpp @@ -114,13 +114,13 @@ struct AtlasRenderer::Impl : public ConnectionTracker bool underlineEnabled, const Vector4& underlineColor, float underlineHeight, - unsigned int depth ) + int depth ) { AtlasManager::AtlasSlot slot; std::vector< MeshRecord > meshContainer; Vector< Extent > extents; TextCacheEntry textCacheEntry; - mDepth = static_cast< int >( depth ); + mDepth = depth; float currentUnderlinePosition = ZERO; float currentUnderlineThickness = underlineHeight; @@ -318,8 +318,11 @@ struct AtlasRenderer::Impl : public ConnectionTracker Material material = mGlyphManager.GetMaterial( meshRecord.mAtlasId ); Dali::Renderer renderer = Dali::Renderer::New( quadGeometry, material ); - renderer.SetDepthIndex( mDepth ); + renderer.SetDepthIndex( CONTENT_DEPTH_INDEX + mDepth ); Actor actor = Actor::New(); +#if defined(DEBUG_ENABLED) + actor.SetName( "Text renderable actor" ); +#endif actor.AddRenderer( renderer ); actor.SetSize( 1.0f, 1.0f ); actor.SetColor( meshRecord.mColor ); @@ -647,7 +650,7 @@ struct AtlasRenderer::Impl : public ConnectionTracker Dali::Renderer renderer = Dali::Renderer::New( quadGeometry, material ); // Ensure shadow is behind the text... - renderer.SetDepthIndex( mDepth + CONTENT_DEPTH_INDEX - 1 ); + renderer.SetDepthIndex( CONTENT_DEPTH_INDEX + mDepth - 1 ); Actor actor = Actor::New(); actor.AddRenderer( renderer ); actor.SetSize( 1.0f, 1.0f ); @@ -731,7 +734,7 @@ Text::RendererPtr AtlasRenderer::New() return Text::RendererPtr( new AtlasRenderer() ); } -Actor AtlasRenderer::Render( Text::ViewInterface& view, unsigned int depth ) +Actor AtlasRenderer::Render( Text::ViewInterface& view, int depth ) { UnparentAndReset( mImpl->mActor ); diff --git a/dali-toolkit/internal/text/rendering/atlas/text-atlas-renderer.h b/dali-toolkit/internal/text/rendering/atlas/text-atlas-renderer.h index 4107f82..809c236 100644 --- a/dali-toolkit/internal/text/rendering/atlas/text-atlas-renderer.h +++ b/dali-toolkit/internal/text/rendering/atlas/text-atlas-renderer.h @@ -51,7 +51,7 @@ public: * @param[in] depth The depth in the tree of the parent. * @return The Renderable actor used to position the text. */ - virtual Actor Render( ViewInterface& view, unsigned int depth ); + virtual Actor Render( ViewInterface& view, int depth ); protected: diff --git a/dali-toolkit/internal/text/rendering/text-renderer.h b/dali-toolkit/internal/text/rendering/text-renderer.h index 1b272ea..17be8d8 100644 --- a/dali-toolkit/internal/text/rendering/text-renderer.h +++ b/dali-toolkit/internal/text/rendering/text-renderer.h @@ -55,7 +55,7 @@ public: * @param[in] depth The depth in the tree of the parent. * @return The Renderable actor used to position the text. */ - virtual Actor Render( ViewInterface& view, unsigned int depth ) = 0; + virtual Actor Render( ViewInterface& view, int depth ) = 0; protected: -- 2.7.4