Merge "Fixed bug when delete first row in the tableView" into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / renderers / image / image-renderer.h
1 #ifndef __DALI_TOOLKIT_INTERNAL_IMAGE_RENDERER_H__
2 #define __DALI_TOOLKIT_INTERNAL_IMAGE_RENDERER_H__
3
4 /*
5  * Copyright (c) 2015 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-toolkit/internal/controls/renderers/control-renderer-impl.h>
23
24 // EXTERNAL INCLUDES
25 #include <dali/public-api/images/image.h>
26 #include <dali/public-api/images/image-operations.h>
27 #include <dali/public-api/images/resource-image.h>
28
29 namespace Dali
30 {
31
32 namespace Toolkit
33 {
34
35 namespace Internal
36 {
37
38 class ImageRenderer;
39 typedef IntrusivePtr< ImageRenderer > ImageRendererPtr;
40
41 /**
42  * The renderer which renders an image to the control's quad
43  *
44  * The following properties are optional
45  *
46  * | %Property Name          | Type             |
47  * |-------------------------|------------------|
48  * | imageUrl                | STRING           |
49  * | imageFittingMode        | STRING           |
50  * | imageSamplingMode       | STRING           |
51  * | imageDesiredWidth       | INT              |
52  * | imageDesiredHeight      | INT              |
53  *
54  * where imageFittingMode should be one of the following fitting modes:
55  *   "shrinkToFit"
56  *   "scaleToFill"
57  *   "fitWidth"
58  *   "fitHeight"
59  *   "default"
60  *
61  * where imageSamplingMode should be one of the following sampling modes:
62  *   "box"
63  *   "nearest"
64  *   "linear"
65  *   "boxThenNearest"
66  *   "boxThenLinear"
67  *   "noFilter"
68  *   "dontCare"
69  *   "default"
70  *
71  */
72 class ImageRenderer: public ControlRenderer, public ConnectionTracker
73 {
74 public:
75
76   /**
77    * @brief Constructor.
78    *
79    * @param[in] factoryCache A pointer pointing to the RendererFactoryCache object
80    */
81   ImageRenderer( RendererFactoryCache& factoryCache );
82
83   /**
84    * @brief A reference counted object may only be deleted by calling Unreference().
85    */
86   ~ImageRenderer();
87
88 public:  // from ControlRenderer
89
90   /**
91    * @copydoc ControlRenderer::SetSize
92    */
93   virtual void SetSize( const Vector2& size );
94
95   /**
96    * @copydoc ControlRenderer::GetNaturalSize
97    */
98   virtual void GetNaturalSize( Vector2& naturalSize ) const;
99
100   /**
101    * @copydoc ControlRenderer::SetClipRect
102    */
103   virtual void SetClipRect( const Rect<int>& clipRect );
104
105   /**
106    * @copydoc ControlRenderer::SetOffset
107    */
108   virtual void SetOffset( const Vector2& offset );
109
110   /**
111    * @copydoc ControlRenderer::CreatePropertyMap
112    */
113   virtual void DoCreatePropertyMap( Property::Map& map ) const;
114
115 protected:
116   /**
117    * @copydoc ControlRenderer::DoInitialize
118    */
119   virtual void DoInitialize( Actor& actor, const Property::Map& propertyMap );
120
121   /**
122    * @copydoc ControlRenderer::DoSetOnStage
123    */
124   virtual void DoSetOnStage( Actor& actor );
125
126   /**
127    * @copydoc ControlRenderer::DoSetOffStage
128    */
129   virtual void DoSetOffStage( Actor& actor );
130
131 public:
132
133   /**
134    * @brief Sets the image of this renderer to the resource at imageUrl
135    * The renderer will load the Image asynchronously when the associated actor is put on stage, and destroy the image when it is off stage
136    *
137    * @param[in] actor The Actor the renderer is applied to if, empty if the renderer has not been applied to any Actor
138    * @param[in] imageUrl The URL to to image resource to use
139    */
140   void SetImage( Actor& actor, const std::string& imageUrl );
141
142   /**
143    * @brief Sets the image of this renderer to the resource at imageUrl
144    * The renderer will load the Image asynchronously when the associated actor is put on stage, and destroy the image when it is off stage
145    *
146    * @param[in] actor The Actor the renderer is applied to if, empty if the renderer has not been applied to any Actor
147    * @param[in] imageUrl The URL to to image resource to use
148    * @param[in] desiredWidth The desired width of the resource to load
149    * @param[in] desiredHeight The desired height of the resource to load
150    * @param[in] fittingMode The FittingMode of the resource to load
151    * @param[in] samplingMode The SamplingMode of the resource to load
152    */
153   void SetImage( Actor& actor, const std::string& imageUrl, int desiredWidth, int desiredHeight, Dali::FittingMode::Type fittingMode, Dali::SamplingMode::Type samplingMode );
154
155   /**
156    * @brief Sets the image of this renderer to use
157    *
158    * @param[in] actor The Actor the renderer is applied to if, empty if the renderer has not been applied to any Actor
159    * @param[in] image The image to use
160    */
161   void SetImage( Actor& actor, const Image& image );
162
163 private:
164
165   /**
166    * @brief Applies the image to the material used for this renderer
167    *
168    * @param[in] image The Image to apply to the material used for this renderer
169    */
170   void ApplyImageToSampler( const Image& image );
171
172   /**
173    * @brief Initializes the Dali::Renderer from an image url string
174    *
175    * @param[in] imageUrl The image url string to intialize this ImageRenderer from
176    */
177   void InitializeRenderer( const std::string& imageUrl );
178
179   /**
180    * @brief Initializes the Dali::Renderer from an image handle
181    *
182    * @param[in] image The image handle to intialize this ImageRenderer from
183    */
184   void InitializeRenderer( const Image& image );
185
186   /**
187    * @brief Creates the Dali::Renderer (potentially from the renderer cache), initializing it
188    *
189    * @return Returns the created Dali::Renderer
190    */
191   Renderer CreateRenderer() const;
192
193   /**
194    * Callback function of image resource loading succeed
195    * @param[in] image The Image content that we attempted to load from mImageUrl
196    */
197   void OnImageLoaded( ResourceImage image );
198
199 private:
200   Image mImage;
201
202   std::string mImageUrl;
203   Dali::ImageDimensions mDesiredSize;
204   Dali::FittingMode::Type mFittingMode;
205   Dali::SamplingMode::Type mSamplingMode;
206
207 };
208
209 } // namespace Internal
210
211 } // namespace Toolkit
212
213 } // namespace Dali
214
215 #endif /* __DALI_TOOLKIT_INTERNAL_IMAGE_RENDERER_H__ */