1 #ifndef __DALI_INTERNAL_TEXT_ATTACHMENT_H__
2 #define __DALI_INTERNAL_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/public-api/math/radian.h>
23 #include <dali/public-api/math/vector2.h>
24 #include <dali/public-api/math/vector4.h>
25 #include <dali/public-api/text/text-style.h>
26 #include <dali/internal/event/actor-attachments/renderable-attachment-impl.h>
27 #include <dali/internal/event/actor-attachments/actor-attachment-declarations.h>
28 #include <dali/internal/event/text/font-declarations.h>
29 #include <dali/internal/event/text/text-request-helper.h>
30 #include <dali/internal/event/text/resource/glyph-texture-observer.h>
31 #include <dali/internal/common/owner-pointer.h>
32 #include <dali/integration-api/text-array.h>
49 * An attachment for rendering text from a font atlas.
51 class TextAttachment : public RenderableAttachment, public GlyphTextureObserver
56 * Create a new TextAttachment.
57 * @param[in] stage The stage to use for messaging
58 * @param[in] parentNode The node to attach a scene-object to.
59 * @param [in] text The text which will be displayed.
60 * @param [in] font The font which will be used for the text.
61 * @return A smart-pointer to the newly allocated TextAttachment.
63 static TextAttachmentPtr New( Stage& stage, const SceneGraph::Node& parentNode, const Integration::TextArray& text, FontPointer font );
66 * Set the text label displayed by the attachment
67 * @param [in] text The new text label
69 void SetText(const Integration::TextArray& text);
72 * Get the text label displayed by the attachment
73 * @return The text label
75 const Integration::TextArray& GetText() const
77 // This is not animatable; the cached value is up-to-date.
82 * Get the natural text size
83 * @return the natural size of the text.
85 const Vector2& GetNaturalTextSize() const
87 // This is not animatable; the cached value is up-to-date.
92 * Set the font used to display the text label displayed by the attachment
93 * @param [in] font The new font
95 void SetFont(Font& font);
98 * Get the font used to display the text label displayed by the attachment
99 * @return The font currently in use
108 * @param[in] color The text color
110 void SetTextColor(const Vector4& color);
114 * @return The text color
116 Vector4 GetTextColor() const;
119 * Resets to default the text color.
121 void ResetTextColor();
124 * @copydoc Dali::TextActor::SetWeight()
126 void SetWeight( TextStyle::Weight weight );
129 * @copydoc Dali::TextActor::GetWeight()
131 TextStyle::Weight GetWeight() const;
134 * Resets to default the text weight.
139 * @copydoc Dali::TextActor::SetSmoothEdge(const float)
141 void SetSmoothEdge( float smoothEdge );
144 * Retrieve the smooth edge value.
145 * @return the smooth edge value.
147 float GetSmoothEdge() const;
150 * Resets to default the smooth edge.
152 void ResetSmoothEdge();
155 * Enable italics on the text actor, the text will be sheared by the given angle.
156 * @param[in] angle Italics angle in radians.
158 void SetItalics( Radian angle );
161 * @copydoc Dali::TextActor::GetItalics()
163 bool GetItalics() const;
166 * @copydoc Dali::TextActor::GetItalicsAngle()
168 Radian GetItalicsAngle() const;
171 * Resets to default the italics.
176 * @copydoc Dali::TextActor::SetUnderline()
178 void SetUnderline( bool enable, float thickness, float position );
181 * @copydoc Dali::TextActor::GetUnderline()
183 bool GetUnderline() const;
186 * @copydoc Internal::TextActor::GetUnderlineThickness()
188 float GetUnderlineThickness() const;
191 * @copydoc Internal::TextActor::GetUnderlinePosition()
193 float GetUnderlinePosition() const;
196 * Resets to default the text underline.
198 void ResetUnderline();
201 * @copydoc Dali::TextActor::SetOutline(const bool,const Vector4&,const Vector2&)
203 void SetOutline( bool enable, const Vector4& color, const Vector2& thickness );
207 * @return \e true if outline is enabled, otherwise \e false.
209 bool GetOutline() const;
212 * Retrieve outline parameters.
213 * @param[out] color The outline color.
214 * @param[out] thickness The outline parameters.
216 void GetOutlineParams( Vector4& color, Vector2& thickness ) const;
219 * Resets to default the text outline.
224 * @copydoc Dali::TextActor::SetGlow(const bool,const Vector4&,const float)
226 void SetGlow( bool enable, const Vector4& color, float intensity );
230 * @return \e true if glow is enabled, otherwise \e false.
232 bool GetGlow() const;
235 * Retrieve glow parameters.
236 * @param[out] color The glow color.
237 * @param[out] intensity The glow intensity.
239 void GetGlowParams( Vector4& color, float& intensity ) const;
242 * Resets to default the text glow.
247 * @copydoc Dali::TextActor::SetShadow(const bool,const Vector4&,const Vector2&,const float)
249 void SetShadow( bool enable, const Vector4& color, const Vector2& offset, float size );
252 * Retrieve the shadow state.
253 * @return \e true if shadow is enabled, otherwise \e false.
255 bool GetShadow() const;
258 * Retrieve shadow parameters.
259 * @param[out] color The shadow color.
260 * @param[out] offset The shadow offset.
261 * @param[out] size The shadow size.
263 void GetShadowParams( Vector4& color, Vector2& offset, float& size ) const;
266 * Resets to default the text shadow.
271 * @see Dali::TextActor::SetGradientColor()
272 * @see Dali::TextActor::SetGradientStartPoint()
273 * @see Dali::TextActor::SetGradientEndPoint()
275 void SetGradient( const Vector4& color, const Vector2& startPoint, const Vector2& endPoint );
278 * @copydoc Dali::TextActor::GetGradientColor()
280 const Vector4& GetGradientColor() const;
283 * @copydoc Dali::TextActor::GetGradientStartPoint()
285 const Vector2& GetGradientStartPoint() const;
288 * @copydoc Dali::TextActor::GetGradientEndPoint()
290 const Vector2& GetGradientEndPoint() const;
293 * Resets to default the text gradient.
295 void ResetGradient();
298 * Retrieves the text style.
300 * @param[out] style The text style.
302 void GetTextStyle( TextStyle& style ) const;
305 * Measure the natural size of a text string, as displayed in this font.
306 * @return The natural size of the text.
308 Vector3 MeasureText() const;
311 * Inform the text attachment the text / font it is using has changed.
312 * The TextChanged() and TextNotRequired() functions are used to avoid duplicate
313 * requests for text. For example if the text is changed, and the font is changed
314 * then we want to avoid requesting the new text with the old font, then the new
315 * text with the new font.
320 * @return true if all text has been loaded and is ready to display
325 * Calculates the weighted smoothing value.
327 void CalculateWeightedSmoothing( TextStyle::Weight weight, float smoothEdge );
329 public: // glyph texture observer
332 * @copydoc Dali::Internal::GlyphTextureObserver::TextureResized()
334 virtual void TextureResized( const TextureIdList& oldTextureIds, unsigned int newTextureId );
337 * @copydoc Dali::Internal::GlyphTextureObserver::TextureSplit()
339 virtual void TextureSplit( FontId fontId, const TextureIdList& oldTextureIds, unsigned int newTextureId );
344 * Check if the text has been modified
345 * @return true if the text or it's formating has been modified
347 bool IsTextModified();
350 * First stage construction of a TextAttachment.
351 * @param[in] stage Used to send messages to scene-graph.
353 TextAttachment( Stage& stage );
356 * @copydoc Dali::Internal::RenderableAttachment::OnStageConnection2()
358 virtual void OnStageConnection2();
361 * @copydoc Dali::Internal::RenderableAttachment::OnStageDisconnection2()
363 virtual void OnStageDisconnection2();
366 * @copydoc Dali::Internal::RenderableAttachment::GetSceneObject()
368 virtual const SceneGraph::RenderableAttachment& GetSceneObject() const;
371 * Update any text & font changes to the on stage scene graph text attachment
373 void SetTextChanges();
378 * A reference counted object may only be deleted by calling Unreference()
380 virtual ~TextAttachment();
384 const SceneGraph::TextAttachment* mSceneObject; ///< Not owned
386 TextRequestHelper mTextRequestHelper; ///< Text request helper
387 FontPointer mFont; ///< The font resource
388 Vector4* mTextColor; ///< on demand storage for text color
389 TextStyle mStyle; ///< on demand storage for text effects parameters ( do not store font parameters and color )
390 ///< Font parameters are stored in the FontPointer member. Inside the TextStyle, font parameters and color are allocated in the same struct,
391 ///< so store the text color in the style will allocate space for the font parameters as well, wasting space.
392 // Cached values for public getters
393 Integration::TextArray mText;
395 bool mTextChanged:1; ///< whether the text has changed
396 bool mFontChanged:1; ///< whether the font has changed
397 bool mUnderlineChanged:1; ///< whether the underline has changed
398 bool mItalicsChanged:1; ///< whether the italics has changed
399 bool mTextureIdSet:1; ///< flag to signify if the texture id has been set on the scene-graph text-attachment
400 unsigned int mTextureId; ///< the texture id of the glyph atlas being used
401 Vector2 mTextSize; ///< text natural size
403 OwnerPointer< TextVertexBuffer > mVertexBuffer; ///< vertex data to display the text
406 } // namespace Internal
410 #endif // __DALI_INTERNAL_TEXT_ATTACHMENT_H__