a8320c6e9a76eb4611acd0df3c94d6865d394ab8
[platform/core/uifw/dali-core.git] / dali / internal / event / actors / text-actor-impl.h
1 #ifndef __DALI_INTERNAL_TEXT_ACTOR_H__
2 #define __DALI_INTERNAL_TEXT_ACTOR_H__
3
4 /*
5  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 // INTERNAL INCLUDES
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>
29
30
31 namespace Dali
32 {
33
34 namespace Internal
35 {
36
37 class Font;
38
39 /**
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.
44  *
45  */
46 class TextActor : public RenderableActor, public TextObserver
47 {
48 public:
49
50   enum TextRequestMode
51   {
52     REQUEST_NEW_TEXT,       ///< When changing font, request new text
53     DONT_REQUEST_NEW_TEXT   ///< When changing font, don't request new text
54   };
55
56   /**
57    * @see Dali::TextActor::New( const Text& text, const TextActorParameters& parameters )
58    * @return A pointer to a new TextActor.
59    */
60   static TextActorPtr New( const Integration::TextArray& utfCodes, const TextActorParameters& parameters );
61
62   /**
63    * @copydoc Dali::Internal::Actor::OnInitialize
64    */
65   void OnInitialize();
66
67   /**
68    * @copydoc Dali::TextActor::GetText()
69    */
70   const std::string GetText() const;
71
72   /**
73    * @copybrief Dali::TextActor::SetText(const std::string&)
74    * @param[in] utfCodes  An std::vector containing the UTF-32 codes
75    */
76   void SetText(const Integration::TextArray& utfCodes);
77
78   /**
79    * @copydoc Dali::TextActor::SetToNaturalSize()
80    */
81   void SetToNaturalSize();
82
83   /**
84    * @copydoc Dali::TextActor::GetFont()
85    */
86   Font* GetFont() const;
87
88   /**
89    * @copydoc Dali::TextActor::SetFont()
90    * @param TextRequestMode whether new text should be requested
91    */
92   void SetFont(Font& font, TextRequestMode mode = REQUEST_NEW_TEXT );
93
94   /**
95    * @copydoc Dali::TextActor::SetGradientColor()
96    */
97   void SetGradientColor( const Vector4& color );
98
99   /**
100    * @copydoc Dali::TextActor::GetGradientColor()
101    */
102   const Vector4& GetGradientColor() const;
103
104   /**
105    * @copydoc Dali::TextActor::SetGradientStartPoint()
106    */
107   void SetGradientStartPoint( const Vector2& position );
108
109   /**
110    * @copydoc Dali::TextActor::SetGradientStartPoint()
111    */
112   const Vector2& GetGradientStartPoint() const;
113
114   /**
115    * @copydoc Dali::TextActor::SetGradientEndPoint()
116    */
117   void SetGradientEndPoint( const Vector2& position );
118
119   /**
120    * @copydoc Dali::TextActor::GetGradientEndPoint()
121    */
122   const Vector2& GetGradientEndPoint() const;
123
124   /**
125    * @see Dali::TextActor::SetGradientColor()
126    * @see Dali::TextActor::SetGradientStartPoint()
127    * @see Dali::TextActor::SetGradientEndPoint()
128    */
129   void SetGradient( const Vector4& color, const Vector2& startPoint, const Vector2& endPoint );
130
131   /**
132    * @copydoc Dali::TextActor::SetTextStyle( const TextStyle& style )
133    * @param mode whether new text should be requested
134    */
135   void SetTextStyle( const TextStyle& style, TextRequestMode mode = REQUEST_NEW_TEXT );
136
137   /**
138    * @copydoc Dali::TextActor::GetTextStyle()
139    */
140   TextStyle GetTextStyle() const;
141
142   /**
143    * @copydoc Dali::TextActor::SetTextColor(const Vector4&)
144    */
145   void SetTextColor(const Vector4& color);
146
147   /**
148    * @copydoc Dali::TextActor::GetTextColor()
149    */
150   Vector4 GetTextColor() const;
151
152   /**
153    * @copydoc Dali::TextActor::SetSmoothEdge(const float)
154    */
155   void SetSmoothEdge( float smoothEdge );
156
157   /**
158    * @copydoc Dali::TextActor::SetOutline( bool,const Vector4&,const Vector2&)
159    */
160   void SetOutline( bool enable, const Vector4& color, const Vector2& thickness );
161
162   /**
163    * @copydoc Dali::TextActor::SetGlow(const bool,const Vector4&,const float)
164    */
165   void SetGlow( bool enable, const Vector4& color, float intensity );
166
167   /**
168    * @copydoc Dali::TextActor::SetShadow(const bool,const Vector4&,const Vector2&,const float)
169    */
170   void SetShadow( bool enable, const Vector4& color, const Vector2& offset, float size );
171
172   /**
173    * Enable italics on the text actor, the text will be sheared by the given angle.
174    * @param[in] angle Italics angle in radians.
175    */
176   void SetItalics( Radian angle );
177
178   /**
179    * @copydoc Dali::TextActor::GetItalics()
180    */
181   bool GetItalics() const;
182
183   /**
184    * @copydoc Dali::TextActor::GetItalicsAngle()
185    */
186   Radian GetItalicsAngle() const;
187
188   /**
189    * @copydoc Dali::TextActor::SetUnderline()
190    */
191   void SetUnderline( bool enable, float thickness, float position );
192
193   /**
194    * @copydoc Dali::TextActor::GetUnderline()
195    */
196   bool GetUnderline() const;
197
198   /**
199    * @return The underline's thickness.
200    */
201   float GetUnderlineThickness() const;
202
203   /**
204    * @return The underline's position.
205    */
206   float GetUnderlinePosition() const;
207
208   /**
209    * @copydoc Dali::TextActor::SetWeight()
210    */
211   void SetWeight( TextStyle::Weight weight );
212
213   /**
214    * @copydoc Dali::TextActor::GetWeight()
215    */
216   TextStyle::Weight GetWeight() const;
217
218   /**
219    * @copydoc Dali::TextActor::SetFontDetectionAutomatic()
220    */
221   void SetFontDetectionAutomatic(bool value);
222
223   /**
224    * @copydoc Dali::TextActor::IsFontDetectionAutomatic()
225    */
226   bool IsFontDetectionAutomatic() const;
227
228 public: // From Actor
229
230   /**
231    * @copydoc Dali::Actor::GetNaturalSize()
232    */
233   virtual Vector3 GetNaturalSize() const;
234
235 private: // from Actor
236
237   /**
238    * @copydoc Actor::OnSizeSet
239    */
240   virtual void OnSizeSet(const Vector3& targetSize);
241
242   /**
243    * @copydoc Actor::OnSizeAnimation( Animation& animation, const Vector3& targetSize )
244    */
245   virtual void OnSizeAnimation(Animation& animation, const Vector3& targetSize);
246
247 private: // From RenderableActor
248
249   /**
250    * @copydoc RenderableActor::GetRenderableAttachment
251    */
252   virtual RenderableAttachment& GetRenderableAttachment() const;
253
254 protected:
255
256   /**
257    * Protected constructor; see also TextActor::New()
258    */
259   TextActor(bool fontDetection);
260
261   /**
262    * A reference counted object may only be deleted by calling Unreference()
263    */
264   virtual ~TextActor();
265
266 public:
267
268   /**
269    * @copydoc Dali::Image::GetLoadingState()
270    */
271   Dali::LoadingState GetLoadingState() const { return mLoadingState; }
272
273   /**
274    * @copydoc Dali::TextActor::TextAvailableSignal()
275    */
276   Dali::TextActor::TextSignalType& TextAvailableSignal() { return mLoadingFinished; }
277
278   /**
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.
286    */
287   static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
288
289 public: // From TextObserver
290
291   /**
292    * @copydoc Dali::Internal::TextObserver::TextLoaded()
293    */
294   virtual void TextLoaded();
295
296 private:
297
298   /**
299    * Text has been changed observe ticket or
300    * emit text available signal
301    */
302   void TextChanged();
303
304   /**
305    * Checks whether the text is loaded or not
306    * @return true if text is loaded
307    */
308   bool CheckTextLoadState();
309
310   /**
311    * Stop observing text loads on the current font.
312    */
313   void StopObservingTextLoads();
314
315   /**
316    * Start observing text loads on the current font.
317    */
318   void StartObservingTextLoads();
319
320   // Undefined
321   TextActor(const TextActor&);
322
323   // Undefined
324   TextActor& operator=(const TextActor& rhs);
325
326 private: // ProxyObject default non-animatable properties
327   /**
328    * copydoc Dali::Internal::ProxyObject
329    */
330   virtual unsigned int GetDefaultPropertyCount() const ;
331
332   /**
333    * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyIndices()
334    */
335   virtual void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const;
336
337   /**
338    * copydoc Dali::Internal::ProxyObject
339    */
340   virtual const char* GetDefaultPropertyName( Property::Index index ) const ;
341
342   /**
343    * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyIndex()
344    */
345   virtual Property::Index GetDefaultPropertyIndex(const std::string& name) const;
346
347   /**
348    * copydoc Dali::Internal::ProxyObject
349    */
350   virtual bool IsDefaultPropertyWritable( Property::Index index ) const ;
351
352   /**
353    * copydoc Dali::Internal::ProxyObject
354    */
355   virtual bool IsDefaultPropertyAnimatable( Property::Index index ) const ;
356
357   /**
358    * @copydoc Dali::Internal::ProxyObject::IsDefaultPropertyAConstraintInput()
359    */
360   virtual bool IsDefaultPropertyAConstraintInput( Property::Index index ) const;
361
362   /**
363    * copydoc Dali::Internal::ProxyObject
364    */
365   virtual Property::Type GetDefaultPropertyType( Property::Index index ) const ;
366
367   /**
368    * copydoc Dali::Internal::ProxyObject
369    */
370   virtual void SetDefaultProperty( Property::Index index, const Property::Value& propertyValue ) ;
371
372   /**
373    * copydoc Dali::Internal::ProxyObject
374    */
375   virtual Property::Value GetDefaultProperty( Property::Index index ) const ;
376
377 protected:
378
379   TextAttachmentPtr mTextAttachment; ///< Used to display the text
380
381   Dali::LoadingState mLoadingState;
382
383 private:
384
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
390 };
391
392 } // namespace Internal
393
394 // Helpers for public-api forwarding methods
395
396 inline Internal::TextActor& GetImplementation(Dali::TextActor& actor)
397 {
398   DALI_ASSERT_ALWAYS( actor && "Actor handle is empty" );
399
400   BaseObject& handle = actor.GetBaseObject();
401
402   return static_cast<Internal::TextActor&>(handle);
403 }
404
405 inline const Internal::TextActor& GetImplementation(const Dali::TextActor& actor)
406 {
407   DALI_ASSERT_ALWAYS( actor && "Actor handle is empty" );
408
409   const BaseObject& handle = actor.GetBaseObject();
410
411   return static_cast<const Internal::TextActor&>(handle);
412 }
413
414 } // namespace Dali
415
416 #endif // __DALI_INTERNAL_TEXT_ACTOR_H__