PixelArea support for ImageView
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / public-api / controls / image-view / image-view.h
1 #ifndef __DALI_TOOLKIT_IMAGE_VIEW_H__
2 #define __DALI_TOOLKIT_IMAGE_VIEW_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/public-api/controls/control.h>
23
24 // EXTERNAL INCLUDES
25 #include <dali/public-api/images/image-operations.h>
26
27 namespace Dali
28 {
29
30 namespace Toolkit
31 {
32
33 namespace Internal DALI_INTERNAL
34 {
35 class ImageView;
36 }
37 /**
38  * @addtogroup dali_toolkit_controls_image_view
39  * @{
40  */
41
42 /**
43  *
44  * @brief ImageView is a class for displaying an Image.
45  */
46 class DALI_IMPORT_API ImageView : public Control
47 {
48 public:
49   /**
50    * @brief The start and end property ranges for this control.
51    */
52   enum PropertyRange
53   {
54     PROPERTY_START_INDEX = Control::CONTROL_PROPERTY_END_INDEX + 1,
55     PROPERTY_END_INDEX =   PROPERTY_START_INDEX + 1000,              ///< Reserve property indices
56
57     ANIMATABLE_PROPERTY_START_INDEX = ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX,        ///< @since DALi 1.1.18
58     ANIMATABLE_PROPERTY_END_INDEX =   ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 1000  ///< Reserve animatable property indices, @since DALi 1.1.18
59   };
60
61   /**
62    * @brief An enumeration of properties belonging to the ImageView class.
63    */
64   struct Property
65   {
66     enum
67     {
68       // Event side properties
69       RESOURCE_URL = PROPERTY_START_INDEX, ///< name "resourceUrl",  @deprecated DALi 1.1.16 Use IMAGE instead.  type string
70       IMAGE,                               ///< name "image",        @see SetImage(),                            type string if it is a url, map otherwise
71
72       // Animatable properties
73       PIXEL_AREA = ANIMATABLE_PROPERTY_START_INDEX,  ///< name "pixelArea", @since DALi 1.1.18                   type Vector4, Pixel area is a relative value with the whole image area as [0.0, 0.0, 1.0, 1.0].
74     };
75   };
76
77 public:
78
79   /**
80    * @brief Create an uninitialized ImageView.
81    */
82   ImageView();
83
84   /**
85    * @brief Create an initialized ImageView.
86    *
87    * @return A handle to a newly allocated Dali ImageView.
88    *
89    * @note ImageView will not display anything.
90    */
91   static ImageView New();
92
93   /**
94    * @brief Create an initialized ImageView from an Image.
95    *
96    * If the handle is empty, ImageView will not display anything.
97    *
98    * @param[in] image The Image to display.
99    * @return A handle to a newly allocated ImageView.
100    */
101   static ImageView New( Image image );
102
103   /**
104    * @brief Create an initialized ImageView from an Image resource URL
105    *
106    * If the string is empty, ImageView will not display anything.
107    *
108    * @param[in] url The url of the image resource to display.
109    * @return A handle to a newly allocated ImageView.
110    */
111   static ImageView New( const std::string& url );
112
113   /**
114    * @brief Create an initialized ImageView from an Image resource URL
115    *
116    * If the string is empty, ImageView will not display anything.
117    *
118    * @since DALi 1.1.10
119    *
120    * @param[in] url The url of the image resource to display.
121    * @param [in] size The width and height to fit the loaded image to.
122    * @return A handle to a newly allocated ImageView.
123    *
124    * @note A valid size is preferable for efficiency.
125    *       However, do not set a size that is bigger than the actual image size, as up-scaling is not available.
126    *       The content of the area not covered by the actual image is undefined and will not be cleared.
127    */
128   static ImageView New( const std::string& url, ImageDimensions size );
129
130   /**
131    * @brief Destructor
132    *
133    * This is non-virtual since derived Handle types must not contain data or virtual methods.
134    */
135   ~ImageView();
136
137   /**
138    * @brief Copy constructor.
139    *
140    * @param[in] imageView ImageView to copy. The copied ImageView will point at the same implementation
141    */
142   ImageView( const ImageView& imageView );
143
144   /**
145    * @brief Assignment operator.
146    *
147    * @param[in] imageView The ImageView to assign from.
148    * @return The updated ImageView.
149    */
150   ImageView& operator=( const ImageView& imageView );
151
152   /**
153    * @brief Downcast an Object handle to ImageView.
154    *
155    * If handle points to a ImageView the downcast produces valid
156    * handle. If not the returned handle is left uninitialized.
157    *
158    * @param[in] handle Handle to an object
159    * @return handle to a ImageView or an uninitialized handle
160    */
161   static ImageView DownCast( BaseHandle handle );
162
163   /**
164    * @brief Sets this ImageView from an Image
165    *
166    * If the handle is empty, ImageView will display nothing
167    * @param[in] image The Image to display.
168    */
169   void SetImage( Image image );
170
171   /**
172    * @brief Sets this ImageView from an Image URL
173    *
174    * If the URL is empty, ImageView will not display anything.
175    *
176    * @since DALi 1.1.4
177    *
178    * @param[in] url The Image resource to display.
179    */
180   void SetImage( const std::string& url );
181
182   /**
183    * @brief Sets this ImageView from an Image URL
184    *
185    * If the URL is empty, ImageView will not display anything.
186    *
187    * @since DALi 1.1.10
188    *
189    * @param[in] url A URL to the image resource to display.
190    * @param [in] size The width and height to fit the loaded image to.
191    */
192   void SetImage( const std::string& url, ImageDimensions size );
193
194   /**
195    * @deprecated Gets the Image
196    *
197    * @return The Image currently set to this ImageView
198    */
199   Image GetImage() const;
200
201 public: // Not intended for application developers
202
203   /**
204    * @brief Creates a handle using the Toolkit::Internal implementation.
205    *
206    * @param[in]  implementation  The ImageView implementation.
207    */
208   DALI_INTERNAL ImageView( Internal::ImageView& implementation );
209
210   /**
211    * @brief Allows the creation of this ImageView from an Internal::CustomActor pointer.
212    *
213    * @param[in]  internal  A pointer to the internal CustomActor.
214    */
215   DALI_INTERNAL ImageView( Dali::Internal::CustomActor* internal );
216
217 };
218
219 /**
220  * @}
221  */
222 } // namespace Toolkit
223
224 } // namespace Dali
225
226 #endif // __DALI_TOOLKIT_IMAGE_VIEW_H__