[dali_2.3.21] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / image-view / image-view-impl.h
1 #ifndef DALI_TOOLKIT_INTERNAL_IMAGE_VIEW_H
2 #define DALI_TOOLKIT_INTERNAL_IMAGE_VIEW_H
3
4 /*
5  * Copyright (c) 2023 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 // EXTERNAL INCLUDES
22 #include <dali/public-api/object/property-map.h>
23
24 // INTERNAL INCLUDES
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>
28
29 namespace Dali
30 {
31 namespace Toolkit
32 {
33 class ImageView;
34
35 namespace Internal
36 {
37 class ImageView : public Control
38 {
39 protected:
40   /**
41    * Construct a new ImageView.
42    *
43    * @param[in] additionalBehaviour additional behaviour flags for this ImageView
44    */
45   ImageView(ControlBehaviour additionalBehaviour);
46
47   /**
48    * A reference counted object may only be deleted by calling Unreference()
49    */
50   virtual ~ImageView();
51
52 public:
53   /**
54    * Create a new ImageView.
55    *
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.
58    */
59   static Toolkit::ImageView New(ControlBehaviour additionalBehaviour = ControlBehaviour::CONTROL_BEHAVIOUR_DEFAULT);
60
61   /**
62    * @brief Sets this ImageView from an Dali::Property::Map
63    *
64    * If the handle is empty, ImageView will display nothing
65    * @param[in] map The Dali::Property::Map to use for to display.
66    */
67   void SetImage(const Dali::Property::Map& map);
68
69   /**
70    * @copydoc Dali::Toolkit::SetImage
71    */
72   void SetImage(const std::string& imageUrl, ImageDimensions size);
73
74   /**
75    * @brief Unregister ImageView IMAGE visual
76    *
77    * ImageView will display nothing
78    */
79   void ClearImageVisual();
80
81   /**
82    * @brief Set whether the Pre-multiplied Alpha Blending is required
83    *
84    * @param[in] preMultipled whether alpha is pre-multiplied.
85    */
86   void EnablePreMultipliedAlpha(bool preMultipled);
87
88   /**
89    * @brief Query whether alpha is pre-multiplied.
90    *
91    * @return True if alpha is pre-multiplied, false otherwise.
92    */
93   bool IsPreMultipliedAlphaEnabled() const;
94
95   // Properties
96   /**
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.
101    */
102   static void SetProperty(BaseObject* object, Property::Index index, const Property::Value& value);
103
104   /**
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.
109    */
110   static Property::Value GetProperty(BaseObject* object, Property::Index propertyIndex);
111
112   /**
113    * @brief Set the depth index of this image renderer
114    *
115    * Renderer with higher depth indices are rendered in front of other visuals with smaller values
116    *
117    * @param[in] depthIndex The depth index of this renderer
118    */
119   void SetDepthIndex(int depthIndex);
120
121   /**
122    * @brief Set the placeholder url
123    */
124   void SetPlaceholderUrl(const std::string& url);
125
126   /**
127    * @brief Get the placeholder url
128    */
129   std::string GetPlaceholderUrl() const;
130
131   /**
132    * @brief Enable the transition effect
133    */
134   void EnableTransitionEffect(bool effectEnable);
135
136   /**
137    * @brief Query whether transition effect is enabled
138    */
139   bool IsTransitionEffectEnabled() const;
140
141   /**
142    * @brief callback when animation for placeholder or previous visual transition effect is finished
143    */
144   void OnTransitionAnimationFinishedCallback(Animation& animation);
145
146 private: // From Control
147   /**
148    * @copydoc Toolkit::Control::OnInitialize
149    */
150   void OnInitialize();
151
152   /**
153    * @copydoc Toolkit::Control::GetNaturalSize
154    */
155   Vector3 GetNaturalSize() override;
156
157   /**
158    * @copydoc Toolkit::Control::GetHeightForWidth()
159    */
160   float GetHeightForWidth(float width) override;
161
162   /**
163    * @copydoc Toolkit::Control::GetWidthForHeight()
164    */
165   float GetWidthForHeight(float height) override;
166
167   /**
168    * @copydoc Toolkit::Control::OnRelayout()
169    */
170   void OnRelayout(const Vector2& size, RelayoutContainer& container) override;
171
172   /**
173    * @copydoc Toolkit::Control::OnCreateTransitions()
174    */
175   virtual void OnCreateTransitions(std::vector<std::pair<Dali::Property::Index, Dali::Property::Map>>& sourceProperties,
176                                    std::vector<std::pair<Dali::Property::Index, Dali::Property::Map>>& destinationProperties,
177                                    Dali::Toolkit::Control                                              source,
178                                    Dali::Toolkit::Control                                              destination) override;
179
180   /**
181    * @copydoc Toolkit::Control::OnUpdateVisualProperties()
182    */
183   virtual void OnUpdateVisualProperties(const std::vector<std::pair<Dali::Property::Index, Dali::Property::Map>>& properties) override;
184
185 private:
186   /**
187    * @brief Callback for ResourceReadySignal
188    * param[in] control signal prototype
189    */
190   void OnResourceReady(Toolkit::Control control);
191
192   /**
193    * @brief Set TransformMap for fittingMode
194    * param[in] finalSize The size for fittingMode
195    * param[in] textureSize The size of texture
196    * param[in] offset The offset for fittingMode
197    * param[in] fittingMode The mode for fitting image
198    * param[in] transformMap  The map for fitting image
199    */
200   void SetTransformMapForFittingMode(Vector2 finalSize, Vector2 textureSize, Vector2 offset, Visual::FittingMode fittingMode, Property::Map& transformMap);
201
202   /**
203    * @brief Apply fittingMode
204    */
205   void ApplyFittingMode(const Vector2& size);
206
207    /**
208    * @brief Create placeholder image if it set. placeholder image is shown when image view is waiting for the image to load.
209    */
210   void CreatePlaceholderImage();
211
212   /**
213    * @brief Show placeholder image if it set. placeholder image is shown when image view is waiting for the image to load.
214    */
215   void ShowPlaceholderImage();
216
217   /**
218    * @brief Hide placeholder image if it set.
219    */
220   void HidePlaceholderImage();
221
222   /**
223    * @brief Transition image with effect when image is replaced.
224    */
225   void TransitionImageWithEffect();
226
227   /**
228    * @brief Clear the transition animation
229    */
230   void ClearTransitionAnimation();
231
232 private:
233   // Undefined
234   ImageView(const ImageView&);
235   ImageView& operator=(const ImageView&);
236
237 private:
238   Toolkit::Visual::Base mVisual;
239   Toolkit::Visual::Base mPreviousVisual;
240   Toolkit::Visual::Base mPlaceholderVisual;
241
242   std::string     mUrl;                                    ///< the url for the image if the image came from a URL, empty otherwise
243   std::string     mPlaceholderUrl;                         ///< the url for the placeholder image if the image came from a PLACEHOLDER_IMAGE, empty otherwise
244   Property::Map   mPropertyMap;                            ///< the Property::Map if the image came from a Property::Map, empty otherwise
245   Property::Map   mShaderMap;                              ///< the Property::Map if the custom shader is set, empty otherwise
246   ImageDimensions mImageSize;                              ///< the image size
247
248   Animation       mTransitionAnimation;                    ///< the animation for transition effect
249   float           mTransitionTargetAlpha;                  ///< Keep image's alpha value
250   bool            mImageVisualPaddingSetByTransform : 1;   ///< Flag to indicate Padding was set using a transform.
251   bool            mImageViewPixelAreaSetByFittingMode : 1; ///< Flag to indicate pixel area was set by fitting Mode
252   bool            mTransitionEffect :1;                    ///< Flag to indicate TransitionEffect is enabled
253   bool            mNeedLazyFittingMode:1;                  ///< Flag to indicate FittingMode will be applying lazy
254   bool            mImageReplaced:1;                        ///< Flag to indicate image is replaced
255 };
256
257 } // namespace Internal
258
259 // Helpers for public-api forwarding methods
260 inline Toolkit::Internal::ImageView& GetImpl(Toolkit::ImageView& obj)
261 {
262   DALI_ASSERT_ALWAYS(obj);
263   Dali::RefObject& handle = obj.GetImplementation();
264   return static_cast<Toolkit::Internal::ImageView&>(handle);
265 }
266
267 inline const Toolkit::Internal::ImageView& GetImpl(const Toolkit::ImageView& obj)
268 {
269   DALI_ASSERT_ALWAYS(obj);
270   const Dali::RefObject& handle = obj.GetImplementation();
271   return static_cast<const Toolkit::Internal::ImageView&>(handle);
272 }
273
274 } // namespace Toolkit
275
276 } // namespace Dali
277
278 #endif // DALI_TOOLKIT_INTERNAL_IMAGE_VIEW_H