1 #ifndef DALI_TOOLKIT_IMAGE_VIEW_H
2 #define DALI_TOOLKIT_IMAGE_VIEW_H
5 * Copyright (c) 2020 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <dali-toolkit/public-api/controls/control.h>
25 #include <dali/public-api/images/image-operations.h>
33 namespace Internal DALI_INTERNAL
38 * @addtogroup dali_toolkit_controls_image_view
43 * @brief ImageView is a class for displaying an image resource.
45 * An instance of ImageView can be created using a URL or an Image instance.
47 * Some resources can be loaded before the ImageView is staged ( already cached ), in these cases if the connection to
48 * ResouceReadySignal is done after the resource is set then signal will be missed.
50 * To protect against this, IsResourceReady() can be checked before connecting to ResourceReadySignal,
51 * or the signal connection can be done before setting the resource.
54 * auto myImageView = ImageView::New( resourceUrl );
55 * if ( myImageView.IsResourceReady() )
61 * myImageView.ResourceReadySignal.Connect( .... )
65 * OR Connect to signal before setting resource
68 * auto myImageView = ImageView::New();
69 * myImageView.ResourceReadySignal.Connect( .... )
70 * myImageView.SetProperty( ImageView::Property::IMAGE, resourceUrl );
76 class DALI_TOOLKIT_API ImageView : public Control
81 * @brief Enumeration for the start and end property ranges for this control.
86 PROPERTY_START_INDEX = Control::CONTROL_PROPERTY_END_INDEX + 1, ///< @SINCE_1_0.0
87 PROPERTY_END_INDEX = PROPERTY_START_INDEX + 1000, ///< Reserve property indices @SINCE_1_0.0
89 ANIMATABLE_PROPERTY_START_INDEX = ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX, ///< @SINCE_1_1.18
90 ANIMATABLE_PROPERTY_END_INDEX = ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 1000 ///< Reserve animatable property indices, @SINCE_1_1.18
94 * @brief Enumeration for the instance of properties belonging to the ImageView class.
100 * @brief Enumeration for the instance of properties belonging to the ImageView class.
105 // Event side properties
107 RESERVED_PROPERTY_01 = PROPERTY_START_INDEX, ///< Reserved index for a removed property.
110 * @brief name "image", type string if it is a url, map otherwise.
116 * @brief name "preMultipliedAlpha", type Boolean.
118 * @pre image must be initialized.
120 PRE_MULTIPLIED_ALPHA,
123 // Animatable properties
126 * @brief name "pixelArea", type Vector4.
127 * @details Pixel area is a relative value with the whole image area as [0.0, 0.0, 1.0, 1.0].
130 PIXEL_AREA = ANIMATABLE_PROPERTY_START_INDEX,
137 * @brief Creates an uninitialized ImageView.
143 * @brief Create an initialized ImageView.
146 * @return A handle to a newly allocated Dali ImageView
148 * @note ImageView will not display anything.
150 static ImageView New();
153 * @brief Creates an initialized ImageView from an URL to an image resource.
155 * If the string is empty, ImageView will not display anything.
160 * @param[in] url The url of the image resource to display
161 * @return A handle to a newly allocated ImageView
163 static ImageView New( const std::string& url );
166 * @brief Creates an initialized ImageView from a URL to an image resource.
168 * If the string is empty, ImageView will not display anything.
173 * @param[in] url The url of the image resource to display
174 * @param [in] size The width and height to which to fit the loaded image
175 * @return A handle to a newly allocated ImageView
176 * @note A valid size is preferable for efficiency.
177 * However, do not set a size that is bigger than the actual image size, as up-scaling is not available.
178 * The content of the area not covered by the actual image is undefined and will not be cleared.
180 static ImageView New( const std::string& url, ImageDimensions size );
185 * This is non-virtual since derived Handle types must not contain data or virtual methods.
191 * @brief Copy constructor.
194 * @param[in] imageView ImageView to copy. The copied ImageView will point at the same implementation
196 ImageView( const ImageView& imageView );
199 * @brief Assignment operator.
202 * @param[in] imageView The ImageView to assign from
203 * @return The updated ImageView
205 ImageView& operator=( const ImageView& imageView );
208 * @brief Downcasts a handle to ImageView handle.
210 * If handle points to a ImageView, the downcast produces valid handle.
211 * If not, the returned handle is left uninitialized.
214 * @param[in] handle Handle to an object
215 * @return Handle to a ImageView or an uninitialized handle
217 static ImageView DownCast( BaseHandle handle );
220 * @brief Sets this ImageView from the given URL.
222 * If the URL is empty, ImageView will not display anything.
227 * @param[in] url The URL to the image resource to display
229 void SetImage( const std::string& url );
232 * @brief Sets this ImageView from the given URL.
234 * If the URL is empty, ImageView will not display anything.
239 * @param[in] url The URL to the image resource to display
240 * @param [in] size The width and height to fit the loaded image to
242 void SetImage( const std::string& url, ImageDimensions size );
244 public: // Not intended for application developers
248 * @brief Creates a handle using the Toolkit::Internal implementation.
251 * @param[in] implementation The ImageView implementation
253 DALI_INTERNAL ImageView( Internal::ImageView& implementation );
256 * @brief Allows the creation of this ImageView from an Internal::CustomActor pointer.
259 * @param[in] internal A pointer to the internal CustomActor
261 DALI_INTERNAL ImageView( Dali::Internal::CustomActor* internal );
269 } // namespace Toolkit
273 #endif // DALI_TOOLKIT_IMAGE_VIEW_H