Merge branch 'devel/new_mesh' into devel/master
[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::SetPixelArea()
83    */
84   void SetPixelArea( const PixelArea& pixelArea );
85
86   /**
87    * @copydoc Dali::ImageActor::GetPixelArea()
88    */
89   const PixelArea& GetPixelArea() const;
90
91   /**
92    * @copydoc Dali::ImageActor::IsPixelAreaSet()
93    */
94   bool IsPixelAreaSet() const;
95
96   /**
97    * @copydoc Dali::ImageActor::ClearPixelArea()
98    */
99   void ClearPixelArea();
100
101   /**
102    * @copydoc Dali::ImageActor::SetStyle()
103    */
104   void SetStyle( Style style );
105
106   /**
107    * @copydoc Dali::ImageActor::GetStyle()
108    */
109   Style GetStyle() const;
110
111   /**
112    * @copydoc Dali::ImageActor::SetNinePatchBorder
113    */
114   void SetNinePatchBorder( const Vector4& border, bool inPixels = false );
115
116   /**
117    * @copydoc Dali::ImageActor::GetNinePatchBorder
118    */
119   Vector4 GetNinePatchBorder() const;
120
121   /**
122    * Retrieve the attachment which renders the image.
123    * @return The attachment.
124    */
125   ImageAttachment& GetImageAttachment();
126
127
128   /**
129    * @copydoc Dali::RenderableActor::SetSortModifier()
130    */
131   void SetSortModifier(float modifier);
132
133   /**
134    * @copydoc Dali::RenderableActor::GetSortModifier()
135    */
136   float GetSortModifier() const;
137
138   /**
139    * @copydoc Dali::RenderableActor::SetDepthIndex()
140    */
141   void SetDepthIndex( int depthIndex );
142
143   /**
144    * @copydoc Dali::RenderableActor::GetDepthIndex()
145    */
146   int GetDepthIndex() const;
147
148   /**
149    * @copydoc Dali::RenderableActor::SetCullFace()
150    */
151   void SetCullFace(CullFaceMode mode);
152
153   /**
154    * @copydoc Dali::RenderableActor::GetCullFace()
155    */
156   CullFaceMode GetCullFace() const;
157
158   /**
159    * @copydoc Dali::RenderableActor::SetBlendMode()
160    */
161   void SetBlendMode( BlendingMode::Type mode );
162
163   /**
164    * @copydoc Dali::RenderableActor::GetBlendMode()
165    */
166   BlendingMode::Type GetBlendMode() const;
167
168   /**
169    * @copydoc Dali::RenderableActor::SetBlendFunc()
170    */
171   void SetBlendFunc( BlendingFactor::Type srcFactorRgba,   BlendingFactor::Type destFactorRgba );
172
173   /**
174    * @copydoc Dali::RenderableActor::SetBlendFunc()
175    */
176   void SetBlendFunc( BlendingFactor::Type srcFactorRgb,   BlendingFactor::Type destFactorRgb,
177                      BlendingFactor::Type srcFactorAlpha, BlendingFactor::Type destFactorAlpha );
178
179   /**
180    * @copydoc Dali::RenderableActor::GetBlendFunc()
181    */
182   void GetBlendFunc( BlendingFactor::Type& srcFactorRgb,   BlendingFactor::Type& destFactorRgb,
183                      BlendingFactor::Type& srcFactorAlpha, BlendingFactor::Type& destFactorAlpha ) const;
184
185   /**
186    * @copydoc Dali::RenderableActor::SetBlendEquation()
187    */
188   void SetBlendEquation( BlendingEquation::Type equationRgba );
189
190   /**
191    * @copydoc Dali::RenderableActor::SetBlendEquation()
192    */
193   void SetBlendEquation( BlendingEquation::Type equationRgb, BlendingEquation::Type equationAlpha );
194
195   /**
196    * @copydoc Dali::RenderableActor::GetBlendEquation()
197    */
198   void GetBlendEquation( BlendingEquation::Type& equationRgb, BlendingEquation::Type& equationAlpha ) const;
199
200   /**
201    * @copydoc Dali::RenderableActor::SetBlendColor()
202    */
203   void SetBlendColor( const Vector4& color );
204
205   /**
206    * @copydoc Dali::RenderableActor::GetBlendColor()
207    */
208   const Vector4& GetBlendColor() const;
209
210   /**
211    * @copydoc Dali::RenderableActor::SetFilterMode()
212    */
213   void SetFilterMode( FilterMode::Type minFilter, FilterMode::Type magFilter );
214
215   /**
216    * @copydoc Dali::RenderableActor::GetFilterMode()
217    */
218   void GetFilterMode( FilterMode::Type& minFilter, FilterMode::Type& magFilter ) const;
219
220 public:
221   /**
222    * @copydoc Actor::SetShaderEffect
223    */
224   virtual void SetShaderEffect(ShaderEffect& effect);
225
226   /**
227    * @copydoc Actor::GetShaderEffect
228    */
229   virtual ShaderEffectPtr GetShaderEffect() const;
230
231   /**
232    * @copydoc Actor::RemoveShaderEffect
233    */
234   virtual void RemoveShaderEffect();
235
236 public: // Default property extensions from Object
237
238   /**
239    * @copydoc Dali::Internal::Object::GetDefaultPropertyCount()
240    */
241   virtual unsigned int GetDefaultPropertyCount() const;
242
243   /**
244    * @copydoc Dali::Internal::Object::GetDefaultPropertyIndices()
245    */
246   virtual void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const;
247
248   /**
249    * @copydoc Dali::Internal::Object::GetDefaultPropertyName()
250    */
251   virtual const char* GetDefaultPropertyName(Property::Index index) const;
252
253   /**
254    * @copydoc Dali::Internal::Object::GetDefaultPropertyIndex()
255    */
256   virtual Property::Index GetDefaultPropertyIndex(const std::string& name) const;
257
258   /**
259    * @copydoc Dali::Internal::Object::IsDefaultPropertyWritable()
260    */
261   virtual bool IsDefaultPropertyWritable(Property::Index index) const;
262
263   /**
264    * @copydoc Dali::Internal::Object::IsDefaultPropertyAnimatable()
265    */
266   virtual bool IsDefaultPropertyAnimatable(Property::Index index) const;
267
268   /**
269    * @copydoc Dali::Internal::Object::IsDefaultPropertyAConstraintInput()
270    */
271   virtual bool IsDefaultPropertyAConstraintInput( Property::Index index ) const;
272
273   /**
274    * @copydoc Dali::Internal::Object::GetDefaultPropertyType()
275    */
276   virtual Property::Type GetDefaultPropertyType(Property::Index index) const;
277
278   /**
279    * @copydoc Dali::Internal::Object::SetDefaultProperty()
280    */
281   virtual void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue);
282
283   /**
284    * @copydoc Dali::Internal::Object::GetDefaultProperty()
285    */
286   virtual Property::Value GetDefaultProperty( Property::Index index ) const;
287
288 public: // From Actor
289
290   /**
291    * @copydoc Dali::Actor::GetNaturalSize()
292    */
293   virtual Vector3 GetNaturalSize() const;
294
295 private: // From RenderableActor
296
297   /**
298    * @copydoc RenderableActor::GetRenderableAttachment
299    */
300   virtual RenderableAttachment& GetRenderableAttachment() const;
301
302 protected:
303
304   /**
305    * Protected constructor; see also ImageActor::New()
306    */
307   ImageActor();
308
309   /**
310    * A reference counted object may only be deleted by calling Unreference()
311    */
312   virtual ~ImageActor();
313
314 private:
315
316   /**
317    * Calculate the natural size of this image actor
318    *
319    * @return Return the natural size as a Vector2
320    */
321   Vector2 CalculateNaturalSize() const;
322
323   /**
324    * From Actor; used to trigger fade-in animations.
325    */
326   virtual void OnStageConnectionInternal();
327
328   /**
329    * From Actor; used to notify Image.
330    */
331   virtual void OnStageDisconnectionInternal();
332
333 private:
334
335   ImageAttachmentPtr mImageAttachment; ///< Used to display the image (holds a pointer to currently showed Image)
336
337 };
338
339 } // namespace Internal
340
341 // Helpers for public-api forwarding methods
342
343 inline Internal::ImageActor& GetImplementation(Dali::ImageActor& image)
344 {
345   DALI_ASSERT_ALWAYS(image && "Image handle is empty");
346
347   BaseObject& handle = image.GetBaseObject();
348
349   return static_cast<Internal::ImageActor&>(handle);
350 }
351
352 inline const Internal::ImageActor& GetImplementation(const Dali::ImageActor& image)
353 {
354   DALI_ASSERT_ALWAYS(image && "Image handle is empty");
355
356   const BaseObject& handle = image.GetBaseObject();
357
358   return static_cast<const Internal::ImageActor&>(handle);
359 }
360
361 } // namespace Dali
362
363 #endif // __DALI_INTERNAL_IMAGE_ACTOR_H__