Merge "Follow the include-order coding conventions" into tizen
[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 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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
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
21 // INTERNAL HEADERS
22 #include <dali/public-api/math/vector2.h>
23 #include <dali/public-api/math/vector4.h>
24 #include <dali/public-api/common/dali-vector.h>
25
26 namespace Dali
27 {
28
29 namespace Internal
30 {
31
32
33   // Number of bits for an index mask - increase if more attributes are added...
34   const unsigned int TEXT_PARAMETER_BITS = 2u;
35
36   // Set mask for this number of bits
37   const unsigned int TEXT_PARAMETER_MASK = ~( -1 << TEXT_PARAMETER_BITS );
38
39   // Shift values for attribute indices
40   const unsigned int OUTLINE_INDEX_SHIFT = 0u;
41   const unsigned int GLOW_INDEX_SHIFT = OUTLINE_INDEX_SHIFT + TEXT_PARAMETER_BITS;
42   const unsigned int DROP_SHADOW_INDEX_SHIFT = GLOW_INDEX_SHIFT + TEXT_PARAMETER_BITS;
43   const unsigned int GRADIENT_INDEX_SHIFT = DROP_SHADOW_INDEX_SHIFT + TEXT_PARAMETER_BITS;
44   const unsigned int TEXT_PARAMETER_FLAGS = GRADIENT_INDEX_SHIFT + TEXT_PARAMETER_BITS;
45
46   // Position in flags for attribute index
47   const unsigned int OUTLINE_INDEX = 0u;                                                 // bits 0,1
48   const unsigned int GLOW_INDEX = TEXT_PARAMETER_MASK << GLOW_INDEX_SHIFT;               // bits 2,3
49   const unsigned int DROP_SHADOW_INDEX = TEXT_PARAMETER_MASK << DROP_SHADOW_INDEX_SHIFT; // bits 4,5
50   const unsigned int GRADIENT_INDEX = TEXT_PARAMETER_MASK << GRADIENT_INDEX_SHIFT;       // bits 6,7
51
52   // Flag positions for attributes ( gradient has two as parameters can be set independently )
53   const unsigned int OUTLINE_EXISTS = 1u << TEXT_PARAMETER_FLAGS;                        // bit 8
54   const unsigned int OUTLINE_ENABLED = 1u << ( TEXT_PARAMETER_FLAGS + 1u );              // bit 9
55   const unsigned int GLOW_EXISTS = 1u << ( TEXT_PARAMETER_FLAGS + 2u );                  // bit 10
56   const unsigned int GLOW_ENABLED = 1u << ( TEXT_PARAMETER_FLAGS + 3u );                 // bit 11
57   const unsigned int DROP_SHADOW_EXISTS = 1u << ( TEXT_PARAMETER_FLAGS + 4u );           // bit 12
58   const unsigned int DROP_SHADOW_ENABLED = 1u << ( TEXT_PARAMETER_FLAGS + 5u );          // bit 13
59   const unsigned int GRADIENT_EXISTS = 1u << ( TEXT_PARAMETER_FLAGS + 6u );              // bit 14
60   const unsigned int GRADIENT_ENABLED = 1u << ( TEXT_PARAMETER_FLAGS + 7u );             // bit 15
61   const unsigned int ATTRIBUTE_END = GRADIENT_ENABLED;
62
63 /**
64  * class TextParameters internal class to encapsulate (and allow on demand allocation) of
65  * text effect parameters like, outline, glow and shadow
66  */
67 class TextParameters
68 {
69 public:
70
71   /**
72    * @brief Outline attributes
73    */
74   struct OutlineAttributes
75   {
76     Vector4 mOutlineColor;
77     Vector2 mOutlineThickness;
78   };
79
80   /**
81    * @brief Glow attributes
82    */
83   struct GlowAttributes
84   {
85     Vector4 mGlowColor;
86     float mGlowIntensity;
87   };
88
89   /**
90    * @brief Drop Shadow attributes
91    */
92   struct DropShadowAttributes
93   {
94     Vector4 mDropShadowColor;
95     Vector2 mDropShadowOffset;
96     float   mDropShadowSize;
97   };
98
99   /**
100    * @brief Gradient attributes
101    */
102   struct GradientAttributes
103   {
104     Vector4 mGradientColor;
105     Vector2 mGradientStartPoint;
106     Vector2 mGradientEndPoint;
107   };
108
109   /**
110    * Constructor
111    */
112   TextParameters();
113
114   /**
115    * Destructor
116    */
117   ~TextParameters();
118
119   /// @copydoc Dali::TextActor::SetOutline
120   void SetOutline( bool enable, const Vector4& color, const Vector2& thickness );
121
122   /// @copydoc Dali::TextActor::SetGlow
123   void SetGlow( bool enable, const Vector4& color, float intensity );
124
125   /// @copydoc Dali::TextActor::SetShadow
126   void SetShadow( bool enable, const Vector4& color, const Vector2& offset, float size );
127
128   /**
129    * @brief Set Gradient parameters.
130    * @param[in] color The gradient color (end-point color)
131    * @param[in] start The relative position of the gradient start point.
132    * @param[in] end   The relative position of the gradient end point.
133    */
134   void SetGradient( const Vector4& color, const Vector2& start, const Vector2& end );
135
136   /**
137    * @brief Get the Gradient Color
138    *
139    * @return Gradient Color
140    */
141   const Vector4& GetOutlineColor() const;
142
143   /**
144    * @brief Get Outline Thickness
145    *
146    * @return Outline Thickness
147    */
148   const Vector2& GetOutlineThickness() const;
149
150   /**
151    * @brief Get Glow Color
152    *
153    * @return Glow Color
154    */
155   const Vector4& GetGlowColor() const;
156
157   /**
158    * @brief Get Glow Intensity
159    *
160    * @return Glow Intensity
161    */
162   float GetGlowIntensity() const;
163
164   /**
165    * @brief Get Drop Shadow Color
166    *
167    * @return Drop Shadow Color
168    */
169   const Vector4& GetDropShadowColor() const;
170
171   /**
172    * @brief Get Drop Shadow Offset
173    *
174    * @return Drop Shadow Offset
175    */
176   const Vector2& GetDropShadowOffset() const;
177
178   /**
179    * @brief Get Drop Shadow Size
180    *
181    * @return Drop Shadow Size
182    */
183   float GetDropShadowSize() const;
184
185   /**
186    * @brief Get Gradient Color
187    *
188    * @return Gradient Color
189    */
190   const Vector4& GetGradientColor() const;
191
192   /**
193    * @brief Get Gradient Start Point
194    *
195    * @return Position of Gradient Start Point
196    */
197   const Vector2& GetGradientStartPoint() const;
198
199   /**
200    * @brief Get Gradient End Point
201    *
202    * @return Position of Gradient End Point
203    */
204   const Vector2& GetGradientEndPoint() const;
205
206   /**
207    * @brief Get if Outline is enabled
208    *
209    * @return true if enabled, false if not
210    */
211   bool IsOutlineEnabled() const
212   {
213     return ( ( mFlags & OUTLINE_ENABLED ) != 0 );
214   }
215
216   /**
217    * @brief Get if Glow is enabled
218    *
219    * @return true if enabled, false if not
220    */
221   bool IsGlowEnabled() const
222   {
223     return ( ( mFlags & GLOW_ENABLED ) != 0 );
224   }
225
226   /**
227    * @brief Get if Drop Shadow is enabled
228    *
229    * @return true if enabled, false if not
230    */
231   bool IsDropShadowEnabled() const
232   {
233     return ( ( mFlags & DROP_SHADOW_ENABLED ) != 0 );
234   }
235
236   /**
237    * @brief Get if Gradient is enabled
238    *
239    * @return true if enabled, false if not
240    */
241   bool IsGradientEnabled() const
242   {
243     return ( ( mFlags & GRADIENT_ENABLED ) != 0 );
244   }
245
246 private: // unimplemented copy constructor and assignment operator
247   TextParameters( const TextParameters& copy );
248   TextParameters& operator=(const TextParameters& rhs);
249
250   Vector<char*> mParameters;    // container for any used attributes
251
252 #if ( ATTRIBUTE_END > 0x8000 )
253   unsigned int mFlags;          // flags for used attributes, packed with position in container
254 #else
255   unsigned short mFlags;        // might be rendered irrelevant by alignment / packing
256 #endif
257
258 }; // class TextParameters
259
260 } // namespace Internal
261
262 } // namespace Dali
263
264 #endif // __INTERNAL_TEXT_PARAMETERS_H__