1 #ifndef DALI_TOOLKIT_TEXT_SCROLLER_H
2 #define DALI_TOOLKIT_TEXT_SCROLLER_H
5 * Copyright (c) 2019 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
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>
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>
42 class ScrollerInterface;
44 typedef IntrusivePtr<TextScroller> TextScrollerPtr;
47 * @brief A helper class for scrolling text
49 class TextScroller : public RefObject, public ConnectionTracker
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.
57 * @param[in] scrollerInterface scroller interface
59 static TextScrollerPtr New( ScrollerInterface& scrollerInterface );
62 * @brief Set parameters relating to source required for scrolling
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
74 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 );
77 * @brief Set the gap distance to elapse before the text wraps around
78 * @param[in] gap distance to elapse
80 void SetGap( int gap );
83 * @brief Get the distance before scrolling wraps
84 * @return gap distance to elapse
89 * @brief Set speed the text should scroll
90 * @param[in] scrollSpeed pixels per second
92 void SetSpeed( int scrollSpeed );
95 * @brief Get the speed of text scrolling
96 * @return speed in pixels per second
101 * @brief Set the number of times the text scrolling should loop, can stop current scrolling by passing in 0;
102 * @param[in] loopCount number of times the scrolled text should loop, 0 to stop scrolling
104 void SetLoopCount( int loopCount );
107 * @brief Get the number of loops
108 * @return int number of loops
110 int GetLoopCount() const;
113 * @brief Set the delay time of scroll animation loop
114 * @param[in] float delay time seconds of loops
116 void SetLoopDelay( float delay );
119 * @brief Get the delay time of scroll
120 * @return float delay time seconds of loops
122 float GetLoopDelay() const;
125 * @brief Set the mode of scrolling stop
126 * @param[in] stopMode type when text scrolling is stoped.
128 void SetStopMode( TextLabel::AutoScrollStopMode::Type stopMode );
131 * @brief Stop the auto scrolling.
133 void StopScrolling();
136 * @brief Get the mode of scrolling stop
137 * @return stopMode type when text scrolling is stoped.
139 TextLabel::AutoScrollStopMode::Type GetStopMode() const;
141 private: // Implementation
146 TextScroller( ScrollerInterface& scrollerInterface );
154 TextScroller( const TextScroller& handle );
157 TextScroller& operator=( const TextScroller& handle );
160 * @brief Callback for end of animation
161 * @param[in] animation Animation handle
163 void AutoScrollAnimationFinished( Dali::Animation& animation );
166 * @brief variables required to set up scrolling animation
167 * @param[in] scrollingTextActor actor that shows scrolling text
168 * @param[in] scrollAmount distance to animate text for the given duration
169 * @param[in] scrollDuration duration of aninmation
170 * @param[in] loopCount number of times to loop the scrolling text
172 void StartScrolling( Actor scrollingTextActor, float scrollAmount, float scrollDuration, int loopCount );
176 ScrollerInterface& mScrollerInterface; // Interface implemented by control that requires scrolling
177 Property::Index mScrollDeltaIndex; // Property used by shader to represent distance to scroll
178 Animation mScrollAnimation; // Animation used to update the mScrollDeltaIndex
179 Dali::Renderer mRenderer; // Renderer used to render the text
180 Shader mShader; // Shader originally used by the renderer while not scrolling
181 TextureSet mTextureSet; // Texture originally used by the renderer while not scrolling
183 int mScrollSpeed; ///< Speed which text should automatically scroll at
184 int mLoopCount; ///< Number of time the text should scroll
185 float mLoopDelay; ///< Time delay of loop start
186 float mWrapGap; ///< Gap before text wraps around when scrolling
187 TextLabel::AutoScrollStopMode::Type mStopMode; ///< Stop mode of scrolling text, when loop count is 0.
189 }; // TextScroller class
193 } // namespace Toolkit
197 #endif // DALI_TOOLKIT_TEXT_SCROLLER_H