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_FRAMEWORK
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 * 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;
64 static const char* const SIGNAL_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 * Create an uninitialized TextActor handle. This can be initialised with TextActor::New().
92 * Calling member functions with an uninitialized handle is not allowed.
97 * Create a TextActor object with no text
98 * @return A handle to a newly allocated Dali resource.
100 static TextActor New();
103 * Create a TextActor object with LeftToRight text and font detection
104 * @param [in] text The text which will be displayed
105 * @return A handle to a newly allocated Dali resource.
107 static TextActor New(const std::string& text);
110 * @copydoc New(const std::string& text)
112 static TextActor New(const Text& text);
115 * Create a TextActor object with LeftToRight text
116 * @param [in] text The text which will be displayed
117 * @param [in] fontDetection Try to detect font in case text is not supported with current one.
118 * @return A handle to a newly allocated Dali resource.
120 static TextActor New(const std::string& text, bool fontDetection);
123 * @copydoc New(const std::string& text, bool fontDetection)
125 static TextActor New(const Text& text, bool fontDetection);
128 * Create a TextActor object
129 * @param [in] text The text which will be displayed
130 * @param [in] fontDetection Try to detect font in case text is not supported with current one.
131 * @param [in] isLeftToRight Text is displayed from left to right if true, otherwise from right to left.
132 * @return A handle to a newly allocated Dali resource.
134 static TextActor New(const std::string& text, bool fontDetection, bool isLeftToRight);
137 * @copydoc New(const std::string& text, bool fontDetection, bool isLeftToRight)
139 static TextActor New(const Text& text, bool fontDetection, bool isLeftToRight);
142 * Create a TextActor object with LeftToRight text and font detection
143 * @param [in] text The text which will be displayed
144 * @param [in] font The font which will be used for the text
145 * @return A handle to a newly allocated Dali resource.
147 static TextActor New(const std::string& text, Font font);
150 * @copydoc New(const std::string& text, Font font)
152 static TextActor New(const Text& text, Font font);
155 * Create a TextActor object with LeftToRight text
156 * @param [in] text The text which will be displayed
157 * @param [in] font The font which will be used for the text
158 * @param [in] fontDetection Try to detect font in case text is not supported with current one.
159 * @return A handle to a newly allocated Dali resource.
161 static TextActor New(const std::string& text, Font font, bool fontDetection);
164 * @copydoc New(const std::string& text, Font font, bool fontDetection)
166 static TextActor New(const Text& text, Font font, bool fontDetection);
169 * Create a TextActor object
170 * @param [in] text The text which will be displayed
171 * @param [in] font The font which will be used for the text
172 * @param [in] fontDetection Try to detect font in case text is not supported with current one.
173 * @param [in] isLeftToRight Text is displayed from left to right if true, otherwise from right to left.
174 * @return A handle to a newly allocated Dali resource.
176 static TextActor New(const std::string& text, Font font, bool fontDetection, bool isLeftToRight);
179 * @copydoc New(const std::string& text, Font font, bool fontDetection, bool isLeftToRight)
181 static TextActor New(const Text& text, Font font, bool fontDetection, bool isLeftToRight);
184 * Create a TextActor object
185 * @param [in] text The text which will be displayed
186 * @param [in] style The style which will be used for the text
187 * @param [in] fontDetection Try to detect font in case text is not supported with current one.
188 * @param [in] isLeftToRight Text is displayed from left to right if true, otherwise from right to left.
189 * @return A handle to a newly allocated Dali resource.
191 static TextActor New(const Text& text, const TextStyle& style, bool fontDetection, bool isLeftToRight);
194 * Downcast an Object handle to TextActor. If handle points to a TextActor the
195 * downcast produces valid handle. If not the returned handle is left uninitialized.
196 * @param[in] handle to An object
197 * @return handle to a TextActor or an uninitialized handle
199 static TextActor DownCast( BaseHandle handle );
202 * Virtual destructor.
203 * Dali::Object derived classes typically do not contain member data.
205 virtual ~TextActor();
208 * @copydoc Dali::BaseHandle::operator=
210 using BaseHandle::operator=;
213 * Get the text label displayed by the actor
214 * @pre The text actor has been initialized.
215 * @return The text label
217 std::string GetText() const;
220 * Set the text label displayed by the actor
221 * @pre The text actor has been initialized.
222 * @param [in] text The new text label
224 void SetText(const std::string& text);
227 * @copydoc SetText(const std::string& text)
229 void SetText(const Text& text);
232 * Set text to the natural size of the text string
233 * After this method the text actor always uses the natural size of the text
234 * when SetText is called unless SetSize is called to override the size.
236 void SetToNaturalSize();
239 * Get the font used to display the text label displayed by the actor
240 * @pre The text actor has been initialized.
241 * @return The font currently in use
243 Font GetFont() const;
246 * Set the font used to display the text label displayed by the actor
247 * @pre The text actor has been initialized.
248 * @param [in] font The new font
250 void SetFont(Font& font);
252 // styling and effects
255 * Set the gradient color
256 * This is the color associated with the gradient end point.
257 * @param[in] color The gradient color (end-point color)
259 void SetGradientColor( const Vector4& color );
262 * Get the gradient color
263 * This is the color associated with the gradient end point.
264 * @return The gradient color (end-point color)
266 Vector4 GetGradientColor() const;
269 * Set the gradient start point.
270 * This is a 2D position between the coordinate range:
271 * 0.0,0.0 (Left,Top) to 1.0,1.0 (Right,Bottom) within
272 * the outputted Text. Actor::COLOR will represent this point
274 * @param[in] position The relative position of the gradient start point.
276 void SetGradientStartPoint( const Vector2& position );
279 * Get the gradient start point.
280 * @return The relative position of the gradient start point.
282 Vector2 GetGradientStartPoint() const;
285 * Set the gradient end point.
286 * This is a 2D position between the coordinate range:
287 * 0.0,0.0 (Left,Top) to 1.0,1.0 (Right,Bottom) within
288 * the outputted Text. TextActor::GRADIENT_COLOR will represent
289 * this point in the gradient.
290 * @param[in] position The relative position of the gradient end point.
292 void SetGradientEndPoint( const Vector2& position );
295 * Get the gradient end point.
296 * @return The relative position of the gradient end point.
298 Vector2 GetGradientEndPoint() const;
302 * @param[in] style The text style.
304 void SetTextStyle( const TextStyle& style );
307 * Retrieves a copy of the text style.
308 * @return The text style.
310 TextStyle GetTextStyle() const;
313 * Set the text color. This is blended with the Actor color
314 * @param[in] color The text color (Default: WHITE)
316 void SetTextColor( const Vector4& color );
319 * Get the text color.
320 * @return The text color.
322 Vector4 GetTextColor() const;
325 * Set soft edge smoothing
326 * @param[in] smoothEdge Specify the distance field value for the center of the text edge.
327 * 0 <= smoothEdge <= 1
329 void SetSmoothEdge(const float smoothEdge = TextStyle::DEFAULT_SMOOTH_EDGE_DISTANCE_FIELD);
333 * @param[in] enable Set to true to enable text outlining.
334 * @param[in] color Outline color.
335 * @param[in] thickness Thickness of outline. The outline thickness is determined by two parameters.
336 * thickness[0] Specifies the distance field value for the center of the outline.
337 * thickness[1] Specifies the softness/width/anti-aliasing of the outlines inner edge.
338 * SetSmoothEdge() specifies the smoothness/anti-aliasing of the text outer edge.
339 * 0 <= smoothEdge[0] <= 1.
340 * 0 <= smoothEdge[1] <= 1.
342 void SetOutline(const bool enable, const Vector4& color, const Vector2& thickness = TextStyle::DEFAULT_OUTLINE_THICKNESS);
346 * @param[in] enable Set to true to enable text outer glow.
347 * @param[in] color Glow color.
348 * @param[in] intensity Determines the amount of glow around text.
349 * The edge of the text is at the value set with SetSmoothEdge().
350 * SetSmoothEdge() The distance field value at which the glow becomes fully transparent.
352 void SetGlow(const bool enable, const Vector4& color, const float intensity = TextStyle::DEFAULT_GLOW_INTENSITY);
356 * @param[in] enable Set to true to enable text drop shadow.
357 * @param[in] color Shadow color
358 * @param[in] offset Offset in pixels. To avoid cropping of the drop shadow limit the offset to PointSize / 3.5
359 * @param[in] size Size of shadow in pixels. 0 means the shadow is the same size as the text.
361 void SetShadow(const bool enable, const Vector4& color, const Vector2& offset = TextStyle::DEFAULT_SHADOW_OFFSET,
362 const float size = TextStyle::DEFAULT_SHADOW_SIZE );
365 * Enable italics on the text actor, the text will be sheared by the given angle.
366 * @param[in] enabled True will enable italics, false disable it.
367 * @param[in] angle Italics angle in degrees.
369 void SetItalics( const bool enabled, const Degree& angle = TextStyle::DEFAULT_ITALICS_ANGLE );
372 * Enable italics on the text actor, the text will be sheared by the given angle.
373 * @param[in] enabled True will enable italics, false disable it.
374 * @param[in] angle Italics angle in radians.
376 void SetItalics( const bool enabled, const Radian& angle );
379 * Get text italics for the actor.
380 * @returns True if italics is enabled.
382 bool GetItalics() const;
385 * Get text italics angle.
386 * @returns Angle as a Radian.
388 const Radian& GetItalicsAngle() const;
391 * Set text underline.
392 * @param[in] enable Boolean indicating if the text should be underlined or not.
394 void SetUnderline( bool enable );
397 * Get text underline.
398 * @return Boolean indicating if the text should be underlined or not.
400 bool GetUnderline() const;
404 * @param weight Text weight.
406 void SetWeight( TextStyle::Weight weight );
410 * @return Text weight.
412 TextStyle::Weight GetWeight() const;
415 * Try to detect font in case text is not supported with current one.
416 * @param [in] value true or false
418 void SetFontDetectionAutomatic(bool value);
421 * Query whether TextActor is using automatic font detection.
422 * @return true or false
424 bool IsFontDetectionAutomatic() const;
427 * Query whether the font has been loaded and built. Should be used by the application to determine whether the
428 * font is ready to be queried for metrics
429 * @return The loading state, either Loading, Success or Failed.
431 LoadingState GetLoadingState() const;
434 * Emitted when text loads successfully and is available for displaying, or when the loading fails.
435 * @return A signal object to Connect() with.
437 TextSignalV2& TextAvailableSignal();
439 public: // Not intended for use by Application developers
442 * This constructor is used by Dali New() methods
443 * @param [in] actor A pointer to a newly allocated Dali resource
445 explicit DALI_INTERNAL TextActor(Internal::TextActor* actor);
453 #endif // __DALI_TEXT_ACTOR_H__