Add GetNaturalSize to Actor and deriving classes.
[platform/core/uifw/dali-core.git] / dali / internal / event / actors / image-actor-impl.h
1 #ifndef __DALI_INTERNAL_IMAGE_ACTOR_H__
2 #define __DALI_INTERNAL_IMAGE_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/image-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/actor-attachments/image-attachment-impl.h>
27 #include <dali/internal/event/animation/animation-impl.h>
28 #include <dali/internal/event/images/nine-patch-image-impl.h>
29
30 namespace Dali
31 {
32
33 namespace Internal
34 {
35
36 class Image;
37
38 /**
39  * An actor which displays an Image object.
40  *
41  * This handles image fade-in if required, waiting for the image to load.
42  *
43  * If a new image is set on the actor, then this ensures that the old image
44  * is displayed until the new image is ready to render to prevent flashing
45  * to the actor color. This will also happen if the image is reloaded.
46  *
47  * This is achieved by using two connector objects to Image: mImageNext and
48  * mImageAttachment's member object. The first one points to the Image object that is going to
49  * be displayed next, the second one to the Image that is currently being displayed.
50  */
51 class ImageActor : public RenderableActor
52 {
53 public:
54
55   typedef Dali::ImageActor::Style Style;
56   typedef Dali::ImageActor::PixelArea PixelArea;
57
58   /**
59    * @brief Create an image actor instance.
60    * @return A smart-pointer to a newly allocated image actor.
61    */
62   static ImageActorPtr New();
63
64   /**
65    * @copydoc Dali::Internal::Actor::OnInitialize
66    */
67   void OnInitialize() ;
68
69   /**
70    * @see Dali::ImageActor::SetImage()
71    * @param[in] ImagePtr reference to the image object to display. Reference to avoid unnecessary increment/decrement reference.
72    */
73   void SetImage( ImagePtr& image );
74
75   /**
76    * Retrieve the image rendered by the actor's attachment.
77    * @return smart pointer to the image or an empty one if no image is assigned
78    */
79   ImagePtr GetImage();
80
81   /**
82    * @copydoc Dali::ImageActor::SetToNaturalSize()
83    */
84   void SetToNaturalSize();
85
86   /**
87    * @copydoc Dali::ImageActor::SetPixelArea()
88    */
89   void SetPixelArea( const PixelArea& pixelArea );
90
91   /**
92    * @copydoc Dali::ImageActor::GetPixelArea()
93    */
94   const PixelArea& GetPixelArea() const;
95
96   /**
97    * @copydoc Dali::ImageActor::IsPixelAreaSet()
98    */
99   bool IsPixelAreaSet() const;
100
101   /**
102    * @copydoc Dali::ImageActor::ClearPixelArea()
103    */
104   void ClearPixelArea();
105
106   /**
107    * @copydoc Dali::ImageActor::SetStyle()
108    */
109   void SetStyle( Style style );
110
111   /**
112    * @copydoc Dali::ImageActor::GetStyle()
113    */
114   Style GetStyle() const;
115
116   /**
117    * @copydoc Dali::ImageActor::SetNinePatchBorder
118    */
119   void SetNinePatchBorder( const Vector4& border, bool inPixels = false );
120
121   /**
122    * @copydoc Dali::ImageActor::GetNinePatchBorder
123    */
124   Vector4 GetNinePatchBorder() const;
125
126   /**
127    * Retrieve the attachment which renders the image.
128    * @return The attachment.
129    */
130   ImageAttachment& GetImageAttachment();
131
132 public: // Default property extensions from ProxyObject
133
134   /**
135    * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyCount()
136    */
137   virtual unsigned int GetDefaultPropertyCount() const;
138
139   /**
140    * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyIndices()
141    */
142   virtual void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const;
143
144   /**
145    * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyName()
146    */
147   virtual const std::string& GetDefaultPropertyName(Property::Index index) const;
148
149   /**
150    * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyIndex()
151    */
152   virtual Property::Index GetDefaultPropertyIndex(const std::string& name) const;
153
154   /**
155    * @copydoc Dali::Internal::ProxyObject::IsDefaultPropertyWritable()
156    */
157   virtual bool IsDefaultPropertyWritable(Property::Index index) const;
158
159   /**
160    * @copydoc Dali::Internal::ProxyObject::IsDefaultPropertyAnimatable()
161    */
162   virtual bool IsDefaultPropertyAnimatable(Property::Index index) const;
163
164   /**
165    * @copydoc Dali::Internal::ProxyObject::IsDefaultPropertyAConstraintInput()
166    */
167   virtual bool IsDefaultPropertyAConstraintInput( Property::Index index ) const;
168
169   /**
170    * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyType()
171    */
172   virtual Property::Type GetDefaultPropertyType(Property::Index index) const;
173
174   /**
175    * @copydoc Dali::Internal::ProxyObject::SetDefaultProperty()
176    */
177   virtual void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue);
178
179   /**
180    * @copydoc Dali::Internal::ProxyObject::GetDefaultProperty()
181    */
182   virtual Property::Value GetDefaultProperty( Property::Index index ) const;
183
184 public: // From Actor
185
186   /**
187    * @copydoc Dali::Actor::GetNaturalSize()
188    */
189   virtual Vector3 GetNaturalSize() const;
190
191 private: // From RenderableActor
192
193   /**
194    * @copydoc RenderableActor::GetRenderableAttachment
195    */
196   virtual RenderableAttachment& GetRenderableAttachment() const;
197
198 protected:
199
200   /**
201    * Protected constructor; see also ImageActor::New()
202    */
203   ImageActor();
204
205   /**
206    * A reference counted object may only be deleted by calling Unreference()
207    */
208   virtual ~ImageActor();
209
210 private:
211
212   /**
213    * Helper to set the actor to the image's natural size
214    */
215   void SetNaturalSize();
216
217   /**
218    * Calculate the natural size of this image actor
219    *
220    * @return Return the natural size as a Vector2
221    */
222   Vector2 CalculateNaturalSize() const;
223
224   /**
225    * From Actor.
226    * This is called after SizeSet() has been called.
227    */
228   virtual void OnSizeSet( const Vector3& targetSize );
229
230   /**
231    * @copydoc Actor::OnSizeAnimation( Animation& animation, const Vector3& targetSize )
232    */
233   virtual void OnSizeAnimation(Animation& animation, const Vector3& targetSize);
234
235   /**
236    * From Actor; used to trigger fade-in animations.
237    */
238   virtual void OnStageConnectionInternal();
239
240   /**
241    * From Actor; used to notify Image.
242    */
243   virtual void OnStageDisconnectionInternal();
244
245 private:
246
247   ImageAttachmentPtr mImageAttachment; ///< Used to display the image (holds a pointer to currently showed Image)
248
249   // flags, compressed to bitfield (uses only 1 byte)
250   bool mUsingNaturalSize:1;      ///< True only when the actor is using
251   bool mInternalSetSize:1;       ///< True whilst setting size internally, false at all other times
252
253   static bool mFirstInstance ;
254   static DefaultPropertyLookup* mDefaultImageActorPropertyLookup; ///< Default properties
255
256 };
257
258 } // namespace Internal
259
260 // Helpers for public-api forwarding methods
261
262 inline Internal::ImageActor& GetImplementation(Dali::ImageActor& image)
263 {
264   DALI_ASSERT_ALWAYS(image && "Image handle is empty");
265
266   BaseObject& handle = image.GetBaseObject();
267
268   return static_cast<Internal::ImageActor&>(handle);
269 }
270
271 inline const Internal::ImageActor& GetImplementation(const Dali::ImageActor& image)
272 {
273   DALI_ASSERT_ALWAYS(image && "Image handle is empty");
274
275   const BaseObject& handle = image.GetBaseObject();
276
277   return static_cast<const Internal::ImageActor&>(handle);
278 }
279
280 } // namespace Dali
281
282 #endif // __DALI_INTERNAL_IMAGE_ACTOR_H__