stop text scrolling when label is disconnected from scene
[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) 2021 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/internal/text/text-definitions.h>
29 #include <dali-toolkit/public-api/controls/text-controls/text-label.h>
30 #include <dali-toolkit/public-api/text/text-enumerations.h>
31
32 namespace Dali
33 {
34 namespace Toolkit
35 {
36 namespace Text
37 {
38 class TextScroller;
39 class ScrollerInterface;
40
41 typedef IntrusivePtr<TextScroller> TextScrollerPtr;
42
43 /**
44  * @brief A helper class for scrolling text
45  */
46 class TextScroller : public RefObject, public ConnectionTracker
47 {
48 public:
49   /**
50    * @brief Text Scrolling helper, used to automatically scroll text, SetParameters should be called before scrolling is needed.
51    * CleanUp removes the Scrolling actors from stage whilst keeping the Scroller object alive and preserving Speed, Gap and Loop count.
52    *
53    * @param[in] scrollerInterface scroller interface
54    */
55   static TextScrollerPtr New(ScrollerInterface& scrollerInterface);
56
57   /**
58    * @brief Set parameters relating to source required for scrolling
59    *
60    * @param[in] scrollingTextActor actor containing the text to be scrolled
61    * @param[in] renderer renderer to render the text
62    * @param[in] textureSet texture of the text to be scrolled
63    * @param[in] controlSize size of the control to scroll within
64    * @param[in] textureSize size of the texture
65    * @param[in] wrapGap The gap before scrolling wraps
66    * @param[in] direction text direction true for right to left text
67    * @param[in] horizontalAlignment horizontal alignment of the text
68    * @param[in] verticalAlignment vertical alignment of the text
69    */
70   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);
71
72   /**
73    * @brief Set the gap distance to elapse before the text wraps around
74    * @param[in] gap distance to elapse
75    */
76   void SetGap(int gap);
77
78   /**
79    * @brief Get the distance before scrolling wraps
80    * @return gap distance to elapse
81    */
82   int GetGap() const;
83
84   /**
85    * @brief Set speed the text should scroll
86    * @param[in] scrollSpeed pixels per second
87    */
88   void SetSpeed(int scrollSpeed);
89
90   /**
91    * @brief Get the speed of text scrolling
92    * @return speed in pixels per second
93    */
94   int GetSpeed() const;
95
96   /**
97    * @brief Set the number of times the text scrolling should loop, can stop current scrolling by passing in 0;
98    * @param[in] loopCount number of times the scrolled text should loop, 0 to stop scrolling
99    */
100   void SetLoopCount(int loopCount);
101
102   /**
103    * @brief Get the number of loops
104    * @return int number of loops
105    */
106   int GetLoopCount() const;
107
108   /**
109    * @brief Set the delay time of scroll animation loop
110    * @param[in] float delay time seconds of loops
111    */
112   void SetLoopDelay(float delay);
113
114   /**
115    * @brief Get the delay time of scroll
116    * @return float delay time seconds of loops
117    */
118   float GetLoopDelay() const;
119
120   /**
121    * @brief Set the mode of scrolling stop
122    * @param[in] stopMode type when text scrolling is stoped.
123    */
124   void SetStopMode(TextLabel::AutoScrollStopMode::Type stopMode);
125
126   /**
127    * @brief Stop the auto scrolling.
128    * @param[in] immediate Stop scrolling immediately.
129    */
130   void StopScrolling(bool immediate);
131
132   /**
133    * @brief Get the mode of scrolling stop
134    * @return stopMode type when text scrolling is stoped.
135    */
136   TextLabel::AutoScrollStopMode::Type GetStopMode() const;
137
138 private: // Implementation
139   /**
140    * Constructor
141    */
142   TextScroller(ScrollerInterface& scrollerInterface);
143
144   /**
145    * Destructor
146    */
147   ~TextScroller();
148
149   // Undefined
150   TextScroller(const TextScroller& handle);
151
152   // Undefined
153   TextScroller& operator=(const TextScroller& handle);
154
155   /**
156    * @brief Callback for end of animation
157    * @param[in] animation Animation handle
158    */
159   void AutoScrollAnimationFinished(Dali::Animation& animation);
160
161   /**
162    * @brief variables required to set up scrolling animation
163    * @param[in] scrollingTextActor actor that shows scrolling text
164    * @param[in] scrollAmount distance to animate text for the given duration
165    * @param[in] scrollDuration duration of aninmation
166    * @param[in] loopCount number of times to loop the scrolling text
167    */
168   void StartScrolling(Actor scrollingTextActor, float scrollAmount, float scrollDuration, int loopCount);
169
170 private:
171   ScrollerInterface& mScrollerInterface; // Interface implemented by control that requires scrolling
172   Property::Index    mScrollDeltaIndex;  // Property used by shader to represent distance to scroll
173   Animation          mScrollAnimation;   // Animation used to update the mScrollDeltaIndex
174   Dali::Renderer     mRenderer;          // Renderer used to render the text
175   Shader             mShader;            // Shader originally used by the renderer while not scrolling
176   TextureSet         mTextureSet;        // Texture originally used by the renderer while not scrolling
177
178   int                                 mScrollSpeed; ///< Speed which text should automatically scroll at
179   int                                 mLoopCount;   ///< Number of time the text should scroll
180   float                               mLoopDelay;   ///< Time delay of loop start
181   float                               mWrapGap;     ///< Gap before text wraps around when scrolling
182   TextLabel::AutoScrollStopMode::Type mStopMode;    ///< Stop mode of scrolling text, when loop count is 0.
183
184 }; // TextScroller class
185
186 } // namespace Text
187
188 } // namespace Toolkit
189
190 } // namespace Dali
191
192 #endif // DALI_TOOLKIT_TEXT_SCROLLER_H