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