1 #ifndef __DALI_INTERNAL_SCENE_GRAPH_TEXT_ATTACHMENT_H__
2 #define __DALI_INTERNAL_SCENE_GRAPH_TEXT_ATTACHMENT_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/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>
42 * An attachment for rendering text from a font atlas.
44 class TextAttachment : public RenderableAttachment
49 * Construct a new TextAttachment.
50 * @return a new TextAttachment
52 static TextAttachment* New();
57 virtual ~TextAttachment();
60 * @copydoc RenderableAttachment::GetRenderer().
62 virtual Renderer& GetRenderer();
65 * @copydoc RenderableAttachment::GetRenderer().
67 virtual const Renderer& GetRenderer() const;
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
75 void SetTextVertexBuffer( BufferIndex updateBufferIndex, TextVertexBuffer* vertexBuffer );
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
82 void SetTextFontSize( BufferIndex updateBufferIndex, float pixelSize );
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)
89 void SetGradientColor( BufferIndex updateBufferIndex, const Vector4& color );
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.
96 void SetGradientStartPoint( BufferIndex updateBufferIndex, const Vector2& position );
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.
103 void SetGradientEndPoint( BufferIndex updateBufferIndex, const Vector2& position );
106 * Set the text color.
107 * @param[in] updateBufferIndex The current update buffer index.
108 * @param[in] color The text color.
110 void SetTextColor( BufferIndex updateBufferIndex, const Vector4& color );
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.
119 void SetOutline( BufferIndex updateBufferIndex, bool enable, const Vector4& color, const Vector2& thickness );
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.
128 void SetGlow( BufferIndex updateBufferIndex, bool enable, const Vector4& color, float intensity );
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.
138 void SetDropShadow( BufferIndex updateBufferIndex, bool enable, const Vector4& color, const Vector2& offset, const float size );
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.
145 void SetSmoothEdge( BufferIndex updateBufferIndex, float smoothEdge );
148 * @copydoc RenderableAttachment::ShaderChanged()
150 virtual void ShaderChanged( BufferIndex updateBufferIndex );
153 * @copydoc RenderableAttachment::SizeChanged()
155 virtual void SizeChanged( BufferIndex updateBufferIndex );
158 * @copydoc RenderableAttachment::DoPrepareRender()
160 virtual void DoPrepareRender( BufferIndex updateBufferIndex );
163 * @copydoc RenderableAttachment::IsFullyOpaque()
165 virtual bool IsFullyOpaque( BufferIndex updateBufferIndex )
167 return false; // false since drawing text requires alpha
171 * @copydoc RenderableAttachment::GetScaleForSize()
173 virtual void DoGetScaleForSize( const Vector3& nodeSize, Vector3& scaling );
178 * Protected constructor. See New()
185 * @copydoc RenderableAttachment::ConnectToSceneGraph2().
187 virtual void ConnectToSceneGraph2( BufferIndex updateBufferIndex );
190 * @copydoc RenderableAttachment::OnDestroy2().
192 virtual void OnDestroy2();
195 * @copydoc RenderableAttachment::DoPrepareResources()
197 virtual bool DoPrepareResources( BufferIndex updateBufferIndex, ResourceManager& resourceManager );
200 TextAttachment(const TextAttachment&);
203 TextAttachment& operator=(const TextAttachment& rhs);
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
211 unsigned int mAtlasId; ///< atlas Id from last vertex buffer
215 inline void SetTextVertexBufferMessage( EventToUpdate& eventToUpdate, const TextAttachment& attachment, TextVertexBuffer& buffer)
217 typedef MessageDoubleBuffered1< TextAttachment, OwnerPointer< TextVertexBuffer> > LocalType;
219 // Reserve some memory inside the message queue
220 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
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 );
226 inline void SetTextFontSizeMessage( EventToUpdate& eventToUpdate, const TextAttachment& attachment, float pixelSize )
228 typedef MessageDoubleBuffered1< TextAttachment, float > LocalType;
230 // Reserve some memory inside the message queue
231 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
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 );
237 inline void SetGradientColorMessage( EventToUpdate& eventToUpdate, const TextAttachment& attachment, const Vector4& color )
239 typedef MessageDoubleBuffered1< TextAttachment, Vector4 > LocalType;
241 // Reserve some memory inside the message queue
242 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
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 );
248 inline void SetGradientStartPointMessage( EventToUpdate& eventToUpdate, const TextAttachment& attachment, const Vector2& position )
250 typedef MessageDoubleBuffered1< TextAttachment, Vector2 > LocalType;
252 // Reserve some memory inside the message queue
253 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
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 );
259 inline void SetGradientEndPointMessage( EventToUpdate& eventToUpdate, const TextAttachment& attachment, const Vector2& position )
261 typedef MessageDoubleBuffered1< TextAttachment, Vector2 > LocalType;
263 // Reserve some memory inside the message queue
264 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
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 );
270 inline void SetTextColorMessage( EventToUpdate& eventToUpdate, const TextAttachment& attachment, const Vector4& color )
272 typedef MessageDoubleBuffered1< TextAttachment, Vector4 > LocalType;
274 // Reserve some memory inside the message queue
275 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
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 );
281 inline void SetOutlineMessage( EventToUpdate& eventToUpdate, const TextAttachment& attachment, bool enable, const Vector4& color, const Vector2& params )
283 typedef MessageDoubleBuffered3< TextAttachment, bool, Vector4, Vector2 > LocalType;
285 // Reserve some memory inside the message queue
286 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
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 );
292 inline void SetGlowMessage( EventToUpdate& eventToUpdate, const TextAttachment& attachment, bool enable, const Vector4& color, float params )
294 typedef MessageDoubleBuffered3< TextAttachment, bool, Vector4, float > LocalType;
296 // Reserve some memory inside the message queue
297 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
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 );
303 inline void SetDropShadowMessage( EventToUpdate& eventToUpdate, const TextAttachment& attachment, bool enable, const Vector4& color, const Vector2& offset, const float size )
305 typedef MessageDoubleBuffered4< TextAttachment, bool, Vector4, Vector2, float > LocalType;
307 // Reserve some memory inside the message queue
308 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
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 );
314 inline void SetSmoothEdgeMessage( EventToUpdate& eventToUpdate, const TextAttachment& attachment, float params )
316 typedef MessageDoubleBuffered1< TextAttachment, float > LocalType;
318 // Reserve some memory inside the message queue
319 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
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 );
325 } // namespace SceneGraph
327 } // namespace Internal
331 #endif // __DALI_INTERNAL_SCENE_GRAPH_TEXT_ATTACHMENT_H__