1 #ifndef __DALI_TEXT_ACTOR_H__
2 #define __DALI_TEXT_ACTOR_H__
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
7 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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 * @addtogroup CAPI_DALI_ACTORS_MODULE
30 #include <dali/public-api/actors/renderable-actor.h>
31 #include <dali/public-api/common/loading-state.h>
32 #include <dali/public-api/common/constants.h>
33 #include <dali/public-api/math/vector2.h>
34 #include <dali/public-api/text/text-style.h>
35 #include <dali/public-api/text/text.h>
37 namespace Dali DALI_IMPORT_API
42 namespace Internal DALI_INTERNAL
48 * @brief TextActor is a basic actor for displaying a text label
50 * By default the text actor always uses the natural size of the text when SetText is called,
51 * unless SetSize is called to override the size or size is animated to some other size.
52 * Natural size for TextActor is the same as the size returned by Font::MeasureText( string )
53 * using the font that the TextActor is using.
55 * By default CullFaceMode is set to CullNone to enable the TextActor to be viewed from all angles.
57 class DALI_IMPORT_API TextActor : public RenderableActor
61 typedef SignalV2< void (TextActor) > TextSignalV2; ///< Text available signal type
64 static const char* const SIGNAL_TEXT_LOADING_FINISHED; ///< name "text-loading-finished"
66 // Default Properties; additional to RenderableActor properties
67 static const Property::Index TEXT; ///< name "text" type STRING
68 static const Property::Index FONT; ///< name "font" type STRING
69 static const Property::Index FONT_STYLE; ///< name "font-style" type STRING
70 static const Property::Index OUTLINE_ENABLE; ///< name "outline-enable" type BOOLEAN
71 static const Property::Index OUTLINE_COLOR; ///< name "outline-color" type VECTOR4
72 static const Property::Index OUTLINE_THICKNESS_WIDTH; ///< name "outline-thickness-width" type VECTOR2
73 static const Property::Index SMOOTH_EDGE; ///< name "smooth-edge" type FLOAT
74 static const Property::Index GLOW_ENABLE; ///< name "glow-enable" type BOOLEAN
75 static const Property::Index GLOW_COLOR; ///< name "glow-color" type VECTOR4
76 static const Property::Index GLOW_INTENSITY; ///< name "glow-intensity" type FLOAT
77 static const Property::Index SHADOW_ENABLE; ///< name "shadow-enable" type BOOLEAN
78 static const Property::Index SHADOW_COLOR; ///< name "shadow-color" type VECTOR4
79 static const Property::Index SHADOW_OFFSET; ///< name "shadow-offset" type VECTOR2
80 static const Property::Index ITALICS_ANGLE; ///< name "italics-angle" type FLOAT
81 static const Property::Index UNDERLINE; ///< name "underline" type BOOLEAN
82 static const Property::Index WEIGHT; ///< name "weight" type INTEGER
83 static const Property::Index FONT_DETECTION_AUTOMATIC; ///< name "font-detection-automatic" type BOOLEAN
84 static const Property::Index GRADIENT_COLOR; ///< name "gradient-color" type VECTOR4
85 static const Property::Index GRADIENT_START_POINT; ///< name "gradient-start-point" type VECTOR2
86 static const Property::Index GRADIENT_END_POINT; ///< name "gradient-end-point" type VECTOR2
87 static const Property::Index SHADOW_SIZE; ///< name "shadow-size" type FLOAT
88 static const Property::Index TEXT_COLOR; ///< name "text-color" type VECTOR4
91 * @brief Create an uninitialized TextActor handle.
93 * This can be initialised with TextActor::New().
94 * Calling member functions with an uninitialized handle is not allowed.
99 * @brief Create a TextActor object with no text.
101 * @return A handle to a newly allocated Dali resource.
103 static TextActor New();
106 * @brief Create a TextActor object with LeftToRight text and font detection
108 * @param [in] text The text which will be displayed
109 * @return A handle to a newly allocated Dali resource.
111 static TextActor New(const std::string& text);
114 * @copydoc New(const std::string& text)
116 static TextActor New(const Text& text);
119 * @brief Create a TextActor object with LeftToRight text.
121 * @param [in] text The text which will be displayed
122 * @param [in] fontDetection Try to detect font in case text is not supported with current one.
123 * @return A handle to a newly allocated Dali resource.
125 static TextActor New(const std::string& text, bool fontDetection);
128 * @copydoc New(const std::string& text, bool fontDetection)
130 static TextActor New(const Text& text, bool fontDetection);
133 * @brief Create a TextActor object.
135 * @param [in] text The text which will be displayed
136 * @param [in] fontDetection Try to detect font in case text is not supported with current one.
137 * @param [in] isLeftToRight Text is displayed from left to right if true, otherwise from right to left.
138 * @return A handle to a newly allocated Dali resource.
140 static TextActor New(const std::string& text, bool fontDetection, bool isLeftToRight);
143 * @copydoc New(const std::string& text, bool fontDetection, bool isLeftToRight)
145 static TextActor New(const Text& text, bool fontDetection, bool isLeftToRight);
148 * @brief Create a TextActor object with LeftToRight text and font detection.
150 * @param [in] text The text which will be displayed
151 * @param [in] font The font which will be used for the text
152 * @return A handle to a newly allocated Dali resource.
154 static TextActor New(const std::string& text, Font font);
157 * @copydoc New(const std::string& text, Font font)
159 static TextActor New(const Text& text, Font font);
162 * @brief Create a TextActor object with LeftToRight text.
164 * @param [in] text The text which will be displayed
165 * @param [in] font The font which will be used for the text
166 * @param [in] fontDetection Try to detect font in case text is not supported with current one.
167 * @return A handle to a newly allocated Dali resource.
169 static TextActor New(const std::string& text, Font font, bool fontDetection);
172 * @copydoc New(const std::string& text, Font font, bool fontDetection)
174 static TextActor New(const Text& text, Font font, bool fontDetection);
177 * @brief Create a TextActor object.
179 * @param [in] text The text which will be displayed
180 * @param [in] font The font which will be used for the text
181 * @param [in] fontDetection Try to detect font in case text is not supported with current one.
182 * @param [in] isLeftToRight Text is displayed from left to right if true, otherwise from right to left.
183 * @return A handle to a newly allocated Dali resource.
185 static TextActor New(const std::string& text, Font font, bool fontDetection, bool isLeftToRight);
188 * @copydoc New(const std::string& text, Font font, bool fontDetection, bool isLeftToRight)
190 static TextActor New(const Text& text, Font font, bool fontDetection, bool isLeftToRight);
193 * @brief Create a TextActor object.
195 * @param [in] text The text which will be displayed
196 * @param [in] style The style which will be used for the text
197 * @param [in] fontDetection Try to detect font in case text is not supported with current one.
198 * @param [in] isLeftToRight Text is displayed from left to right if true, otherwise from right to left.
199 * @return A handle to a newly allocated Dali resource.
201 static TextActor New(const Text& text, const TextStyle& style, bool fontDetection, bool isLeftToRight);
204 * @brief Downcast an Object handle to TextActor.
206 * If handle points to a TextActor the downcast produces valid
207 * handle. If not the returned handle is left uninitialized.
208 * @param[in] handle to An object
209 * @return handle to a TextActor or an uninitialized handle
211 static TextActor DownCast( BaseHandle handle );
214 * @brief Virtual destructor.
216 * Dali::Object derived classes typically do not contain member data.
218 virtual ~TextActor();
221 * @copydoc Dali::BaseHandle::operator=
223 using BaseHandle::operator=;
226 * @brief Get the text label displayed by the actor.
228 * @pre The text actor has been initialized.
229 * @return The text label
231 std::string GetText() const;
234 * @brief Set the text label displayed by the actor.
236 * @pre The text actor has been initialized.
237 * @param [in] text The new text label
239 void SetText(const std::string& text);
242 * @copydoc SetText(const std::string& text)
244 void SetText(const Text& text);
247 * @brief Set text to the natural size of the text string.
249 * After this method the text actor always uses the natural size of the text
250 * when SetText is called unless SetSize is called to override the size.
252 void SetToNaturalSize();
255 * @brief Get the font used to display the text label displayed by the actor.
257 * @pre The text actor has been initialized.
258 * @return The font currently in use
260 Font GetFont() const;
263 * @brief Set the font used to display the text label displayed by the actor.
265 * @pre The text actor has been initialized.
266 * @param [in] font The new font
268 void SetFont(Font& font);
270 // styling and effects
273 * @brief Set the gradient color.
275 * This is the color associated with the gradient end point.
276 * @param[in] color The gradient color (end-point color)
278 void SetGradientColor( const Vector4& color );
281 * @brief Get the gradient color.
283 * This is the color associated with the gradient end point.
284 * @return The gradient color (end-point color)
286 Vector4 GetGradientColor() const;
289 * @brief Set the gradient start point.
291 * This is a 2D position between the coordinate range:
292 * 0.0,0.0 (Left,Top) to 1.0,1.0 (Right,Bottom) within
293 * the outputted Text. Actor::COLOR will represent this point
295 * @param[in] position The relative position of the gradient start point.
297 void SetGradientStartPoint( const Vector2& position );
300 * @brief Get the gradient start point.
302 * @return The relative position of the gradient start point.
304 Vector2 GetGradientStartPoint() const;
307 * @brief Set the gradient end point.
309 * This is a 2D position between the coordinate range:
310 * 0.0,0.0 (Left,Top) to 1.0,1.0 (Right,Bottom) within
311 * the outputted Text. TextActor::GRADIENT_COLOR will represent
312 * this point in the gradient.
313 * @param[in] position The relative position of the gradient end point.
315 void SetGradientEndPoint( const Vector2& position );
318 * @brief Get the gradient end point.
320 * @return The relative position of the gradient end point.
322 Vector2 GetGradientEndPoint() const;
325 * @brief Sets text style.
327 * @param[in] style The text style.
329 void SetTextStyle( const TextStyle& style );
332 * @brief Retrieves a copy of the text style.
334 * @return The text style.
336 TextStyle GetTextStyle() const;
339 * @brief Set the text color.
341 * This is blended with the Actor color
342 * @param[in] color The text color (Default: WHITE)
344 void SetTextColor( const Vector4& color );
347 * @brief Get the text color.
349 * @return The text color.
351 Vector4 GetTextColor() const;
354 * @brief Set soft edge smoothing.
356 * @param[in] smoothEdge Specify the distance field value for the center of the text edge.
357 * 0 <= smoothEdge <= 1
359 void SetSmoothEdge(const float smoothEdge = TextStyle::DEFAULT_SMOOTH_EDGE_DISTANCE_FIELD);
362 * @brief Set text outlining.
364 * @param[in] enable Set to true to enable text outlining.
365 * @param[in] color Outline color.
366 * @param[in] thickness Thickness of outline. The outline thickness is determined by two parameters.
367 * thickness[0] Specifies the distance field value for the center of the outline.
368 * thickness[1] Specifies the softness/width/anti-aliasing of the outlines inner edge.
369 * SetSmoothEdge() specifies the smoothness/anti-aliasing of the text outer edge.
370 * 0 <= smoothEdge[0] <= 1.
371 * 0 <= smoothEdge[1] <= 1.
373 void SetOutline(const bool enable, const Vector4& color, const Vector2& thickness = TextStyle::DEFAULT_OUTLINE_THICKNESS);
376 * @brief Set text glow.
378 * @param[in] enable Set to true to enable text outer glow.
379 * @param[in] color Glow color.
380 * @param[in] intensity Determines the amount of glow around text.
381 * The edge of the text is at the value set with SetSmoothEdge().
382 * SetSmoothEdge() The distance field value at which the glow becomes fully transparent.
384 void SetGlow(const bool enable, const Vector4& color, const float intensity = TextStyle::DEFAULT_GLOW_INTENSITY);
387 * @brief Set text shadow.
389 * @param[in] enable Set to true to enable text drop shadow.
390 * @param[in] color Shadow color
391 * @param[in] offset Offset in pixels. To avoid cropping of the drop shadow limit the offset to PointSize / 3.5
392 * @param[in] size Size of shadow in pixels. 0 means the shadow is the same size as the text.
394 void SetShadow(const bool enable, const Vector4& color, const Vector2& offset = TextStyle::DEFAULT_SHADOW_OFFSET,
395 const float size = TextStyle::DEFAULT_SHADOW_SIZE );
398 * @brief Enable italics on the text actor, the text will be sheared by the given angle.
400 * @param[in] enabled True will enable italics, false disable it.
401 * @param[in] angle Italics angle in degrees.
403 void SetItalics( const bool enabled, const Degree& angle = TextStyle::DEFAULT_ITALICS_ANGLE );
406 * @brief Enable italics on the text actor, the text will be sheared by the given angle.
408 * @param[in] enabled True will enable italics, false disable it.
409 * @param[in] angle Italics angle in radians.
411 void SetItalics( const bool enabled, const Radian& angle );
414 * @brief Get text italics for the actor.
416 * @returns True if italics is enabled.
418 bool GetItalics() const;
421 * @brief Get text italics angle.
423 * @returns Angle as a Radian.
425 const Radian& GetItalicsAngle() const;
428 * @brief Set text underline.
430 * @param[in] enable Boolean indicating if the text should be underlined or not.
432 void SetUnderline( bool enable );
435 * @brief Get text underline.
437 * @return Boolean indicating if the text should be underlined or not.
439 bool GetUnderline() const;
442 * @brief Set text weight.
444 * @param weight Text weight.
446 void SetWeight( TextStyle::Weight weight );
449 * @brief Get text weight.
451 * @return Text weight.
453 TextStyle::Weight GetWeight() const;
456 * @brief Try to detect font in case text is not supported with current one.
458 * @param [in] value true or false
460 void SetFontDetectionAutomatic(bool value);
463 * @brief Query whether TextActor is using automatic font detection.
465 * @return true or false
467 bool IsFontDetectionAutomatic() const;
470 * @brief Query whether the font has been loaded and built.
472 * Should be used by the application to determine whether the font
473 * is ready to be queried for metrics
474 * @return The loading state, either Loading, Success or Failed.
476 LoadingState GetLoadingState() const;
479 * @brief Emitted when text loads successfully and is available for displaying, or when the loading fails.
481 * @return A signal object to Connect() with.
483 TextSignalV2& TextAvailableSignal();
485 public: // Not intended for use by Application developers
488 * @brief This constructor is used by Dali New() methods
490 * @param [in] actor A pointer to a newly allocated Dali resource
492 explicit DALI_INTERNAL TextActor(Internal::TextActor* actor);
500 #endif // __DALI_TEXT_ACTOR_H__