Optimization to reduce Handle size by 50%
[platform/core/uifw/dali-toolkit.git] / optional / dali-toolkit / public-api / controls / image-view / image-view.h
1 #ifndef __DALI_TOOLKIT_IMAGE_VIEW_H__
2 #define __DALI_TOOLKIT_IMAGE_VIEW_H__
3
4 /*
5  * Copyright (c) 2014 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 // INTERNAL INCLUDES
22 #include <dali-toolkit/public-api/controls/control.h>
23
24 namespace Dali DALI_IMPORT_API
25 {
26
27 namespace Toolkit
28 {
29
30 namespace Internal DALI_INTERNAL
31 {
32 class ImageView;
33 }
34
35 class Button;
36
37 /**
38  * ImageView control loads and displays the correct
39  * image for the current level of detail (LOD) required.
40  * LOD is typically calculated from the Camera distance.
41  *
42  * Example:
43  *
44  * ImageView imageView = ImageView::New();
45  * imageView.SetCameraActor( mCamera );
46  * imageView.SetSize( Vector2(64.0f, 64.0f) );
47  * imageView.SetImage( "my-image.png", ImageView::BitmapType, 0.125f, 4.0f );
48  * layer.Add(imageView);
49  *
50  * The above creates an ImageView at 64x64 in size. Images of 12.5% the size up
51  * to 400% the size of imageView are created
52  * i.e. 8x8, 16x16, 32x32, 64x64, 128x128, and 256x256
53  *
54  * based on the distance imageView is from mCamera an appropriate, different
55  * image will be loaded and dispayed.
56  */
57 class ImageView : public Control
58 {
59 public:
60
61   /**
62    * Image Types, determines how image should be rendered.
63    */
64   enum ImageType
65   {
66     BitmapType,                            ///< Standard Bitmap image
67     DistanceFieldType                      ///< Distance Field encoded image
68   };
69
70   static const std::string DETAIL_PROPERTY_NAME;                          ///< The level of detail property
71
72 public:
73
74   /**
75    * Creates an empty ImageView handle
76    */
77   ImageView();
78
79   /**
80    * Copy constructor. Creates another handle that points to the same real object
81    * @param handle to copy from
82    */
83   ImageView( const ImageView& handle );
84
85   /**
86    * Assignment operator. Changes this handle to point to another real object
87    */
88   ImageView& operator=( const ImageView& handle );
89
90   /**
91    * @brief Destructor
92    *
93    * This is non-virtual since derived Handle types must not contain data or virtual methods.
94    */
95   ~ImageView();
96
97   /**
98    * Create the Poup control
99    * @return A handle to the ImageView control.
100    */
101   static ImageView New();
102
103   /**
104    * Downcast an Object handle to ImageView. If handle points to an ImageView the
105    * downcast produces valid handle. If not the returned handle is left uninitialized.
106    * @param[in] handle Handle to an object
107    * @return handle to a ImageView or an uninitialized handle
108    */
109   static ImageView DownCast( BaseHandle handle );
110
111 public:
112
113   /**
114    * Load image into ImageView for level of detail scaling.
115    * Will automatically create different sized versions
116    * of the source image.
117    *
118    * @param[in] filename The image path to load
119    * @param[in] type The type of image e.g. BitmapType or DistanceFieldType
120    */
121   void SetImage(const std::string& filename, ImageType type);
122
123   /**
124    * Load image into ImageView for level of detail scaling.
125    * The minimum scale is a percentage of the size of the
126    * image view, and represents the smallest version of the
127    * source image to display e.g. 0.125 for 12.5%
128    * While the maximum scale represents the largest version of
129    * the source image to display e.g. 1.00 for 100% (original
130    * image view size)
131    *
132    * @note ImageView SetSize must be set specified prior to
133    * calling this.
134    *
135    * @param[in] filename The image path to load
136    * @param[in] type The type of image e.g. BitmapImage or DistanceFieldImage
137    * @param[in] min The minimum scale detail to load.
138    * @param[in] max The maximum scale detail to load.
139    */
140   void SetImage(const std::string& filename, ImageType type, float min, float max);
141
142   /**
143    * Sets an image to displayed for the entire detail range.
144    * Regardless of the detail level this image will be displayed.
145    *
146    * @param[in] image The image to display
147    */
148   void SetImage(Image image);
149
150   /**
151    * Sets the camera to use for determining level of detail.
152    * Which is based on distance from camera to this ImageView.
153    * The detailFactor is the distance at which the ImageView
154    * should appear at 100% scale. Which may differ based on
155    * Projection, and ShaderEffect settings.
156    * @param[in] camera The camera
157    */
158   void SetCameraActor(CameraActor camera);
159
160   /**
161    * Sets the camera to use for determining level of detail.
162    * Which is based on distance from camera to this ImageView.
163    * The detailFactor is the distance at which the ImageView
164    * should appear at 100% scale. Which may differ based on
165    * Projection, and ShaderEffect settings.
166    * @param[in] camera The camera
167    * @param[in] detailFactor The Camera distance where detail should be 1.0
168    * (ImageView should appear at 100% scale)
169    */
170   void SetCameraActor(CameraActor camera, float detailFactor);
171
172   /**
173    * Sets the current detail level.
174    * @note This sets the detail property value.
175    * @param[in] detail The level of detail to be viewed at.
176    */
177   void SetDetail(float detail);
178
179 public: // Not intended for application developers
180
181   /**
182    * Creates a handle using the Toolkit::Internal implementation.
183    * @param[in]  implementation  The Control implementation.
184    */
185   ImageView(Internal::ImageView& implementation);
186
187   /**
188    * Allows the creation of this Control from an Internal::CustomActor pointer.
189    * @param[in]  internal  A pointer to the internal CustomActor.
190    */
191   ImageView(Dali::Internal::CustomActor* internal);
192 };
193
194 } // namespace Toolkit
195
196 } // namespace Dali
197
198 #endif // __DALI_TOOLKIT_IMAGE_VIEW_H__