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] 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 * @return A smart-pointer to the newly allocated TextAttachment.
62 static TextAttachmentPtr New( const SceneGraph::Node& parentNode, const Integration::TextArray& text, FontPointer font );
65 * Set the text label displayed by the attachment
66 * @param [in] text The new text label
68 void SetText(const Integration::TextArray& text);
71 * Get the text label displayed by the attachment
72 * @return The text label
74 const Integration::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
107 * @param[in] color The text color
109 void SetTextColor(const Vector4& color);
113 * @return The text color
115 Vector4 GetTextColor() const;
118 * Resets to default the text color.
120 void ResetTextColor();
123 * @copydoc Dali::TextActor::SetWeight()
125 void SetWeight( TextStyle::Weight weight );
128 * @copydoc Dali::TextActor::GetWeight()
130 TextStyle::Weight GetWeight() const;
133 * Resets to default the text weight.
138 * @copydoc Dali::TextActor::SetSmoothEdge(const float)
140 void SetSmoothEdge( float smoothEdge );
143 * Retrieve the smooth edge value.
144 * @return the smooth edge value.
146 float GetSmoothEdge() const;
149 * Resets to default the smooth edge.
151 void ResetSmoothEdge();
154 * Enable italics on the text actor, the text will be sheared by the given angle.
155 * @param[in] angle Italics angle in radians.
157 void SetItalics( Radian angle );
160 * @copydoc Dali::TextActor::GetItalics()
162 bool GetItalics() const;
165 * @copydoc Dali::TextActor::GetItalicsAngle()
167 Radian GetItalicsAngle() const;
170 * Resets to default the italics.
175 * @copydoc Dali::TextActor::SetUnderline()
177 void SetUnderline( bool enable, float thickness, float position );
180 * @copydoc Dali::TextActor::GetUnderline()
182 bool GetUnderline() const;
185 * @copydoc Internal::TextActor::GetUnderlineThickness()
187 float GetUnderlineThickness() const;
190 * @copydoc Internal::TextActor::GetUnderlinePosition()
192 float GetUnderlinePosition() const;
195 * Resets to default the text underline.
197 void ResetUnderline();
200 * @copydoc Dali::TextActor::SetOutline(const bool,const Vector4&,const Vector2&)
202 void SetOutline( bool enable, const Vector4& color, const Vector2& thickness );
206 * @return \e true if outline is enabled, otherwise \e false.
208 bool GetOutline() const;
211 * Retrieve outline parameters.
212 * @param[out] color The outline color.
213 * @param[out] thickness The outline parameters.
215 void GetOutlineParams( Vector4& color, Vector2& thickness ) const;
218 * Resets to default the text outline.
223 * @copydoc Dali::TextActor::SetGlow(const bool,const Vector4&,const float)
225 void SetGlow( bool enable, const Vector4& color, float intensity );
229 * @return \e true if glow is enabled, otherwise \e false.
231 bool GetGlow() const;
234 * Retrieve glow parameters.
235 * @param[out] color The glow color.
236 * @param[out] intensity The glow intensity.
238 void GetGlowParams( Vector4& color, float& intensity ) const;
241 * Resets to default the text glow.
246 * @copydoc Dali::TextActor::SetShadow(const bool,const Vector4&,const Vector2&,const float)
248 void SetShadow( bool enable, const Vector4& color, const Vector2& offset, float size );
251 * Retrieve the shadow state.
252 * @return \e true if shadow is enabled, otherwise \e false.
254 bool GetShadow() const;
257 * Retrieve shadow parameters.
258 * @param[out] color The shadow color.
259 * @param[out] offset The shadow offset.
260 * @param[out] size The shadow size.
262 void GetShadowParams( Vector4& color, Vector2& offset, float& size ) const;
265 * Resets to default the text shadow.
270 * @see Dali::TextActor::SetGradientColor()
271 * @see Dali::TextActor::SetGradientStartPoint()
272 * @see Dali::TextActor::SetGradientEndPoint()
274 void SetGradient( const Vector4& color, const Vector2& startPoint, const Vector2& endPoint );
277 * @copydoc Dali::TextActor::GetGradientColor()
279 const Vector4& GetGradientColor() const;
282 * @copydoc Dali::TextActor::GetGradientStartPoint()
284 const Vector2& GetGradientStartPoint() const;
287 * @copydoc Dali::TextActor::GetGradientEndPoint()
289 const Vector2& GetGradientEndPoint() const;
292 * Resets to default the text gradient.
294 void ResetGradient();
297 * Retrieves the text style.
299 * @param[out] style The text style.
301 void GetTextStyle( TextStyle& style ) const;
304 * Measure the natural size of a text string, as displayed in this font.
305 * @return The natural size of the text.
307 Vector3 MeasureText() const;
310 * Inform the text attachment the text / font it is using has changed.
311 * The TextChanged() and TextNotRequired() functions are used to avoid duplicate
312 * requests for text. For example if the text is changed, and the font is changed
313 * then we want to avoid requesting the new text with the old font, then the new
314 * text with the new font.
319 * @return true if all text has been loaded and is ready to display
324 * Calculates the weighted smoothing value.
326 void CalculateWeightedSmoothing( TextStyle::Weight weight, float smoothEdge );
328 public: // glyph texture observer
331 * @copydoc Dali::Internal::GlyphTextureObserver::TextureResized()
333 virtual void TextureResized( const TextureIdList& oldTextureIds, unsigned int newTextureId );
336 * @copydoc Dali::Internal::GlyphTextureObserver::TextureSplit()
338 virtual void TextureSplit( FontId fontId, const TextureIdList& oldTextureIds, unsigned int newTextureId );
343 * Check if the text has been modified
344 * @return true if the text or it's formating has been modified
346 bool IsTextModified();
349 * First stage construction of a TextAttachment.
350 * @param[in] stage Used to send messages to scene-graph.
352 TextAttachment( Stage& stage );
355 * @copydoc Dali::Internal::RenderableAttachment::OnStageConnection2()
357 virtual void OnStageConnection2();
360 * @copydoc Dali::Internal::RenderableAttachment::OnStageDisconnection2()
362 virtual void OnStageDisconnection2();
365 * @copydoc Dali::Internal::RenderableAttachment::GetSceneObject()
367 virtual const SceneGraph::RenderableAttachment& GetSceneObject() const;
370 * Update any text & font changes to the on stage scene graph text attachment
372 void SetTextChanges();
377 * A reference counted object may only be deleted by calling Unreference()
379 virtual ~TextAttachment();
383 const SceneGraph::TextAttachment* mSceneObject; ///< Not owned
385 TextRequestHelper mTextRequestHelper; ///< Text request helper
386 FontPointer mFont; ///< The font resource
387 Vector4* mTextColor; ///< on demand storage for text color
388 TextStyle mStyle; ///< on demand storage for text effects parameters ( do not store font parameters and color )
389 ///< Font parameters are stored in the FontPointer member. Inside the TextStyle, font parameters and color are allocated in the same struct,
390 ///< so store the text color in the style will allocate space for the font parameters as well, wasting space.
391 // Cached values for public getters
392 Integration::TextArray mText;
394 bool mTextChanged:1; ///< whether the text has changed
395 bool mFontChanged:1; ///< whether the font has changed
396 bool mUnderlineChanged:1; ///< whether the underline has changed
397 bool mItalicsChanged:1; ///< whether the italics has changed
398 bool mTextureIdSet:1; ///< flag to signify if the texture id has been set on the scene-graph text-attachment
399 unsigned int mTextureId; ///< the texture id of the glyph atlas being used
400 Vector2 mTextSize; ///< text natural size
402 OwnerPointer< TextVertexBuffer > mVertexBuffer; ///< vertex data to display the text
405 } // namespace Internal
409 #endif // __DALI_INTERNAL_TEXT_ATTACHMENT_H__