1 #ifndef DALI_TOOLKIT_INTERNAL_IMAGE_VIEW_H
2 #define DALI_TOOLKIT_INTERNAL_IMAGE_VIEW_H
5 * Copyright (c) 2023 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/public-api/object/property-map.h>
25 #include <dali-toolkit/internal/visuals/image/image-visual.h>
26 #include <dali-toolkit/public-api/controls/control-impl.h>
27 #include <dali-toolkit/public-api/controls/image-view/image-view.h>
37 class ImageView : public Control
41 * Construct a new ImageView.
43 * @param[in] additionalBehaviour additional behaviour flags for this ImageView
45 ImageView(ControlBehaviour additionalBehaviour);
48 * A reference counted object may only be deleted by calling Unreference()
54 * Create a new ImageView.
56 * @param[in] additionalBehaviour custom behavior flags for this ImageView. Default is CONTROL_BEHAVIOUR_DEFAULT
57 * @return A smart-pointer to the newly allocated ImageView.
59 static Toolkit::ImageView New(ControlBehaviour additionalBehaviour = ControlBehaviour::CONTROL_BEHAVIOUR_DEFAULT);
62 * @brief Sets this ImageView from an Dali::Property::Map
64 * If the handle is empty, ImageView will display nothing
65 * @param[in] map The Dali::Property::Map to use for to display.
67 void SetImage(const Dali::Property::Map& map);
70 * @copydoc Dali::Toolkit::SetImage
72 void SetImage(const std::string& imageUrl, ImageDimensions size);
75 * @brief Unregister ImageView IMAGE visual
77 * ImageView will display nothing
79 void ClearImageVisual();
82 * @brief Set whether the Pre-multiplied Alpha Blending is required
84 * @param[in] preMultipled whether alpha is pre-multiplied.
86 void EnablePreMultipliedAlpha(bool preMultipled);
89 * @brief Query whether alpha is pre-multiplied.
91 * @return True if alpha is pre-multiplied, false otherwise.
93 bool IsPreMultipliedAlphaEnabled() const;
97 * Called when a property of an object of this type is set.
98 * @param[in] object The object whose property is set.
99 * @param[in] index The property index.
100 * @param[in] value The new property value.
102 static void SetProperty(BaseObject* object, Property::Index index, const Property::Value& value);
105 * Called to retrieve a property of an object of this type.
106 * @param[in] object The object whose property is to be retrieved.
107 * @param[in] index The property index.
108 * @return The current value of the property.
110 static Property::Value GetProperty(BaseObject* object, Property::Index propertyIndex);
113 * @brief Set the depth index of this image renderer
115 * Renderer with higher depth indices are rendered in front of other visuals with smaller values
117 * @param[in] depthIndex The depth index of this renderer
119 void SetDepthIndex(int depthIndex);
122 * @brief Set the placeholder url
124 void SetPlaceholderUrl(const std::string& url);
127 * @brief Get the placeholder url
129 std::string GetPlaceholderUrl() const;
132 * @brief Enable the transition effect
134 void EnableTransitionEffect(bool effectEnable);
137 * @brief Query whether transition effect is enabled
139 bool IsTransitionEffectEnabled() const;
142 * @brief Set the transition effect option.
144 void SetTransitionEffectOption(const Property::Map& map);
147 * @brief callback when animation for placeholder or previous visual transition effect is finished
149 void OnTransitionAnimationFinishedCallback(Animation& animation);
151 private: // From Control
153 * @copydoc Toolkit::Control::OnInitialize
158 * @copydoc Toolkit::Control::GetNaturalSize
160 Vector3 GetNaturalSize() override;
163 * @copydoc Toolkit::Control::GetHeightForWidth()
165 float GetHeightForWidth(float width) override;
168 * @copydoc Toolkit::Control::GetWidthForHeight()
170 float GetWidthForHeight(float height) override;
173 * @copydoc Toolkit::Control::OnRelayout()
175 void OnRelayout(const Vector2& size, RelayoutContainer& container) override;
178 * @copydoc Toolkit::Control::OnCreateTransitions()
180 virtual void OnCreateTransitions(std::vector<std::pair<Dali::Property::Index, Dali::Property::Map>>& sourceProperties,
181 std::vector<std::pair<Dali::Property::Index, Dali::Property::Map>>& destinationProperties,
182 Dali::Toolkit::Control source,
183 Dali::Toolkit::Control destination) override;
186 * @copydoc Toolkit::Control::OnUpdateVisualProperties()
188 virtual void OnUpdateVisualProperties(const std::vector<std::pair<Dali::Property::Index, Dali::Property::Map>>& properties) override;
192 * @brief Callback for ResourceReadySignal
193 * param[in] control signal prototype
195 void OnResourceReady(Toolkit::Control control);
198 * @brief Create placeholder image if it set. placeholder image is shown when image view is waiting for the image to load.
200 void CreatePlaceholderImage();
203 * @brief Show placeholder image if it set. placeholder image is shown when image view is waiting for the image to load.
205 void ShowPlaceholderImage();
208 * @brief Hide placeholder image if it set.
210 void HidePlaceholderImage();
213 * @brief Transition image with effect when image is replaced.
215 void TransitionImageWithEffect();
218 * @brief Clear the transition animation
220 void ClearTransitionAnimation();
224 ImageView(const ImageView&);
225 ImageView& operator=(const ImageView&);
228 Toolkit::Visual::Base mVisual;
229 Toolkit::Visual::Base mPreviousVisual;
230 Toolkit::Visual::Base mPlaceholderVisual;
232 std::string mUrl; ///< the url for the image if the image came from a URL, empty otherwise
233 std::string mPlaceholderUrl; ///< the url for the placeholder image if the image came from a PLACEHOLDER_IMAGE, empty otherwise
234 Property::Map mPropertyMap; ///< the Property::Map if the image came from a Property::Map, empty otherwise
235 Property::Map mShaderMap; ///< the Property::Map if the custom shader is set, empty otherwise
236 Property::Map mTransitionEffectOptionMap; ///< the Property::Map if the transition effect option is set, empty otherwise
237 ImageDimensions mImageSize; ///< the image size
239 Animation mTransitionAnimation; ///< the animation for transition effect
240 float mTransitionTargetAlpha; ///< Keep image's alpha value
241 bool mTransitionEffect :1; ///< Flag to indicate TransitionEffect is enabled
242 bool mImageReplaced:1; ///< Flag to indicate image is replaced
245 } // namespace Internal
247 // Helpers for public-api forwarding methods
248 inline Toolkit::Internal::ImageView& GetImpl(Toolkit::ImageView& obj)
250 DALI_ASSERT_ALWAYS(obj);
251 Dali::RefObject& handle = obj.GetImplementation();
252 return static_cast<Toolkit::Internal::ImageView&>(handle);
255 inline const Toolkit::Internal::ImageView& GetImpl(const Toolkit::ImageView& obj)
257 DALI_ASSERT_ALWAYS(obj);
258 const Dali::RefObject& handle = obj.GetImplementation();
259 return static_cast<const Toolkit::Internal::ImageView&>(handle);
262 } // namespace Toolkit
266 #endif // DALI_TOOLKIT_INTERNAL_IMAGE_VIEW_H