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 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/public-api/math/radian.h>
22 #include <dali/public-api/math/vector2.h>
23 #include <dali/public-api/math/vector4.h>
24 #include <dali/public-api/text/text-style.h>
25 #include <dali/internal/event/actor-attachments/renderable-attachment-impl.h>
26 #include <dali/internal/event/actor-attachments/actor-attachment-declarations.h>
27 #include <dali/internal/event/text/font-declarations.h>
28 #include <dali/internal/common/text-array.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>
48 * An attachment for rendering text from a font atlas.
50 class TextAttachment : public RenderableAttachment, public GlyphTextureObserver
55 * Create a new TextAttachment.
56 * @param[in] parentNode The node to attach a scene-object to.
57 * @param [in] text The text which will be displayed.
58 * @param [in] font The font which will be used for the text.
59 * @param [in] isLeftToRight Text is displayed from left to right if true, otherwise from right to left.
60 * @return A smart-pointer to the newly allocated TextAttachment.
62 static TextAttachmentPtr New( const SceneGraph::Node& parentNode, const TextArray& text, FontPointer font, bool isLeftToRight );
65 * Set the text label displayed by the attachment
66 * @param [in] text The new text label
68 void SetText(const TextArray& text);
71 * Get the text label displayed by the attachment
72 * @return The text label
74 const TextArray& GetText() const
76 // This is not animatable; the cached value is up-to-date.
81 * Get the natural text size
82 * @return the natural size of the text.
84 const Vector2& GetNaturalTextSize() const
86 // This is not animatable; the cached value is up-to-date.
91 * Set the font used to display the text label displayed by the attachment
92 * @param [in] font The new font
94 void SetFont(Font& font);
97 * Get the font used to display the text label displayed by the attachment
98 * @return The font currently in use
106 * @copydoc Dali::TextActor::SetGradientColor()
108 void SetGradientColor( const Vector4& color );
111 * @copydoc Dali::TextActor::GetGradientColor()
113 const Vector4& GetGradientColor() const;
116 * @copydoc Dali::TextActor::SetGradientStartPoint()
118 void SetGradientStartPoint( const Vector2& position );
121 * @copydoc Dali::TextActor::GetGradientStartPoint()
123 const Vector2& GetGradientStartPoint() const;
126 * @copydoc Dali::TextActor::SetGradientEndPoint()
128 void SetGradientEndPoint( const Vector2& position );
131 * @copydoc Dali::TextActor::GetGradientEndPoint()
133 const Vector2& GetGradientEndPoint() const;
136 * @copydoc Dali::TextActor::SetSmoothEdge(const float)
138 void SetSmoothEdge(const float smoothEdge);
141 * Retrieve the smooth edge value.
142 * @return the smooth edge value.
144 float GetSmoothEdge() const;
147 * @copydoc Dali::TextActor::SetOutline(const bool,const Vector4&,const Vector2&)
149 void SetOutline( bool enable, const Vector4& color, const Vector2& thickness );
153 * @return \e true if outline is enabled, otherwise \e false.
155 bool GetOutline() const;
158 * Retrieve outline parameters.
159 * @param[out] color The outline color.
160 * @param[out] thickness The outline parameters.
162 void GetOutlineParams( Vector4& color, Vector2& thickness ) const;
165 * @copydoc Dali::TextActor::SetGlow(const bool,const Vector4&,const float)
167 void SetGlow( bool enable, const Vector4& color, const float intensity);
171 * @return \e true if glow is enabled, otherwise \e false.
173 bool GetGlow() const;
176 * Retrieve glow parameters.
177 * @param[out] color The glow color.
178 * @param[out] intensity The glow intensity.
180 void GetGlowParams( Vector4& color, float& intensity ) const;
183 * @copydoc Dali::TextActor::SetShadow(const bool,const Vector4&,const Vector2&,const float)
185 void SetShadow( bool enable, const Vector4& color, const Vector2& offset, const float size);
188 * Retrieve the shadow state.
189 * @return \e true if shadow is enabled, otherwise \e false.
191 bool GetShadow() const;
194 * Retrieve shadow parameters.
195 * @param[out] color The shadow color.
196 * @param[out] offset The shadow offset.
197 * @param[out] size The shadow size.
199 void GetShadowParams( Vector4& color, Vector2& offset, float& size ) const;
203 * @param[in] color The text color
205 void SetTextColor(const Vector4& color);
209 * @return The text color
211 Vector4 GetTextColor() const;
214 * Enable italics on the text actor, the text will be sheared by the given angle.
215 * @param[in] angle Italics angle in radians.
217 void SetItalics( const Radian& angle );
220 * @copydoc Dali::TextActor::GetItalics()
222 const Radian& GetItalics() const;
225 * @copydoc Dali::TextActor::SetUnderline()
227 void SetUnderline( bool enable, float thickness, float position );
230 * @copydoc Dali::TextActor::GetUnderline()
232 bool GetUnderline() const;
235 * @copydoc Internal::TextActor::GetUnderlineThickness()
237 float GetUnderlineThickness() const;
240 * @copydoc Internal::TextActor::GetUnderlinePosition()
242 float GetUnderlinePosition() const;
245 * @copydoc Dali::TextActor::SetWeight()
247 void SetWeight( TextStyle::Weight weight );
250 * @copydoc Dali::TextActor::GetWeight()
252 TextStyle::Weight GetWeight() const;
255 * Measure the natural size of a text string, as displayed in this font.
256 * @return The natural size of the text.
258 Vector3 MeasureText() const;
261 * Inform the text attachment the text / font it is using has changed.
262 * The TextChanged() and TextNotRequired() functions are used to avoid duplicate
263 * requests for text. For example if the text is changed, and the font is changed
264 * then we want to avoid requesting the new text with the old font, then the new
265 * text with the new font.
270 * @return true if all text has been loaded and is ready to display
274 public: // glyph texture observer
277 * @copydoc Dali::Internal::GlyphTextureObserver::TextureResized()
279 virtual void TextureResized( const TextureIdList& oldTextureIds, unsigned int newTextureId );
282 * @copydoc Dali::Internal::GlyphTextureObserver::TextureSplit()
284 virtual void TextureSplit( FontId fontId, const TextureIdList& oldTextureIds, unsigned int newTextureId );
289 * Check if the text has been modified
290 * @return true if the text or it's formating has been modified
292 bool IsTextModified();
295 * Allocate a TextParameters object on this TextAttachment if one does not exist
297 void AllocateTextParameters();
300 * First stage construction of a TextAttachment.
301 * @param[in] stage Used to send messages to scene-graph.
303 TextAttachment( Stage& stage );
306 * @copydoc Dali::Internal::RenderableAttachment::OnStageConnection2()
308 virtual void OnStageConnection2();
311 * @copydoc Dali::Internal::RenderableAttachment::OnStageDisconnection2()
313 virtual void OnStageDisconnection2();
316 * @copydoc Dali::Internal::RenderableAttachment::GetSceneObject()
318 virtual const SceneGraph::RenderableAttachment& GetSceneObject() const;
321 * Update any text & font changes to the on stage scene graph text attachment
323 void SetTextChanges();
326 * Send new texture-id message
328 void SendTextureIdMessage();
331 * Make a request to load the current text
332 * @param uniqueText the text to request to be loaded
334 void RequestText( const TextArray& uniqueText );
339 * A reference counted object may only be deleted by calling Unreference()
341 virtual ~TextAttachment();
345 const SceneGraph::TextAttachment* mSceneObject; ///< Not owned
347 TextRequestHelper mTextRequestHelper; ///< Text request helper
348 FontPointer mFont; ///< The font resource
350 // Cached values for public getters
353 bool mUnderlineEnabled:1; ///< whether the text is underlined
354 bool mIsLeftToRight:1; ///< whether the text is left to right
355 bool mTextChanged:1; ///< whether the text has changed
356 bool mFontChanged:1; ///< whether the font has changed
357 bool mUnderlineChanged:1; ///< whether the underline has changed
358 bool mItalicsChanged:1; ///< whether the italics has changed
359 bool mItalicsEnabled:1; ///< whether italics are enabled
360 bool mTextureIdSet:1; ///< flag to signify if the texture id has been set on the scene-graph text-attachment
361 unsigned int mTextureId; ///< the texture id of the glyph atlas being used
362 float mSmoothing; ///< edge smoothing for the font
363 Radian mItalicsAngle; ///< font italics angle
364 float mUnderlineThickness; ///< The underline's thickness.
365 float mUnderlinePosition; ///< The underline's position.
366 Vector2 mTextSize; ///< text natural size
367 TextStyle::Weight mWeight; ///< font weight
369 OwnerPointer< TextVertexBuffer > mVertexBuffer; ///< vertex data to display the text
370 OwnerPointer< TextParameters > mTextParameters; ///< on demand storage for text effect parameters
371 Vector4* mTextColor; ///< on demand storage for text color
374 } // namespace Internal
378 #endif // __DALI_INTERNAL_TEXT_ATTACHMENT_H__