1 #ifndef __DALI_TEXT_ACTOR_H__
2 #define __DALI_TEXT_ACTOR_H__
5 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
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>
36 struct TextActorParameters;
39 namespace Internal DALI_INTERNAL
45 * @brief TextActor is a basic actor for displaying a text label
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.
52 * By default CullFaceMode is set to CullNone to enable the TextActor to be viewed from all angles.
55 * | %Signal Name | Method |
56 * |-----------------------|----------------------------|
57 * | text-loading-finished | @ref TextAvailableSignal() |
59 class DALI_IMPORT_API TextActor : public RenderableActor
63 typedef Signal< void (TextActor) > TextSignalType; ///< Text available signal type
65 // Default Properties; additional to RenderableActor properties
66 static const Property::Index TEXT; ///< name "text" type STRING
67 static const Property::Index FONT; ///< name "font" type STRING
68 static const Property::Index FONT_STYLE; ///< name "font-style" type STRING
69 static const Property::Index OUTLINE_ENABLE; ///< name "outline-enable" type BOOLEAN
70 static const Property::Index OUTLINE_COLOR; ///< name "outline-color" type VECTOR4
71 static const Property::Index OUTLINE_THICKNESS_WIDTH; ///< name "outline-thickness-width" type VECTOR2
72 static const Property::Index SMOOTH_EDGE; ///< name "smooth-edge" type FLOAT
73 static const Property::Index GLOW_ENABLE; ///< name "glow-enable" type BOOLEAN
74 static const Property::Index GLOW_COLOR; ///< name "glow-color" type VECTOR4
75 static const Property::Index GLOW_INTENSITY; ///< name "glow-intensity" type FLOAT
76 static const Property::Index SHADOW_ENABLE; ///< name "shadow-enable" type BOOLEAN
77 static const Property::Index SHADOW_COLOR; ///< name "shadow-color" type VECTOR4
78 static const Property::Index SHADOW_OFFSET; ///< name "shadow-offset" type VECTOR2
79 static const Property::Index ITALICS_ANGLE; ///< name "italics-angle" type FLOAT
80 static const Property::Index UNDERLINE; ///< name "underline" type BOOLEAN
81 static const Property::Index WEIGHT; ///< name "weight" type INTEGER
82 static const Property::Index FONT_DETECTION_AUTOMATIC; ///< name "font-detection-automatic" type BOOLEAN
83 static const Property::Index GRADIENT_COLOR; ///< name "gradient-color" type VECTOR4
84 static const Property::Index GRADIENT_START_POINT; ///< name "gradient-start-point" type VECTOR2
85 static const Property::Index GRADIENT_END_POINT; ///< name "gradient-end-point" type VECTOR2
86 static const Property::Index SHADOW_SIZE; ///< name "shadow-size" type FLOAT
87 static const Property::Index TEXT_COLOR; ///< name "text-color" type VECTOR4
90 * @brief Create an uninitialized TextActor handle.
92 * This can be initialised with TextActor::New().
93 * Calling member functions with an uninitialized handle is not allowed.
98 * @brief Create a TextActor object with no text.
100 * @return A handle to a newly allocated Dali resource.
102 static TextActor New();
105 * @brief Create a TextActor object with text, a default style and font detection.
107 * @param[in] text The text which will be displayed
109 static TextActor New( const Text& text );
112 * @brief Create a TextActor object with text.
114 * The style and whether to automatically detect the font could be set in the parameters.
116 * @param[in] text The text which will be displayed
117 * @param[in] parameters Text parameters.
119 static TextActor New( const Text& text, const TextActorParameters& parameters );
122 * @brief Downcast an Object handle to TextActor.
124 * If handle points to a TextActor the downcast produces valid
125 * handle. If not the returned handle is left uninitialized.
126 * @param[in] handle to An object
127 * @return handle to a TextActor or an uninitialized handle
129 static TextActor DownCast( BaseHandle handle );
134 * This is non-virtual since derived Handle types must not contain data or virtual methods.
139 * @brief Copy constructor
141 * @param [in] copy The actor to copy.
143 TextActor(const TextActor& copy);
146 * @brief Assignment operator
148 * @param [in] rhs The actor to copy.
150 TextActor& operator=(const TextActor& rhs);
153 * @brief Get the text label displayed by the actor.
155 * @pre The text actor has been initialized.
156 * @return The text label
158 std::string GetText() const;
161 * @brief Set the text label displayed by the actor.
163 * @pre The text actor has been initialized.
164 * @param [in] text The new text label
166 void SetText(const Text& text);
169 * @brief Set text to the natural size of the text string.
171 * After this method the text actor always uses the natural size of the text
172 * when SetText is called unless SetSize is called to override the size.
174 void SetToNaturalSize();
177 * @brief Get the font used to display the text label displayed by the actor.
179 * @pre The text actor has been initialized.
180 * @return The font currently in use
182 Font GetFont() const;
185 * @brief Set the font used to display the text label displayed by the actor.
187 * @pre The text actor has been initialized.
188 * @param [in] font The new font
190 void SetFont(Font& font);
192 // styling and effects
195 * @brief Set the gradient color.
197 * This is the color associated with the gradient end point.
198 * @param[in] color The gradient color (end-point color)
200 void SetGradientColor( const Vector4& color );
203 * @brief Get the gradient color.
205 * This is the color associated with the gradient end point.
206 * @return The gradient color (end-point color)
208 Vector4 GetGradientColor() const;
211 * @brief Set the gradient start point.
213 * This is a 2D position between the coordinate range:
214 * 0.0,0.0 (Left,Top) to 1.0,1.0 (Right,Bottom) within
215 * the outputted Text. Actor::COLOR will represent this point
217 * @param[in] position The relative position of the gradient start point.
219 void SetGradientStartPoint( const Vector2& position );
222 * @brief Get the gradient start point.
224 * @return The relative position of the gradient start point.
226 Vector2 GetGradientStartPoint() const;
229 * @brief Set the gradient end point.
231 * This is a 2D position between the coordinate range:
232 * 0.0,0.0 (Left,Top) to 1.0,1.0 (Right,Bottom) within
233 * the outputted Text. TextActor::GRADIENT_COLOR will represent
234 * this point in the gradient.
235 * @param[in] position The relative position of the gradient end point.
237 void SetGradientEndPoint( const Vector2& position );
240 * @brief Get the gradient end point.
242 * @return The relative position of the gradient end point.
244 Vector2 GetGradientEndPoint() const;
247 * @brief Sets text style.
249 * @param[in] style The text style.
251 void SetTextStyle( const TextStyle& style );
254 * @brief Retrieves a copy of the text style.
256 * @return The text style.
258 TextStyle GetTextStyle() const;
261 * @brief Set the text color.
263 * This is blended with the Actor color
264 * @param[in] color The text color (Default: WHITE)
266 void SetTextColor( const Vector4& color );
269 * @brief Get the text color.
271 * @return The text color.
273 Vector4 GetTextColor() const;
276 * @brief Set soft edge smoothing.
278 * @param[in] smoothEdge Specify the distance field value for the center of the text edge.
279 * 0 <= smoothEdge <= 1
281 void SetSmoothEdge( float smoothEdge = TextStyle::DEFAULT_SMOOTH_EDGE_DISTANCE_FIELD );
284 * @brief Set text outlining.
286 * @param[in] enable Set to true to enable text outlining.
287 * @param[in] color Outline color.
288 * @param[in] thickness Thickness of outline. The outline thickness is determined by two parameters.
289 * thickness[0] Specifies the distance field value for the center of the outline.
290 * thickness[1] Specifies the softness/width/anti-aliasing of the outlines inner edge.
291 * SetSmoothEdge() specifies the smoothness/anti-aliasing of the text outer edge.
292 * 0 <= smoothEdge[0] <= 1.
293 * 0 <= smoothEdge[1] <= 1.
295 void SetOutline( bool enable, const Vector4& color, const Vector2& thickness = TextStyle::DEFAULT_OUTLINE_THICKNESS );
298 * @brief Set text glow.
300 * @param[in] enable Set to true to enable text outer glow.
301 * @param[in] color Glow color.
302 * @param[in] intensity Determines the amount of glow around text.
303 * The edge of the text is at the value set with SetSmoothEdge().
304 * SetSmoothEdge() The distance field value at which the glow becomes fully transparent.
306 void SetGlow( bool enable, const Vector4& color, float intensity = TextStyle::DEFAULT_GLOW_INTENSITY );
309 * @brief Set text shadow.
311 * @param[in] enable Set to true to enable text drop shadow.
312 * @param[in] color Shadow color
313 * @param[in] offset Offset in pixels. To avoid cropping of the drop shadow limit the offset to PointSize / 3.5
314 * @param[in] size Size of shadow in pixels. 0 means the shadow is the same size as the text.
316 void SetShadow( bool enable, const Vector4& color, const Vector2& offset = TextStyle::DEFAULT_SHADOW_OFFSET,
317 float size = TextStyle::DEFAULT_SHADOW_SIZE );
320 * @brief Enable italics on the text actor, the text will be sheared by the given angle.
322 * @param[in] enabled True will enable italics, false disable it.
323 * @param[in] angle Italics angle in degrees.
325 void SetItalics( bool enabled, Degree angle = TextStyle::DEFAULT_ITALICS_ANGLE );
328 * @brief Enable italics on the text actor, the text will be sheared by the given angle.
330 * @param[in] enabled True will enable italics, false disable it.
331 * @param[in] angle Italics angle in radians.
333 void SetItalics( bool enabled, Radian angle );
336 * @brief Get text italics for the actor.
338 * @returns True if italics is enabled.
340 bool GetItalics() const;
343 * @brief Get text italics angle.
345 * @returns Angle as a Radian.
347 Radian GetItalicsAngle() const;
350 * @brief Set text underline.
352 * @param[in] enable Boolean indicating if the text should be underlined or not.
354 void SetUnderline( bool enable );
357 * @brief Get text underline.
359 * @return Boolean indicating if the text should be underlined or not.
361 bool GetUnderline() const;
364 * @brief Set text weight.
366 * @param weight Text weight.
368 void SetWeight( TextStyle::Weight weight );
371 * @brief Get text weight.
373 * @return Text weight.
375 TextStyle::Weight GetWeight() const;
378 * @brief Try to detect font in case text is not supported with current one.
380 * @param [in] value true or false
382 void SetFontDetectionAutomatic(bool value);
385 * @brief Query whether TextActor is using automatic font detection.
387 * @return true or false
389 bool IsFontDetectionAutomatic() const;
392 * @brief Query whether the font has been loaded and built.
394 * Should be used by the application to determine whether the font
395 * is ready to be queried for metrics
396 * @return The loading state, either Loading, Success or Failed.
398 LoadingState GetLoadingState() const;
401 * @brief Emitted when text loads successfully and is available for displaying, or when the loading fails.
403 * @return A signal object to Connect() with.
405 TextSignalType& TextAvailableSignal();
407 public: // Not intended for use by Application developers
410 * @brief This constructor is used by Dali New() methods
412 * @param [in] actor A pointer to a newly allocated Dali resource
414 explicit DALI_INTERNAL TextActor(Internal::TextActor* actor);
419 #endif // __DALI_TEXT_ACTOR_H__