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/common/text-array.h>
30 #include <dali/internal/event/text/text-request-helper.h>
31 #include <dali/internal/event/text/resource/glyph-texture-observer.h>
32 #include <dali/internal/common/owner-pointer.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] parentNode The node to attach a scene-object to.
58 * @param [in] text The text which will be displayed.
59 * @param [in] font The font which will be used for the text.
60 * @param [in] isLeftToRight Text is displayed from left to right if true, otherwise from right to left.
61 * @return A smart-pointer to the newly allocated TextAttachment.
63 static TextAttachmentPtr New( const SceneGraph::Node& parentNode, const TextArray& text, FontPointer font, bool isLeftToRight );
66 * Set the text label displayed by the attachment
67 * @param [in] text The new text label
69 void SetText(const TextArray& text);
72 * Get the text label displayed by the attachment
73 * @return The text label
75 const 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
107 * @copydoc Dali::TextActor::SetGradientColor()
109 void SetGradientColor( const Vector4& color );
112 * @copydoc Dali::TextActor::GetGradientColor()
114 const Vector4& GetGradientColor() const;
117 * @copydoc Dali::TextActor::SetGradientStartPoint()
119 void SetGradientStartPoint( const Vector2& position );
122 * @copydoc Dali::TextActor::GetGradientStartPoint()
124 const Vector2& GetGradientStartPoint() const;
127 * @copydoc Dali::TextActor::SetGradientEndPoint()
129 void SetGradientEndPoint( const Vector2& position );
132 * @copydoc Dali::TextActor::GetGradientEndPoint()
134 const Vector2& GetGradientEndPoint() const;
137 * @copydoc Dali::TextActor::SetSmoothEdge(const float)
139 void SetSmoothEdge(const float smoothEdge);
142 * Retrieve the smooth edge value.
143 * @return the smooth edge value.
145 float GetSmoothEdge() const;
148 * @copydoc Dali::TextActor::SetOutline(const bool,const Vector4&,const Vector2&)
150 void SetOutline( bool enable, const Vector4& color, const Vector2& thickness );
154 * @return \e true if outline is enabled, otherwise \e false.
156 bool GetOutline() const;
159 * Retrieve outline parameters.
160 * @param[out] color The outline color.
161 * @param[out] thickness The outline parameters.
163 void GetOutlineParams( Vector4& color, Vector2& thickness ) const;
166 * @copydoc Dali::TextActor::SetGlow(const bool,const Vector4&,const float)
168 void SetGlow( bool enable, const Vector4& color, const float intensity);
172 * @return \e true if glow is enabled, otherwise \e false.
174 bool GetGlow() const;
177 * Retrieve glow parameters.
178 * @param[out] color The glow color.
179 * @param[out] intensity The glow intensity.
181 void GetGlowParams( Vector4& color, float& intensity ) const;
184 * @copydoc Dali::TextActor::SetShadow(const bool,const Vector4&,const Vector2&,const float)
186 void SetShadow( bool enable, const Vector4& color, const Vector2& offset, const float size);
189 * Retrieve the shadow state.
190 * @return \e true if shadow is enabled, otherwise \e false.
192 bool GetShadow() const;
195 * Retrieve shadow parameters.
196 * @param[out] color The shadow color.
197 * @param[out] offset The shadow offset.
198 * @param[out] size The shadow size.
200 void GetShadowParams( Vector4& color, Vector2& offset, float& size ) const;
204 * @param[in] color The text color
206 void SetTextColor(const Vector4& color);
210 * @return The text color
212 Vector4 GetTextColor() const;
215 * Enable italics on the text actor, the text will be sheared by the given angle.
216 * @param[in] angle Italics angle in radians.
218 void SetItalics( const Radian& angle );
221 * @copydoc Dali::TextActor::GetItalics()
223 const Radian& GetItalics() const;
226 * @copydoc Dali::TextActor::SetUnderline()
228 void SetUnderline( bool enable, float thickness, float position );
231 * @copydoc Dali::TextActor::GetUnderline()
233 bool GetUnderline() const;
236 * @copydoc Internal::TextActor::GetUnderlineThickness()
238 float GetUnderlineThickness() const;
241 * @copydoc Internal::TextActor::GetUnderlinePosition()
243 float GetUnderlinePosition() const;
246 * @copydoc Dali::TextActor::SetWeight()
248 void SetWeight( TextStyle::Weight weight );
251 * @copydoc Dali::TextActor::GetWeight()
253 TextStyle::Weight GetWeight() const;
256 * Measure the natural size of a text string, as displayed in this font.
257 * @return The natural size of the text.
259 Vector3 MeasureText() const;
262 * Inform the text attachment the text / font it is using has changed.
263 * The TextChanged() and TextNotRequired() functions are used to avoid duplicate
264 * requests for text. For example if the text is changed, and the font is changed
265 * then we want to avoid requesting the new text with the old font, then the new
266 * text with the new font.
271 * @return true if all text has been loaded and is ready to display
275 public: // glyph texture observer
278 * @copydoc Dali::Internal::GlyphTextureObserver::TextureResized()
280 virtual void TextureResized( const TextureIdList& oldTextureIds, unsigned int newTextureId );
283 * @copydoc Dali::Internal::GlyphTextureObserver::TextureSplit()
285 virtual void TextureSplit( FontId fontId, const TextureIdList& oldTextureIds, unsigned int newTextureId );
290 * Check if the text has been modified
291 * @return true if the text or it's formating has been modified
293 bool IsTextModified();
296 * Allocate a TextParameters object on this TextAttachment if one does not exist
298 void AllocateTextParameters();
301 * First stage construction of a TextAttachment.
302 * @param[in] stage Used to send messages to scene-graph.
304 TextAttachment( Stage& stage );
307 * @copydoc Dali::Internal::RenderableAttachment::OnStageConnection2()
309 virtual void OnStageConnection2();
312 * @copydoc Dali::Internal::RenderableAttachment::OnStageDisconnection2()
314 virtual void OnStageDisconnection2();
317 * @copydoc Dali::Internal::RenderableAttachment::GetSceneObject()
319 virtual const SceneGraph::RenderableAttachment& GetSceneObject() const;
322 * Update any text & font changes to the on stage scene graph text attachment
324 void SetTextChanges();
327 * Send new texture-id message
329 void SendTextureIdMessage();
332 * Make a request to load the current text
333 * @param uniqueText the text to request to be loaded
335 void RequestText( const TextArray& uniqueText );
340 * A reference counted object may only be deleted by calling Unreference()
342 virtual ~TextAttachment();
346 const SceneGraph::TextAttachment* mSceneObject; ///< Not owned
348 TextRequestHelper mTextRequestHelper; ///< Text request helper
349 FontPointer mFont; ///< The font resource
351 // Cached values for public getters
354 bool mUnderlineEnabled:1; ///< whether the text is underlined
355 bool mIsLeftToRight:1; ///< whether the text is left to right
356 bool mTextChanged:1; ///< whether the text has changed
357 bool mFontChanged:1; ///< whether the font has changed
358 bool mUnderlineChanged:1; ///< whether the underline has changed
359 bool mItalicsChanged:1; ///< whether the italics has changed
360 bool mItalicsEnabled:1; ///< whether italics are enabled
361 bool mTextureIdSet:1; ///< flag to signify if the texture id has been set on the scene-graph text-attachment
362 unsigned int mTextureId; ///< the texture id of the glyph atlas being used
363 float mSmoothing; ///< edge smoothing for the font
364 Radian mItalicsAngle; ///< font italics angle
365 float mUnderlineThickness; ///< The underline's thickness.
366 float mUnderlinePosition; ///< The underline's position.
367 Vector2 mTextSize; ///< text natural size
368 TextStyle::Weight mWeight; ///< font weight
370 OwnerPointer< TextVertexBuffer > mVertexBuffer; ///< vertex data to display the text
371 OwnerPointer< TextParameters > mTextParameters; ///< on demand storage for text effect parameters
372 Vector4* mTextColor; ///< on demand storage for text color
375 } // namespace Internal
379 #endif // __DALI_INTERNAL_TEXT_ATTACHMENT_H__