Revert "License conversion from Flora to Apache 2.0"
[platform/core/uifw/dali-core.git] / dali / internal / update / node-attachments / scene-graph-text-attachment.h
1 #ifndef __DALI_INTERNAL_SCENE_GRAPH_TEXT_ATTACHMENT_H__
2 #define __DALI_INTERNAL_SCENE_GRAPH_TEXT_ATTACHMENT_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 INCLUDES
21 #include <dali/internal/common/event-to-update.h>
22 #include <dali/internal/common/owner-pointer.h>
23 #include <dali/internal/update/resources/resource-manager.h>
24 #include <dali/internal/update/node-attachments/scene-graph-renderable-attachment.h>
25
26 namespace Dali
27 {
28
29 namespace Internal
30 {
31
32 class TextParameters;
33
34 namespace SceneGraph
35 {
36
37 class TextRenderer;
38 class Shader;
39 class RenderQueue;
40
41 /**
42  * An attachment for rendering text from a font atlas.
43  */
44 class TextAttachment : public RenderableAttachment
45 {
46 public:
47
48   /**
49    * Construct a new TextAttachment.
50    * @return a new TextAttachment
51    */
52   static TextAttachment* New();
53
54   /**
55    * Virtual destructor
56    */
57   virtual ~TextAttachment();
58
59   /**
60    * @copydoc RenderableAttachment::GetRenderer().
61    */
62   virtual Renderer& GetRenderer();
63
64   /**
65    * @copydoc RenderableAttachment::GetRenderer().
66    */
67   virtual const Renderer& GetRenderer() const;
68
69   /**
70    * Set the text vertex buffer; ownership is passed to the renderer.
71    * This is to avoid duplicate data being held in the text-attachment and the scene-graph-text-attachment.
72    * @param[in] updateBufferIndex The current update buffer index.
73    * @param[in] vertexBuffer vertex buffer
74    */
75   void SetTextVertexBuffer( BufferIndex updateBufferIndex, TextVertexBuffer* vertexBuffer );
76
77   /**
78    * Set the pixel size of the font, this is passed to the renderer
79    * @param updateBufferIndex The current update buffer index.
80    * @param pixelSize The new pixel size
81    */
82   void SetTextFontSize( BufferIndex updateBufferIndex, float pixelSize );
83
84   /**
85    * Set the color associated with the gradient end point.
86    * @param[in] updateBufferIndex The current update buffer index.
87    * @param[in] color The gradient color (end-point color)
88    */
89   void SetGradientColor( BufferIndex updateBufferIndex, const Vector4& color );
90
91   /**
92    * Set the gradient start point.
93    * @param[in] updateBufferIndex The current update buffer index.
94    * @param[in] position The relative position of the gradient start point.
95    */
96   void SetGradientStartPoint( BufferIndex updateBufferIndex, const Vector2& position );
97
98   /**
99    * Set the gradient end point.
100    * @param[in] updateBufferIndex The current update buffer index.
101    * @param[in] position The relative position of the gradient end point.
102    */
103   void SetGradientEndPoint( BufferIndex updateBufferIndex, const Vector2& position );
104
105   /**
106    * Set the text color.
107    * @param[in] updateBufferIndex The current update buffer index.
108    * @param[in] color The text color.
109    */
110   void SetTextColor( BufferIndex updateBufferIndex, const Vector4& color );
111
112   /**
113    * Set text outlining.
114    * @param[in] updateBufferIndex The current update buffer index.
115    * @param[in] enable Set to true to enable text outlining.
116    * @param[in] color Outline color.
117    * @param[in] thickness Thickness of outline.
118    */
119   void SetOutline( BufferIndex updateBufferIndex, bool enable, const Vector4& color, const Vector2& thickness );
120
121   /**
122    * Set text glow.
123    * @param[in] updateBufferIndex The current update buffer index.
124    * @param[in] enable Set to true to enable text outer glow.
125    * @param[in] color Glow color.
126    * @param[in] intensity Determines the amount of glow around text.
127    */
128   void SetGlow( BufferIndex updateBufferIndex, bool enable, const Vector4& color, float intensity );
129
130   /**
131    * Set text shadow.
132    * @param[in] updateBufferIndex The current update buffer index.
133    * @param[in] enable  Set to true to enable text drop shadow.
134    * @param[in] color   Shadow color.
135    * @param[in] offset  Offset in pixels. To avoid cropping of the drop shadow limit the offset to PointSize / 3.5.
136    * @param[in] size    Size of shadow in pixels. 0 means the shadow is the same size as the text.
137    */
138   void SetDropShadow( BufferIndex updateBufferIndex, bool enable, const Vector4& color, const Vector2& offset, const float size );
139
140   /**
141    * Set soft edge smoothing.
142    * @param[in] updateBufferIndex The current update buffer index.
143    * @param[in] smoothEdge Specify the distance field value for the center of the text edge.
144    */
145   void SetSmoothEdge( BufferIndex updateBufferIndex, float smoothEdge );
146
147   /**
148    * @copydoc RenderableAttachment::ShaderChanged()
149    */
150   virtual void ShaderChanged( BufferIndex updateBufferIndex );
151
152   /**
153    * @copydoc RenderableAttachment::SizeChanged()
154    */
155   virtual void SizeChanged( BufferIndex updateBufferIndex );
156
157   /**
158    * @copydoc RenderableAttachment::DoPrepareRender()
159    */
160   virtual void DoPrepareRender( BufferIndex updateBufferIndex );
161
162   /**
163    * @copydoc RenderableAttachment::IsFullyOpaque()
164    */
165   virtual bool IsFullyOpaque( BufferIndex updateBufferIndex )
166   {
167     return false; // false since drawing text requires alpha
168   }
169
170   /**
171    * @copydoc RenderableAttachment::GetScaleForSize()
172    */
173   virtual void DoGetScaleForSize( const Vector3& nodeSize, Vector3& scaling );
174
175 protected:
176
177   /**
178    * Protected constructor. See New()
179    */
180   TextAttachment();
181
182 private:
183
184   /**
185    * @copydoc RenderableAttachment::ConnectToSceneGraph2().
186    */
187   virtual void ConnectToSceneGraph2( BufferIndex updateBufferIndex );
188
189   /**
190    * @copydoc RenderableAttachment::OnDestroy2().
191    */
192   virtual void OnDestroy2();
193
194   /**
195    * @copydoc RenderableAttachment::DoPrepareResources()
196    */
197   virtual bool DoPrepareResources( BufferIndex updateBufferIndex, ResourceManager& resourceManager );
198
199   // Undefined
200   TextAttachment(const TextAttachment&);
201
202   // Undefined
203   TextAttachment& operator=(const TextAttachment& rhs);
204
205 private:
206
207   TextRenderer* mTextRenderer;    ///< Raw-pointers to renderer that is owned by RenderManager
208   Vector2 mGeometrySize;          ///< used for geometry scaling
209   Vector2 mGeometryScaling;       ///< used for geometry scaling
210
211   unsigned int mAtlasId;          ///< atlas Id from last vertex buffer
212
213 };
214
215 inline void SetTextVertexBufferMessage( EventToUpdate& eventToUpdate, const TextAttachment& attachment, TextVertexBuffer& buffer)
216 {
217   typedef MessageDoubleBuffered1< TextAttachment, OwnerPointer< TextVertexBuffer> > LocalType;
218
219   // Reserve some memory inside the message queue
220   unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
221
222   // Construct message in the message queue memory; note that delete should not be called on the return value
223   new (slot) LocalType( &attachment, &TextAttachment::SetTextVertexBuffer, &buffer );
224 }
225
226 inline void SetTextFontSizeMessage( EventToUpdate& eventToUpdate, const TextAttachment& attachment, float pixelSize )
227 {
228   typedef MessageDoubleBuffered1< TextAttachment, float > LocalType;
229
230   // Reserve some memory inside the message queue
231   unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
232
233   // Construct message in the message queue memory; note that delete should not be called on the return value
234   new (slot) LocalType( &attachment, &TextAttachment::SetTextFontSize, pixelSize );
235 }
236
237 inline void SetGradientColorMessage( EventToUpdate& eventToUpdate, const TextAttachment& attachment, const Vector4& color )
238 {
239   typedef MessageDoubleBuffered1< TextAttachment, Vector4 > LocalType;
240
241   // Reserve some memory inside the message queue
242   unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
243
244   // Construct message in the message queue memory; note that delete should not be called on the return value
245   new (slot) LocalType( &attachment, &TextAttachment::SetGradientColor, color );
246 }
247
248 inline void SetGradientStartPointMessage( EventToUpdate& eventToUpdate, const TextAttachment& attachment, const Vector2& position )
249 {
250   typedef MessageDoubleBuffered1< TextAttachment, Vector2 > LocalType;
251
252   // Reserve some memory inside the message queue
253   unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
254
255   // Construct message in the message queue memory; note that delete should not be called on the return value
256   new (slot) LocalType( &attachment, &TextAttachment::SetGradientStartPoint, position );
257 }
258
259 inline void SetGradientEndPointMessage( EventToUpdate& eventToUpdate, const TextAttachment& attachment, const Vector2& position )
260 {
261   typedef MessageDoubleBuffered1< TextAttachment, Vector2 > LocalType;
262
263   // Reserve some memory inside the message queue
264   unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
265
266   // Construct message in the message queue memory; note that delete should not be called on the return value
267   new (slot) LocalType( &attachment, &TextAttachment::SetGradientEndPoint, position );
268 }
269
270 inline void SetTextColorMessage( EventToUpdate& eventToUpdate, const TextAttachment& attachment, const Vector4& color )
271 {
272   typedef MessageDoubleBuffered1< TextAttachment, Vector4 > LocalType;
273
274   // Reserve some memory inside the message queue
275   unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
276
277   // Construct message in the message queue memory; note that delete should not be called on the return value
278   new (slot) LocalType( &attachment, &TextAttachment::SetTextColor, color );
279 }
280
281 inline void SetOutlineMessage( EventToUpdate& eventToUpdate, const TextAttachment& attachment, bool enable, const Vector4& color, const Vector2& params )
282 {
283   typedef MessageDoubleBuffered3< TextAttachment, bool, Vector4, Vector2 > LocalType;
284
285   // Reserve some memory inside the message queue
286   unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
287
288   // Construct message in the message queue memory; note that delete should not be called on the return value
289   new (slot) LocalType( &attachment, &TextAttachment::SetOutline, enable, color, params );
290 }
291
292 inline void SetGlowMessage( EventToUpdate& eventToUpdate, const TextAttachment& attachment, bool enable, const Vector4& color, float params )
293 {
294   typedef MessageDoubleBuffered3< TextAttachment, bool, Vector4, float > LocalType;
295
296   // Reserve some memory inside the message queue
297   unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
298
299   // Construct message in the message queue memory; note that delete should not be called on the return value
300   new (slot) LocalType( &attachment, &TextAttachment::SetGlow, enable, color, params );
301 }
302
303 inline void SetDropShadowMessage( EventToUpdate& eventToUpdate, const TextAttachment& attachment, bool enable, const Vector4& color, const Vector2& offset, const float size )
304 {
305   typedef MessageDoubleBuffered4< TextAttachment, bool, Vector4, Vector2, float > LocalType;
306
307   // Reserve some memory inside the message queue
308   unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
309
310   // Construct message in the message queue memory; note that delete should not be called on the return value
311   new (slot) LocalType( &attachment, &TextAttachment::SetDropShadow, enable, color, offset, size );
312 }
313
314 inline void SetSmoothEdgeMessage( EventToUpdate& eventToUpdate, const TextAttachment& attachment, float params )
315 {
316   typedef MessageDoubleBuffered1< TextAttachment, float > LocalType;
317
318   // Reserve some memory inside the message queue
319   unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
320
321   // Construct message in the message queue memory; note that delete should not be called on the return value
322   new (slot) LocalType( &attachment, &TextAttachment::SetSmoothEdge, params );
323 }
324
325 } // namespace SceneGraph
326
327 } // namespace Internal
328
329 } // namespace Dali
330
331 #endif // __DALI_INTERNAL_SCENE_GRAPH_TEXT_ATTACHMENT_H__