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=dbc16ebb3e875d6bd493b0f2f1cf44a573384b6b;hp=49173e9beed950356e0d046b62b903f41c6856a9;hb=8e797fefb152f7f387a111ccc3771c5f81aa4eab;hpb=d9e73542cfca2591f40ca9ffeefa1e20e0c2bbd0 diff --git a/dali-toolkit/internal/text/text-scroller.cpp b/dali-toolkit/internal/text/text-scroller.cpp index 49173e9..dbc16eb 100644 --- a/dali-toolkit/internal/text/text-scroller.cpp +++ b/dali-toolkit/internal/text/text-scroller.cpp @@ -43,8 +43,6 @@ 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 - varying highp float vRatio;\n - uniform mediump mat4 uMvpMatrix;\n uniform mediump vec3 uSize;\n uniform mediump float uDelta;\n uniform mediump vec2 uTextureSize;\n @@ -52,34 +50,43 @@ const char* VERTEX_SHADER_SCROLL = DALI_COMPOSE_SHADER( uniform mediump float uHorizontalAlign;\n uniform mediump float uVerticalAlign;\n \n + uniform mediump mat4 uModelMatrix;\n + uniform mediump mat4 uViewMatrix;\n + uniform mediump mat4 uProjection;\n + \n + //Visual size and offset + uniform mediump vec2 offset;\n + uniform mediump vec2 size;\n + uniform mediump vec4 offsetSizeMode;\n + uniform mediump vec2 origin;\n + uniform mediump vec2 anchorPoint;\n + void main()\n {\n - {\n - float smallTextPadding = max( uSize.x - uTextureSize.x, 0. );\n - float gap = max( uGap, smallTextPadding );\n - float delta = floor ( uDelta ) + 0.5;\n - vTexCoord.x = ( delta + uHorizontalAlign * ( uTextureSize.x - uSize.x ) + floor( aPosition.x * uSize.x ) + 0.5 - gap * 0.5 ) / (uTextureSize.x + gap) + 0.5;\n - vTexCoord.y = ( uVerticalAlign * ( uTextureSize.y - uSize.y ) + floor( aPosition.y * uSize.y ) + 0.5 ) / ( uTextureSize.y ) + 0.5;\n - vRatio = uTextureSize.x / ( uTextureSize.x + gap );\n - gl_Position = uMvpMatrix * vec4( floor( aPosition * uSize.xy ), 0.0, 1.0 );\n - }\n + mediump vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy );\n + mediump vec2 visualSize = mix( uSize.xy * size, size, offsetSizeMode.zw );\n + \n + mediump float delta = floor ( uDelta ) + 0.5;\n + vTexCoord.x = ( delta + uHorizontalAlign * ( uTextureSize.x - visualSize.x - uGap ) + floor( aPosition.x * visualSize.x ) + 0.5 - uGap * 0.5 ) / uTextureSize.x + 0.5;\n + vTexCoord.y = ( uVerticalAlign * ( uTextureSize.y - visualSize.y ) + floor( aPosition.y * visualSize.y ) + 0.5 ) / ( uTextureSize.y ) + 0.5;\n + \n + mediump vec4 vertexPosition = vec4( floor( ( aPosition + anchorPoint ) * visualSize + ( visualOffset + origin ) * uSize.xy ), 0.0, 1.0 );\n + mediump vec4 nonAlignedVertex = uViewMatrix * uModelMatrix * vertexPosition;\n + mediump vec4 pixelAlignedVertex = vec4 ( floor( nonAlignedVertex.xyz ), 1.0 );\n + \n + gl_Position = uProjection * pixelAlignedVertex;\n }\n ); const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER( varying highp vec2 vTexCoord;\n - varying highp float vRatio;\n uniform sampler2D sTexture;\n \n void main()\n {\n - highp vec2 texCoord;\n - texCoord.y = vTexCoord.y;\n - texCoord.x = fract( vTexCoord.x ) / vRatio;\n - if ( texCoord.x > 1.0 || texCoord.y > 1.0 )\n + if ( vTexCoord.y > 1.0 )\n discard;\n - \n - gl_FragColor = texture2D( sTexture, texCoord );\n + gl_FragColor = texture2D( sTexture, vTexCoord );\n }\n ); @@ -88,24 +95,24 @@ const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER( * * -0.5f aligns the text to the left, 0.0f aligns the text to the center, 0.5f aligns the text to the right. * The final alignment depends on two factors: - * 1) The alignment value of the text label (Use Text::Layout::HorizontalAlignment enumerations). + * 1) The alignment value of the text label (Use Text::HorizontalAlignment enumerations). * 2) The text direction, i.e. whether it's LTR or RTL (0 = LTR, 1 = RTL). */ -const float HORIZONTAL_ALIGNMENT_TABLE[ Text::Layout::HORIZONTAL_ALIGN_COUNT ][ 2 ] = +const float HORIZONTAL_ALIGNMENT_TABLE[ Text::HorizontalAlignment::END+1 ][ 2 ] = { - // HORIZONTAL_ALIGN_BEGIN + // HorizontalAlignment::BEGIN { -0.5f, // LTR 0.5f // RTL }, - // HORIZONTAL_ALIGN_CENTER + // HorizontalAlignment::CENTER { 0.0f, // LTR 0.0f // RTL }, - // HORIZONTAL_ALIGN_END + // HorizontalAlignment::END { 0.5f, // LTR -0.5f // RTL @@ -116,13 +123,13 @@ const float HORIZONTAL_ALIGNMENT_TABLE[ Text::Layout::HORIZONTAL_ALIGN_COUNT ][ * @brief How the text should be aligned vertically when scrolling the text. * * -0.5f aligns the text to the top, 0.0f aligns the text to the center, 0.5f aligns the text to the bottom. - * The alignment depends on the alignment value of the text label (Use Text::Layout::VerticalAlignment enumerations). + * The alignment depends on the alignment value of the text label (Use Text::VerticalAlignment enumerations). */ -const float VERTICAL_ALIGNMENT_TABLE[ Text::Layout::VERTICAL_ALIGN_COUNT ] = +const float VERTICAL_ALIGNMENT_TABLE[ Text::VerticalAlignment::BOTTOM+1 ] = { - -0.5f, // VERTICAL_ALIGN_TOP - 0.0f, // VERTICAL_ALIGN_CENTER - 0.5f // VERTICAL_ALIGN_BOTTOM + -0.5f, // VerticalAlignment::TOP + 0.0f, // VerticalAlignment::CENTER + 0.5f // VerticalAlignment::BOTTOM }; } // namespace @@ -184,9 +191,9 @@ float TextScroller::GetLoopDelay() const return mLoopDelay; } -void TextScroller::SetStopMode( DevelTextLabel::AutoScrollStopMode::Type stopMode ) +void TextScroller::SetStopMode( TextLabel::AutoScrollStopMode::Type stopMode ) { - DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextScroller::SetAutoScrollStopMode [%s]\n",(stopMode == DevelTextLabel::AutoScrollStopMode::IMMEDIATE)?"IMMEDIATE":"FINISH_LOOP" ); + DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextScroller::SetAutoScrollStopMode [%s]\n",(stopMode == TextLabel::AutoScrollStopMode::IMMEDIATE)?"IMMEDIATE":"FINISH_LOOP" ); mStopMode = stopMode; } @@ -196,13 +203,13 @@ void TextScroller::StopScrolling() { switch( mStopMode ) { - case DevelTextLabel::AutoScrollStopMode::IMMEDIATE: + case TextLabel::AutoScrollStopMode::IMMEDIATE: { mScrollAnimation.Stop(); mScrollerInterface.ScrollingFinished(); break; } - case DevelTextLabel::AutoScrollStopMode::FINISH_LOOP: + case TextLabel::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; @@ -215,7 +222,7 @@ void TextScroller::StopScrolling() } } -DevelTextLabel::AutoScrollStopMode::Type TextScroller::GetStopMode() const +TextLabel::AutoScrollStopMode::Type TextScroller::GetStopMode() const { return mStopMode; } @@ -227,7 +234,7 @@ TextScroller::TextScroller( ScrollerInterface& scrollerInterface ) mLoopCount( 1 ), mLoopDelay( 0.0f ), mWrapGap( 0.0f ), - mStopMode( DevelTextLabel::AutoScrollStopMode::FINISH_LOOP ) + mStopMode( TextLabel::AutoScrollStopMode::FINISH_LOOP ) { DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextScroller Default Constructor\n" ); } @@ -236,10 +243,10 @@ TextScroller::~TextScroller() { } -void TextScroller::SetParameters( Actor scrollingTextActor, Renderer renderer, TextureSet textureSet, const Size& controlSize, const Size& textNaturalSize, CharacterDirection direction, Layout::HorizontalAlignment horizontalAlignment, Layout::VerticalAlignment verticalAlignment ) +void TextScroller::SetParameters( Actor scrollingTextActor, Renderer renderer, TextureSet textureSet, const Size& controlSize, const Size& textureSize, const float wrapGap, CharacterDirection direction, HorizontalAlignment::Type horizontalAlignment, VerticalAlignment::Type verticalAlignment ) { - DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextScroller::SetParameters controlSize[%f,%f] offscreenSize[%f,%f] direction[%d]\n", - controlSize.x, controlSize.y, textNaturalSize.x, textNaturalSize.y, direction ); + DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextScroller::SetParameters controlSize[%f,%f] textureSize[%f,%f] direction[%d]\n", + controlSize.x, controlSize.y, textureSize.x, textureSize.y, direction ); mRenderer = renderer; @@ -272,19 +279,19 @@ void TextScroller::SetParameters( Actor scrollingTextActor, Renderer renderer, T mRenderer.SetShader( shader ); mRenderer.SetTextures( textureSet ); - DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextScroller::SetParameters mWrapGap[%f]\n", mWrapGap ); + DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextScroller::SetParameters wrapGap[%f]\n", wrapGap ); const float horizontalAlign = HORIZONTAL_ALIGNMENT_TABLE[ horizontalAlignment ][ direction ]; const float verticalAlign = VERTICAL_ALIGNMENT_TABLE[ verticalAlignment ]; DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextScroller::SetParameters horizontalAlign[%f], verticalAlign[%f]\n", horizontalAlign, verticalAlign ); - scrollingTextActor.RegisterProperty( "uTextureSize", textNaturalSize ); + scrollingTextActor.RegisterProperty( "uTextureSize", textureSize ); scrollingTextActor.RegisterProperty( "uHorizontalAlign", horizontalAlign ); scrollingTextActor.RegisterProperty( "uVerticalAlign", verticalAlign ); - scrollingTextActor.RegisterProperty( "uGap", mWrapGap ); + scrollingTextActor.RegisterProperty( "uGap", wrapGap ); mScrollDeltaIndex = scrollingTextActor.RegisterProperty( "uDelta", 0.0f ); - float scrollAmount = std::max( textNaturalSize.width + mWrapGap, controlSize.width ); + float scrollAmount = std::max( textureSize.width, controlSize.width ); float scrollDuration = scrollAmount / mScrollSpeed; if ( direction )