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