Merge "Check for NULL return value in button-impl.cpp" into 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) 2016 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-toolkit/devel-api/controls/text-controls/text-label-devel.h>
26
27 // INTERNAL INCLUDES
28 #include <dali-toolkit/internal/text/text-definitions.h>
29
30 namespace Dali
31 {
32
33 namespace Toolkit
34 {
35
36 namespace Text
37 {
38
39 class TextScroller;
40 class ScrollerInterface;
41
42 typedef IntrusivePtr<TextScroller> TextScrollerPtr;
43
44 /**
45  * @brief A helper class for scrolling text
46  */
47 class TextScroller : public RefObject, public ConnectionTracker
48 {
49 public:
50
51   /**
52    * @brief Text Scrolling helper, used to automatically scroll text, SetParameters should be called before scrolling is needed.
53    * CleanUp removes the Scrolling actors from stage whilst keeping the Scroller object alive and preserving Speed, Gap and Loop count.
54    *
55    * @param[in] scrollerInterface scroller interface
56    */
57   static TextScrollerPtr New( ScrollerInterface& scrollerInterface );
58
59   /**
60    * @brief Set parameters relating to source required for scrolling
61    *
62    * @param[in] sourceActor source actor to be scrolled
63    * @param[in] controlSize size of the control to scroll within
64    * @param[in] offScreenSize size of the sourceActor
65    * @param[in] direction text direction true for right to left text
66    * @param[in] alignmentOffset alignment of source text
67    *
68    */
69   void SetParameters( Actor sourceActor, const Size& controlSize, const Size& offScreenSize, CharacterDirection direction, float alignmentOffset );
70
71   /**
72    * @brief Set the gap distance to elapse before the text wraps around
73    * @param[in] gap distance to elapse
74    */
75   void SetGap( int gap );
76
77   /**
78    * @brief Get the distance before scrolling wraps
79    * @return gap distance to elapse
80    */
81   int GetGap() const;
82
83   /**
84    * @brief Set speed the text should scroll
85    * @param[in] scrollSpeed pixels per second
86    */
87   void SetSpeed( int scrollSpeed );
88
89   /**
90    * @brief Get the speed of text scrolling
91    * @return speed in pixels per second
92    */
93   int GetSpeed() const;
94
95   /**
96    * @brief Set the number of times the text scrolling should loop, can stop current scrolling by passing in 0;
97    * @param[in] loopCount number of times the scrolled text should loop, 0 to stop scrolling
98    */
99   void SetLoopCount( int loopCount );
100
101   /**
102    * @brief Get the number of loops
103    * @return int number of loops
104    */
105   int GetLoopCount() const;
106
107   /**
108    * @brief Set the delay time of scroll animation loop
109    * @param[in] float delay time seconds of loops
110    */
111   void SetLoopDelay( float delay );
112
113   /**
114    * @brief Get the delay time of scroll
115    * @return float delay time seconds of loops
116    */
117   float GetLoopDelay() const;
118
119   /**
120    * @brief Set the mode of scrolling stop
121    * @param[in] stopMode type when text scrolling is stoped.
122    */
123   void SetStopMode( DevelTextLabel::AutoScrollStopMode::Type stopMode );
124
125   /**
126    * @brief Get the mode of scrolling stop
127    * @return stopMode type when text scrolling is stoped.
128    */
129   DevelTextLabel::AutoScrollStopMode::Type GetStopMode() const;
130
131   /**
132    * @brief Get the camera used to look at source, should be added to the parent of target actor.
133    * @return camera Actor
134    */
135   Actor GetSourceCamera() const;
136
137   /**
138    * @brief Get the resulting scrolling text actor, add to target actor which will show scrolling text
139    * @return mesh Actor
140    */
141   Actor GetScrollingText() const;
142
143 private: // Implementation
144
145   /**
146    * Constructor
147    */
148   TextScroller( ScrollerInterface& scrollerInterface );
149
150   /**
151    * Destructor
152    */
153   ~TextScroller();
154
155   // Undefined
156   TextScroller( const TextScroller& handle );
157
158   // Undefined
159   TextScroller& operator=( const TextScroller& handle );
160
161   /**
162    * @brief Callback for end of animation
163    * @param[in] animation Animation handle
164    */
165   void AutoScrollAnimationFinished( Dali::Animation& animation );
166
167   /**
168    * @brief variables required to set up scrolling animation
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( float scrollAmount, float scrollDuration, int loopCount );
174
175   /**
176    * @brief When scrolling ended, the actors are cleaned up so no longer staged.
177    */
178   void CleanUp();
179
180 private:
181
182   RenderTask         mRenderTask;               // Renders full text to a FrameBuffer which is then scrolled.
183   CameraActor        mOffscreenCameraActor;     // Camera used by render task
184   Actor              mScrollingTextActor;       // Actor used to show scrolling text
185   ScrollerInterface& mScrollerInterface;        // Interface implemented by control that requires scrolling
186   Property::Index    mScrollDeltaIndex;         // Property used by shader to represent distance to scroll
187   Animation          mScrollAnimation;          // Animation used to update the mScrollDeltaIndex
188
189   int   mScrollSpeed;                                   ///< Speed which text should automatically scroll at
190   int   mLoopCount;                                     ///< Number of time the text should scroll
191   float mLoopDelay;                                     ///< Time delay of loop start
192   float mWrapGap;                                       ///< Gap before text wraps around when scrolling
193   DevelTextLabel::AutoScrollStopMode::Type  mStopMode;  ///< Stop mode of scrolling text, when loop count is 0.
194
195 }; // TextScroller class
196
197 } // namespace Text
198
199 } // namespace Toolkit
200
201 } // namespace Dali
202
203 #endif // __DALI_TOOLKIT_TEXT_SCROLLER_H__
204