[3.0] Mark Clipping API as being part of the Tizen 3 version
[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/internal/event/actors/actor-declarations.h>
26 #include <dali/internal/event/actors/actor-impl.h>
27 #include <dali/internal/event/animation/animation-impl.h>
28 #include <dali/internal/event/effects/shader-effect-impl.h>
29 #include <dali/internal/event/images/nine-patch-image-impl.h>
30 #include <dali/internal/event/rendering/texture-set-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.
42  */
43 class ImageActor : public Actor
44 {
45 public:
46
47   typedef Dali::ImageActor::PixelArea PixelArea;
48
49   /**
50    * @brief Create an image actor instance.
51    * @return A smart-pointer to a newly allocated image actor.
52    */
53   static ImageActorPtr New();
54
55   /**
56    * @copydoc Dali::Internal::Actor::OnInitialize
57    */
58   void OnInitialize() ;
59
60   /**
61    * @see Dali::ImageActor::SetImage()
62    * @param[in] ImagePtr reference to the image object to display. Reference to avoid unnecessary increment/decrement reference.
63    */
64   void SetImage( ImagePtr& image );
65
66   /**
67    * Retrieve the image rendered by the actor.
68    * @return smart pointer to the image or an empty one if no image is assigned
69    */
70   ImagePtr GetImage() const;
71
72   /**
73    * @copydoc Dali::ImageActor::SetPixelArea()
74    */
75   void SetPixelArea( const PixelArea& pixelArea );
76
77   /**
78    * @copydoc Dali::ImageActor::GetPixelArea()
79    */
80   const PixelArea& GetPixelArea() const;
81
82   /**
83    * @copydoc Dali::ImageActor::IsPixelAreaSet()
84    */
85   bool IsPixelAreaSet() const;
86
87   /**
88    * @copydoc Dali::ImageActor::ClearPixelArea()
89    */
90   void ClearPixelArea();
91
92   /**
93    * @copydoc Dali::ImageActor::SetStyle()
94    */
95   void SetStyle( Dali::ImageActor::Style style );
96
97   /**
98    * @copydoc Dali::ImageActor::GetStyle()
99    */
100   Dali::ImageActor::Style GetStyle() const;
101
102   /**
103    * @copydoc Dali::ImageActor::SetNinePatchBorder()
104    */
105   void SetNinePatchBorder( const Vector4& border );
106
107   /**
108    * @copydoc Dali::ImageActor::GetNinePatchBorder()
109    */
110   Vector4 GetNinePatchBorder() const;
111
112   /**
113    * @copydoc Dali::RenderableActor::SetSortModifier()
114    */
115   void SetSortModifier(float modifier);
116
117   /**
118    * @copydoc Dali::RenderableActor::GetSortModifier()
119    */
120   float GetSortModifier() const;
121
122   /**
123    * @copydoc Dali::RenderableActor::SetBlendMode()
124    */
125   void SetBlendMode( BlendingMode::Type mode );
126
127   /**
128    * @copydoc Dali::RenderableActor::GetBlendMode()
129    */
130   BlendingMode::Type GetBlendMode() const;
131
132   /**
133    * @copydoc Dali::RenderableActor::SetBlendFunc()
134    */
135   void SetBlendFunc( BlendingFactor::Type srcFactorRgba,   BlendingFactor::Type destFactorRgba );
136
137   /**
138    * @copydoc Dali::RenderableActor::SetBlendFunc()
139    */
140   void SetBlendFunc( BlendingFactor::Type srcFactorRgb,   BlendingFactor::Type destFactorRgb,
141                      BlendingFactor::Type srcFactorAlpha, BlendingFactor::Type destFactorAlpha );
142
143   /**
144    * @copydoc Dali::RenderableActor::GetBlendFunc()
145    */
146   void GetBlendFunc( BlendingFactor::Type& srcFactorRgb,   BlendingFactor::Type& destFactorRgb,
147                      BlendingFactor::Type& srcFactorAlpha, BlendingFactor::Type& destFactorAlpha ) const;
148
149   /**
150    * @copydoc Dali::RenderableActor::SetBlendEquation()
151    */
152   void SetBlendEquation( BlendingEquation::Type equationRgba );
153
154   /**
155    * @copydoc Dali::RenderableActor::SetBlendEquation()
156    */
157   void SetBlendEquation( BlendingEquation::Type equationRgb, BlendingEquation::Type equationAlpha );
158
159   /**
160    * @copydoc Dali::RenderableActor::GetBlendEquation()
161    */
162   void GetBlendEquation( BlendingEquation::Type& equationRgb, BlendingEquation::Type& equationAlpha ) const;
163
164   /**
165    * @copydoc Dali::RenderableActor::SetBlendColor()
166    */
167   void SetBlendColor( const Vector4& color );
168
169   /**
170    * @copydoc Dali::RenderableActor::GetBlendColor()
171    */
172   const Vector4& GetBlendColor() const;
173
174   /**
175    * @copydoc Dali::RenderableActor::SetFilterMode()
176    */
177   void SetFilterMode( FilterMode::Type minFilter, FilterMode::Type magFilter );
178
179   /**
180    * @copydoc Dali::RenderableActor::GetFilterMode()
181    */
182   void GetFilterMode( FilterMode::Type& minFilter, FilterMode::Type& magFilter ) const;
183
184   /**
185    * @brief Allows this ImageActor to respond to the eventa that the shader effect's effect texture has been changed
186    */
187   void EffectImageUpdated();
188
189 public:
190   /**
191    * @copydoc Actor::SetShaderEffect
192    */
193   virtual void SetShaderEffect(ShaderEffect& effect);
194
195   /**
196    * @copydoc Actor::GetShaderEffect
197    */
198   virtual ShaderEffectPtr GetShaderEffect() const;
199
200   /**
201    * @copydoc Actor::RemoveShaderEffect
202    */
203   virtual void RemoveShaderEffect();
204
205 private:
206
207   /**
208    * @copydoc Actor::OnRelayout
209    */
210   virtual void OnRelayout( const Vector2& size, RelayoutContainer& container );
211
212   /**
213    * @copydoc Actor::OnSizeSet
214    */
215   virtual void OnSizeSet( const Vector3& targetSize );
216
217 public: // Default property extensions from Object
218
219   /**
220    * @copydoc Dali::Internal::Object::GetDefaultPropertyCount()
221    */
222   virtual unsigned int GetDefaultPropertyCount() const;
223
224   /**
225    * @copydoc Dali::Internal::Object::GetDefaultPropertyIndices()
226    */
227   virtual void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const;
228
229   /**
230    * @copydoc Dali::Internal::Object::GetDefaultPropertyName()
231    */
232   virtual const char* GetDefaultPropertyName(Property::Index index) const;
233
234   /**
235    * @copydoc Dali::Internal::Object::GetDefaultPropertyIndex()
236    */
237   virtual Property::Index GetDefaultPropertyIndex(const std::string& name) const;
238
239   /**
240    * @copydoc Dali::Internal::Object::IsDefaultPropertyWritable()
241    */
242   virtual bool IsDefaultPropertyWritable(Property::Index index) const;
243
244   /**
245    * @copydoc Dali::Internal::Object::IsDefaultPropertyAnimatable()
246    */
247   virtual bool IsDefaultPropertyAnimatable(Property::Index index) const;
248
249   /**
250    * @copydoc Dali::Internal::Object::IsDefaultPropertyAConstraintInput()
251    */
252   virtual bool IsDefaultPropertyAConstraintInput( Property::Index index ) const;
253
254   /**
255    * @copydoc Dali::Internal::Object::GetDefaultPropertyType()
256    */
257   virtual Property::Type GetDefaultPropertyType(Property::Index index) const;
258
259   /**
260    * @copydoc Dali::Internal::Object::SetDefaultProperty()
261    */
262   virtual void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue);
263
264   /**
265    * @copydoc Dali::Internal::Object::GetDefaultProperty()
266    */
267   virtual Property::Value GetDefaultProperty( Property::Index index ) const;
268
269 public: // From Actor
270
271   /**
272    * @copydoc Dali::Actor::GetNaturalSize()
273    */
274   virtual Vector3 GetNaturalSize() const;
275
276 protected:
277
278   /**
279    * Protected constructor; see also ImageActor::New()
280    */
281   ImageActor();
282
283   /**
284    * A reference counted object may only be deleted by calling Unreference()
285    */
286   virtual ~ImageActor();
287
288 private:
289
290   /**
291    * Calculate the natural size of this image actor
292    *
293    * @return Return the natural size as a Vector2
294    */
295   Vector2 CalculateNaturalSize() const;
296
297   /**
298    * Update the grid geometry.
299    */
300   void UpdateGeometry();
301
302   /**
303    * Update the texture rect uniform
304    */
305   void UpdateTexureRect();
306
307 private:
308
309   ShaderEffectPtr         mShaderEffect;            ///< Optional referenced shader effect
310   RendererPtr             mRenderer;                ///< The renderer used to render the image
311   PixelArea               mPixelArea;               ///< The pixel area of the image to render
312   Vector4                 mBlendColor;              ///< The blend color for this ImageActor
313   Vector4                 mNinePatchBorder;         ///< Nine-patch not supported, but this is used to store what is set so it can be returned for backwards compatibility.
314   Vector2                 mActorSize;               ///< The actor size
315   Uint16Pair              mGridSize;                ///< The geometry grid size
316   int                     mRendererIndex;           ///< The index location of mRenderer
317   FilterMode::Type        mMinFilter;               ///< The minification filter currently set
318   FilterMode::Type        mMagFilter;               ///< The magnification filter currently set
319   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.
320   bool                    mIsPixelAreaSet;          ///< Flag indicating if the pixel area has been set
321 };
322
323 } // namespace Internal
324
325 // Helpers for public-api forwarding methods
326
327 inline Internal::ImageActor& GetImplementation(Dali::ImageActor& image)
328 {
329   DALI_ASSERT_ALWAYS(image && "Image handle is empty");
330
331   BaseObject& handle = image.GetBaseObject();
332
333   return static_cast<Internal::ImageActor&>(handle);
334 }
335
336 inline const Internal::ImageActor& GetImplementation(const Dali::ImageActor& image)
337 {
338   DALI_ASSERT_ALWAYS(image && "Image handle is empty");
339
340   const BaseObject& handle = image.GetBaseObject();
341
342   return static_cast<const Internal::ImageActor&>(handle);
343 }
344
345 } // namespace Dali
346
347 #endif // __DALI_INTERNAL_IMAGE_ACTOR_H__