X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Ftext%2Ftext-scroller.cpp;h=c80cf7d05e2097d688ea32e81b8e76adba859071;hp=5b7b99b1f17b14ab9b85b8f4ea64119214816279;hb=6efee146b4c4e40df991b9e3425f97c66150df10;hpb=00fdaec1c1d0ae69756e720ac5d3bc3acc5bd2a9 diff --git a/dali-toolkit/internal/text/text-scroller.cpp b/dali-toolkit/internal/text/text-scroller.cpp index 5b7b99b..c80cf7d 100644 --- a/dali-toolkit/internal/text/text-scroller.cpp +++ b/dali-toolkit/internal/text/text-scroller.cpp @@ -19,14 +19,15 @@ #include // EXTERNAL INCLUDES -#include -#include -#include -#include -#include #include #include #include +#include +#include +#include +#include +#include +#include // INTERNAL INCLUDES #include @@ -50,7 +51,9 @@ const char* VERTEX_SHADER_SCROLL = DALI_COMPOSE_SHADER( attribute mediump vec2 aPosition;\n varying highp vec2 vTexCoord;\n varying highp float vRatio;\n - uniform mediump mat4 uMvpMatrix;\n + uniform mediump mat4 uModelMatrix;\n + uniform mediump mat4 uViewMatrix;\n + uniform mediump mat4 uProjection;\n uniform mediump vec3 uSize;\n uniform mediump float uDelta;\n uniform mediump vec2 uTextureSize; @@ -60,25 +63,29 @@ const char* VERTEX_SHADER_SCROLL = DALI_COMPOSE_SHADER( void main()\n {\n {\n - mediump vec4 vertexPosition = vec4(aPosition*uSize.xy, 0.0, 1.0);\n + highp vec4 vertexPosition = vec4(aPosition*uSize.xy, 0.0, 1.0);\n + vertexPosition = uViewMatrix * uModelMatrix * vertexPosition ;\n + vertexPosition.x = floor( vertexPosition.x ) + 0.5; + vertexPosition.y = floor( vertexPosition.y ) + 0.5; float smallTextPadding = max(uSize.x - uTextureSize.x, 0. );\n float gap = max( uGap, smallTextPadding );\n - vTexCoord.x = ( uDelta + ( uRtl * ( uTextureSize.x - uSize.x ) ) + ( aPosition.x * uSize.x ) )/ ( uTextureSize.x+gap );\n - vTexCoord.y = aPosition.y;\n + float delta = floor ( uDelta ) + 0.5; + vTexCoord.x = ( delta + ( uRtl * ( uTextureSize.x - uSize.x ) ) + ( aPosition.x * uSize.x ) )/ ( uTextureSize.x + gap );\n + vTexCoord.y = ( 0.5 + floor( aPosition.y * uSize.y ) )/ ( uTextureSize.y ) ;\n vRatio = uTextureSize.x / ( uTextureSize.x + gap );\n - gl_Position = uMvpMatrix * vertexPosition;\n + gl_Position = uProjection * vertexPosition; }\n }\n ); const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER( - varying mediump vec2 vTexCoord;\n + varying highp vec2 vTexCoord;\n varying highp float vRatio;\n uniform sampler2D sTexture;\n \n void main()\n {\n - mediump vec2 texCoord;\n + highp vec2 texCoord;\n texCoord.y = vTexCoord.y;\n texCoord.x = fract( vTexCoord.x ) / vRatio;\n if ( texCoord.x > 1.0 )\n @@ -165,13 +172,13 @@ void CreateGeometry( Geometry& geometry ) */ 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 ); + sampler.SetFilterMode(FilterMode::LINEAR, FilterMode::LINEAR ); TextureSet textureSet = TextureSet::New(); - textureSet.SetImage( 0u, frameBufferImage ); + TextureSetImage( textureSet, 0u, frameBufferImage ); textureSet.SetSampler( 0u, sampler ); Geometry meshGeometry; @@ -194,15 +201,15 @@ TextScrollerPtr TextScroller::New( ScrollerInterface& scrollerInterface ) return textScroller; } -void TextScroller::SetGap( float gap ) +void TextScroller::SetGap( int gap ) { - DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextScroller::SetGap gap[%f]\n", gap ); - mWrapGap = gap; + DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextScroller::SetGap gap[%d]\n", gap ); + mWrapGap = static_cast(gap); } -float TextScroller::GetGap() const +int TextScroller::GetGap() const { - return mWrapGap; + return static_cast(mWrapGap); } void TextScroller::SetSpeed( int scrollSpeed ) @@ -227,7 +234,23 @@ void TextScroller::SetLoopCount( int loopCount ) 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 + switch( mStopMode ) + { + case DevelTextLabel::AutoScrollStopMode::IMMEDIATE: + { + mScrollAnimation.Stop(); + break; + } + case DevelTextLabel::AutoScrollStopMode::FINISH_LOOP: + { + mScrollAnimation.SetLoopCount( 1 ); // As animation already playing this allows the current animation to finish instead of trying to stop mid-way + break; + } + default: + { + DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Undifined AutoScrollStopMode\n" ); + } + } } } DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextScroller::SetLoopCount [%d] Status[%s]\n", mLoopCount, (loopCount)?"looping":"stop" ); @@ -238,6 +261,27 @@ int TextScroller::GetLoopCount() const return mLoopCount; } +void TextScroller::SetLoopDelay( float delay ) +{ + mLoopDelay = delay; +} + +float TextScroller::GetLoopDelay() const +{ + return mLoopDelay; +} + +void TextScroller::SetStopMode( DevelTextLabel::AutoScrollStopMode::Type stopMode ) +{ + DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextScroller::SetAutoScrollStopMode [%s]\n",(stopMode == DevelTextLabel::AutoScrollStopMode::IMMEDIATE)?"IMMEDIATE":"FINISH_LOOP" ); + mStopMode = stopMode; +} + +DevelTextLabel::AutoScrollStopMode::Type TextScroller::GetStopMode() const +{ + return mStopMode; +} + Actor TextScroller::GetSourceCamera() const { return mOffscreenCameraActor; @@ -252,7 +296,9 @@ TextScroller::TextScroller( ScrollerInterface& scrollerInterface ) : mScrollerIn mScrollDeltaIndex( Property::INVALID_INDEX ), mScrollSpeed( MINIMUM_SCROLL_SPEED ), mLoopCount( 1 ), - mWrapGap( 0.0f ) + mLoopDelay( 0.0f ), + mWrapGap( 0.0f ), + mStopMode( DevelTextLabel::AutoScrollStopMode::FINISH_LOOP ) { DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextScroller Default Constructor\n" ); } @@ -262,12 +308,19 @@ TextScroller::~TextScroller() CleanUp(); } -void TextScroller::SetParameters( Actor sourceActor, const Size& controlSize, const Size& offScreenSize, CharacterDirection direction, const Vector2 alignmentOffset ) +void TextScroller::SetParameters( Actor sourceActor, const Size& controlSize, const Size& offScreenSize, CharacterDirection direction, float alignmentOffset ) { - DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextScroller::SetParameters controlSize[%f,%f] offscreenSize[%f,%f] direction[%d] alignmentOffset[%f,%f]\n", - controlSize.x, controlSize.y, offScreenSize.x, offScreenSize.y, direction, alignmentOffset.x, alignmentOffset.y ); + 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 ); + + CleanUp(); // If already scrolling then restart with new parameters + + if ( mScrollAnimation ) + { + mScrollAnimation.Clear(); + } - FrameBufferImage offscreenRenderTargetForText = FrameBufferImage::New( offScreenSize.width, offScreenSize.height, Pixel::RGBA8888, Dali::Image::UNUSED ); + FrameBufferImage offscreenRenderTargetForText = FrameBufferImage::New( offScreenSize.width, offScreenSize.height, Pixel::RGBA8888 ); Renderer renderer; CreateCameraActor( offScreenSize, mOffscreenCameraActor ); @@ -277,7 +330,7 @@ void TextScroller::SetParameters( Actor sourceActor, const Size& controlSize, co // Reposition camera to match alignment of target, RTL text has direction=true if ( direction ) { - mOffscreenCameraActor.SetX( alignmentOffset.x + offScreenSize.width*0.5f ); + mOffscreenCameraActor.SetX( alignmentOffset + offScreenSize.width*0.5f ); } else { @@ -319,7 +372,7 @@ void TextScroller::StartScrolling( float scrollAmount, float scrollDuration, int 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.AnimateTo( Property( mScrollingTextActor, mScrollDeltaIndex ), scrollAmount, TimePeriod( mLoopDelay, scrollDuration ) ); mScrollAnimation.SetEndAction( Animation::Discard ); mScrollAnimation.SetLoopCount( loopCount ); mScrollAnimation.FinishedSignal().Connect( this, &TextScroller::AutoScrollAnimationFinished );