TextParameters object now contains only the specific parameters set
[platform/core/uifw/dali-core.git] / dali / internal / common / text-parameters.h
1 #ifndef __INTERNAL_TEXT_PARAMETERS_H__
2 #define __INTERNAL_TEXT_PARAMETERS_H__
3
4 //
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
6 //
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
10 //
11 //     http://floralicense.org/license/
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 // INTERNAL HEADERS
21 #include <dali/public-api/math/vector2.h>
22 #include <dali/public-api/math/vector4.h>
23
24 #include <dali/public-api/object/any.h>
25 #include <vector>
26
27 namespace Dali
28 {
29
30 namespace Internal
31 {
32
33
34   // Number of bits for an index mask - increase if more attributes are added...
35   const unsigned int TEXT_PARAMETER_BITS = 2;
36
37   // Set mask for this number of bits
38   const unsigned int TEXT_PARAMETER_MASK = ~( -1 << TEXT_PARAMETER_BITS );
39
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;
46
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;
52
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;
60
61 /**
62  * class TextParameters internal class to encapsulate (and allow on demand allocation) of
63  * text effect parameters like, outline, glow and shadow
64  */
65 class TextParameters
66 {
67 public:
68
69   /**
70    * @brief Outline attributes
71    */
72   struct OutlineAttributes
73   {
74     Vector4 mOutlineColor;
75     Vector2 mOutlineThickness;
76   };
77
78   /**
79    * @brief Glow attributes
80    */
81   struct GlowAttributes
82   {
83     Vector4 mGlowColor;
84     float mGlowIntensity;
85   };
86
87   /**
88    * @brief Drop Shadow attributes
89    */
90   struct DropShadowAttributes
91   {
92     Vector4 mDropShadowColor;
93     Vector2 mDropShadowOffset;
94     float   mDropShadowSize;
95   };
96
97   /**
98    * @brief Gradient attributes
99    */
100   struct GradientAttributes
101   {
102     Vector4 mGradientColor;
103     Vector2 mGradientStartPoint;
104     Vector2 mGradientEndPoint;
105   };
106
107   /**
108    * Constructor
109    */
110   TextParameters();
111
112   /**
113    * Destructor
114    */
115   ~TextParameters();
116
117   /// @copydoc Dali::TextActor::SetOutline
118   void SetOutline( bool enable, const Vector4& color, const Vector2& thickness );
119
120   /// @copydoc Dali::TextActor::SetGlow
121   void SetGlow( bool enable, const Vector4& color, const float intensity);
122
123   /// @copydoc Dali::TextActor::SetShadow
124   void SetShadow(bool enable, const Vector4& color, const Vector2& offset, const float size);
125
126   /**
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.
131    */
132   void SetGradient( const Vector4& color, const Vector2& start, const Vector2& end);
133
134   /**
135    * @brief Set Gradient color
136    *
137    * @param color Gradient color
138    */
139   void SetGradientColor( const Vector4& color );
140
141   /**
142    * @brief Set Gradient Start Point
143    *
144    * @param start Position of gradient start
145    */
146   void SetGradientStartPoint( const Vector2& start );
147
148   /**
149    * @brief Set Gradient End Point
150    *
151    * @param end Position of gradient end
152    */
153   void SetGradientEndPoint( const Vector2& end );
154
155   /**
156    * @brief Get the Gradient Color
157    *
158    * @return Gradient Color
159    */
160   const Vector4& GetOutlineColor();
161
162   /**
163    * @brief Get Outline Thickness
164    *
165    * @return Outline Thickness
166    */
167   const Vector2& GetOutlineThickness();
168
169   /**
170    * @brief Get Glow Color
171    *
172    * @return Glow Color
173    */
174   const Vector4& GetGlowColor();
175
176   /**
177    * @brief Get Glow Intensity
178    *
179    * @return Glow Intensity
180    */
181   float GetGlowIntensity();
182
183   /**
184    * @brief Get Drop Shadow Color
185    *
186    * @return Drop Shadow Color
187    */
188   const Vector4& GetDropShadowColor();
189
190   /**
191    * @brief Get Drop Shadow Offset
192    *
193    * @return Drop Shadow Offset
194    */
195   const Vector2& GetDropShadowOffset();
196
197   /**
198    * @brief Get Drop Shadow Size
199    *
200    * @return Drop Shadow Size
201    */
202   float GetDropShadowSize();
203
204   /**
205    * @brief Get Gradient Color
206    *
207    * @return Gradient Color
208    */
209   const Vector4& GetGradientColor();
210
211   /**
212    * @brief Get Gradient Start Point
213    *
214    * @return Position of Gradient Start Point
215    */
216   const Vector2& GetGradientStartPoint();
217
218   /**
219    * @brief Get Gradient End Point
220    *
221    * @return Position of Gradient End Point
222    */
223   const Vector2& GetGradientEndPoint();
224
225   /**
226    * @brief Get if Outline is enabled
227    *
228    * @return true if enabled, false if not
229    */
230   const bool IsOutlineEnabled() const
231   {
232     return ( ( mFlags & OUTLINE_ENABLED ) != 0 );
233   }
234
235   /**
236    * @brief Get if Glow is enabled
237    *
238    * @return true if enabled, false if not
239    */
240   const bool IsGlowEnabled() const
241   {
242     return ( ( mFlags & GLOW_ENABLED ) != 0 );
243   }
244
245   /**
246    * @brief Get if Drop Shadow is enabled
247    *
248    * @return true if enabled, false if not
249    */
250   const bool IsDropShadowEnabled() const
251   {
252     return ( ( mFlags & DROP_SHADOW_ENABLED ) != 0 );
253   }
254
255   /**
256    * @brief Get if Gradient is enabled
257    *
258    * @return true if enabled, false if not
259    */
260   const bool IsGradientEnabled() const
261   {
262     return ( ( mFlags & GRADIENT_ENABLED ) != 0 );
263   }
264
265   /**
266    * @brief Enable Gradient
267    *
268    * @param enable Set gradient enabled flag to enable
269    */
270   void SetGradientEnabled( bool enable )
271   {
272     if ( enable )
273     {
274       mFlags |= GRADIENT_ENABLED;
275     }
276     else
277     {
278       mFlags &=~GRADIENT_ENABLED;
279     }
280   }
281
282 private: // unimplemented copy constructor and assignment operator
283   TextParameters( const TextParameters& copy );
284   TextParameters& operator=(const TextParameters& rhs);
285
286   std::vector< Dali::Any > mParameters;         // container for any used attributes
287
288 #if ( ATTRIBUTE_END > 0x8000 )
289   unsigned int mFlags;                          // flags for used attributes, packed with position in container
290 #else
291   unsigned short mFlags;                        // might be rendered irrelevant by alignment / packing
292 #endif
293
294 }; // class TextParameters
295
296 } // namespace Internal
297
298 } // namespace Dali
299
300 #endif // __INTERNAL_TEXT_PARAMETERS_H__