#include <dali-toolkit/internal/text/text-scroller.h>
// EXTERNAL INCLUDES
-#include <dali/devel-api/rendering/geometry.h>
-#include <dali/devel-api/rendering/renderer.h>
-#include <dali/devel-api/rendering/sampler.h>
-#include <dali/devel-api/rendering/shader.h>
-#include <dali/integration-api/debug.h>
#include <dali/public-api/common/stage.h>
#include <dali/public-api/images/frame-buffer-image.h>
#include <dali/public-api/render-tasks/render-task-list.h>
+#include <dali/public-api/rendering/geometry.h>
+#include <dali/public-api/rendering/renderer.h>
+#include <dali/public-api/rendering/sampler.h>
+#include <dali/public-api/rendering/shader.h>
+#include <dali/devel-api/images/texture-set-image.h>
+#include <dali/integration-api/debug.h>
// INTERNAL INCLUDES
#include <dali-toolkit/internal/text/text-scroller-interface.h>
+#include <dali-toolkit/internal/text/text-scroller-data.h>
namespace Dali
{
namespace Toolkit
{
+namespace Text
+{
+extern const int MINIMUM_SCROLL_SPEED;
+} // namespace
+
namespace
{
Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_SCROLLING");
#endif
-const int MINIMUM_SCROLL_SPEED = 1; // Speed should be set by Property system.
-
const char* VERTEX_SHADER_SCROLL = DALI_COMPOSE_SHADER(
attribute mediump vec2 aPosition;\n
varying highp vec2 vTexCoord;\n
*/
void CreateRenderer( FrameBufferImage frameBufferImage, Dali::Renderer& renderer )
{
- Shader shader = Shader::New( VERTEX_SHADER_SCROLL , FRAGMENT_SHADER, Shader::HINT_NONE );
+ Shader shader = Shader::New( VERTEX_SHADER_SCROLL , FRAGMENT_SHADER, Shader::Hint::NONE );
Sampler sampler = Sampler::New();
sampler.SetFilterMode(FilterMode::NEAREST, FilterMode::NEAREST );
TextureSet textureSet = TextureSet::New();
- textureSet.SetImage( 0u, frameBufferImage );
+ TextureSetImage( textureSet, 0u, frameBufferImage );
textureSet.SetSampler( 0u, sampler );
Geometry meshGeometry;
return textScroller;
}
-void TextScroller::SetGap( int gap )
-{
- DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextScroller::SetGap gap[%d]\n", gap );
- mWrapGap = static_cast<float>(gap);
-}
-
-int TextScroller::GetGap() const
-{
- return static_cast<int>(mWrapGap);
-}
-
-void TextScroller::SetSpeed( int scrollSpeed )
-{
- mScrollSpeed = std::max( MINIMUM_SCROLL_SPEED, scrollSpeed );
-}
-
-int TextScroller::GetSpeed() const
-{
- return mScrollSpeed;
-}
-
-void TextScroller::SetLoopCount( int loopCount )
-{
- if ( loopCount > 0 )
- {
- mLoopCount = loopCount;
- }
-
- if ( mScrollAnimation && mScrollAnimation.GetState() == Animation::PLAYING )
- {
- if ( loopCount == 0 ) // Request to stop looping
- {
- DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextScroller::SetLoopCount Single loop forced\n" );
- mScrollAnimation.SetLoopCount( 1 ); // As animation already playing this allows the current animation to finish instead of trying to stop mid-way
- }
- }
- DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextScroller::SetLoopCount [%d] Status[%s]\n", mLoopCount, (loopCount)?"looping":"stop" );
-}
-
-int TextScroller::GetLoopCount() const
-{
- return mLoopCount;
-}
-
Actor TextScroller::GetSourceCamera() const
{
return mOffscreenCameraActor;
return mScrollingTextActor;
}
-TextScroller::TextScroller( ScrollerInterface& scrollerInterface ) : mScrollerInterface( scrollerInterface ),
- mScrollDeltaIndex( Property::INVALID_INDEX ),
- mScrollSpeed( MINIMUM_SCROLL_SPEED ),
- mLoopCount( 1 ),
- mWrapGap( 0.0f )
+TextScroller::TextScroller( ScrollerInterface& scrollerInterface )
+: mScrollerInterface( scrollerInterface ),
+ mScrollDeltaIndex( Property::INVALID_INDEX )
{
DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextScroller Default Constructor\n" );
}
CleanUp();
}
-void TextScroller::SetParameters( Actor sourceActor, const Size& controlSize, const Size& offScreenSize, CharacterDirection direction, float alignmentOffset )
+void TextScroller::StartScrolling( Actor sourceActor,
+ const ScrollerData& data )
{
- DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextScroller::SetParameters controlSize[%f,%f] offscreenSize[%f,%f] direction[%d] alignmentOffset[%f]\n",
- controlSize.x, controlSize.y, offScreenSize.x, offScreenSize.y, direction, alignmentOffset );
-
- FrameBufferImage offscreenRenderTargetForText = FrameBufferImage::New( offScreenSize.width, offScreenSize.height, Pixel::RGBA8888, Dali::Image::UNUSED );
+ DALI_LOG_INFO( gLogFilter,
+ Debug::Verbose,
+ "TextScroller::StartScrolling controlSize[%f,%f] offscreenSize[%f,%f] direction[%d] alignmentOffset[%f]\n",
+ data.mControlSize.x, data.mControlSize.y,
+ data.mOffscreenSize.x, data.mOffscreenSize.y,
+ data.mAutoScrollDirectionRTL,
+ data.mAlignmentOffset );
+
+ FrameBufferImage offscreenRenderTargetForText = FrameBufferImage::New( data.mOffscreenSize.width, data.mOffscreenSize.height, Pixel::RGBA8888 );
Renderer renderer;
- CreateCameraActor( offScreenSize, mOffscreenCameraActor );
+ CreateCameraActor( data.mOffscreenSize, mOffscreenCameraActor );
CreateRenderer( offscreenRenderTargetForText, renderer );
CreateRenderTask( sourceActor, mOffscreenCameraActor, offscreenRenderTargetForText, mRenderTask );
// Reposition camera to match alignment of target, RTL text has direction=true
- if ( direction )
+ if( data.mAutoScrollDirectionRTL )
{
- mOffscreenCameraActor.SetX( alignmentOffset + offScreenSize.width*0.5f );
+ mOffscreenCameraActor.SetX( data.mAlignmentOffset + data.mOffscreenSize.width * 0.5f );
}
else
{
- mOffscreenCameraActor.SetX( offScreenSize.width * 0.5f );
+ mOffscreenCameraActor.SetX( data.mOffscreenSize.width * 0.5f );
}
- mOffscreenCameraActor.SetY( offScreenSize.height * 0.5f );
+ mOffscreenCameraActor.SetY( data.mOffscreenSize.height * 0.5f );
- DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextScroller::SetParameters mWrapGap[%f]\n", mWrapGap )
+ DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextScroller::SetParameters mWrapGap[%f]\n", data.mWrapGap )
mScrollingTextActor = Actor::New();
mScrollingTextActor.AddRenderer( renderer );
- mScrollingTextActor.RegisterProperty( "uTextureSize", offScreenSize );
- mScrollingTextActor.RegisterProperty( "uRtl", ((direction)?1.0f:0.0f) );
- mScrollingTextActor.RegisterProperty( "uGap", mWrapGap );
- mScrollingTextActor.SetSize( controlSize.width, std::min( offScreenSize.height, controlSize.height ) );
+ mScrollingTextActor.RegisterProperty( "uTextureSize", data.mOffscreenSize );
+ mScrollingTextActor.RegisterProperty( "uRtl", ( data.mAutoScrollDirectionRTL ? 1.f : 0.f ) );
+ mScrollingTextActor.RegisterProperty( "uGap", data.mWrapGap );
+ mScrollingTextActor.SetSize( data.mControlSize.width, std::min( data.mOffscreenSize.height, data.mControlSize.height ) );
mScrollDeltaIndex = mScrollingTextActor.RegisterProperty( "uDelta", 0.0f );
- float scrollAmount = std::max( offScreenSize.width + mWrapGap, controlSize.width );
- float scrollDuration = scrollAmount / mScrollSpeed;
+ float scrollAmount = std::max( data.mOffscreenSize.width + data.mWrapGap, data.mControlSize.width );
+ float scrollSpeed = std::max( MINIMUM_SCROLL_SPEED, data.mScrollSpeed );
+ float scrollDuration = scrollAmount / scrollSpeed;
- if ( direction )
+ if( data.mAutoScrollDirectionRTL )
{
scrollAmount = -scrollAmount; // reverse direction of scrollung
}
- StartScrolling( scrollAmount, scrollDuration, mLoopCount );
+ mScrollAnimation = Animation::New( scrollDuration );
+ mScrollAnimation.AnimateTo( Property( mScrollingTextActor, mScrollDeltaIndex ), scrollAmount );
+ mScrollAnimation.SetEndAction( Animation::Discard );
+ mScrollAnimation.SetLoopCount( data.mLoopCount );
+ mScrollAnimation.FinishedSignal().Connect( this, &TextScroller::AutoScrollAnimationFinished );
+ mScrollAnimation.Play();
+}
+
+void TextScroller::StopScrolling()
+{
+ if( mScrollAnimation &&
+ ( mScrollAnimation.GetState() == Animation::PLAYING ) )
+ {
+ DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextScroller::SetLoopCount Single loop forced\n" );
+ mScrollAnimation.SetLoopCount( 1 ); // As animation already playing this allows the current animation to finish instead of trying to stop mid-way
+ }
}
void TextScroller::AutoScrollAnimationFinished( Dali::Animation& animation )
mScrollerInterface.ScrollingFinished();
}
-void TextScroller::StartScrolling( float scrollAmount, float scrollDuration, int loopCount )
-{
- DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextScroller::StartScrolling scrollAmount[%f] scrollDuration[%f], loop[%d] speed[%d]\n", scrollAmount, scrollDuration, loopCount, mScrollSpeed );
-
- mScrollAnimation = Animation::New( scrollDuration );
- mScrollAnimation.AnimateTo( Property( mScrollingTextActor, mScrollDeltaIndex ), scrollAmount );
- mScrollAnimation.SetEndAction( Animation::Discard );
- mScrollAnimation.SetLoopCount( loopCount );
- mScrollAnimation.FinishedSignal().Connect( this, &TextScroller::AutoScrollAnimationFinished );
- mScrollAnimation.Play();
-}
-
void TextScroller::CleanUp()
{
if ( Stage::IsInstalled() )