* Fixes issues with the inherited alpha channel.
Change-Id: I6a3f125d6de10d4d3d8673a6b340f05ae0edd3f6
Signed-off-by: Victor Cebollada <v.cebollada@samsung.com>
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 ) ) );
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 ) );
// 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 );
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;
}
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;
DALI_TEST_EQUALS( field.GetProperty<int>( 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<int>( TextField::Property::EXCEED_POLICY ), static_cast<int>( 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<int>( TextField::Property::EXCEED_POLICY ), static_cast<int>( Dali::Toolkit::TextField::EXCEED_POLICY_ORIGINAL ), TEST_LOCATION );
// Check that the Alignment properties can be correctly set
field.SetProperty( TextField::Property::HORIZONTAL_ALIGNMENT, "END" );
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 ) ) );
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 ) );
// 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 );
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;
}
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;
SendPan(application, Gesture::Finished, pos);
Wait(application, RENDER_FRAME_INTERVAL);
- Actor offscreenRoot = field.GetChildAt( 1u );
+ Actor stencil = field.GetChildAt( 1u );
END_TEST;
}
// INTERNAL INCLUDES
#include <dali-toolkit/public-api/text/rendering-backend.h>
+#include <dali-toolkit/public-api/visuals/color-visual-properties.h>
#include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
+#include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
#include <dali-toolkit/internal/text/rendering/text-backend.h>
#include <dali-toolkit/internal/text/text-effects-style.h>
#include <dali-toolkit/internal/text/text-font-style.h>
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 )
mRenderer = Backend::Get().NewRenderer( mRenderingBackend );
}
- EnableClipping( size );
RenderText( updateTextType );
}
void TextEditor::RenderText( Text::Controller::UpdateTextType updateTextType )
{
- Actor self = Self();
Actor renderableActor;
if( Text::Controller::NONE_UPDATED != ( Text::Controller::MODEL_UPDATED & 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<Actor>::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 );
}
}
}
}
-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();
TextEditor::~TextEditor()
{
- mClipper.Reset();
+ UnparentAndReset( mStencil );
if( ( NULL != mIdleCallback ) && Adaptor::IsAvailable() )
{
// INTERNAL INCLUDES
#include <dali-toolkit/public-api/controls/control-impl.h>
#include <dali-toolkit/public-api/controls/text-controls/text-editor.h>
-#include <dali-toolkit/internal/text/clipping/text-clipper.h>
#include <dali-toolkit/internal/text/decorator/text-decorator.h>
#include <dali-toolkit/internal/text/text-control-interface.h>
#include <dali-toolkit/internal/text/text-editable-control-interface.h>
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.
Text::ControllerPtr mController;
Text::RendererPtr mRenderer;
Text::DecoratorPtr mDecorator;
- Text::ClipperPtr mClipper;
+ Toolkit::Control mStencil;
std::vector<Actor> mClippingDecorationActors; ///< Decoration actors which need clipping.
Actor mRenderableActor;
// INTERNAL INCLUDES
#include <dali-toolkit/public-api/text/rendering-backend.h>
+#include <dali-toolkit/public-api/visuals/color-visual-properties.h>
#include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
+#include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
#include <dali-toolkit/internal/text/rendering/text-backend.h>
#include <dali-toolkit/internal/text/text-effects-style.h>
#include <dali-toolkit/internal/text/text-font-style.h>
}
case Toolkit::TextField::Property::EXCEED_POLICY:
{
- // TODO
+ impl.mExceedPolicy = value.Get<int>();
+
+ if( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == impl.mExceedPolicy )
+ {
+ impl.EnableClipping();
+ }
+ else
+ {
+ UnparentAndReset( impl.mStencil );
+ }
+ impl.RequestTextRelayout();
break;
}
case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
}
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,
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 )
mRenderer = Backend::Get().NewRenderer( mRenderingBackend );
}
- EnableClipping( size );
RenderText( updateTextType );
}
void TextField::RenderText( Text::Controller::UpdateTextType updateTextType )
{
- Actor self = Self();
Actor renderableActor;
if( Text::Controller::NONE_UPDATED != ( Text::Controller::MODEL_UPDATED & 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<Actor>::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 );
}
}
}
}
-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 );
}
}
TextField::~TextField()
{
- mClipper.Reset();
+ UnparentAndReset( mStencil );
if( ( NULL != mIdleCallback ) && Adaptor::IsAvailable() )
{
// INTERNAL INCLUDES
#include <dali-toolkit/public-api/controls/control-impl.h>
#include <dali-toolkit/public-api/controls/text-controls/text-field.h>
-#include <dali-toolkit/internal/text/clipping/text-clipper.h>
#include <dali-toolkit/internal/text/decorator/text-decorator.h>
#include <dali-toolkit/internal/text/text-control-interface.h>
#include <dali-toolkit/internal/text/text-editable-control-interface.h>
/**
* @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.
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<Actor> mClippingDecorationActors; ///< Decoration actors which need clipping.
Actor mRenderableActor;
$(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 \
+++ /dev/null
-/*
- * 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 <dali-toolkit/internal/text/clipping/text-clipper.h>
-
-// EXTERNAL INCLUDES
-#include <dali/public-api/common/stage.h>
-#include <dali/public-api/render-tasks/render-task-list.h>
-#include <dali/public-api/rendering/renderer.h>
-
-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
+++ /dev/null
-#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 <dali/public-api/actors/layer.h>
-#include <dali/public-api/actors/camera-actor.h>
-#include <dali/public-api/render-tasks/render-task.h>
-#include <dali-toolkit/public-api/controls/image-view/image-view.h>
-#include <dali/public-api/signals/connection-tracker.h>
-
-namespace Dali
-{
-
-namespace Toolkit
-{
-
-namespace Text
-{
-
-class Clipper;
-typedef IntrusivePtr<Clipper> 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__