Merge branch devel/master (1.0.49) into tizen
[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/devel-api/rendering/cull-face.h>
25 #include <dali/internal/event/actors/actor-declarations.h>
26 #include <dali/internal/event/actors/actor-impl.h>
27 #include <dali/internal/event/actor-attachments/image-attachment-impl.h>
28 #include <dali/internal/event/animation/animation-impl.h>
29 #include <dali/internal/event/images/nine-patch-image-impl.h>
30
31 namespace Dali
32 {
33
34 namespace Internal
35 {
36
37 class Image;
38
39 /**
40  * An actor which displays an Image object.
41  *
42  * This handles image fade-in if required, waiting for the image to load.
43  *
44  * If a new image is set on the actor, then this ensures that the old image
45  * is displayed until the new image is ready to render to prevent flashing
46  * to the actor color. This will also happen if the image is reloaded.
47  *
48  * This is achieved by using two connector objects to Image: mImageNext and
49  * mImageAttachment's member object. The first one points to the Image object that is going to
50  * be displayed next, the second one to the Image that is currently being displayed.
51  */
52 class ImageActor : public Actor
53 {
54 public:
55
56   typedef Dali::ImageActor::Style Style;
57   typedef Dali::ImageActor::PixelArea PixelArea;
58
59   /**
60    * @brief Create an image actor instance.
61    * @return A smart-pointer to a newly allocated image actor.
62    */
63   static ImageActorPtr New();
64
65   /**
66    * @copydoc Dali::Internal::Actor::OnInitialize
67    */
68   void OnInitialize() ;
69
70   /**
71    * @see Dali::ImageActor::SetImage()
72    * @param[in] ImagePtr reference to the image object to display. Reference to avoid unnecessary increment/decrement reference.
73    */
74   void SetImage( ImagePtr& image );
75
76   /**
77    * Retrieve the image rendered by the actor's attachment.
78    * @return smart pointer to the image or an empty one if no image is assigned
79    */
80   ImagePtr GetImage();
81
82   /**
83    * @copydoc Dali::ImageActor::SetPixelArea()
84    */
85   void SetPixelArea( const PixelArea& pixelArea );
86
87   /**
88    * @copydoc Dali::ImageActor::GetPixelArea()
89    */
90   const PixelArea& GetPixelArea() const;
91
92   /**
93    * @copydoc Dali::ImageActor::IsPixelAreaSet()
94    */
95   bool IsPixelAreaSet() const;
96
97   /**
98    * @copydoc Dali::ImageActor::ClearPixelArea()
99    */
100   void ClearPixelArea();
101
102   /**
103    * @copydoc Dali::ImageActor::SetStyle()
104    */
105   void SetStyle( Style style );
106
107   /**
108    * @copydoc Dali::ImageActor::GetStyle()
109    */
110   Style GetStyle() const;
111
112   /**
113    * @copydoc Dali::ImageActor::SetNinePatchBorder
114    */
115   void SetNinePatchBorder( const Vector4& border, bool inPixels = false );
116
117   /**
118    * @copydoc Dali::ImageActor::GetNinePatchBorder
119    */
120   Vector4 GetNinePatchBorder() const;
121
122   /**
123    * Retrieve the attachment which renders the image.
124    * @return The attachment.
125    */
126   ImageAttachment& GetImageAttachment();
127
128
129   /**
130    * @copydoc Dali::RenderableActor::SetSortModifier()
131    */
132   void SetSortModifier(float modifier);
133
134   /**
135    * @copydoc Dali::RenderableActor::GetSortModifier()
136    */
137   float GetSortModifier() const;
138
139   /**
140    * @copydoc Dali::RenderableActor::SetDepthIndex()
141    */
142   void SetDepthIndex( int depthIndex );
143
144   /**
145    * @copydoc Dali::RenderableActor::GetDepthIndex()
146    */
147   int GetDepthIndex() const;
148
149   /**
150    * @copydoc Dali::RenderableActor::SetCullFace()
151    */
152   void SetCullFace(CullFaceMode mode);
153
154   /**
155    * @copydoc Dali::RenderableActor::GetCullFace()
156    */
157   CullFaceMode GetCullFace() const;
158
159   /**
160    * @copydoc Dali::RenderableActor::SetBlendMode()
161    */
162   void SetBlendMode( BlendingMode::Type mode );
163
164   /**
165    * @copydoc Dali::RenderableActor::GetBlendMode()
166    */
167   BlendingMode::Type GetBlendMode() const;
168
169   /**
170    * @copydoc Dali::RenderableActor::SetBlendFunc()
171    */
172   void SetBlendFunc( BlendingFactor::Type srcFactorRgba,   BlendingFactor::Type destFactorRgba );
173
174   /**
175    * @copydoc Dali::RenderableActor::SetBlendFunc()
176    */
177   void SetBlendFunc( BlendingFactor::Type srcFactorRgb,   BlendingFactor::Type destFactorRgb,
178                      BlendingFactor::Type srcFactorAlpha, BlendingFactor::Type destFactorAlpha );
179
180   /**
181    * @copydoc Dali::RenderableActor::GetBlendFunc()
182    */
183   void GetBlendFunc( BlendingFactor::Type& srcFactorRgb,   BlendingFactor::Type& destFactorRgb,
184                      BlendingFactor::Type& srcFactorAlpha, BlendingFactor::Type& destFactorAlpha ) const;
185
186   /**
187    * @copydoc Dali::RenderableActor::SetBlendEquation()
188    */
189   void SetBlendEquation( BlendingEquation::Type equationRgba );
190
191   /**
192    * @copydoc Dali::RenderableActor::SetBlendEquation()
193    */
194   void SetBlendEquation( BlendingEquation::Type equationRgb, BlendingEquation::Type equationAlpha );
195
196   /**
197    * @copydoc Dali::RenderableActor::GetBlendEquation()
198    */
199   void GetBlendEquation( BlendingEquation::Type& equationRgb, BlendingEquation::Type& equationAlpha ) const;
200
201   /**
202    * @copydoc Dali::RenderableActor::SetBlendColor()
203    */
204   void SetBlendColor( const Vector4& color );
205
206   /**
207    * @copydoc Dali::RenderableActor::GetBlendColor()
208    */
209   const Vector4& GetBlendColor() const;
210
211   /**
212    * @copydoc Dali::RenderableActor::SetFilterMode()
213    */
214   void SetFilterMode( FilterMode::Type minFilter, FilterMode::Type magFilter );
215
216   /**
217    * @copydoc Dali::RenderableActor::GetFilterMode()
218    */
219   void GetFilterMode( FilterMode::Type& minFilter, FilterMode::Type& magFilter ) const;
220
221 public:
222   /**
223    * @copydoc Actor::SetShaderEffect
224    */
225   virtual void SetShaderEffect(ShaderEffect& effect);
226
227   /**
228    * @copydoc Actor::GetShaderEffect
229    */
230   virtual ShaderEffectPtr GetShaderEffect() const;
231
232   /**
233    * @copydoc Actor::RemoveShaderEffect
234    */
235   virtual void RemoveShaderEffect();
236
237 public: // Default property extensions from Object
238
239   /**
240    * @copydoc Dali::Internal::Object::GetDefaultPropertyCount()
241    */
242   virtual unsigned int GetDefaultPropertyCount() const;
243
244   /**
245    * @copydoc Dali::Internal::Object::GetDefaultPropertyIndices()
246    */
247   virtual void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const;
248
249   /**
250    * @copydoc Dali::Internal::Object::GetDefaultPropertyName()
251    */
252   virtual const char* GetDefaultPropertyName(Property::Index index) const;
253
254   /**
255    * @copydoc Dali::Internal::Object::GetDefaultPropertyIndex()
256    */
257   virtual Property::Index GetDefaultPropertyIndex(const std::string& name) const;
258
259   /**
260    * @copydoc Dali::Internal::Object::IsDefaultPropertyWritable()
261    */
262   virtual bool IsDefaultPropertyWritable(Property::Index index) const;
263
264   /**
265    * @copydoc Dali::Internal::Object::IsDefaultPropertyAnimatable()
266    */
267   virtual bool IsDefaultPropertyAnimatable(Property::Index index) const;
268
269   /**
270    * @copydoc Dali::Internal::Object::IsDefaultPropertyAConstraintInput()
271    */
272   virtual bool IsDefaultPropertyAConstraintInput( Property::Index index ) const;
273
274   /**
275    * @copydoc Dali::Internal::Object::GetDefaultPropertyType()
276    */
277   virtual Property::Type GetDefaultPropertyType(Property::Index index) const;
278
279   /**
280    * @copydoc Dali::Internal::Object::SetDefaultProperty()
281    */
282   virtual void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue);
283
284   /**
285    * @copydoc Dali::Internal::Object::GetDefaultProperty()
286    */
287   virtual Property::Value GetDefaultProperty( Property::Index index ) const;
288
289 public: // From Actor
290
291   /**
292    * @copydoc Dali::Actor::GetNaturalSize()
293    */
294   virtual Vector3 GetNaturalSize() const;
295
296 private: // From RenderableActor
297
298   /**
299    * @copydoc RenderableActor::GetRenderableAttachment
300    */
301   virtual RenderableAttachment& GetRenderableAttachment() const;
302
303 protected:
304
305   /**
306    * Protected constructor; see also ImageActor::New()
307    */
308   ImageActor();
309
310   /**
311    * A reference counted object may only be deleted by calling Unreference()
312    */
313   virtual ~ImageActor();
314
315 private:
316
317   /**
318    * Calculate the natural size of this image actor
319    *
320    * @return Return the natural size as a Vector2
321    */
322   Vector2 CalculateNaturalSize() const;
323
324   /**
325    * From Actor; used to trigger fade-in animations.
326    */
327   virtual void OnStageConnectionInternal();
328
329   /**
330    * From Actor; used to notify Image.
331    */
332   virtual void OnStageDisconnectionInternal();
333
334 private:
335
336   ImageAttachmentPtr mImageAttachment; ///< Used to display the image (holds a pointer to currently showed Image)
337
338 };
339
340 } // namespace Internal
341
342 // Helpers for public-api forwarding methods
343
344 inline Internal::ImageActor& GetImplementation(Dali::ImageActor& image)
345 {
346   DALI_ASSERT_ALWAYS(image && "Image handle is empty");
347
348   BaseObject& handle = image.GetBaseObject();
349
350   return static_cast<Internal::ImageActor&>(handle);
351 }
352
353 inline const Internal::ImageActor& GetImplementation(const Dali::ImageActor& image)
354 {
355   DALI_ASSERT_ALWAYS(image && "Image handle is empty");
356
357   const BaseObject& handle = image.GetBaseObject();
358
359   return static_cast<const Internal::ImageActor&>(handle);
360 }
361
362 } // namespace Dali
363
364 #endif // __DALI_INTERNAL_IMAGE_ACTOR_H__