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 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/object/ref-object.h>
23 #include <dali/public-api/actors/text-actor.h>
24 #include <dali/internal/event/actors/actor-declarations.h>
25 #include <dali/internal/event/actors/renderable-actor-impl.h>
26 #include <dali/internal/event/text/text-observer.h>
27 #include <dali/internal/event/actor-attachments/actor-attachment-declarations.h>
28 #include <dali/integration-api/text-array.h>
40 * TextActor implementation.
41 * A text actor is an actor with a TextAttachment.
42 * If no size is given to the actor, then after the font has loaded
43 * the actor will be set to the size of the text displayed.
46 class TextActor : public RenderableActor, public TextObserver
52 REQUEST_NEW_TEXT, ///< When changing font, request new text
53 DONT_REQUEST_NEW_TEXT ///< When changing font, don't request new text
57 * @see Dali::TextActor::New( const Text& text, const TextActorParameters& parameters )
58 * @return A pointer to a new TextActor.
60 static TextActorPtr New( const Integration::TextArray& utfCodes, const TextActorParameters& parameters );
63 * @copydoc Dali::Internal::Actor::OnInitialize
68 * @copydoc Dali::TextActor::GetText()
70 const std::string GetText() const;
73 * @copybrief Dali::TextActor::SetText(const std::string&)
74 * @param[in] utfCodes An std::vector containing the UTF-32 codes
76 void SetText(const Integration::TextArray& utfCodes);
79 * @copydoc Dali::TextActor::SetToNaturalSize()
81 void SetToNaturalSize();
84 * @copydoc Dali::TextActor::GetFont()
86 Font* GetFont() const;
89 * @copydoc Dali::TextActor::SetFont()
90 * @param TextRequestMode whether new text should be requested
92 void SetFont(Font& font, TextRequestMode mode = REQUEST_NEW_TEXT );
95 * @copydoc Dali::TextActor::SetGradientColor()
97 void SetGradientColor( const Vector4& color );
100 * @copydoc Dali::TextActor::GetGradientColor()
102 const Vector4& GetGradientColor() const;
105 * @copydoc Dali::TextActor::SetGradientStartPoint()
107 void SetGradientStartPoint( const Vector2& position );
110 * @copydoc Dali::TextActor::SetGradientStartPoint()
112 const Vector2& GetGradientStartPoint() const;
115 * @copydoc Dali::TextActor::SetGradientEndPoint()
117 void SetGradientEndPoint( const Vector2& position );
120 * @copydoc Dali::TextActor::GetGradientEndPoint()
122 const Vector2& GetGradientEndPoint() const;
125 * @see Dali::TextActor::SetGradientColor()
126 * @see Dali::TextActor::SetGradientStartPoint()
127 * @see Dali::TextActor::SetGradientEndPoint()
129 void SetGradient( const Vector4& color, const Vector2& startPoint, const Vector2& endPoint );
132 * @copydoc Dali::TextActor::SetTextStyle( const TextStyle& style )
133 * @param mode whether new text should be requested
135 void SetTextStyle( const TextStyle& style, TextRequestMode mode = REQUEST_NEW_TEXT );
138 * @copydoc Dali::TextActor::GetTextStyle()
140 TextStyle GetTextStyle() const;
143 * @copydoc Dali::TextActor::SetTextColor(const Vector4&)
145 void SetTextColor(const Vector4& color);
148 * @copydoc Dali::TextActor::GetTextColor()
150 Vector4 GetTextColor() const;
153 * @copydoc Dali::TextActor::SetSmoothEdge(const float)
155 void SetSmoothEdge( float smoothEdge );
158 * @copydoc Dali::TextActor::SetOutline( bool,const Vector4&,const Vector2&)
160 void SetOutline( bool enable, const Vector4& color, const Vector2& thickness );
163 * @copydoc Dali::TextActor::SetGlow(const bool,const Vector4&,const float)
165 void SetGlow( bool enable, const Vector4& color, float intensity );
168 * @copydoc Dali::TextActor::SetShadow(const bool,const Vector4&,const Vector2&,const float)
170 void SetShadow( bool enable, const Vector4& color, const Vector2& offset, float size );
173 * Enable italics on the text actor, the text will be sheared by the given angle.
174 * @param[in] angle Italics angle in radians.
176 void SetItalics( Radian angle );
179 * @copydoc Dali::TextActor::GetItalics()
181 bool GetItalics() const;
184 * @copydoc Dali::TextActor::GetItalicsAngle()
186 Radian GetItalicsAngle() const;
189 * @copydoc Dali::TextActor::SetUnderline()
191 void SetUnderline( bool enable, float thickness, float position );
194 * @copydoc Dali::TextActor::GetUnderline()
196 bool GetUnderline() const;
199 * @return The underline's thickness.
201 float GetUnderlineThickness() const;
204 * @return The underline's position.
206 float GetUnderlinePosition() const;
209 * @copydoc Dali::TextActor::SetWeight()
211 void SetWeight( TextStyle::Weight weight );
214 * @copydoc Dali::TextActor::GetWeight()
216 TextStyle::Weight GetWeight() const;
219 * @copydoc Dali::TextActor::SetFontDetectionAutomatic()
221 void SetFontDetectionAutomatic(bool value);
224 * @copydoc Dali::TextActor::IsFontDetectionAutomatic()
226 bool IsFontDetectionAutomatic() const;
228 public: // From Actor
231 * @copydoc Dali::Actor::GetNaturalSize()
233 virtual Vector3 GetNaturalSize() const;
235 private: // from Actor
238 * @copydoc Actor::OnSizeSet
240 virtual void OnSizeSet(const Vector3& targetSize);
243 * @copydoc Actor::OnSizeAnimation( Animation& animation, const Vector3& targetSize )
245 virtual void OnSizeAnimation(Animation& animation, const Vector3& targetSize);
247 private: // From RenderableActor
250 * @copydoc RenderableActor::GetRenderableAttachment
252 virtual RenderableAttachment& GetRenderableAttachment() const;
257 * Protected constructor; see also TextActor::New()
259 TextActor(bool fontDetection);
262 * A reference counted object may only be deleted by calling Unreference()
264 virtual ~TextActor();
269 * @copydoc Dali::Image::GetLoadingState()
271 Dali::LoadingState GetLoadingState() const { return mLoadingState; }
274 * @copydoc Dali::TextActor::TextAvailableSignal()
276 Dali::TextActor::TextSignalType& TextAvailableSignal() { return mLoadingFinished; }
279 * Connects a callback function with the text actors signals.
280 * @param[in] object The object providing the signal.
281 * @param[in] tracker Used to disconnect the signal.
282 * @param[in] signalName The signal to connect to.
283 * @param[in] functor A newly allocated FunctorDelegate.
284 * @return True if the signal was connected.
285 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
287 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
289 public: // From TextObserver
292 * @copydoc Dali::Internal::TextObserver::TextLoaded()
294 virtual void TextLoaded();
299 * Text has been changed observe ticket or
300 * emit text available signal
305 * Checks whether the text is loaded or not
306 * @return true if text is loaded
308 bool CheckTextLoadState();
311 * Stop observing text loads on the current font.
313 void StopObservingTextLoads();
316 * Start observing text loads on the current font.
318 void StartObservingTextLoads();
321 TextActor(const TextActor&);
324 TextActor& operator=(const TextActor& rhs);
326 private: // Object default non-animatable properties
328 * copydoc Dali::Internal::Object
330 virtual unsigned int GetDefaultPropertyCount() const ;
333 * @copydoc Dali::Internal::Object::GetDefaultPropertyIndices()
335 virtual void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const;
338 * copydoc Dali::Internal::Object
340 virtual const char* GetDefaultPropertyName( Property::Index index ) const ;
343 * @copydoc Dali::Internal::Object::GetDefaultPropertyIndex()
345 virtual Property::Index GetDefaultPropertyIndex(const std::string& name) const;
348 * copydoc Dali::Internal::Object
350 virtual bool IsDefaultPropertyWritable( Property::Index index ) const ;
353 * copydoc Dali::Internal::Object
355 virtual bool IsDefaultPropertyAnimatable( Property::Index index ) const ;
358 * @copydoc Dali::Internal::Object::IsDefaultPropertyAConstraintInput()
360 virtual bool IsDefaultPropertyAConstraintInput( Property::Index index ) const;
363 * copydoc Dali::Internal::Object
365 virtual Property::Type GetDefaultPropertyType( Property::Index index ) const ;
368 * copydoc Dali::Internal::Object
370 virtual void SetDefaultProperty( Property::Index index, const Property::Value& propertyValue ) ;
373 * copydoc Dali::Internal::Object
375 virtual Property::Value GetDefaultProperty( Property::Index index ) const ;
379 TextAttachmentPtr mTextAttachment; ///< Used to display the text
381 Dali::LoadingState mLoadingState;
385 Dali::TextActor::TextSignalType mLoadingFinished;
386 bool mUsingNaturalSize:1; ///< whether the actor is using natural size
387 bool mInternalSetSize:1; ///< to determine when we are internally setting size
388 bool mFontDetection:1; ///< tells whether TextActor should query platform abstraction after SetText
389 bool mObserving:1; ///< Whether the text actor is waiting for text to load
392 } // namespace Internal
394 // Helpers for public-api forwarding methods
396 inline Internal::TextActor& GetImplementation(Dali::TextActor& actor)
398 DALI_ASSERT_ALWAYS( actor && "Actor handle is empty" );
400 BaseObject& handle = actor.GetBaseObject();
402 return static_cast<Internal::TextActor&>(handle);
405 inline const Internal::TextActor& GetImplementation(const Dali::TextActor& actor)
407 DALI_ASSERT_ALWAYS( actor && "Actor handle is empty" );
409 const BaseObject& handle = actor.GetBaseObject();
411 return static_cast<const Internal::TextActor&>(handle);
416 #endif // __DALI_INTERNAL_TEXT_ACTOR_H__