(Text Controller) Remove meaningless check to see if an unsigned int is positive...
[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
26 // INTERNAL INCLUDES
27 #include <dali-toolkit/internal/text/text-definitions.h>
28
29 namespace Dali
30 {
31
32 namespace Toolkit
33 {
34
35 namespace Text
36 {
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   /**
51    * @brief Text Scrolling helper, used to automatically scroll text, SetParameters should be called before scrolling is needed.
52    * CleanUp removes the Scrolling actors from stage whilst keeping the Scroller object alive and preserving Speed, Gap and Loop count.
53    *
54    * @param[in] scrollerInterface scroller interface
55    */
56   static TextScrollerPtr New( ScrollerInterface& scrollerInterface );
57
58   /**
59    * @brief Set parameters relating to source required for scrolling
60    *
61    * @param[in] sourceActor source actor to be scrolled
62    * @param[in] controlSize size of the control to scroll within
63    * @param[in] offScreenSize size of the sourceActor
64    * @param[in] direction text direction true for right to left text
65    * @param[in] alignmentOffset alignment of source text
66    *
67    */
68   void SetParameters( Actor sourceActor, const Size& controlSize, const Size& offScreenSize, CharacterDirection direction, float alignmentOffset );
69
70   /**
71    * @brief Set the gap distance to elapse before the text wraps around
72    * @param[in] gap distance to elapse
73    */
74   void SetGap( int gap );
75
76   /**
77    * @brief Get the distance before scrolling wraps
78    * @return gap distance to elapse
79    */
80   int GetGap() const;
81
82   /**
83    * @brief Set speed the text should scroll
84    * @param[in] scrollSpeed pixels per second
85    */
86   void SetSpeed( int scrollSpeed );
87
88   /**
89    * @brief Get the speed of text scrolling
90    * @return speed in pixels per second
91    */
92   int GetSpeed() const;
93
94   /**
95    * @brief Set the number of times the text scrolling should loop, can stop current scrolling by passing in 0;
96    * @param[in] loopCount number of times the scrolled text should loop, 0 to stop scrolling
97    */
98   void SetLoopCount( int loopCount );
99
100   /**
101    * @brief Get the number of loops
102    * @return int number of loops
103    */
104   int GetLoopCount() const;
105
106   /**
107    * @brief Get the camera used to look at source, should be added to the parent of target actor.
108    * @return camera Actor
109    */
110   Actor GetSourceCamera() const;
111
112   /**
113    * @brief Get the resulting scrolling text actor, add to target actor which will show scrolling text
114    * @return mesh Actor
115    */
116   Actor GetScrollingText() const;
117
118 private: // Implementation
119
120   /**
121    * Constructor
122    */
123   TextScroller( ScrollerInterface& scrollerInterface );
124
125   /**
126    * Destructor
127    */
128   ~TextScroller();
129
130   // Undefined
131   TextScroller( const TextScroller& handle );
132
133   // Undefined
134   TextScroller& operator=( const TextScroller& handle );
135
136   /**
137    * @brief Callback for end of animation
138    * @param[in] animation Animation handle
139    */
140   void AutoScrollAnimationFinished( Dali::Animation& animation );
141
142   /**
143    * @brief variables required to set up scrolling animation
144    * @param[in] scrollAmount distance to animate text for the given duration
145    * @param[in] scrollDuration duration of aninmation
146    * @param[in] loopCount number of times to loop the scrolling text
147    */
148   void StartScrolling( float scrollAmount, float scrollDuration, int loopCount );
149
150   /**
151    * @brief When scrolling ended, the actors are cleaned up so no longer staged.
152    */
153   void CleanUp();
154
155 private:
156
157   RenderTask         mRenderTask;               // Renders full text to a FrameBuffer which is then scrolled.
158   CameraActor        mOffscreenCameraActor;     // Camera used by render task
159   Actor              mScrollingTextActor;       // Actor used to show scrolling text
160   ScrollerInterface& mScrollerInterface;        // Interface implemented by control that requires scrolling
161   Property::Index    mScrollDeltaIndex;         // Property used by shader to represent distance to scroll
162   Animation          mScrollAnimation;          // Animation used to update the mScrollDeltaIndex
163
164   int   mScrollSpeed;            ///< Speed which text should automatically scroll at
165   int   mLoopCount;              ///< Number of time the text should scroll
166   float mWrapGap;                ///< Gap before text wraps around when scrolling
167
168 }; // TextScroller class
169
170 } // namespace Text
171
172 } // namespace Toolkit
173
174 } // namespace Dali
175
176 #endif // __DALI_TOOLKIT_TEXT_SCROLLER_H__
177