/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 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.
#include <dali-toolkit/internal/text/text-scroller.h>
// EXTERNAL INCLUDES
-#include <dali/public-api/common/stage.h>
#include <dali/integration-api/debug.h>
// INTERNAL INCLUDES
#include <dali-toolkit/internal/text/text-scroller-interface.h>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
namespace Dali
{
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
- uniform mediump vec3 uSize;\n
- uniform mediump float uDelta;\n
- uniform mediump vec2 uTextureSize;\n
- uniform mediump float uGap;\n
- 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
- 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
- uniform sampler2D sTexture;\n
- uniform lowp vec4 uColor;\n
- uniform lowp vec3 mixColor;\n
- uniform lowp float opacity;\n
- uniform lowp float preMultipliedAlpha;\n
- \n
- lowp vec4 visualMixColor()\n
- {\n
- return vec4( mixColor * mix( 1.0, opacity, preMultipliedAlpha ), opacity );\n
- }\n
- \n
- void main()\n
- {\n
- if ( vTexCoord.y > 1.0 )\n
- discard;\n
- \n
- mediump vec4 textTexture = texture2D( sTexture, vTexCoord );\n
- textTexture.rgb *= mix( 1.0, textTexture.a, preMultipliedAlpha );\n
- \n
- gl_FragColor = textTexture * uColor * visualMixColor();
- }\n
-);
-
/**
* @brief How the text should be aligned horizontally when scrolling the text.
*
// Reset to the original shader and texture before scrolling
mRenderer.SetShader(mShader);
- mRenderer.SetTextures( mTextureSet );
+ if( mTextureSet )
+ {
+ mRenderer.SetTextures( mTextureSet );
+ }
}
mShader = mRenderer.GetShader();
mTextureSet = mRenderer.GetTextures();
// Set the shader and texture for scrolling
- Shader shader = Shader::New( VERTEX_SHADER_SCROLL, FRAGMENT_SHADER, Shader::Hint::NONE );
+ Shader shader = Shader::New( SHADER_TEXT_SCROLLER_SHADER_VERT, SHADER_TEXT_SCROLLER_SHADER_FRAG, Shader::Hint::NONE );
mRenderer.SetShader( shader );
mRenderer.SetTextures( textureSet );
DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextScroller::SetParameters wrapGap[%f]\n", wrapGap );
- const float horizontalAlign = HORIZONTAL_ALIGNMENT_TABLE[ horizontalAlignment ][ direction ];
+ float horizontalAlign;
+
+ if( textureSize.x > controlSize.x )
+ {
+ // if Text is elided, scroll should start at the begin of text.
+ horizontalAlign = HORIZONTAL_ALIGNMENT_TABLE[HorizontalAlignment::BEGIN][ direction ];
+ }
+ else
+ {
+ 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", textureSize );
- scrollingTextActor.RegisterProperty( "uHorizontalAlign", horizontalAlign );
- scrollingTextActor.RegisterProperty( "uVerticalAlign", verticalAlign );
- scrollingTextActor.RegisterProperty( "uGap", wrapGap );
- mScrollDeltaIndex = scrollingTextActor.RegisterProperty( "uDelta", 0.0f );
+ shader.RegisterProperty( "uTextureSize", textureSize );
+ shader.RegisterProperty( "uHorizontalAlign", horizontalAlign );
+ shader.RegisterProperty( "uVerticalAlign", verticalAlign );
+ shader.RegisterProperty( "uGap", wrapGap );
+ mScrollDeltaIndex = shader.RegisterProperty( "uDelta", 0.0f );
float scrollAmount = std::max( textureSize.width, controlSize.width );
float scrollDuration = scrollAmount / mScrollSpeed;
{
DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextScroller::StartScrolling scrollAmount[%f] scrollDuration[%f], loop[%d] speed[%d]\n", scrollAmount, scrollDuration, loopCount, mScrollSpeed );
+ Shader shader = mRenderer.GetShader();
mScrollAnimation = Animation::New( scrollDuration );
- mScrollAnimation.AnimateTo( Property( scrollingTextActor, mScrollDeltaIndex ), scrollAmount, TimePeriod( mLoopDelay, scrollDuration ) );
- mScrollAnimation.SetEndAction( Animation::Discard );
+ mScrollAnimation.AnimateTo( Property( shader, mScrollDeltaIndex ), scrollAmount, TimePeriod( mLoopDelay, scrollDuration ) );
+ mScrollAnimation.SetEndAction( Animation::DISCARD );
mScrollAnimation.SetLoopCount( loopCount );
mScrollAnimation.FinishedSignal().Connect( this, &TextScroller::AutoScrollAnimationFinished );
mScrollAnimation.Play();