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 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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <dali/internal/common/owner-pointer.h>
23 #include <dali/internal/event/common/event-thread-services.h>
24 #include <dali/internal/update/resources/resource-manager.h>
25 #include <dali/internal/update/node-attachments/scene-graph-renderable-attachment.h>
43 * An attachment for rendering text from a font atlas.
45 class TextAttachment : public RenderableAttachment
50 * Construct a new TextAttachment.
51 * @return a new TextAttachment
53 static TextAttachment* New();
58 virtual ~TextAttachment();
61 * @copydoc RenderableAttachment::GetRenderer().
63 virtual Renderer& GetRenderer();
66 * @copydoc RenderableAttachment::GetRenderer().
68 virtual const Renderer& GetRenderer() const;
71 * Set the text vertex buffer; ownership is passed to the renderer.
72 * This is to avoid duplicate data being held in the text-attachment and the scene-graph-text-attachment.
73 * @param[in] updateBufferIndex The current update buffer index.
74 * @param[in] vertexBuffer vertex buffer
76 void SetTextVertexBuffer( BufferIndex updateBufferIndex, TextVertexBuffer* vertexBuffer );
79 * Set the pixel size of the font, this is passed to the renderer
80 * @param updateBufferIndex The current update buffer index.
81 * @param pixelSize The new pixel size
83 void SetTextFontSize( BufferIndex updateBufferIndex, float pixelSize );
86 * Sets the gradient start point, the gradient end point and the color associated with the gradient end point.
87 * @param[in] updateBufferIndex The current update buffer index.
88 * @param[in] color The gradient color (end-point color)
89 * @param[in] startPoint The relative position of the gradient start point.
90 * @param[in] endPoint The relative position of the gradient end point.
92 void SetGradient( BufferIndex updateBufferIndex, const Vector4& color, const Vector2& startPoint, const Vector2& endPoint );
96 * @param[in] updateBufferIndex The current update buffer index.
97 * @param[in] color The text color.
99 void SetTextColor( BufferIndex updateBufferIndex, const Vector4& color );
102 * Set text outlining.
103 * @param[in] updateBufferIndex The current update buffer index.
104 * @param[in] enable Set to true to enable text outlining.
105 * @param[in] color Outline color.
106 * @param[in] thickness Thickness of outline.
108 void SetOutline( BufferIndex updateBufferIndex, bool enable, const Vector4& color, const Vector2& thickness );
112 * @param[in] updateBufferIndex The current update buffer index.
113 * @param[in] enable Set to true to enable text outer glow.
114 * @param[in] color Glow color.
115 * @param[in] intensity Determines the amount of glow around text.
117 void SetGlow( BufferIndex updateBufferIndex, bool enable, const Vector4& color, float intensity );
121 * @param[in] updateBufferIndex The current update buffer index.
122 * @param[in] enable Set to true to enable text drop shadow.
123 * @param[in] color Shadow color.
124 * @param[in] offset Offset in pixels. To avoid cropping of the drop shadow limit the offset to PointSize / 3.5.
125 * @param[in] size Size of shadow in pixels. 0 means the shadow is the same size as the text.
127 void SetDropShadow( BufferIndex updateBufferIndex, bool enable, const Vector4& color, const Vector2& offset, const float size );
130 * Set soft edge smoothing.
131 * @param[in] updateBufferIndex The current update buffer index.
132 * @param[in] smoothEdge Specify the distance field value for the center of the text edge.
134 void SetSmoothEdge( BufferIndex updateBufferIndex, float smoothEdge );
137 * @copydoc RenderableAttachment::ShaderChanged()
139 virtual void ShaderChanged( BufferIndex updateBufferIndex );
142 * @copydoc RenderableAttachment::SizeChanged()
144 virtual void SizeChanged( BufferIndex updateBufferIndex );
147 * @copydoc RenderableAttachment::DoPrepareRender()
149 virtual void DoPrepareRender( BufferIndex updateBufferIndex );
152 * @copydoc RenderableAttachment::IsFullyOpaque()
154 virtual bool IsFullyOpaque( BufferIndex updateBufferIndex )
156 return false; // false since drawing text requires alpha
160 * @copydoc RenderableAttachment::GetScaleForSize()
162 virtual void DoGetScaleForSize( const Vector3& nodeSize, Vector3& scaling );
167 * Protected constructor. See New()
174 * @copydoc RenderableAttachment::ConnectToSceneGraph2().
176 virtual void ConnectToSceneGraph2( BufferIndex updateBufferIndex );
179 * @copydoc RenderableAttachment::OnDestroy2().
181 virtual void OnDestroy2();
184 * @copydoc RenderableAttachment::DoPrepareResources()
186 virtual bool DoPrepareResources( BufferIndex updateBufferIndex, ResourceManager& resourceManager );
189 TextAttachment(const TextAttachment&);
192 TextAttachment& operator=(const TextAttachment& rhs);
196 TextRenderer* mTextRenderer; ///< Raw-pointers to renderer that is owned by RenderManager
197 Vector2 mGeometrySize; ///< used for geometry scaling
198 Vector2 mGeometryScaling; ///< used for geometry scaling
200 unsigned int mAtlasId; ///< atlas Id from last vertex buffer
204 inline void SetTextVertexBufferMessage( EventThreadServices& eventThreadServices, const TextAttachment& attachment, TextVertexBuffer& buffer)
206 typedef MessageDoubleBuffered1< TextAttachment, OwnerPointer< TextVertexBuffer> > LocalType;
208 // Reserve some memory inside the message queue
209 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
211 // Construct message in the message queue memory; note that delete should not be called on the return value
212 new (slot) LocalType( &attachment, &TextAttachment::SetTextVertexBuffer, &buffer );
215 inline void SetTextFontSizeMessage( EventThreadServices& eventThreadServices, const TextAttachment& attachment, float pixelSize )
217 typedef MessageDoubleBuffered1< TextAttachment, float > LocalType;
219 // Reserve some memory inside the message queue
220 unsigned int* slot = eventThreadServices.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::SetTextFontSize, pixelSize );
226 inline void SetGradientMessage( EventThreadServices& eventThreadServices, const TextAttachment& attachment, const Vector4& color, const Vector2& startPoint, const Vector2& endPoint )
228 typedef MessageDoubleBuffered3< TextAttachment, Vector4, Vector2, Vector2 > LocalType;
230 // Reserve some memory inside the message queue
231 unsigned int* slot = eventThreadServices.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::SetGradient, color, startPoint, endPoint );
237 inline void SetTextColorMessage( EventThreadServices& eventThreadServices, const TextAttachment& attachment, const Vector4& color )
239 typedef MessageDoubleBuffered1< TextAttachment, Vector4 > LocalType;
241 // Reserve some memory inside the message queue
242 unsigned int* slot = eventThreadServices.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::SetTextColor, color );
248 inline void SetOutlineMessage( EventThreadServices& eventThreadServices, const TextAttachment& attachment, bool enable, const Vector4& color, const Vector2& params )
250 typedef MessageDoubleBuffered3< TextAttachment, bool, Vector4, Vector2 > LocalType;
252 // Reserve some memory inside the message queue
253 unsigned int* slot = eventThreadServices.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::SetOutline, enable, color, params );
259 inline void SetGlowMessage( EventThreadServices& eventThreadServices, const TextAttachment& attachment, bool enable, const Vector4& color, float params )
261 typedef MessageDoubleBuffered3< TextAttachment, bool, Vector4, float > LocalType;
263 // Reserve some memory inside the message queue
264 unsigned int* slot = eventThreadServices.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::SetGlow, enable, color, params );
270 inline void SetDropShadowMessage( EventThreadServices& eventThreadServices, const TextAttachment& attachment, bool enable, const Vector4& color, const Vector2& offset, const float size )
272 typedef MessageDoubleBuffered4< TextAttachment, bool, Vector4, Vector2, float > LocalType;
274 // Reserve some memory inside the message queue
275 unsigned int* slot = eventThreadServices.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::SetDropShadow, enable, color, offset, size );
281 inline void SetSmoothEdgeMessage( EventThreadServices& eventThreadServices, const TextAttachment& attachment, float params )
283 typedef MessageDoubleBuffered1< TextAttachment, float > LocalType;
285 // Reserve some memory inside the message queue
286 unsigned int* slot = eventThreadServices.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::SetSmoothEdge, params );
292 } // namespace SceneGraph
294 } // namespace Internal
298 #endif // __DALI_INTERNAL_SCENE_GRAPH_TEXT_ATTACHMENT_H__