Merge "Remove obsolete and non functional SizeChanged signal from actor" into tizen
[platform/core/uifw/dali-core.git] / dali / public-api / actors / text-actor.h
1 #ifndef __DALI_TEXT_ACTOR_H__
2 #define __DALI_TEXT_ACTOR_H__
3
4 /*
5  * Copyright (c) 2014 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
22 // EXTERNAL INCLUDES
23 #include <string>
24
25 // INTERNAL INCLUDES
26 #include <dali/public-api/actors/renderable-actor.h>
27 #include <dali/public-api/common/loading-state.h>
28 #include <dali/public-api/common/constants.h>
29 #include <dali/public-api/math/vector2.h>
30 #include <dali/public-api/text/text-style.h>
31 #include <dali/public-api/text/text.h>
32
33 namespace Dali
34 {
35
36 struct TextActorParameters;
37 class Font;
38
39 namespace Internal DALI_INTERNAL
40 {
41 class TextActor;
42 }
43
44 /**
45  * @brief TextActor is a basic actor for displaying a text label
46  *
47  * By default the text actor always uses the natural size of the text when SetText is called,
48  * unless SetSize is called to override the size or size is animated to some other size.
49  * Natural size for TextActor is the same as the size returned by Font::MeasureText( string )
50  * using the font that the TextActor is using.
51  *
52  * By default CullFaceMode is set to CullNone to enable the TextActor to be viewed from all angles.
53  */
54 class DALI_IMPORT_API TextActor : public RenderableActor
55 {
56 public:
57
58   typedef Signal< void (TextActor) > TextSignalType;     ///< Text available signal type
59
60   //Signal Names
61   static const char* const SIGNAL_TEXT_LOADING_FINISHED; ///< name "text-loading-finished"
62
63   // Default Properties; additional to RenderableActor properties
64   static const Property::Index TEXT;                              ///< name "text"                     type STRING
65   static const Property::Index FONT;                              ///< name "font"                     type STRING
66   static const Property::Index FONT_STYLE;                        ///< name "font-style"               type STRING
67   static const Property::Index OUTLINE_ENABLE;                    ///< name "outline-enable"           type BOOLEAN
68   static const Property::Index OUTLINE_COLOR;                     ///< name "outline-color"            type VECTOR4
69   static const Property::Index OUTLINE_THICKNESS_WIDTH;           ///< name "outline-thickness-width"  type VECTOR2
70   static const Property::Index SMOOTH_EDGE;                       ///< name "smooth-edge"              type FLOAT
71   static const Property::Index GLOW_ENABLE;                       ///< name "glow-enable"              type BOOLEAN
72   static const Property::Index GLOW_COLOR;                        ///< name "glow-color"               type VECTOR4
73   static const Property::Index GLOW_INTENSITY;                    ///< name "glow-intensity"           type FLOAT
74   static const Property::Index SHADOW_ENABLE;                     ///< name "shadow-enable"            type BOOLEAN
75   static const Property::Index SHADOW_COLOR;                      ///< name "shadow-color"             type VECTOR4
76   static const Property::Index SHADOW_OFFSET;                     ///< name "shadow-offset"            type VECTOR2
77   static const Property::Index ITALICS_ANGLE;                     ///< name "italics-angle"            type FLOAT
78   static const Property::Index UNDERLINE;                         ///< name "underline"                type BOOLEAN
79   static const Property::Index WEIGHT;                            ///< name "weight"                   type INTEGER
80   static const Property::Index FONT_DETECTION_AUTOMATIC;          ///< name "font-detection-automatic" type BOOLEAN
81   static const Property::Index GRADIENT_COLOR;                    ///< name "gradient-color"           type VECTOR4
82   static const Property::Index GRADIENT_START_POINT;              ///< name "gradient-start-point"     type VECTOR2
83   static const Property::Index GRADIENT_END_POINT;                ///< name "gradient-end-point"       type VECTOR2
84   static const Property::Index SHADOW_SIZE;                       ///< name "shadow-size"              type FLOAT
85   static const Property::Index TEXT_COLOR;                        ///< name "text-color"               type VECTOR4
86
87   /**
88    * @brief Create an uninitialized TextActor handle.
89    *
90    * This can be initialised with TextActor::New().
91    * Calling member functions with an uninitialized handle is not allowed.
92    */
93   TextActor();
94
95   /**
96    * @brief Create a TextActor object with no text.
97    *
98    * @return A handle to a newly allocated Dali resource.
99    */
100   static TextActor New();
101
102   /**
103    * @brief Create a TextActor object with text, a default style and font detection.
104    *
105    * @param[in] text The text which will be displayed
106    */
107   static TextActor New( const Text& text );
108
109   /**
110    * @brief Create a TextActor object with text.
111    *
112    * The style and whether to automatically detect the font could be set in the parameters.
113    *
114    * @param[in] text The text which will be displayed
115    * @param[in] parameters Text parameters.
116    */
117   static TextActor New( const Text& text, const TextActorParameters& parameters );
118
119   /**
120    * @brief Downcast an Object handle to TextActor.
121    *
122    * If handle points to a TextActor the downcast produces valid
123    * handle. If not the returned handle is left uninitialized.
124    * @param[in] handle to An object
125    * @return handle to a TextActor or an uninitialized handle
126    */
127   static TextActor DownCast( BaseHandle handle );
128
129   /**
130    * @brief Destructor
131    *
132    * This is non-virtual since derived Handle types must not contain data or virtual methods.
133    */
134   ~TextActor();
135
136   /**
137    * @brief Copy constructor
138    *
139    * @param [in] copy The actor to copy.
140    */
141   TextActor(const TextActor& copy);
142
143   /**
144    * @brief Assignment operator
145    *
146    * @param [in] rhs The actor to copy.
147    */
148   TextActor& operator=(const TextActor& rhs);
149
150   /**
151    * @brief Get the text label displayed by the actor.
152    *
153    * @pre The text actor has been initialized.
154    * @return The text label
155    */
156   std::string GetText() const;
157
158   /**
159    * @brief Set the text label displayed by the actor.
160    *
161    * @pre The text actor has been initialized.
162    * @param [in] text The new text label
163    */
164   void SetText(const Text& text);
165
166   /**
167    * @brief Set text to the natural size of the text string.
168    *
169    * After this method the text actor always uses the natural size of the text
170    * when SetText is called unless SetSize is called to override the size.
171    */
172   void SetToNaturalSize();
173
174   /**
175    * @brief Get the font used to display the text label displayed by the actor.
176    *
177    * @pre The text actor has been initialized.
178    * @return The font currently in use
179    */
180   Font GetFont() const;
181
182   /**
183    * @brief Set the font used to display the text label displayed by the actor.
184    *
185    * @pre The text actor has been initialized.
186    * @param [in] font The new font
187    */
188   void SetFont(Font& font);
189
190   // styling and effects
191
192   /**
193    * @brief Set the gradient color.
194    *
195    * This is the color associated with the gradient end point.
196    * @param[in] color The gradient color (end-point color)
197    */
198   void SetGradientColor( const Vector4& color );
199
200   /**
201    * @brief Get the gradient color.
202    *
203    * This is the color associated with the gradient end point.
204    * @return The gradient color (end-point color)
205    */
206   Vector4 GetGradientColor() const;
207
208   /**
209    * @brief Set the gradient start point.
210    *
211    * This is a 2D position between the coordinate range:
212    * 0.0,0.0 (Left,Top) to 1.0,1.0 (Right,Bottom) within
213    * the outputted Text. Actor::COLOR will represent this point
214    * in the gradient.
215    * @param[in] position The relative position of the gradient start point.
216    */
217   void SetGradientStartPoint( const Vector2& position );
218
219   /**
220    * @brief Get the gradient start point.
221    *
222    * @return The relative position of the gradient start point.
223    */
224   Vector2 GetGradientStartPoint() const;
225
226   /**
227    * @brief Set the gradient end point.
228    *
229    * This is a 2D position between the coordinate range:
230    * 0.0,0.0 (Left,Top) to 1.0,1.0 (Right,Bottom) within
231    * the outputted Text. TextActor::GRADIENT_COLOR will represent
232    * this point in the gradient.
233    * @param[in] position The relative position of the gradient end point.
234    */
235   void SetGradientEndPoint( const Vector2& position );
236
237   /**
238    * @brief Get the gradient end point.
239    *
240    * @return The relative position of the gradient end point.
241    */
242   Vector2 GetGradientEndPoint() const;
243
244   /**
245    * @brief Sets text style.
246    *
247    * @param[in] style The text style.
248    */
249   void SetTextStyle( const TextStyle& style );
250
251   /**
252    * @brief Retrieves a copy of the text style.
253    *
254    * @return The text style.
255    */
256   TextStyle GetTextStyle() const;
257
258   /**
259    * @brief Set the text color.
260    *
261    * This is blended with the Actor color
262    * @param[in] color The text color (Default: WHITE)
263    */
264   void SetTextColor( const Vector4& color );
265
266   /**
267    * @brief Get the text color.
268    *
269    * @return The text color.
270    */
271   Vector4 GetTextColor() const;
272
273   /**
274    * @brief Set soft edge smoothing.
275    *
276    * @param[in] smoothEdge Specify the distance field value for the center of the text edge.
277    *                   0 <= smoothEdge <= 1
278    */
279   void SetSmoothEdge( float smoothEdge = TextStyle::DEFAULT_SMOOTH_EDGE_DISTANCE_FIELD );
280
281   /**
282    * @brief Set text outlining.
283    *
284    * @param[in] enable  Set to true to enable text outlining.
285    * @param[in] color   Outline color.
286    * @param[in] thickness Thickness of outline. The outline thickness is determined by two parameters.
287    *                      thickness[0] Specifies the distance field value for the center of the outline.
288    *                      thickness[1] Specifies the softness/width/anti-aliasing of the outlines inner edge.
289    *                      SetSmoothEdge() specifies the smoothness/anti-aliasing of the text outer edge.
290    *                      0 <= smoothEdge[0] <= 1.
291    *                      0 <= smoothEdge[1] <= 1.
292    */
293   void SetOutline( bool enable, const Vector4& color, const Vector2& thickness = TextStyle::DEFAULT_OUTLINE_THICKNESS );
294
295   /**
296    * @brief Set text glow.
297    *
298    * @param[in] enable  Set to true to enable text outer glow.
299    * @param[in] color   Glow color.
300    * @param[in] intensity Determines the amount of glow around text.
301    *                      The edge of the text is at the value set with SetSmoothEdge().
302    *                      SetSmoothEdge() The distance field value at which the glow becomes fully transparent.
303    */
304   void SetGlow( bool enable, const Vector4& color, float intensity = TextStyle::DEFAULT_GLOW_INTENSITY );
305
306   /**
307    * @brief Set text shadow.
308    *
309    * @param[in] enable  Set to true to enable text drop shadow.
310    * @param[in] color   Shadow color
311    * @param[in] offset  Offset in pixels. To avoid cropping of the drop shadow limit the offset to PointSize / 3.5
312    * @param[in] size    Size of shadow in pixels. 0 means the shadow is the same size as the text.
313    */
314   void SetShadow( bool enable, const Vector4& color, const Vector2& offset = TextStyle::DEFAULT_SHADOW_OFFSET,
315                   float size = TextStyle::DEFAULT_SHADOW_SIZE );
316
317   /**
318    * @brief Enable italics on the text actor, the text will be sheared by the given angle.
319    *
320    * @param[in] enabled True will enable italics, false disable it.
321    * @param[in] angle Italics angle in degrees.
322    */
323   void SetItalics( bool enabled, Degree angle = TextStyle::DEFAULT_ITALICS_ANGLE );
324
325   /**
326    * @brief Enable italics on the text actor, the text will be sheared by the given angle.
327    *
328    * @param[in] enabled True will enable italics, false disable it.
329    * @param[in] angle Italics angle in radians.
330    */
331   void SetItalics( bool enabled, Radian angle );
332
333   /**
334    * @brief Get text italics for the actor.
335    *
336    * @returns True if italics is enabled.
337    */
338   bool GetItalics() const;
339
340   /**
341    * @brief Get text italics angle.
342    *
343    * @returns Angle as a Radian.
344    */
345   Radian GetItalicsAngle() const;
346
347   /**
348    * @brief Set text underline.
349    *
350    * @param[in] enable Boolean indicating if the text should be underlined or not.
351    */
352   void SetUnderline( bool enable );
353
354   /**
355    * @brief Get text underline.
356    *
357    * @return  Boolean indicating if the text should be underlined or not.
358    */
359   bool GetUnderline() const;
360
361   /**
362    * @brief Set text weight.
363    *
364    * @param weight Text weight.
365    */
366   void SetWeight( TextStyle::Weight weight );
367
368   /**
369    * @brief Get text weight.
370    *
371    * @return Text weight.
372    */
373   TextStyle::Weight GetWeight() const;
374
375   /**
376    * @brief Try to detect font in case text is not supported with current one.
377    *
378    * @param [in] value true or false
379    */
380   void SetFontDetectionAutomatic(bool value);
381
382   /**
383    * @brief Query whether TextActor is using automatic font detection.
384    *
385    * @return true or false
386    */
387   bool IsFontDetectionAutomatic() const;
388
389   /**
390    * @brief Query whether the font has been loaded and built.
391    *
392    * Should be used by the application to determine whether the font
393    * is ready to be queried for metrics
394    * @return The loading state, either Loading, Success or Failed.
395    */
396   LoadingState GetLoadingState() const;
397
398   /**
399    * @brief Emitted when text loads successfully and is available for displaying, or when the loading fails.
400    *
401    * @return A signal object to Connect() with.
402    */
403   TextSignalType& TextAvailableSignal();
404
405 public: // Not intended for use by Application developers
406
407   /**
408    * @brief This constructor is used by Dali New() methods
409    * e
410    * @param [in] actor A pointer to a newly allocated Dali resource
411    */
412   explicit DALI_INTERNAL TextActor(Internal::TextActor* actor);
413 };
414
415 } // namespace Dali
416
417 #endif // __DALI_TEXT_ACTOR_H__