From: Adeel Kazmi Date: Mon, 5 Jun 2017 10:19:20 +0000 (+0000) Subject: Merge "Text scroller renderer bug fix" into devel/master X-Git-Tag: dali_1.2.43~7 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=commitdiff_plain;h=5e86784bcfbc88120549a72284a23b98adbc90ae;hp=-c Merge "Text scroller renderer bug fix" into devel/master --- 5e86784bcfbc88120549a72284a23b98adbc90ae diff --combined dali-toolkit/internal/text/text-scroller.cpp index 3419e99,adcf901..590f919 --- a/dali-toolkit/internal/text/text-scroller.cpp +++ b/dali-toolkit/internal/text/text-scroller.cpp @@@ -1,5 -1,5 +1,5 @@@ /* - * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * Copyright (c) 2017 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. @@@ -58,7 -58,7 +58,7 @@@ const char* VERTEX_SHADER_SCROLL = DALI uniform mediump float uDelta;\n uniform mediump vec2 uTextureSize; uniform mediump float uGap;\n - uniform mediump float uRtl;\n + uniform mediump float uAlign;\n \n void main()\n {\n @@@ -70,7 -70,7 +70,7 @@@ float smallTextPadding = max(uSize.x - uTextureSize.x, 0. );\n float gap = max( uGap, smallTextPadding );\n float delta = floor ( uDelta ) + 0.5; - vTexCoord.x = ( delta + ( uRtl * ( uTextureSize.x - uSize.x ) ) + ( aPosition.x * uSize.x ) )/ ( uTextureSize.x + gap );\n + vTexCoord.x = ( delta + ( uAlign * ( 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 = uProjection * vertexPosition; @@@ -96,54 -96,6 +96,54 @@@ const char* FRAGMENT_SHADER = DALI_COMP ); /** + * @brief How the text should be aligned when scrolling the text. + * + * 0.0f aligns the text to the left, 1.0f aligns the text to the right. + * The final alignment depends on three factors: + * 1) The alignment value of the text label (Use Text::Layout::HorizontalAlignment enumerations). + * 2) The text direction, i.e. whether it's LTR or RTL (0 = LTR, 1 = RTL). + * 3) Whether the text is greater than the size of the control ( 0 = Text width <= Control width, 1 = Text width > Control width ). + */ +const float ALIGNMENT_TABLE[ Text::Layout::HORIZONTAL_ALIGN_COUNT ][ 2 ][ 2 ] = +{ + // HORIZONTAL_ALIGN_BEGIN + { + { // LTR + 0.0f, // Text width <= Control width + 0.0f // Text width > Control width + }, + { // RTL + 1.0f, // Text width <= Control width + 1.0f // Text width > Control width + } + }, + + // HORIZONTAL_ALIGN_CENTER + { + { // LTR + 0.5f, // Text width <= Control width + 0.0f // Text width > Control width + }, + { // RTL + 0.5f, // Text width <= Control width + 1.0f // Text width > Control width + } + }, + + // HORIZONTAL_ALIGN_END + { + { // LTR + 1.0f, // Text width <= Control width + 0.0f // Text width > Control width + }, + { // RTL + 0.0f, // Text width <= Control width + 1.0f // Text width > Control width + } + } +}; + +/** * @brief Create and set up a camera for the render task to use * * @param[in] sizeOfTarget size of the source camera to look at @@@ -233,6 -185,7 +233,7 @@@ void CreateRenderer( FrameBufferImage f CreateGeometry( meshGeometry ); renderer = Renderer::New( meshGeometry, shader ); + renderer.SetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, true ); renderer.SetTextures( textureSet ); } @@@ -272,11 -225,35 +273,11 @@@ int TextScroller::GetSpeed() cons void TextScroller::SetLoopCount( int loopCount ) { - if ( loopCount > 0 ) + 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" ); - 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" ); } @@@ -301,32 -278,6 +302,32 @@@ void TextScroller::SetStopMode( DevelTe mStopMode = stopMode; } +void TextScroller::StopScrolling() +{ + if ( mScrollAnimation && mScrollAnimation.GetState() == Animation::PLAYING ) + { + switch( mStopMode ) + { + case DevelTextLabel::AutoScrollStopMode::IMMEDIATE: + { + mScrollAnimation.Stop(); + CleanUp(); + mScrollerInterface.ScrollingFinished(); + 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" ); + } + } + } +} + DevelTextLabel::AutoScrollStopMode::Type TextScroller::GetStopMode() const { return mStopMode; @@@ -358,27 -309,15 +359,27 @@@ TextScroller::~TextScroller( CleanUp(); } -void TextScroller::SetParameters( Actor sourceActor, const Size& controlSize, const Size& offScreenSize, CharacterDirection direction, float alignmentOffset ) +void TextScroller::SetParameters( Actor sourceActor, const Size& controlSize, const Size& offScreenSize, CharacterDirection direction, float alignmentOffset, Layout::HorizontalAlignment horizontalAlignment ) { 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 + float animationProgress = 0.0f; + int remainedLoop = mLoopCount; if ( mScrollAnimation ) { + if( mScrollAnimation.GetState() == Animation::PLAYING ) + { + animationProgress = mScrollAnimation.GetCurrentProgress(); + + if( mLoopCount > 0 ) // If not a ininity loop, then calculate remained loop + { + remainedLoop = mLoopCount - ( mScrollAnimation.GetCurrentLoop() ); + remainedLoop = ( remainedLoop <= 0 ? 1 : remainedLoop ); + } + } mScrollAnimation.Clear(); } @@@ -389,58 -328,24 +390,58 @@@ CreateRenderer( offscreenRenderTargetForText, renderer ); CreateRenderTask( sourceActor, mOffscreenCameraActor, offscreenRenderTargetForText, mRenderTask ); - // Reposition camera to match alignment of target, RTL text has direction=true - if ( direction ) - { - mOffscreenCameraActor.SetX( alignmentOffset + offScreenSize.width*0.5f ); - } - else + float xPosition = 0.0f; + switch( horizontalAlignment ) { - mOffscreenCameraActor.SetX( offScreenSize.width * 0.5f ); + case Layout::HORIZONTAL_ALIGN_BEGIN: + { + // Reposition camera to match alignment of target, RTL text has direction=true + if ( direction ) + { + xPosition = alignmentOffset + offScreenSize.width * 0.5f; + } + else + { + xPosition = offScreenSize.width * 0.5f; + } + break; + } + + case Layout::HORIZONTAL_ALIGN_CENTER: + { + xPosition = controlSize.width * 0.5f; + break; + } + + case Layout::HORIZONTAL_ALIGN_END: + { + // Reposition camera to match alignment of target, RTL text has direction=true + if ( direction ) + { + xPosition = offScreenSize.width * 0.5f; + } + else + { + xPosition = alignmentOffset + offScreenSize.width * 0.5f; + } + break; + } } + DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextScroller::SetParameters xPosition[%f]\n", xPosition ); + + mOffscreenCameraActor.SetX( xPosition ); mOffscreenCameraActor.SetY( offScreenSize.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", mWrapGap ); + + const float align = ALIGNMENT_TABLE[ horizontalAlignment ][ direction ][ offScreenSize.width > controlSize.width ]; + DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextScroller::SetParameters align[%f]\n", align ); mScrollingTextActor = Actor::New(); mScrollingTextActor.AddRenderer( renderer ); mScrollingTextActor.RegisterProperty( "uTextureSize", offScreenSize ); - mScrollingTextActor.RegisterProperty( "uRtl", ((direction)?1.0f:0.0f) ); + mScrollingTextActor.RegisterProperty( "uAlign", align ); mScrollingTextActor.RegisterProperty( "uGap", mWrapGap ); mScrollingTextActor.SetSize( controlSize.width, std::min( offScreenSize.height, controlSize.height ) ); mScrollDeltaIndex = mScrollingTextActor.RegisterProperty( "uDelta", 0.0f ); @@@ -453,8 -358,7 +454,8 @@@ scrollAmount = -scrollAmount; // reverse direction of scrollung } - StartScrolling( scrollAmount, scrollDuration, mLoopCount ); + StartScrolling( scrollAmount, scrollDuration, remainedLoop ); + mScrollAnimation.SetCurrentProgress(animationProgress); } void TextScroller::AutoScrollAnimationFinished( Dali::Animation& animation )