Merge branch 'devel/master (1.1.16)' 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/public-api/math/uint-16-pair.h>
25 #include <dali/devel-api/rendering/cull-face.h>
26 #include <dali/internal/event/actors/actor-declarations.h>
27 #include <dali/internal/event/actors/actor-impl.h>
28 #include <dali/internal/event/animation/animation-impl.h>
29 #include <dali/internal/event/effects/shader-effect-impl.h>
30 #include <dali/internal/event/images/nine-patch-image-impl.h>
31
32 namespace Dali
33 {
34
35 namespace Internal
36 {
37
38 class Image;
39
40 /**
41  * An actor which displays an Image object.
42  *
43  * This handles image fade-in if required, waiting for the image to load.
44  *
45  * If a new image is set on the actor, then this ensures that the old image
46  * is displayed until the new image is ready to render to prevent flashing
47  * to the actor color. This will also happen if the image is reloaded.
48  *
49  * This is achieved by using two connector objects to Image: mImageNext and
50  * mImageAttachment's member object. The first one points to the Image object that is going to
51  * be displayed next, the second one to the Image that is currently being displayed.
52  */
53 class ImageActor : public Actor
54 {
55 public:
56
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() const;
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( Dali::ImageActor::Style style );
106
107   /**
108    * @copydoc Dali::ImageActor::GetStyle()
109    */
110   Dali::ImageActor::Style GetStyle() const;
111
112   /**
113    * @copydoc Dali::ImageActor::SetNinePatchBorder()
114    */
115   void SetNinePatchBorder( const Vector4& border );
116
117   /**
118    * @copydoc Dali::ImageActor::GetNinePatchBorder()
119    */
120   Vector4 GetNinePatchBorder() const;
121
122   /**
123    * @copydoc Dali::RenderableActor::SetSortModifier()
124    */
125   void SetSortModifier(float modifier);
126
127   /**
128    * @copydoc Dali::RenderableActor::GetSortModifier()
129    */
130   float GetSortModifier() const;
131
132   /**
133    * @copydoc Dali::RenderableActor::SetCullFace()
134    */
135   void SetCullFace(CullFaceMode mode);
136
137   /**
138    * @copydoc Dali::RenderableActor::GetCullFace()
139    */
140   CullFaceMode GetCullFace() const;
141
142   /**
143    * @copydoc Dali::RenderableActor::SetBlendMode()
144    */
145   void SetBlendMode( BlendingMode::Type mode );
146
147   /**
148    * @copydoc Dali::RenderableActor::GetBlendMode()
149    */
150   BlendingMode::Type GetBlendMode() const;
151
152   /**
153    * @copydoc Dali::RenderableActor::SetBlendFunc()
154    */
155   void SetBlendFunc( BlendingFactor::Type srcFactorRgba,   BlendingFactor::Type destFactorRgba );
156
157   /**
158    * @copydoc Dali::RenderableActor::SetBlendFunc()
159    */
160   void SetBlendFunc( BlendingFactor::Type srcFactorRgb,   BlendingFactor::Type destFactorRgb,
161                      BlendingFactor::Type srcFactorAlpha, BlendingFactor::Type destFactorAlpha );
162
163   /**
164    * @copydoc Dali::RenderableActor::GetBlendFunc()
165    */
166   void GetBlendFunc( BlendingFactor::Type& srcFactorRgb,   BlendingFactor::Type& destFactorRgb,
167                      BlendingFactor::Type& srcFactorAlpha, BlendingFactor::Type& destFactorAlpha ) const;
168
169   /**
170    * @copydoc Dali::RenderableActor::SetBlendEquation()
171    */
172   void SetBlendEquation( BlendingEquation::Type equationRgba );
173
174   /**
175    * @copydoc Dali::RenderableActor::SetBlendEquation()
176    */
177   void SetBlendEquation( BlendingEquation::Type equationRgb, BlendingEquation::Type equationAlpha );
178
179   /**
180    * @copydoc Dali::RenderableActor::GetBlendEquation()
181    */
182   void GetBlendEquation( BlendingEquation::Type& equationRgb, BlendingEquation::Type& equationAlpha ) const;
183
184   /**
185    * @copydoc Dali::RenderableActor::SetBlendColor()
186    */
187   void SetBlendColor( const Vector4& color );
188
189   /**
190    * @copydoc Dali::RenderableActor::GetBlendColor()
191    */
192   const Vector4& GetBlendColor() const;
193
194   /**
195    * @copydoc Dali::RenderableActor::SetFilterMode()
196    */
197   void SetFilterMode( FilterMode::Type minFilter, FilterMode::Type magFilter );
198
199   /**
200    * @copydoc Dali::RenderableActor::GetFilterMode()
201    */
202   void GetFilterMode( FilterMode::Type& minFilter, FilterMode::Type& magFilter ) const;
203
204   /**
205    * @brief Allows this ImageActor to respond to the eventa that the shader effect's effect texture has been changed
206    */
207   void EffectImageUpdated();
208
209 public:
210   /**
211    * @copydoc Actor::SetShaderEffect
212    */
213   virtual void SetShaderEffect(ShaderEffect& effect);
214
215   /**
216    * @copydoc Actor::GetShaderEffect
217    */
218   virtual ShaderEffectPtr GetShaderEffect() const;
219
220   /**
221    * @copydoc Actor::RemoveShaderEffect
222    */
223   virtual void RemoveShaderEffect();
224
225 public: // Default property extensions from Object
226
227   /**
228    * @copydoc Dali::Internal::Object::GetDefaultPropertyCount()
229    */
230   virtual unsigned int GetDefaultPropertyCount() const;
231
232   /**
233    * @copydoc Dali::Internal::Object::GetDefaultPropertyIndices()
234    */
235   virtual void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const;
236
237   /**
238    * @copydoc Dali::Internal::Object::GetDefaultPropertyName()
239    */
240   virtual const char* GetDefaultPropertyName(Property::Index index) const;
241
242   /**
243    * @copydoc Dali::Internal::Object::GetDefaultPropertyIndex()
244    */
245   virtual Property::Index GetDefaultPropertyIndex(const std::string& name) const;
246
247   /**
248    * @copydoc Dali::Internal::Object::IsDefaultPropertyWritable()
249    */
250   virtual bool IsDefaultPropertyWritable(Property::Index index) const;
251
252   /**
253    * @copydoc Dali::Internal::Object::IsDefaultPropertyAnimatable()
254    */
255   virtual bool IsDefaultPropertyAnimatable(Property::Index index) const;
256
257   /**
258    * @copydoc Dali::Internal::Object::IsDefaultPropertyAConstraintInput()
259    */
260   virtual bool IsDefaultPropertyAConstraintInput( Property::Index index ) const;
261
262   /**
263    * @copydoc Dali::Internal::Object::GetDefaultPropertyType()
264    */
265   virtual Property::Type GetDefaultPropertyType(Property::Index index) const;
266
267   /**
268    * @copydoc Dali::Internal::Object::SetDefaultProperty()
269    */
270   virtual void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue);
271
272   /**
273    * @copydoc Dali::Internal::Object::GetDefaultProperty()
274    */
275   virtual Property::Value GetDefaultProperty( Property::Index index ) const;
276
277 public: // From Actor
278
279   /**
280    * @copydoc Dali::Actor::GetNaturalSize()
281    */
282   virtual Vector3 GetNaturalSize() const;
283
284 protected:
285
286   /**
287    * Protected constructor; see also ImageActor::New()
288    */
289   ImageActor();
290
291   /**
292    * A reference counted object may only be deleted by calling Unreference()
293    */
294   virtual ~ImageActor();
295
296 private:
297
298   /**
299    * Calculate the natural size of this image actor
300    *
301    * @return Return the natural size as a Vector2
302    */
303   Vector2 CalculateNaturalSize() const;
304
305   /**
306    * Update the grid geometry.
307    */
308   void UpdateGeometry();
309
310   /**
311    * Update the texture rect uniform
312    */
313   void UpdateTexureRect();
314
315 private:
316
317   ShaderEffectPtr         mShaderEffect;            ///< Optional referenced shader effect
318   RendererPtr             mRenderer;                ///< The renderer used to render the image
319   PixelArea               mPixelArea;               ///< The pixel area of the image to render
320   Vector4                 mBlendColor;              ///< The blend color for this ImageActor
321   Vector4                 mNinePatchBorder;         ///< Nine-patch not supported, but this is used to store what is set so it can be returned for backwards compatibility.
322   Uint16Pair              mGridSize;                ///< The geometry grid size
323   int                     mRendererIndex;           ///< The index location of mRenderer
324   size_t                  mTextureIndex;            ///< The texture index for this ImageActor's texture
325   size_t                  mEffectTextureIndex;      ///< The texture index for this ImageActor's effect texture
326   FilterMode::Type        mMinFilter;               ///< The minification filter currently set
327   FilterMode::Type        mMagFilter;               ///< The magnification filter currently set
328   Dali::ImageActor::Style mStyle;                   ///< The style set by SetStyle. Not used internally, only used to store what is set so it can be returned for backwards compatibility.
329   bool                    mIsPixelAreaSet;          ///< Flag indicating if the pixel area has been set
330 };
331
332 } // namespace Internal
333
334 // Helpers for public-api forwarding methods
335
336 inline Internal::ImageActor& GetImplementation(Dali::ImageActor& image)
337 {
338   DALI_ASSERT_ALWAYS(image && "Image handle is empty");
339
340   BaseObject& handle = image.GetBaseObject();
341
342   return static_cast<Internal::ImageActor&>(handle);
343 }
344
345 inline const Internal::ImageActor& GetImplementation(const Dali::ImageActor& image)
346 {
347   DALI_ASSERT_ALWAYS(image && "Image handle is empty");
348
349   const BaseObject& handle = image.GetBaseObject();
350
351   return static_cast<const Internal::ImageActor&>(handle);
352 }
353
354 } // namespace Dali
355
356 #endif // __DALI_INTERNAL_IMAGE_ACTOR_H__