Fix text scroll start position issue
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / text-scroller.h
1 #ifndef __DALI_TOOLKIT_TEXT_SCROLLER_H__
2 #define __DALI_TOOLKIT_TEXT_SCROLLER_H__
3
4 /*
5  * Copyright (c) 2017 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <dali/public-api/actors/camera-actor.h>
23 #include <dali/public-api/animation/animation.h>
24 #include <dali/public-api/render-tasks/render-task.h>
25 #include <dali/public-api/rendering/renderer.h>
26
27 // INTERNAL INCLUDES
28 #include <dali-toolkit/public-api/text/text-enumerations.h>
29 #include <dali-toolkit/public-api/controls/text-controls/text-label.h>
30 #include <dali-toolkit/internal/text/text-definitions.h>
31
32 namespace Dali
33 {
34
35 namespace Toolkit
36 {
37
38 namespace Text
39 {
40
41 class TextScroller;
42 class ScrollerInterface;
43
44 typedef IntrusivePtr<TextScroller> TextScrollerPtr;
45
46 /**
47  * @brief A helper class for scrolling text
48  */
49 class TextScroller : public RefObject, public ConnectionTracker
50 {
51 public:
52
53   /**
54    * @brief Text Scrolling helper, used to automatically scroll text, SetParameters should be called before scrolling is needed.
55    * CleanUp removes the Scrolling actors from stage whilst keeping the Scroller object alive and preserving Speed, Gap and Loop count.
56    *
57    * @param[in] scrollerInterface scroller interface
58    */
59   static TextScrollerPtr New( ScrollerInterface& scrollerInterface );
60
61   /**
62    * @brief Set parameters relating to source required for scrolling
63    *
64    * @param[in] scrollingTextActor actor containing the text to be scrolled
65    * @param[in] renderer renderer to render the text
66    * @param[in] textureSet texture of the text to be scrolled
67    * @param[in] controlSize size of the control to scroll within
68    * @param[in] textureSize size of the texture
69    * @param[in] wrapGap The gap before scrolling wraps
70    * @param[in] direction text direction true for right to left text
71    * @param[in] horizontalAlignment horizontal alignment of the text
72    * @param[in] verticalAlignment vertical alignment of the text
73    * @param[in] isTextElided whether text is elided or not
74    */
75   void SetParameters( Actor scrollingTextActor, Dali::Renderer renderer, TextureSet textureSet, const Size& controlSize, const Size& textureSize, const float wrapGap, CharacterDirection direction, HorizontalAlignment::Type horizontalAlignment, VerticalAlignment::Type verticalAlignment, bool isTextElided );
76
77   /**
78    * @brief Set the gap distance to elapse before the text wraps around
79    * @param[in] gap distance to elapse
80    */
81   void SetGap( int gap );
82
83   /**
84    * @brief Get the distance before scrolling wraps
85    * @return gap distance to elapse
86    */
87   int GetGap() const;
88
89   /**
90    * @brief Set speed the text should scroll
91    * @param[in] scrollSpeed pixels per second
92    */
93   void SetSpeed( int scrollSpeed );
94
95   /**
96    * @brief Get the speed of text scrolling
97    * @return speed in pixels per second
98    */
99   int GetSpeed() const;
100
101   /**
102    * @brief Set the number of times the text scrolling should loop, can stop current scrolling by passing in 0;
103    * @param[in] loopCount number of times the scrolled text should loop, 0 to stop scrolling
104    */
105   void SetLoopCount( int loopCount );
106
107   /**
108    * @brief Get the number of loops
109    * @return int number of loops
110    */
111   int GetLoopCount() const;
112
113   /**
114    * @brief Set the delay time of scroll animation loop
115    * @param[in] float delay time seconds of loops
116    */
117   void SetLoopDelay( float delay );
118
119   /**
120    * @brief Get the delay time of scroll
121    * @return float delay time seconds of loops
122    */
123   float GetLoopDelay() const;
124
125   /**
126    * @brief Set the mode of scrolling stop
127    * @param[in] stopMode type when text scrolling is stoped.
128    */
129   void SetStopMode( TextLabel::AutoScrollStopMode::Type stopMode );
130
131   /**
132    * @brief Stop the auto scrolling.
133    */
134   void StopScrolling();
135
136   /**
137    * @brief Get the mode of scrolling stop
138    * @return stopMode type when text scrolling is stoped.
139    */
140   TextLabel::AutoScrollStopMode::Type GetStopMode() const;
141
142 private: // Implementation
143
144   /**
145    * Constructor
146    */
147   TextScroller( ScrollerInterface& scrollerInterface );
148
149   /**
150    * Destructor
151    */
152   ~TextScroller();
153
154   // Undefined
155   TextScroller( const TextScroller& handle );
156
157   // Undefined
158   TextScroller& operator=( const TextScroller& handle );
159
160   /**
161    * @brief Callback for end of animation
162    * @param[in] animation Animation handle
163    */
164   void AutoScrollAnimationFinished( Dali::Animation& animation );
165
166   /**
167    * @brief variables required to set up scrolling animation
168    * @param[in] scrollingTextActor actor that shows scrolling text
169    * @param[in] scrollAmount distance to animate text for the given duration
170    * @param[in] scrollDuration duration of aninmation
171    * @param[in] loopCount number of times to loop the scrolling text
172    */
173   void StartScrolling( Actor scrollingTextActor, float scrollAmount, float scrollDuration, int loopCount );
174
175 private:
176
177   ScrollerInterface& mScrollerInterface;        // Interface implemented by control that requires scrolling
178   Property::Index    mScrollDeltaIndex;         // Property used by shader to represent distance to scroll
179   Animation          mScrollAnimation;          // Animation used to update the mScrollDeltaIndex
180   Dali::Renderer     mRenderer;                 // Renderer used to render the text
181   Shader             mShader;                   // Shader originally used by the renderer while not scrolling
182   TextureSet         mTextureSet;               // Texture originally used by the renderer while not scrolling
183
184   int   mScrollSpeed;                                   ///< Speed which text should automatically scroll at
185   int   mLoopCount;                                     ///< Number of time the text should scroll
186   float mLoopDelay;                                     ///< Time delay of loop start
187   float mWrapGap;                                       ///< Gap before text wraps around when scrolling
188   TextLabel::AutoScrollStopMode::Type  mStopMode;       ///< Stop mode of scrolling text, when loop count is 0.
189
190 }; // TextScroller class
191
192 } // namespace Text
193
194 } // namespace Toolkit
195
196 } // namespace Dali
197
198 #endif // __DALI_TOOLKIT_TEXT_SCROLLER_H__
199