Merge "(AutomatedTests) Ensure warnings are shown as errors" 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/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/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
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::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() const;
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::RenderableActor::SetSortModifier()
103    */
104   void SetSortModifier(float modifier);
105
106   /**
107    * @copydoc Dali::RenderableActor::GetSortModifier()
108    */
109   float GetSortModifier() const;
110
111   /**
112    * @copydoc Dali::RenderableActor::SetCullFace()
113    */
114   void SetCullFace(CullFaceMode mode);
115
116   /**
117    * @copydoc Dali::RenderableActor::GetCullFace()
118    */
119   CullFaceMode GetCullFace() const;
120
121   /**
122    * @copydoc Dali::RenderableActor::SetBlendMode()
123    */
124   void SetBlendMode( BlendingMode::Type mode );
125
126   /**
127    * @copydoc Dali::RenderableActor::GetBlendMode()
128    */
129   BlendingMode::Type GetBlendMode() const;
130
131   /**
132    * @copydoc Dali::RenderableActor::SetBlendFunc()
133    */
134   void SetBlendFunc( BlendingFactor::Type srcFactorRgba,   BlendingFactor::Type destFactorRgba );
135
136   /**
137    * @copydoc Dali::RenderableActor::SetBlendFunc()
138    */
139   void SetBlendFunc( BlendingFactor::Type srcFactorRgb,   BlendingFactor::Type destFactorRgb,
140                      BlendingFactor::Type srcFactorAlpha, BlendingFactor::Type destFactorAlpha );
141
142   /**
143    * @copydoc Dali::RenderableActor::GetBlendFunc()
144    */
145   void GetBlendFunc( BlendingFactor::Type& srcFactorRgb,   BlendingFactor::Type& destFactorRgb,
146                      BlendingFactor::Type& srcFactorAlpha, BlendingFactor::Type& destFactorAlpha ) const;
147
148   /**
149    * @copydoc Dali::RenderableActor::SetBlendEquation()
150    */
151   void SetBlendEquation( BlendingEquation::Type equationRgba );
152
153   /**
154    * @copydoc Dali::RenderableActor::SetBlendEquation()
155    */
156   void SetBlendEquation( BlendingEquation::Type equationRgb, BlendingEquation::Type equationAlpha );
157
158   /**
159    * @copydoc Dali::RenderableActor::GetBlendEquation()
160    */
161   void GetBlendEquation( BlendingEquation::Type& equationRgb, BlendingEquation::Type& equationAlpha ) const;
162
163   /**
164    * @copydoc Dali::RenderableActor::SetBlendColor()
165    */
166   void SetBlendColor( const Vector4& color );
167
168   /**
169    * @copydoc Dali::RenderableActor::GetBlendColor()
170    */
171   const Vector4& GetBlendColor() const;
172
173   /**
174    * @copydoc Dali::RenderableActor::SetFilterMode()
175    */
176   void SetFilterMode( FilterMode::Type minFilter, FilterMode::Type magFilter );
177
178   /**
179    * @copydoc Dali::RenderableActor::GetFilterMode()
180    */
181   void GetFilterMode( FilterMode::Type& minFilter, FilterMode::Type& magFilter ) const;
182
183   /**
184    * @brief Allows this ImageActor to respond to the eventa that the shader effect's effect texture has been changed
185    */
186   void EffectImageUpdated();
187
188 public:
189   /**
190    * @copydoc Actor::SetShaderEffect
191    */
192   virtual void SetShaderEffect(ShaderEffect& effect);
193
194   /**
195    * @copydoc Actor::GetShaderEffect
196    */
197   virtual ShaderEffectPtr GetShaderEffect() const;
198
199   /**
200    * @copydoc Actor::RemoveShaderEffect
201    */
202   virtual void RemoveShaderEffect();
203
204 public: // Default property extensions from Object
205
206   /**
207    * @copydoc Dali::Internal::Object::GetDefaultPropertyCount()
208    */
209   virtual unsigned int GetDefaultPropertyCount() const;
210
211   /**
212    * @copydoc Dali::Internal::Object::GetDefaultPropertyIndices()
213    */
214   virtual void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const;
215
216   /**
217    * @copydoc Dali::Internal::Object::GetDefaultPropertyName()
218    */
219   virtual const char* GetDefaultPropertyName(Property::Index index) const;
220
221   /**
222    * @copydoc Dali::Internal::Object::GetDefaultPropertyIndex()
223    */
224   virtual Property::Index GetDefaultPropertyIndex(const std::string& name) const;
225
226   /**
227    * @copydoc Dali::Internal::Object::IsDefaultPropertyWritable()
228    */
229   virtual bool IsDefaultPropertyWritable(Property::Index index) const;
230
231   /**
232    * @copydoc Dali::Internal::Object::IsDefaultPropertyAnimatable()
233    */
234   virtual bool IsDefaultPropertyAnimatable(Property::Index index) const;
235
236   /**
237    * @copydoc Dali::Internal::Object::IsDefaultPropertyAConstraintInput()
238    */
239   virtual bool IsDefaultPropertyAConstraintInput( Property::Index index ) const;
240
241   /**
242    * @copydoc Dali::Internal::Object::GetDefaultPropertyType()
243    */
244   virtual Property::Type GetDefaultPropertyType(Property::Index index) const;
245
246   /**
247    * @copydoc Dali::Internal::Object::SetDefaultProperty()
248    */
249   virtual void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue);
250
251   /**
252    * @copydoc Dali::Internal::Object::GetDefaultProperty()
253    */
254   virtual Property::Value GetDefaultProperty( Property::Index index ) const;
255
256 public: // From Actor
257
258   /**
259    * @copydoc Dali::Actor::GetNaturalSize()
260    */
261   virtual Vector3 GetNaturalSize() const;
262
263 protected:
264
265   /**
266    * Protected constructor; see also ImageActor::New()
267    */
268   ImageActor();
269
270   /**
271    * A reference counted object may only be deleted by calling Unreference()
272    */
273   virtual ~ImageActor();
274
275 private:
276
277   /**
278    * Calculate the natural size of this image actor
279    *
280    * @return Return the natural size as a Vector2
281    */
282   Vector2 CalculateNaturalSize() const;
283
284   /**
285    * @copydoc Dali::Actor::OnRelayout()
286    */
287   virtual void OnRelayout( const Vector2& size, RelayoutContainer& container );
288
289 private:
290
291   ShaderEffectPtr    mShaderEffect;            ///< Optional referenced shader effect
292   RendererPtr        mRenderer;                ///< The renderer used to render the image
293   PixelArea          mPixelArea;               ///< The pixel area of the image to render
294   Vector4            mBlendColor;              ///< The blend color for this ImageActor
295   int                mRendererIndex;           ///< The index location of mRenderer
296   size_t             mTextureIndex;                        ///< The texture index for this ImageActor's texture
297   size_t             mEffectTextureIndex;      ///< The texture index for this ImageActor's effect texture
298   FilterMode::Type   mMinFilter;               ///< The minification filter currently set
299   FilterMode::Type   mMagFilter;               ///< The magnification filter currently set
300   bool               mIsPixelAreaSet;          ///< Flag indicating if the pixel area has been set
301 };
302
303 } // namespace Internal
304
305 // Helpers for public-api forwarding methods
306
307 inline Internal::ImageActor& GetImplementation(Dali::ImageActor& image)
308 {
309   DALI_ASSERT_ALWAYS(image && "Image handle is empty");
310
311   BaseObject& handle = image.GetBaseObject();
312
313   return static_cast<Internal::ImageActor&>(handle);
314 }
315
316 inline const Internal::ImageActor& GetImplementation(const Dali::ImageActor& image)
317 {
318   DALI_ASSERT_ALWAYS(image && "Image handle is empty");
319
320   const BaseObject& handle = image.GetBaseObject();
321
322   return static_cast<const Internal::ImageActor&>(handle);
323 }
324
325 } // namespace Dali
326
327 #endif // __DALI_INTERNAL_IMAGE_ACTOR_H__