[dali_1.2.52] Merge branch 'devel/master'
[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
26 // INTERNAL INCLUDES
27 #include <dali-toolkit/devel-api/controls/text-controls/text-label-devel.h>
28 #include <dali-toolkit/internal/text/text-definitions.h>
29 #include <dali-toolkit/internal/text/layouts/layout-alignment.h>
30
31 namespace Dali
32 {
33
34 namespace Toolkit
35 {
36
37 namespace Text
38 {
39
40 class TextScroller;
41 class ScrollerInterface;
42
43 typedef IntrusivePtr<TextScroller> TextScrollerPtr;
44
45 /**
46  * @brief A helper class for scrolling text
47  */
48 class TextScroller : public RefObject, public ConnectionTracker
49 {
50 public:
51
52   /**
53    * @brief Text Scrolling helper, used to automatically scroll text, SetParameters should be called before scrolling is needed.
54    * CleanUp removes the Scrolling actors from stage whilst keeping the Scroller object alive and preserving Speed, Gap and Loop count.
55    *
56    * @param[in] scrollerInterface scroller interface
57    */
58   static TextScrollerPtr New( ScrollerInterface& scrollerInterface );
59
60   /**
61    * @brief Set parameters relating to source required for scrolling
62    *
63    * @param[in] sourceActor source actor to be scrolled
64    * @param[in] controlSize size of the control to scroll within
65    * @param[in] offScreenSize size of the sourceActor
66    * @param[in] direction text direction true for right to left text
67    * @param[in] alignmentOffset alignment of source text
68    *
69    */
70   void SetParameters( Actor sourceActor, const Size& controlSize, const Size& offScreenSize, CharacterDirection direction, float alignmentOffset, Layout::HorizontalAlignment horizontalAlignment );
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( DevelTextLabel::AutoScrollStopMode::Type stopMode );
125
126   /**
127    * @brief Stop the auto scrolling.
128    */
129   void StopScrolling();
130
131   /**
132    * @brief Get the mode of scrolling stop
133    * @return stopMode type when text scrolling is stoped.
134    */
135   DevelTextLabel::AutoScrollStopMode::Type GetStopMode() const;
136
137   /**
138    * @brief Get the camera used to look at source, should be added to the parent of target actor.
139    * @return camera Actor
140    */
141   Actor GetSourceCamera() const;
142
143   /**
144    * @brief Get the resulting scrolling text actor, add to target actor which will show scrolling text
145    * @return mesh Actor
146    */
147   Actor GetScrollingText() const;
148
149 private: // Implementation
150
151   /**
152    * Constructor
153    */
154   TextScroller( ScrollerInterface& scrollerInterface );
155
156   /**
157    * Destructor
158    */
159   ~TextScroller();
160
161   // Undefined
162   TextScroller( const TextScroller& handle );
163
164   // Undefined
165   TextScroller& operator=( const TextScroller& handle );
166
167   /**
168    * @brief Callback for end of animation
169    * @param[in] animation Animation handle
170    */
171   void AutoScrollAnimationFinished( Dali::Animation& animation );
172
173   /**
174    * @brief variables required to set up scrolling animation
175    * @param[in] scrollAmount distance to animate text for the given duration
176    * @param[in] scrollDuration duration of aninmation
177    * @param[in] loopCount number of times to loop the scrolling text
178    */
179   void StartScrolling( float scrollAmount, float scrollDuration, int loopCount );
180
181   /**
182    * @brief When scrolling ended, the actors are cleaned up so no longer staged.
183    */
184   void CleanUp();
185
186 private:
187
188   RenderTask         mRenderTask;               // Renders full text to a FrameBuffer which is then scrolled.
189   CameraActor        mOffscreenCameraActor;     // Camera used by render task
190   Actor              mScrollingTextActor;       // Actor used to show scrolling text
191   ScrollerInterface& mScrollerInterface;        // Interface implemented by control that requires scrolling
192   Property::Index    mScrollDeltaIndex;         // Property used by shader to represent distance to scroll
193   Animation          mScrollAnimation;          // Animation used to update the mScrollDeltaIndex
194
195   int   mScrollSpeed;                                   ///< Speed which text should automatically scroll at
196   int   mLoopCount;                                     ///< Number of time the text should scroll
197   float mLoopDelay;                                     ///< Time delay of loop start
198   float mWrapGap;                                       ///< Gap before text wraps around when scrolling
199   DevelTextLabel::AutoScrollStopMode::Type  mStopMode;  ///< Stop mode of scrolling text, when loop count is 0.
200
201 }; // TextScroller class
202
203 } // namespace Text
204
205 } // namespace Toolkit
206
207 } // namespace Dali
208
209 #endif // __DALI_TOOLKIT_TEXT_SCROLLER_H__
210