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 color associated with the gradient end point.
79 * @param[in] updateBufferIndex The current update buffer index.
80 * @param[in] color The gradient color (end-point color)
82 void SetGradientColor( BufferIndex updateBufferIndex, const Vector4& color );
85 * Set the gradient start point.
86 * @param[in] updateBufferIndex The current update buffer index.
87 * @param[in] position The relative position of the gradient start point.
89 void SetGradientStartPoint( BufferIndex updateBufferIndex, const Vector2& position );
92 * Set the gradient end point.
93 * @param[in] updateBufferIndex The current update buffer index.
94 * @param[in] position The relative position of the gradient end point.
96 void SetGradientEndPoint( BufferIndex updateBufferIndex, const Vector2& position );
100 * @param[in] updateBufferIndex The current update buffer index.
101 * @param[in] color The text color.
103 void SetTextColor( BufferIndex updateBufferIndex, const Vector4& color );
106 * Set text outlining.
107 * @param[in] updateBufferIndex The current update buffer index.
108 * @param[in] enable Set to true to enable text outlining.
109 * @param[in] color Outline color.
110 * @param[in] thickness Thickness of outline.
112 void SetOutline( BufferIndex updateBufferIndex, bool enable, const Vector4& color, const Vector2& thickness );
116 * @param[in] updateBufferIndex The current update buffer index.
117 * @param[in] enable Set to true to enable text outer glow.
118 * @param[in] color Glow color.
119 * @param[in] intensity Determines the amount of glow around text.
121 void SetGlow( BufferIndex updateBufferIndex, bool enable, const Vector4& color, float intensity );
125 * @param[in] updateBufferIndex The current update buffer index.
126 * @param[in] enable Set to true to enable text drop shadow.
127 * @param[in] color Shadow color.
128 * @param[in] offset Offset in pixels. To avoid cropping of the drop shadow limit the offset to PointSize / 3.5.
129 * @param[in] size Size of shadow in pixels. 0 means the shadow is the same size as the text.
131 void SetDropShadow( BufferIndex updateBufferIndex, bool enable, const Vector4& color, const Vector2& offset, const float size );
134 * Set soft edge smoothing.
135 * @param[in] updateBufferIndex The current update buffer index.
136 * @param[in] smoothEdge Specify the distance field value for the center of the text edge.
138 void SetSmoothEdge( BufferIndex updateBufferIndex, float smoothEdge );
141 * @copydoc RenderableAttachment::ShaderChanged()
143 virtual void ShaderChanged( BufferIndex updateBufferIndex );
146 * @copydoc RenderableAttachment::SizeChanged()
148 virtual void SizeChanged( BufferIndex updateBufferIndex );
151 * @copydoc RenderableAttachment::DoPrepareRender()
153 virtual void DoPrepareRender( BufferIndex updateBufferIndex );
156 * @copydoc RenderableAttachment::IsFullyOpaque()
158 virtual bool IsFullyOpaque( BufferIndex updateBufferIndex )
160 return false; // false since drawing text requires alpha
164 * @copydoc RenderableAttachment::GetScaleForSize()
166 virtual void DoGetScaleForSize( const Vector3& nodeSize, Vector3& scaling );
171 * Protected constructor. See New()
178 * @copydoc RenderableAttachment::ConnectToSceneGraph2().
180 virtual void ConnectToSceneGraph2( BufferIndex updateBufferIndex );
183 * @copydoc RenderableAttachment::OnDestroy2().
185 virtual void OnDestroy2();
188 * @copydoc RenderableAttachment::DoPrepareResources()
190 virtual bool DoPrepareResources( BufferIndex updateBufferIndex, ResourceManager& resourceManager );
193 TextAttachment(const TextAttachment&);
196 TextAttachment& operator=(const TextAttachment& rhs);
200 TextRenderer* mTextRenderer; ///< Raw-pointers to renderer that is owned by RenderManager
201 Vector2 mGeometrySize; ///< used for geometry scaling
202 Vector2 mGeometryScaling; ///< used for geometry scaling
204 unsigned int mAtlasId; ///< atlas Id from last vertex buffer
208 inline void SetTextVertexBufferMessage( EventToUpdate& eventToUpdate, const TextAttachment& attachment, TextVertexBuffer& buffer)
210 typedef MessageDoubleBuffered1< TextAttachment, OwnerPointer< TextVertexBuffer> > LocalType;
212 // Reserve some memory inside the message queue
213 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
215 // Construct message in the message queue memory; note that delete should not be called on the return value
216 new (slot) LocalType( &attachment, &TextAttachment::SetTextVertexBuffer, &buffer );
219 inline void SetGradientColorMessage( EventToUpdate& eventToUpdate, const TextAttachment& attachment, const Vector4& color )
221 typedef MessageDoubleBuffered1< TextAttachment, Vector4 > LocalType;
223 // Reserve some memory inside the message queue
224 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
226 // Construct message in the message queue memory; note that delete should not be called on the return value
227 new (slot) LocalType( &attachment, &TextAttachment::SetGradientColor, color );
230 inline void SetGradientStartPointMessage( EventToUpdate& eventToUpdate, const TextAttachment& attachment, const Vector2& position )
232 typedef MessageDoubleBuffered1< TextAttachment, Vector2 > LocalType;
234 // Reserve some memory inside the message queue
235 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
237 // Construct message in the message queue memory; note that delete should not be called on the return value
238 new (slot) LocalType( &attachment, &TextAttachment::SetGradientStartPoint, position );
241 inline void SetGradientEndPointMessage( EventToUpdate& eventToUpdate, const TextAttachment& attachment, const Vector2& position )
243 typedef MessageDoubleBuffered1< TextAttachment, Vector2 > LocalType;
245 // Reserve some memory inside the message queue
246 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
248 // Construct message in the message queue memory; note that delete should not be called on the return value
249 new (slot) LocalType( &attachment, &TextAttachment::SetGradientEndPoint, position );
252 inline void SetTextColorMessage( EventToUpdate& eventToUpdate, const TextAttachment& attachment, const Vector4& color )
254 typedef MessageDoubleBuffered1< TextAttachment, Vector4 > LocalType;
256 // Reserve some memory inside the message queue
257 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
259 // Construct message in the message queue memory; note that delete should not be called on the return value
260 new (slot) LocalType( &attachment, &TextAttachment::SetTextColor, color );
263 inline void SetOutlineMessage( EventToUpdate& eventToUpdate, const TextAttachment& attachment, bool enable, const Vector4& color, const Vector2& params )
265 typedef MessageDoubleBuffered3< TextAttachment, bool, Vector4, Vector2 > LocalType;
267 // Reserve some memory inside the message queue
268 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
270 // Construct message in the message queue memory; note that delete should not be called on the return value
271 new (slot) LocalType( &attachment, &TextAttachment::SetOutline, enable, color, params );
274 inline void SetGlowMessage( EventToUpdate& eventToUpdate, const TextAttachment& attachment, bool enable, const Vector4& color, float params )
276 typedef MessageDoubleBuffered3< TextAttachment, bool, Vector4, float > LocalType;
278 // Reserve some memory inside the message queue
279 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
281 // Construct message in the message queue memory; note that delete should not be called on the return value
282 new (slot) LocalType( &attachment, &TextAttachment::SetGlow, enable, color, params );
285 inline void SetDropShadowMessage( EventToUpdate& eventToUpdate, const TextAttachment& attachment, bool enable, const Vector4& color, const Vector2& offset, const float size )
287 typedef MessageDoubleBuffered4< TextAttachment, bool, Vector4, Vector2, float > LocalType;
289 // Reserve some memory inside the message queue
290 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
292 // Construct message in the message queue memory; note that delete should not be called on the return value
293 new (slot) LocalType( &attachment, &TextAttachment::SetDropShadow, enable, color, offset, size );
296 inline void SetSmoothEdgeMessage( EventToUpdate& eventToUpdate, const TextAttachment& attachment, float params )
298 typedef MessageDoubleBuffered1< TextAttachment, float > LocalType;
300 // Reserve some memory inside the message queue
301 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
303 // Construct message in the message queue memory; note that delete should not be called on the return value
304 new (slot) LocalType( &attachment, &TextAttachment::SetSmoothEdge, params );
307 } // namespace SceneGraph
309 } // namespace Internal
313 #endif // __DALI_INTERNAL_SCENE_GRAPH_TEXT_ATTACHMENT_H__