1 #ifndef __INTERNAL_TEXT_PARAMETERS_H__
2 #define __INTERNAL_TEXT_PARAMETERS_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.
21 #include <dali/public-api/math/vector2.h>
22 #include <dali/public-api/math/vector4.h>
24 #include <dali/public-api/object/any.h>
34 // Number of bits for an index mask - increase if more attributes are added...
35 const unsigned int TEXT_PARAMETER_BITS = 2;
37 // Set mask for this number of bits
38 const unsigned int TEXT_PARAMETER_MASK = ~( -1 << TEXT_PARAMETER_BITS );
40 // Shift values for attribute indices
41 const unsigned int OUTLINE_INDEX_SHIFT = 0;
42 const unsigned int GLOW_INDEX_SHIFT = OUTLINE_INDEX_SHIFT + TEXT_PARAMETER_BITS;
43 const unsigned int DROP_SHADOW_INDEX_SHIFT = GLOW_INDEX_SHIFT + TEXT_PARAMETER_BITS;
44 const unsigned int GRADIENT_INDEX_SHIFT = DROP_SHADOW_INDEX_SHIFT + TEXT_PARAMETER_BITS;
45 const unsigned int TEXT_PARAMETER_FLAGS = GRADIENT_INDEX_SHIFT + TEXT_PARAMETER_BITS;
47 // Position in flags for attribute index
48 const unsigned int OUTLINE_INDEX = 0;
49 const unsigned int GLOW_INDEX = TEXT_PARAMETER_MASK << GLOW_INDEX_SHIFT;
50 const unsigned int DROP_SHADOW_INDEX = TEXT_PARAMETER_MASK << DROP_SHADOW_INDEX_SHIFT;
51 const unsigned int GRADIENT_INDEX = TEXT_PARAMETER_MASK << GRADIENT_INDEX_SHIFT;
53 // Flag positions for attributes ( gradient has two as parameters can be set independently )
54 const unsigned int OUTLINE_ENABLED = 1 << TEXT_PARAMETER_FLAGS;
55 const unsigned int GLOW_ENABLED = 1 << ( TEXT_PARAMETER_FLAGS + 1 );
56 const unsigned int DROP_SHADOW_ENABLED = 1 << ( TEXT_PARAMETER_FLAGS + 2 );
57 const unsigned int GRADIENT_EXISTS = 1 << ( TEXT_PARAMETER_FLAGS + 3 );
58 const unsigned int GRADIENT_ENABLED = 1 << ( TEXT_PARAMETER_FLAGS + 4 );
59 const unsigned int ATTRIBUTE_END = GRADIENT_ENABLED;
62 * class TextParameters internal class to encapsulate (and allow on demand allocation) of
63 * text effect parameters like, outline, glow and shadow
70 * @brief Outline attributes
72 struct OutlineAttributes
74 Vector4 mOutlineColor;
75 Vector2 mOutlineThickness;
79 * @brief Glow attributes
88 * @brief Drop Shadow attributes
90 struct DropShadowAttributes
92 Vector4 mDropShadowColor;
93 Vector2 mDropShadowOffset;
94 float mDropShadowSize;
98 * @brief Gradient attributes
100 struct GradientAttributes
102 Vector4 mGradientColor;
103 Vector2 mGradientStartPoint;
104 Vector2 mGradientEndPoint;
117 /// @copydoc Dali::TextActor::SetOutline
118 void SetOutline( bool enable, const Vector4& color, const Vector2& thickness );
120 /// @copydoc Dali::TextActor::SetGlow
121 void SetGlow( bool enable, const Vector4& color, const float intensity);
123 /// @copydoc Dali::TextActor::SetShadow
124 void SetShadow(bool enable, const Vector4& color, const Vector2& offset, const float size);
127 * @brief Set Gradient parameters.
128 * @param[in] color The gradient color (end-point color)
129 * @param[in] start The relative position of the gradient start point.
130 * @param[in] end The relative position of the gradient end point.
132 void SetGradient( const Vector4& color, const Vector2& start, const Vector2& end);
135 * @brief Set Gradient color
137 * @param color Gradient color
139 void SetGradientColor( const Vector4& color );
142 * @brief Set Gradient Start Point
144 * @param start Position of gradient start
146 void SetGradientStartPoint( const Vector2& start );
149 * @brief Set Gradient End Point
151 * @param end Position of gradient end
153 void SetGradientEndPoint( const Vector2& end );
156 * @brief Get the Gradient Color
158 * @return Gradient Color
160 const Vector4& GetOutlineColor();
163 * @brief Get Outline Thickness
165 * @return Outline Thickness
167 const Vector2& GetOutlineThickness();
170 * @brief Get Glow Color
174 const Vector4& GetGlowColor();
177 * @brief Get Glow Intensity
179 * @return Glow Intensity
181 float GetGlowIntensity();
184 * @brief Get Drop Shadow Color
186 * @return Drop Shadow Color
188 const Vector4& GetDropShadowColor();
191 * @brief Get Drop Shadow Offset
193 * @return Drop Shadow Offset
195 const Vector2& GetDropShadowOffset();
198 * @brief Get Drop Shadow Size
200 * @return Drop Shadow Size
202 float GetDropShadowSize();
205 * @brief Get Gradient Color
207 * @return Gradient Color
209 const Vector4& GetGradientColor();
212 * @brief Get Gradient Start Point
214 * @return Position of Gradient Start Point
216 const Vector2& GetGradientStartPoint();
219 * @brief Get Gradient End Point
221 * @return Position of Gradient End Point
223 const Vector2& GetGradientEndPoint();
226 * @brief Get if Outline is enabled
228 * @return true if enabled, false if not
230 const bool IsOutlineEnabled() const
232 return ( ( mFlags & OUTLINE_ENABLED ) != 0 );
236 * @brief Get if Glow is enabled
238 * @return true if enabled, false if not
240 const bool IsGlowEnabled() const
242 return ( ( mFlags & GLOW_ENABLED ) != 0 );
246 * @brief Get if Drop Shadow is enabled
248 * @return true if enabled, false if not
250 const bool IsDropShadowEnabled() const
252 return ( ( mFlags & DROP_SHADOW_ENABLED ) != 0 );
256 * @brief Get if Gradient is enabled
258 * @return true if enabled, false if not
260 const bool IsGradientEnabled() const
262 return ( ( mFlags & GRADIENT_ENABLED ) != 0 );
266 * @brief Enable Gradient
268 * @param enable Set gradient enabled flag to enable
270 void SetGradientEnabled( bool enable )
274 mFlags |= GRADIENT_ENABLED;
278 mFlags &=~GRADIENT_ENABLED;
282 private: // unimplemented copy constructor and assignment operator
283 TextParameters( const TextParameters& copy );
284 TextParameters& operator=(const TextParameters& rhs);
286 std::vector< Dali::Any > mParameters; // container for any used attributes
288 #if ( ATTRIBUTE_END > 0x8000 )
289 unsigned int mFlags; // flags for used attributes, packed with position in container
291 unsigned short mFlags; // might be rendered irrelevant by alignment / packing
294 }; // class TextParameters
296 } // namespace Internal
300 #endif // __INTERNAL_TEXT_PARAMETERS_H__