Merge "Extending Text Styles - Adding Dashed/Double Underline" into 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) 2022 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   ImageView();
44
45   /**
46    * A reference counted object may only be deleted by calling Unreference()
47    */
48   virtual ~ImageView();
49
50 public:
51   /**
52    * Create a new ImageView.
53    * @return A smart-pointer to the newly allocated ImageView.
54    */
55   static Toolkit::ImageView New();
56
57   /**
58    * @brief Sets this ImageView from an Dali::Property::Map
59    *
60    * If the handle is empty, ImageView will display nothing
61    * @param[in] map The Dali::Property::Map to use for to display.
62    */
63   void SetImage(const Dali::Property::Map& map);
64
65   /**
66    * @copydoc Dali::Toolkit::SetImage
67    */
68   void SetImage(const std::string& imageUrl, ImageDimensions size);
69
70   /**
71    * @brief Unregister ImageView IMAGE visual
72    *
73    * ImageView will display nothing
74    */
75   void ClearImageVisual();
76
77   /**
78    * @brief Set whether the Pre-multiplied Alpha Blending is required
79    *
80    * @param[in] preMultipled whether alpha is pre-multiplied.
81    */
82   void EnablePreMultipliedAlpha(bool preMultipled);
83
84   /**
85    * @brief Query whether alpha is pre-multiplied.
86    *
87    * @return True if alpha is pre-multiplied, false otherwise.
88    */
89   bool IsPreMultipliedAlphaEnabled() const;
90
91   // Properties
92   /**
93    * Called when a property of an object of this type is set.
94    * @param[in] object The object whose property is set.
95    * @param[in] index The property index.
96    * @param[in] value The new property value.
97    */
98   static void SetProperty(BaseObject* object, Property::Index index, const Property::Value& value);
99
100   /**
101    * Called to retrieve a property of an object of this type.
102    * @param[in] object The object whose property is to be retrieved.
103    * @param[in] index The property index.
104    * @return The current value of the property.
105    */
106   static Property::Value GetProperty(BaseObject* object, Property::Index propertyIndex);
107
108   /**
109    * @brief Set the depth index of this image renderer
110    *
111    * Renderer with higher depth indices are rendered in front of other visuals with smaller values
112    *
113    * @param[in] depthIndex The depth index of this renderer
114    */
115   void SetDepthIndex(int depthIndex);
116
117 private: // From Control
118   /**
119    * @copydoc Toolkit::Control::OnInitialize
120    */
121   void OnInitialize();
122
123   /**
124    * @copydoc Toolkit::Control::GetNaturalSize
125    */
126   Vector3 GetNaturalSize() override;
127
128   /**
129    * @copydoc Toolkit::Control::GetHeightForWidth()
130    */
131   float GetHeightForWidth(float width) override;
132
133   /**
134    * @copydoc Toolkit::Control::GetWidthForHeight()
135    */
136   float GetWidthForHeight(float height) override;
137
138   /**
139    * @copydoc Toolkit::Control::OnRelayout()
140    */
141   void OnRelayout(const Vector2& size, RelayoutContainer& container) override;
142
143   /**
144    * @copydoc Toolkit::Control::OnCreateTransitions()
145    */
146   virtual void OnCreateTransitions(std::vector<std::pair<Dali::Property::Index, Dali::Property::Map>>& sourceProperties,
147                                    std::vector<std::pair<Dali::Property::Index, Dali::Property::Map>>& destinationProperties,
148                                    Dali::Toolkit::Control                                              source,
149                                    Dali::Toolkit::Control                                              destination) override;
150
151   /**
152    * @copydoc Toolkit::Control::OnUpdateVisualProperties()
153    */
154   virtual void OnUpdateVisualProperties(const std::vector<std::pair<Dali::Property::Index, Dali::Property::Map>>& properties) override;
155
156 private:
157   /**
158    * @brief Callback for ResourceReadySignal
159    * param[in] control signal prototype
160    */
161   void OnResourceReady(Toolkit::Control control);
162
163   /**
164    * @brief Set TransformMap for fittingMode
165    * param[in] finalSize The size for fittingMode
166    * param[in] textureSize The size of texture
167    * param[in] offset The offset for fittingMode
168    * param[in] fittingMode The mode for fitting image
169    * param[in] transformMap  The map for fitting image
170    */
171   void SetTransformMapForFittingMode(Vector2 finalSize, Vector2 textureSize, Vector2 offset, Visual::FittingMode fittingMode, Property::Map& transformMap);
172
173   /**
174    * @brief Apply fittingMode
175    * param[in] finalSize The size for fittingMode
176    * param[in] textureSize The size of texture
177    * param[in] offset The offset for fittingMode
178    * param[in] zeroPadding whether padding is zero
179    * param[in] transformMap  The map for fitting image
180    */
181   void ApplyFittingMode(Vector2 finalSize, Vector2 textureSize, Vector2 offset, bool zeroPadding, Property::Map& transformMap);
182
183 private:
184   // Undefined
185   ImageView(const ImageView&);
186   ImageView& operator=(const ImageView&);
187
188 private:
189   Toolkit::Visual::Base mVisual;
190
191   std::string     mUrl;         ///< the url for the image if the image came from a URL, empty otherwise
192   Property::Map   mPropertyMap; ///< the Property::Map if the image came from a Property::Map, empty otherwise
193   Property::Map   mShaderMap;   ///< the Property::Map if the custom shader is set, empty otherwise
194   ImageDimensions mImageSize;   ///< the image size
195
196   bool mImageVisualPaddingSetByTransform : 1;   //< Flag to indicate Padding was set using a transform.
197   bool mImageViewPixelAreaSetByFittingMode : 1; //< Flag to indicate pixel area was set by fitting Mode
198 };
199
200 } // namespace Internal
201
202 // Helpers for public-api forwarding methods
203 inline Toolkit::Internal::ImageView& GetImpl(Toolkit::ImageView& obj)
204 {
205   DALI_ASSERT_ALWAYS(obj);
206   Dali::RefObject& handle = obj.GetImplementation();
207   return static_cast<Toolkit::Internal::ImageView&>(handle);
208 }
209
210 inline const Toolkit::Internal::ImageView& GetImpl(const Toolkit::ImageView& obj)
211 {
212   DALI_ASSERT_ALWAYS(obj);
213   const Dali::RefObject& handle = obj.GetImplementation();
214   return static_cast<const Toolkit::Internal::ImageView&>(handle);
215 }
216
217 } // namespace Toolkit
218
219 } // namespace Dali
220
221 #endif // DALI_TOOLKIT_INTERNAL_IMAGE_VIEW_H