From 63c638709de19772a74edad2baa53dbc8db23ada Mon Sep 17 00:00:00 2001 From: Victor Cebollada Date: Thu, 8 Dec 2016 14:52:47 +0000 Subject: [PATCH] Text - TextClipper replaced by an Actor with the CLIPPING_MODE enabled. * Fixes issues with the inherited alpha channel. Change-Id: I6a3f125d6de10d4d3d8673a6b340f05ae0edd3f6 Signed-off-by: Victor Cebollada --- .../src/dali-toolkit/utc-Dali-TextEditor.cpp | 40 ++--- .../src/dali-toolkit/utc-Dali-TextField.cpp | 44 +++--- .../controls/text-controls/text-editor-impl.cpp | 70 +++------ .../controls/text-controls/text-editor-impl.h | 10 +- .../controls/text-controls/text-field-impl.cpp | 94 ++++++------ .../controls/text-controls/text-field-impl.h | 7 +- dali-toolkit/internal/file.list | 1 - .../internal/text/clipping/text-clipper.cpp | 166 --------------------- dali-toolkit/internal/text/clipping/text-clipper.h | 123 --------------- 9 files changed, 100 insertions(+), 455 deletions(-) delete mode 100644 dali-toolkit/internal/text/clipping/text-clipper.cpp delete mode 100644 dali-toolkit/internal/text/clipping/text-clipper.h diff --git a/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp b/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp index dd9a805..2dae967 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp @@ -1248,15 +1248,10 @@ int utcDaliTextEditorEvent02(void) application.SendNotification(); application.Render(); - // Check there are the expected number of children ( offscreen root actor, and the offscreen image view - DALI_TEST_EQUALS( editor.GetChildCount(), 2u, TEST_LOCATION ); + // Check there are the expected number of children (the stencil). + DALI_TEST_EQUALS( editor.GetChildCount(), 1u, TEST_LOCATION ); - Actor offscreenRoot = editor.GetChildAt( 0u ); - DALI_TEST_CHECK( offscreenRoot.IsLayer() ); - DALI_TEST_EQUALS( offscreenRoot.GetChildCount(), 1u, TEST_LOCATION ); // The camera actor. - - Actor offscreenImage = editor.GetChildAt( 1u ); - DALI_TEST_CHECK( offscreenImage ); + Actor stencil = editor.GetChildAt( 0u ); // Create a tap event to touch the text editor. application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) ); @@ -1266,11 +1261,11 @@ int utcDaliTextEditorEvent02(void) application.SendNotification(); application.Render(); - Actor layer = editor.GetChildAt( 2u ); + Actor layer = editor.GetChildAt( 1u ); DALI_TEST_CHECK( layer.IsLayer() ); DALI_TEST_EQUALS( layer.GetChildCount(), 1u, TEST_LOCATION ); // The cursor. - DALI_TEST_EQUALS( offscreenRoot.GetChildCount(), 1u, TEST_LOCATION ); // The camera actor. + DALI_TEST_EQUALS( stencil.GetChildCount(), 0u, TEST_LOCATION ); // Now the text editor has the focus, so it can handle the key events. application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) ); @@ -1282,16 +1277,13 @@ int utcDaliTextEditorEvent02(void) // Checks the cursor and the renderer have been created. DALI_TEST_EQUALS( layer.GetChildCount(), 1u, TEST_LOCATION ); // The cursor. - DALI_TEST_EQUALS( offscreenRoot.GetChildCount(), 2u, TEST_LOCATION ); // The camera actor and the renderer + DALI_TEST_EQUALS( stencil.GetChildCount(), 1u, TEST_LOCATION ); // The renderer Control cursor = Control::DownCast( layer.GetChildAt( 0u ) ); DALI_TEST_CHECK( cursor ); - CameraActor camera = CameraActor::DownCast( offscreenRoot.GetChildAt( 0u ) ); - DALI_TEST_CHECK( camera ); - - // The offscreen root actor has a container with all the actors which contain the text renderers. - Actor container = offscreenRoot.GetChildAt( 1u ); + // The stencil actor has a container with all the actors which contain the text renderers. + Actor container = stencil.GetChildAt( 0u ); for( unsigned int index = 0; index < container.GetChildCount(); ++index ) { Renderer renderer = container.GetChildAt( index ).GetRendererAt( 0u ); @@ -1365,7 +1357,7 @@ int utcDaliTextEditorEvent02(void) DALI_TEST_EQUALS( position2, position6, TEST_LOCATION );// Should be in the same position2. // Should not be a renderer. - DALI_TEST_EQUALS( offscreenRoot.GetChildCount(), 1u, TEST_LOCATION ); // The camera actor only. + DALI_TEST_EQUALS( stencil.GetChildCount(), 0u, TEST_LOCATION ); END_TEST; } @@ -1422,22 +1414,18 @@ int utcDaliTextEditorEvent03(void) application.SendNotification(); application.Render(); - // The offscreen root actor should have three actors: the camera, a renderer and the highlight actor. - Actor offscreenRoot = editor.GetChildAt( 0u ); - DALI_TEST_CHECK( offscreenRoot.IsLayer() ); - - CameraActor camera = CameraActor::DownCast( offscreenRoot.GetChildAt( 0u ) ); - DALI_TEST_CHECK( camera ); + // The stencil actor should have two actors: the renderer and the highlight actor. + Actor stencil = editor.GetChildAt( 0u ); - // The offscreen root actor has a container with all the actors which contain the text renderers. - Actor container = offscreenRoot.GetChildAt( 1u ); + // The stencil actor has a container with all the actors which contain the text renderers. + Actor container = stencil.GetChildAt( 0u ); for( unsigned int index = 0; index < container.GetChildCount(); ++index ) { Renderer renderer = container.GetChildAt( index ).GetRendererAt( 0u ); DALI_TEST_CHECK( renderer ); } - Renderer highlight = offscreenRoot.GetChildAt( 2u ).GetRendererAt( 0u ); + Renderer highlight = stencil.GetChildAt( 1u ).GetRendererAt( 0u ); DALI_TEST_CHECK( highlight ); END_TEST; diff --git a/automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp b/automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp index 7dffc69..ced9421 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp @@ -585,7 +585,10 @@ int UtcDaliTextFieldSetPropertyP(void) DALI_TEST_EQUALS( field.GetProperty( TextField::Property::MAX_LENGTH ), maxNumberOfCharacters, TEST_LOCATION ); // Check exceed policy - // Set a different exceed policy is not implemented. + field.SetProperty( TextField::Property::EXCEED_POLICY, Dali::Toolkit::TextField::EXCEED_POLICY_CLIP ); + DALI_TEST_EQUALS( field.GetProperty( TextField::Property::EXCEED_POLICY ), static_cast( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP ), TEST_LOCATION ); + field.SetProperty( TextField::Property::EXCEED_POLICY, Dali::Toolkit::TextField::EXCEED_POLICY_ORIGINAL ); + DALI_TEST_EQUALS( field.GetProperty( TextField::Property::EXCEED_POLICY ), static_cast( Dali::Toolkit::TextField::EXCEED_POLICY_ORIGINAL ), TEST_LOCATION ); // Check that the Alignment properties can be correctly set field.SetProperty( TextField::Property::HORIZONTAL_ALIGNMENT, "END" ); @@ -1460,15 +1463,11 @@ int utcDaliTextFieldEvent02(void) application.SendNotification(); application.Render(); - // Check there are the expected number of children ( offscreen root actor, and the offscreen image view - DALI_TEST_EQUALS( field.GetChildCount(), 2u, TEST_LOCATION ); + // Check there are the expected number of children ( stencil ). + DALI_TEST_EQUALS( field.GetChildCount(), 1u, TEST_LOCATION ); - Actor offscreenRoot = field.GetChildAt( 0u ); - DALI_TEST_CHECK( offscreenRoot.IsLayer() ); - DALI_TEST_EQUALS( offscreenRoot.GetChildCount(), 1u, TEST_LOCATION ); // The camera actor. - - Actor offscreenImage = field.GetChildAt( 1u ); - DALI_TEST_CHECK( offscreenImage ); + Actor stencil = field.GetChildAt( 0u ); + DALI_TEST_EQUALS( stencil.GetChildCount(), 0u, TEST_LOCATION ); // Create a tap event to touch the text field. application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) ); @@ -1478,11 +1477,11 @@ int utcDaliTextFieldEvent02(void) application.SendNotification(); application.Render(); - Actor layer = field.GetChildAt( 2u ); + Actor layer = field.GetChildAt( 1u ); DALI_TEST_CHECK( layer.IsLayer() ); DALI_TEST_EQUALS( layer.GetChildCount(), 1u, TEST_LOCATION ); // The cursor. - DALI_TEST_EQUALS( offscreenRoot.GetChildCount(), 1u, TEST_LOCATION ); // The camera actor. + DALI_TEST_EQUALS( stencil.GetChildCount(), 0u, TEST_LOCATION ); // Now the text field has the focus, so it can handle the key events. application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) ); @@ -1494,16 +1493,13 @@ int utcDaliTextFieldEvent02(void) // Checks the cursor and the renderer have been created. DALI_TEST_EQUALS( layer.GetChildCount(), 1u, TEST_LOCATION ); // The cursor. - DALI_TEST_EQUALS( offscreenRoot.GetChildCount(), 2u, TEST_LOCATION ); // The camera actor and the renderer + DALI_TEST_EQUALS( stencil.GetChildCount(), 1u, TEST_LOCATION ); // The renderer Control cursor = Control::DownCast( layer.GetChildAt( 0u ) ); DALI_TEST_CHECK( cursor ); - CameraActor camera = CameraActor::DownCast( offscreenRoot.GetChildAt( 0u ) ); - DALI_TEST_CHECK( camera ); - // The offscreen root actor has a container with all the actors which contain the text renderers. - Actor container = offscreenRoot.GetChildAt( 1u ); + Actor container = stencil.GetChildAt( 0u ); for( unsigned int index = 0; index < container.GetChildCount(); ++index ) { Renderer renderer = container.GetChildAt( index ).GetRendererAt( 0u ); @@ -1577,7 +1573,7 @@ int utcDaliTextFieldEvent02(void) DALI_TEST_EQUALS( position2, position6, TEST_LOCATION );// Should be in the same position2. // Should not be a renderer. - DALI_TEST_EQUALS( offscreenRoot.GetChildCount(), 1u, TEST_LOCATION ); // The camera actor only. + DALI_TEST_EQUALS( stencil.GetChildCount(), 0u, TEST_LOCATION ); END_TEST; } @@ -1624,22 +1620,18 @@ int utcDaliTextFieldEvent03(void) application.SendNotification(); application.Render(); - // The offscreen root actor should have three actors: the camera, a renderer and the highlight actor. - Actor offscreenRoot = field.GetChildAt( 1u ); - DALI_TEST_CHECK( offscreenRoot.IsLayer() ); - - CameraActor camera = CameraActor::DownCast( offscreenRoot.GetChildAt( 0u ) ); - DALI_TEST_CHECK( camera ); + // The offscreen root actor should have two actors: the renderer and the highlight actor. + Actor stencil = field.GetChildAt( 0u ); // The offscreen root actor has a container with all the actors which contain the text renderers. - Actor container = offscreenRoot.GetChildAt( 1u ); + Actor container = stencil.GetChildAt( 0u ); for( unsigned int index = 0; index < container.GetChildCount(); ++index ) { Renderer renderer = container.GetChildAt( index ).GetRendererAt( 0u ); DALI_TEST_CHECK( renderer ); } - Renderer highlight = offscreenRoot.GetChildAt( 2u ).GetRendererAt( 0u ); + Renderer highlight = stencil.GetChildAt( 1u ).GetRendererAt( 0u ); DALI_TEST_CHECK( highlight ); END_TEST; @@ -1770,7 +1762,7 @@ int utcDaliTextFieldEvent05(void) SendPan(application, Gesture::Finished, pos); Wait(application, RENDER_FRAME_INTERVAL); - Actor offscreenRoot = field.GetChildAt( 1u ); + Actor stencil = field.GetChildAt( 1u ); END_TEST; } diff --git a/dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp b/dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp index 81696b7..51684a4 100644 --- a/dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp @@ -31,7 +31,9 @@ // INTERNAL INCLUDES #include +#include #include +#include #include #include #include @@ -981,6 +983,22 @@ void TextEditor::OnInitialize() self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT ); self.OnStageSignal().Connect( this, &TextEditor::OnStageConnect ); + + // Creates an extra control to be used as stencil buffer. + mStencil = Control::New(); + mStencil.SetAnchorPoint( AnchorPoint::CENTER ); + mStencil.SetParentOrigin( ParentOrigin::CENTER ); + + // Creates a background visual. Even if the color is transparent it updates the stencil. + mStencil.SetProperty( Toolkit::Control::Property::BACKGROUND, + Property::Map().Add( Toolkit::Visual::Property::TYPE, DevelVisual::COLOR ). + Add( ColorVisual::Property::MIX_COLOR, Color::TRANSPARENT ) ); + + // Enable the clipping property. + mStencil.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN ); + mStencil.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); + + self.Add( mStencil ); } void TextEditor::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change ) @@ -1043,7 +1061,6 @@ void TextEditor::OnRelayout( const Vector2& size, RelayoutContainer& container ) mRenderer = Backend::Get().NewRenderer( mRenderingBackend ); } - EnableClipping( size ); RenderText( updateTextType ); } @@ -1069,7 +1086,6 @@ void TextEditor::OnRelayout( const Vector2& size, RelayoutContainer& container ) void TextEditor::RenderText( Text::Controller::UpdateTextType updateTextType ) { - Actor self = Self(); Actor renderableActor; if( Text::Controller::NONE_UPDATED != ( Text::Controller::MODEL_UPDATED & updateTextType ) ) @@ -1092,39 +1108,19 @@ void TextEditor::RenderText( Text::Controller::UpdateTextType updateTextType ) mRenderableActor.SetPosition( scrollOffset.x, scrollOffset.y ); - Actor clipRootActor; - if( mClipper ) - { - clipRootActor = mClipper->GetRootActor(); - } + // Make sure the actors are parented correctly with/without clipping + Actor self = mStencil ? mStencil : Self(); for( std::vector::const_iterator it = mClippingDecorationActors.begin(), endIt = mClippingDecorationActors.end(); it != endIt; ++it ) { - Actor actor = *it; - - if( clipRootActor ) - { - clipRootActor.Add( actor ); - } - else - { - self.Add( actor ); - } + self.Add( *it ); } mClippingDecorationActors.clear(); - // Make sure the actor is parented correctly with/without clipping - if( clipRootActor ) - { - clipRootActor.Add( mRenderableActor ); - } - else - { - self.Add( mRenderableActor ); - } + self.Add( mRenderableActor ); } } @@ -1354,26 +1350,6 @@ void TextEditor::GetHandleImagePropertyValue( Property::Value& value, Text::Han } } -void TextEditor::EnableClipping( const Vector2& size ) -{ - // Not worth to created clip actor if width or height is equal to zero. - if( size.width > Math::MACHINE_EPSILON_1000 && size.height > Math::MACHINE_EPSILON_1000 ) - { - if( !mClipper ) - { - Actor self = Self(); - - mClipper = Clipper::New( size ); - self.Add( mClipper->GetRootActor() ); - self.Add( mClipper->GetImageView() ); - } - else if ( mClipper ) - { - mClipper->Refresh( size ); - } - } -} - void TextEditor::OnClipboardTextSelected( ClipboardEventNotifier& clipboard ) { mController->PasteClipboardItemEvent(); @@ -1429,7 +1405,7 @@ TextEditor::TextEditor() TextEditor::~TextEditor() { - mClipper.Reset(); + UnparentAndReset( mStencil ); if( ( NULL != mIdleCallback ) && Adaptor::IsAvailable() ) { diff --git a/dali-toolkit/internal/controls/text-controls/text-editor-impl.h b/dali-toolkit/internal/controls/text-controls/text-editor-impl.h index 2d7190b..123d0a4 100644 --- a/dali-toolkit/internal/controls/text-controls/text-editor-impl.h +++ b/dali-toolkit/internal/controls/text-controls/text-editor-impl.h @@ -24,7 +24,6 @@ // INTERNAL INCLUDES #include #include -#include #include #include #include @@ -206,13 +205,6 @@ private: // Implementation void GetHandleImagePropertyValue( Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType ); /** - * @brief Enable or disable clipping. - * - * @param[in] size The area to clip within. - */ - void EnableClipping( const Vector2& size ); - - /** * @brief Callback when keyboard is shown/hidden. * * @param[in] keyboardShown True if keyboard is shown. @@ -265,7 +257,7 @@ private: // Data Text::ControllerPtr mController; Text::RendererPtr mRenderer; Text::DecoratorPtr mDecorator; - Text::ClipperPtr mClipper; + Toolkit::Control mStencil; std::vector mClippingDecorationActors; ///< Decoration actors which need clipping. Actor mRenderableActor; 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 e95ac99..7341032 100644 --- a/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp @@ -30,7 +30,9 @@ // INTERNAL INCLUDES #include +#include #include +#include #include #include #include @@ -270,7 +272,17 @@ void TextField::SetProperty( BaseObject* object, Property::Index index, const Pr } case Toolkit::TextField::Property::EXCEED_POLICY: { - // TODO + impl.mExceedPolicy = value.Get(); + + if( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == impl.mExceedPolicy ) + { + impl.EnableClipping(); + } + else + { + UnparentAndReset( impl.mStencil ); + } + impl.RequestTextRelayout(); break; } case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT: @@ -803,7 +815,7 @@ Property::Value TextField::GetProperty( BaseObject* object, Property::Index inde } case Toolkit::TextField::Property::VERTICAL_ALIGNMENT: { - if( impl.mController ) + if( impl.mController ) { const char* name = Scripting::GetEnumerationName< Toolkit::Text::Layout::VerticalAlignment >( impl.mController->GetVerticalAlignment(), VERTICAL_ALIGNMENT_STRING_TABLE, @@ -1160,6 +1172,11 @@ void TextField::OnInitialize() self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT ); self.OnStageSignal().Connect( this, &TextField::OnStageConnect ); + + if( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == mExceedPolicy ) + { + EnableClipping(); + } } void TextField::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change ) @@ -1222,7 +1239,6 @@ void TextField::OnRelayout( const Vector2& size, RelayoutContainer& container ) mRenderer = Backend::Get().NewRenderer( mRenderingBackend ); } - EnableClipping( size ); RenderText( updateTextType ); } @@ -1248,7 +1264,6 @@ void TextField::OnRelayout( const Vector2& size, RelayoutContainer& container ) void TextField::RenderText( Text::Controller::UpdateTextType updateTextType ) { - Actor self = Self(); Actor renderableActor; if( Text::Controller::NONE_UPDATED != ( Text::Controller::MODEL_UPDATED & updateTextType ) ) @@ -1271,39 +1286,19 @@ void TextField::RenderText( Text::Controller::UpdateTextType updateTextType ) mRenderableActor.SetPosition( scrollOffset.x, scrollOffset.y ); - Actor clipRootActor; - if( mClipper ) - { - clipRootActor = mClipper->GetRootActor(); - } + // Make sure the actors are parented correctly with/without clipping + Actor self = mStencil ? mStencil : Self(); for( std::vector::const_iterator it = mClippingDecorationActors.begin(), endIt = mClippingDecorationActors.end(); it != endIt; ++it ) { - Actor actor = *it; - - if( clipRootActor ) - { - clipRootActor.Add( actor ); - } - else - { - self.Add( actor ); - } + self.Add( *it ); } mClippingDecorationActors.clear(); - // Make sure the actor is parented correctly with/without clipping - if( clipRootActor ) - { - clipRootActor.Add( mRenderableActor ); - } - else - { - self.Add( mRenderableActor ); - } + self.Add( mRenderableActor ); } } @@ -1531,31 +1526,26 @@ void TextField::GetHandleImagePropertyValue( Property::Value& value, Text::Hand } } -void TextField::EnableClipping( const Vector2& size ) +void TextField::EnableClipping() { - if( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == mExceedPolicy ) - { - // Not worth to created clip actor if width or height is equal to zero. - if( size.width > Math::MACHINE_EPSILON_1000 && size.height > Math::MACHINE_EPSILON_1000 ) - { - if( !mClipper ) - { - Actor self = Self(); - - mClipper = Clipper::New( size ); - self.Add( mClipper->GetRootActor() ); - self.Add( mClipper->GetImageView() ); - } - else if ( mClipper ) - { - mClipper->Refresh( size ); - } - } - } - else + if( !mStencil ) { - // Note - this will automatically remove the root actor & the image view - mClipper.Reset(); + // Creates an extra control to be used as stencil buffer. + mStencil = Control::New(); + mStencil.SetAnchorPoint( AnchorPoint::CENTER ); + mStencil.SetParentOrigin( ParentOrigin::CENTER ); + + // Creates a background visual. Even if the color is transparent it updates the stencil. + // Property::Map backgroundMap; + mStencil.SetProperty( Toolkit::Control::Property::BACKGROUND, + Property::Map().Add( Toolkit::Visual::Property::TYPE, DevelVisual::COLOR ). + Add( ColorVisual::Property::MIX_COLOR, Color::TRANSPARENT ) ); + + // Enable the clipping property. + mStencil.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN ); + mStencil.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); + + Self().Add( mStencil ); } } @@ -1615,7 +1605,7 @@ TextField::TextField() TextField::~TextField() { - mClipper.Reset(); + UnparentAndReset( mStencil ); if( ( NULL != mIdleCallback ) && Adaptor::IsAvailable() ) { 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 e40c647..a532449 100644 --- a/dali-toolkit/internal/controls/text-controls/text-field-impl.h +++ b/dali-toolkit/internal/controls/text-controls/text-field-impl.h @@ -24,7 +24,6 @@ // INTERNAL INCLUDES #include #include -#include #include #include #include @@ -212,10 +211,8 @@ private: // Implementation /** * @brief Enable or disable clipping. - * - * @param[in] size The area to clip within. */ - void EnableClipping( const Vector2& size ); + void EnableClipping(); /** * @brief Callback when keyboard is shown/hidden. @@ -271,7 +268,7 @@ private: // Data Text::ControllerPtr mController; Text::RendererPtr mRenderer; Text::DecoratorPtr mDecorator; - Text::ClipperPtr mClipper; ///< For EXCEED_POLICY_CLIP + Toolkit::Control mStencil; ///< For EXCEED_POLICY_CLIP std::vector mClippingDecorationActors; ///< Decoration actors which need clipping. Actor mRenderableActor; diff --git a/dali-toolkit/internal/file.list b/dali-toolkit/internal/file.list index c8c98ad..7fa3af7 100644 --- a/dali-toolkit/internal/file.list +++ b/dali-toolkit/internal/file.list @@ -96,7 +96,6 @@ toolkit_src_files = \ $(toolkit_src_dir)/styling/style-manager-impl.cpp \ $(toolkit_src_dir)/text/bidirectional-support.cpp \ $(toolkit_src_dir)/text/character-set-conversion.cpp \ - $(toolkit_src_dir)/text/clipping/text-clipper.cpp \ $(toolkit_src_dir)/text/color-segmentation.cpp \ $(toolkit_src_dir)/text/cursor-helper-functions.cpp \ $(toolkit_src_dir)/text/glyph-metrics-helper.cpp \ diff --git a/dali-toolkit/internal/text/clipping/text-clipper.cpp b/dali-toolkit/internal/text/clipping/text-clipper.cpp deleted file mode 100644 index 11a8fc9..0000000 --- a/dali-toolkit/internal/text/clipping/text-clipper.cpp +++ /dev/null @@ -1,166 +0,0 @@ -/* - * Copyright (c) 2016 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -// CLASS HEADER -#include - -// EXTERNAL INCLUDES -#include -#include -#include - -namespace -{ - -// Currently on desktop machines 2k x 2k is the maximum frame buffer size, on target is 4k x 4k. -const float MAX_OFFSCREEN_RENDERING_SIZE = 2048.f; - -} // namespace - - -namespace Dali -{ - -namespace Toolkit -{ - -namespace Text -{ - -ClipperPtr Clipper::New( const Vector2& size ) -{ - ClipperPtr clipper( new Clipper() ); - - // Second-phase init - clipper->Initialize( size ); - - return clipper; -} - -Actor Clipper::GetRootActor() const -{ - return mOffscreenRootActor; -} - -Actor Clipper::GetImageView() const -{ - return mImageView; -} - -void Clipper::Refresh( const Vector2& size ) -{ - const Size offscreenSize( std::min( MAX_OFFSCREEN_RENDERING_SIZE, size.width ), - std::min( MAX_OFFSCREEN_RENDERING_SIZE, size.height ) ); - - const bool sizeChanged = offscreenSize != mCurrentOffscreenSize; - - if( sizeChanged ) - { - // Reconfigure camera for current size. - mOffscreenCameraActor.SetOrthographicProjection( offscreenSize ); - - // Recreate frame buffer for offscreen rendering when the size changes. - FrameBufferImage frameBufferImage = FrameBufferImage::New( offscreenSize.width, - offscreenSize.height, - Pixel::RGBA8888 ); - - mOffscreenRootActor.SetSize( size ); - - mImageView.SetSize( offscreenSize ); - mImageView.SetImage( frameBufferImage ); - mRenderTask.SetTargetFrameBuffer( frameBufferImage ); - - // Stores current sizPe to avoid create new Dali resources if text changes. - mCurrentOffscreenSize = offscreenSize; - } - - mRenderTask.SetRefreshRate( RenderTask::REFRESH_ONCE ); -} - -void Clipper::Initialize( const Vector2& size ) -{ - const Size offscreenSize( std::min( MAX_OFFSCREEN_RENDERING_SIZE, size.width ), - std::min( MAX_OFFSCREEN_RENDERING_SIZE, size.height ) ); - - // Create a root actor and an image view for offscreen rendering. - mOffscreenRootActor = Layer::New(); - mOffscreenRootActor.SetColorMode( USE_OWN_COLOR ); - mOffscreenRootActor.SetInheritPosition( false ); - mOffscreenRootActor.SetInheritScale( false ); - mOffscreenRootActor.SetDepthTestDisabled( true ); - mOffscreenRootActor.SetSize( offscreenSize ); - - mImageView = ImageView::New(); - mImageView.SetParentOrigin( ParentOrigin::CENTER ); - mImageView.SetScale( Vector3( 1.0f, -1.0f, 1.0f ) ); - mImageView.SetSize( offscreenSize ); - - // Creates a new camera actor. - mOffscreenCameraActor = CameraActor::New(); - mOffscreenCameraActor.SetParentOrigin( ParentOrigin::CENTER ); - mOffscreenCameraActor.SetOrthographicProjection( offscreenSize ); - mOffscreenRootActor.Add( mOffscreenCameraActor ); // camera to shoot the offscreen text - - // Creates a new render task. - mRenderTask = Stage::GetCurrent().GetRenderTaskList().CreateTask(); - mRenderTask.SetSourceActor( mOffscreenRootActor ); - mRenderTask.SetClearColor( Color::TRANSPARENT ); - mRenderTask.SetClearEnabled( true ); - mRenderTask.SetExclusive( true ); - mRenderTask.SetCameraActor( mOffscreenCameraActor ); - - // Creates a frame buffer for offscreen rendering - FrameBufferImage frameBufferImage = FrameBufferImage::New( offscreenSize.width, - offscreenSize.height, - Pixel::RGBA8888 ); - mImageView.SetImage( frameBufferImage ); - mRenderTask.SetTargetFrameBuffer( frameBufferImage ); - mImageView.OnStageSignal().Connect(this, &Clipper::OnStageConnect); - - // Stores current size to avoid create new Dali resources if text changes. - mCurrentOffscreenSize = offscreenSize; -} - -void Clipper::OnStageConnect( Dali::Actor actor ) -{ - Renderer renderer = mImageView.GetRendererAt(0); - renderer.SetProperty( Renderer::Property::BLEND_FACTOR_SRC_RGB, BlendFactor::ONE ); - renderer.SetProperty( Renderer::Property::BLEND_FACTOR_DEST_RGB, BlendFactor::ONE_MINUS_SRC_ALPHA ); - renderer.SetProperty( Renderer::Property::BLEND_FACTOR_SRC_ALPHA, BlendFactor::ONE ); - renderer.SetProperty( Renderer::Property::BLEND_FACTOR_DEST_ALPHA, BlendFactor::ONE ); -} - -Clipper::Clipper() -{ -} - -Clipper::~Clipper() -{ - if( Stage::IsInstalled() ) - { - UnparentAndReset( mOffscreenRootActor ); - UnparentAndReset( mImageView ); - - Stage::GetCurrent().GetRenderTaskList().RemoveTask( mRenderTask ); - } -} - -} // namespace Text - -} // namespace Toolkit - -} // namespace Dali diff --git a/dali-toolkit/internal/text/clipping/text-clipper.h b/dali-toolkit/internal/text/clipping/text-clipper.h deleted file mode 100644 index 5f5be4b..0000000 --- a/dali-toolkit/internal/text/clipping/text-clipper.h +++ /dev/null @@ -1,123 +0,0 @@ -#ifndef __DALI_TOOLKIT_INTERNAL_TEXT_CLIPPER_H__ -#define __DALI_TOOLKIT_INTERNAL_TEXT_CLIPPER_H__ - -/* - * Copyright (c) 2015 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -// EXTERNAL INCLUDES -#include -#include -#include -#include -#include - -namespace Dali -{ - -namespace Toolkit -{ - -namespace Text -{ - -class Clipper; -typedef IntrusivePtr ClipperPtr; - -/** - * @brief A helper class for clipping actors using a FrameBufferImage. - */ -class Clipper : public RefObject, public ConnectionTracker -{ -public: - - /** - * @brief Create a clipper. - * - * @param[in] size The size of the clipping region. - */ - static ClipperPtr New( const Vector2& size ); - - /** - * @brief Children added to this actor will be clipped with the specified region. - * - * @note This is done by rendering to a FrameBufferImage which must then be displayed; see also GetImageView(). - * @return The root actor. - */ - Actor GetRootActor() const; - - /** - * @brief This actor will display the resulting FrameBufferImage. - * - * @return The image view. - */ - Actor GetImageView() const; - - /** - * @brief Refresh the contents of the FrameBufferImage. - * - * @param[in] size The size of the clipping region. - */ - void Refresh( const Vector2& size ); - -private: // Implementation - - /** - * @brief Second-phase init - * - * @param[in] size The size of the clipping region. - */ - void Initialize( const Vector2& size ); - - /** - * The renderer is not created until the clipper actor is set on stage, only by then the blend function could be set. - * - * @param[in] actor The actor connected to stage. - */ - void OnStageConnect( Dali::Actor actor ); - - /** - * Construct a new Clipper. - */ - Clipper(); - - /** - * A reference counted object may only be deleted by calling Unreference() - */ - virtual ~Clipper(); - -private: - - // Undefined copy constructor and assignment operators - Clipper(const Clipper&); - Clipper& operator=(const Clipper& rhs); - -private: // Data - - Layer mOffscreenRootActor; - CameraActor mOffscreenCameraActor; - ImageView mImageView; - RenderTask mRenderTask; - Vector2 mCurrentOffscreenSize; -}; - -} // namespace Text - -} // namespace Toolkit - -} // namespace Dali - -#endif // __DALI_TOOLKIT_INTERNAL_TEXT_CLIPPER_H__ -- 2.7.4