1 #ifndef __DALI_INTERNAL_TEXT_ACTOR_H__
2 #define __DALI_INTERNAL_TEXT_ACTOR_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/object/ref-object.h>
22 #include <dali/public-api/actors/text-actor.h>
23 #include <dali/internal/event/actors/actor-declarations.h>
24 #include <dali/internal/event/actors/renderable-actor-impl.h>
25 #include <dali/internal/event/text/text-observer.h>
26 #include <dali/internal/event/actor-attachments/actor-attachment-declarations.h>
27 #include <dali/internal/common/text-array.h>
39 * TextActor implementation.
40 * A text actor is an actor with a TextAttachment.
41 * If no size is given to the actor, then after the font has loaded
42 * the actor will be set to the size of the text displayed.
45 class TextActor : public RenderableActor, public TextObserver
51 REQUEST_NEW_TEXT, ///< When changing font, request new text
52 DONT_REQUEST_NEW_TEXT ///< When changing font, don't request new text
56 * @copydoc Dali::TextActor::New(const Dali::Text&,bool,bool)
57 * @return A pointer to a new TextActor.
59 static TextActorPtr New(const Dali::Text& text, bool fontDetection, bool isLeftToRight);
62 * @copydoc Dali::TextActor::New(const Dali::Text&,Dali::Font,bool,bool)
63 * @return A pointer to a new TextActor.
65 static TextActorPtr New(const Dali::Text& text, bool fontDetection, bool isLeftToRight, Font& font);
68 * @copydoc Dali::TextActor::New(const Text&,const TextStyle&,bool,bool)
69 * @return A pointer to a new TextActor.
71 static TextActorPtr New(const Dali::Text& text, bool fontDetection, bool isLeftToRight, const Dali::TextStyle& style );
74 * @copydoc Dali::Internal::Actor::OnInitialize
79 * @copydoc Dali::TextActor::GetText()
81 const std::string GetText() const;
84 * @copydoc Dali::TextActor::SetText()
86 void SetText(const std::string& text);
89 * @copydoc Dali::TextActor::SetText()
91 void SetText(const Dali::Text& text);
94 * @copybrief Dali::TextActor::SetText(const std::string&)
95 * @param[in] utfCodes An std::vector containing the UTF-32 codes
97 void SetText(const TextArray& utfCodes);
100 * @copydoc Dali::TextActor::SetToNaturalSize()
102 void SetToNaturalSize();
105 * @copydoc Dali::TextActor::GetFont()
107 Font* GetFont() const;
110 * @copydoc Dali::TextActor::SetFont()
111 * @param TextRequestMode whether new text should be requested
113 void SetFont(Font& font, TextRequestMode mode = REQUEST_NEW_TEXT );
116 * @copydoc Dali::TextActor::SetGradientColor()
118 void SetGradientColor( const Vector4& color );
121 * @copydoc Dali::TextActor::GetGradientColor()
123 const Vector4& GetGradientColor() const;
126 * @copydoc Dali::TextActor::SetGradientStartPoint()
128 void SetGradientStartPoint( const Vector2& position );
131 * @copydoc Dali::TextActor::SetGradientStartPoint()
133 const Vector2& GetGradientStartPoint() const;
136 * @copydoc Dali::TextActor::SetGradientEndPoint()
138 void SetGradientEndPoint( const Vector2& position );
141 * @copydoc Dali::TextActor::GetGradientEndPoint()
143 const Vector2& GetGradientEndPoint() const;
146 * @copydoc Dali::TextActor::SetTextStyle( const TextStyle& style )
147 * @param mode whether new text should be requested
149 void SetTextStyle( const TextStyle& style, TextRequestMode mode = REQUEST_NEW_TEXT );
152 * @copydoc Dali::TextActor::GetTextStyle()
154 TextStyle GetTextStyle() const;
157 * @copydoc Dali::TextActor::SetTextColor(const Vector4&)
159 void SetTextColor(const Vector4& color);
162 * @copydoc Dali::TextActor::GetTextColor()
164 Vector4 GetTextColor() const;
167 * @copydoc Dali::TextActor::SetSmoothEdge(const float)
169 void SetSmoothEdge(const float smoothEdge);
172 * @copydoc Dali::TextActor::SetOutline(const bool,const Vector4&,const Vector2&)
174 void SetOutline(const bool enable, const Vector4& color, const Vector2& thickness);
177 * @copydoc Dali::TextActor::SetGlow(const bool,const Vector4&,const float)
179 void SetGlow(const bool enable, const Vector4& color, const float intensity);
182 * @copydoc Dali::TextActor::SetShadow(const bool,const Vector4&,const Vector2&,const float)
184 void SetShadow(const bool enable, const Vector4& color, const Vector2& offset, const float size);
187 * Enable italics on the text actor, the text will be sheared by the given angle.
188 * @param[in] angle Italics angle in radians.
190 void SetItalics( const Radian& angle );
193 * @copydoc Dali::TextActor::GetItalics()
195 const Radian& GetItalics() const;
198 * @copydoc Dali::TextActor::SetUnderline()
200 void SetUnderline( bool enable, float thickness, float position );
203 * @copydoc Dali::TextActor::GetUnderline()
205 bool GetUnderline() const;
208 * @return The underline's thickness.
210 float GetUnderlineThickness() const;
213 * @return The underline's position.
215 float GetUnderlinePosition() const;
218 * @copydoc Dali::TextActor::SetWeight()
220 void SetWeight( TextStyle::Weight weight );
223 * @copydoc Dali::TextActor::GetWeight()
225 TextStyle::Weight GetWeight() const;
228 * @copydoc Dali::TextActor::SetFontDetectionAutomatic()
230 void SetFontDetectionAutomatic(bool value);
233 * @copydoc Dali::TextActor::IsFontDetectionAutomatic()
235 bool IsFontDetectionAutomatic() const;
237 private: // from Actor
240 * @copydoc Actor::OnSizeSet
242 virtual void OnSizeSet(const Vector3& targetSize);
245 * @copydoc Actor::OnSizeAnimation( Animation& animation, const Vector3& targetSize )
247 virtual void OnSizeAnimation(Animation& animation, const Vector3& targetSize);
249 private: // From RenderableActor
252 * @copydoc RenderableActor::GetRenderableAttachment
254 virtual RenderableAttachment& GetRenderableAttachment() const;
259 * Protected constructor; see also TextActor::New()
261 TextActor(bool fontDetection, bool isLeftToRight );
264 * A reference counted object may only be deleted by calling Unreference()
266 virtual ~TextActor();
271 * @copydoc Dali::Image::GetLoadingState()
273 Dali::LoadingState GetLoadingState() const { return mLoadingState; }
276 * @copydoc Dali::TextActor::TextAvailableSignal()
278 Dali::TextActor::TextSignalV2& TextAvailableSignal() { return mLoadingFinishedV2; }
281 * Connects a callback function with the text actors signals.
282 * @param[in] object The object providing the signal.
283 * @param[in] tracker Used to disconnect the signal.
284 * @param[in] signalName The signal to connect to.
285 * @param[in] functor A newly allocated FunctorDelegate.
286 * @return True if the signal was connected.
287 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
289 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
291 public: // From TextObserver
294 * @copydoc Dali::Internal::TextObserver::TextLoaded()
296 virtual void TextLoaded();
301 * Text has been changed observe ticket or
302 * emit text available signal
307 * Checks whether the text is loaded or not
308 * @return true if text is loaded
310 bool CheckTextLoadState();
313 * Stop observing text loads on the current font.
315 void StopObservingTextLoads();
318 * Start observing text loads on the current font.
320 void StartObservingTextLoads();
323 TextActor(const TextActor&);
326 TextActor& operator=(const TextActor& rhs);
328 private: // ProxyObject default non-animatable properties
330 * copydoc Dali::Internal::ProxyObject
332 virtual unsigned int GetDefaultPropertyCount() const ;
335 * copydoc Dali::Internal::ProxyObject
337 virtual const std::string& GetDefaultPropertyName( Property::Index index ) const ;
340 * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyIndex()
342 virtual Property::Index GetDefaultPropertyIndex(const std::string& name) const;
345 * copydoc Dali::Internal::ProxyObject
347 virtual bool IsDefaultPropertyWritable( Property::Index index ) const ;
350 * copydoc Dali::Internal::ProxyObject
352 virtual bool IsDefaultPropertyAnimatable( Property::Index index ) const ;
355 * copydoc Dali::Internal::ProxyObject
357 virtual Property::Type GetDefaultPropertyType( Property::Index index ) const ;
360 * copydoc Dali::Internal::ProxyObject
362 virtual void SetDefaultProperty( Property::Index index, const Property::Value& propertyValue ) ;
365 * copydoc Dali::Internal::ProxyObject
367 virtual Property::Value GetDefaultProperty( Property::Index index ) const ;
371 TextAttachmentPtr mTextAttachment; ///< Used to display the text
373 Dali::LoadingState mLoadingState;
377 Dali::TextActor::TextSignalV2 mLoadingFinishedV2;
378 bool mUsingNaturalSize:1; ///< whether the actor is using natural size
379 bool mInternalSetSize:1; ///< to determine when we are internally setting size
380 bool mFontDetection:1; ///< tells whether TextActor should query platform abstraction after SetText
381 bool mIsLeftToRight:1; ///< tells whether text is displayed from left to right or from right to left
382 bool mObserving:1; ///< Whether the text actor is waiting for text to load
383 static bool mFirstInstance;
384 static DefaultPropertyLookup* mDefaultTextActorPropertyLookup; ///< Default properties
387 } // namespace Internal
389 // Helpers for public-api forwarding methods
391 inline Internal::TextActor& GetImplementation(Dali::TextActor& actor)
393 DALI_ASSERT_ALWAYS( actor && "Actor handle is empty" );
395 BaseObject& handle = actor.GetBaseObject();
397 return static_cast<Internal::TextActor&>(handle);
400 inline const Internal::TextActor& GetImplementation(const Dali::TextActor& actor)
402 DALI_ASSERT_ALWAYS( actor && "Actor handle is empty" );
404 const BaseObject& handle = actor.GetBaseObject();
406 return static_cast<const Internal::TextActor&>(handle);
411 #endif // __DALI_INTERNAL_TEXT_ACTOR_H__