Conversion to Apache 2.0 license
[platform/core/uifw/dali-toolkit.git] / optional / dali-toolkit / internal / controls / image-view / image-view-impl.h
1 #ifndef __DALI_TOOLKIT_INTERNAL_ImageView_H__
2 #define __DALI_TOOLKIT_INTERNAL_ImageView_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/dali.h>
23 #include <dali-toolkit/public-api/controls/control-impl.h>
24 #include <dali-toolkit/public-api/controls/image-view/image-view.h>
25
26 namespace Dali
27 {
28
29 namespace Toolkit
30 {
31
32 namespace Internal
33 {
34
35 class ImageView;
36
37 typedef IntrusivePtr<ImageView>    ImageViewPtr;
38
39 /**
40  * @copydoc Toolkit::ImageView
41  */
42 class ImageView : public Control
43 {
44 public:
45
46   typedef Toolkit::ImageView::ImageType ImageType;
47
48   /**
49    * ImageRequest element
50    * represents an image to be loaded and displayed
51    * with given attributes.
52    */
53   struct ImageRequest
54   {
55     /**
56      * Default constructor
57      */
58     ImageRequest()
59     {
60     }
61
62     /**
63      * @param[in] filename to load
64      * @param[in] width Width of image.
65      * @param[in] height Height of image.
66      */
67     ImageRequest( const std::string& filename, unsigned int width, unsigned int height )
68     : mFilename( filename )
69     {
70       mAttributes.SetSize( width, height );
71     }
72
73     std::string mFilename;                  ///< filename of image
74     ImageAttributes mAttributes;            ///< attributes of image
75   };
76
77 public:
78
79   /**
80    * Create a new ImageView.
81    * @return A public handle to the newly allocated ImageView.
82    */
83   static Dali::Toolkit::ImageView New();
84
85 public:
86
87   /**
88    * @copydoc Toolkit::ImageView::SetImage(const std::string& filename, ImageType type, float min, float max)
89    */
90   void SetImage(const std::string& filename, ImageType type, float min, float max);
91
92   /**
93    * @copydoc Toolkit::ImageView::SetImage(Image& image);
94    */
95   void SetImage(Image image);
96
97   /**
98    * Adds an image to displayed at a detail range.
99    *
100    * @note If two or more images are specified to be displayed at
101    * the same overlapping range. Then the last image that was added
102    * will be displayed.
103    *
104    * @param[in] req The image to load and display
105    * @param[in] condition The detail condition to be satisified for the image to display
106    */
107   void AddImage(ImageRequest& req, PropertyCondition condition);
108
109   /**
110    * @copydoc Toolkit::ImageView::SetCameraActor
111    */
112   void SetCameraActor(CameraActor camera, float detailFactor);
113
114   /**
115    * @copydoc Toolkit::ImageView::SetDetail
116    */
117   void SetDetail(float detail);
118
119 protected:
120
121   /**
122    * Construct a new ImageView.
123    */
124   ImageView();
125
126   /**
127    * 2nd-phase initialization.
128    */
129   void Initialize();
130
131   /**
132    * A reference counted object may only be deleted by calling Unreference()
133    */
134   virtual ~ImageView();
135
136 private:
137
138   /**
139    * Sets a Bitmap Image as the image to display for this ImageView
140    * min and max represent the minimum and maximum sizes to load.
141    * sizes will be created at 2^n scale factor. where n goes from
142    * ceil(log2(min)) to ceil(log2(max))
143    *
144    * @param[in] filename the image path to load
145    * @param[in] min the minimum size to load
146    * @param[in] max the maximum size to load
147    */
148   void SetImageBitmap(const std::string& filename, float min, float max);
149
150   /**
151    * Sets a Distance Field Image as the image to display for this ImageView
152    *
153    * @param[in] filename the image path to load
154    */
155   void SetImageDistanceField(const std::string& filename);
156
157   /**
158    * Invoked whenever the detail property passes a notification point.
159    * @param[in] notification The notification instance.
160    */
161   virtual void OnDetailChange(PropertyNotification& notification );
162
163 private:
164
165   // Undefined
166   ImageView(const ImageView&);
167
168   // Undefined
169   ImageView& operator=(const ImageView& rhs);
170
171 private:
172
173   Property::Index mPropertyDetail;                              ///< Detail property, changing this affects the level of detail of the content.
174   ImageActor mImageActor;                                       ///< Holding image actor for the various images at differing levels of detail.
175   std::map<PropertyNotification, ImageRequest> mNotifications;  ///< Property Notification -> Image map table.
176
177   PropertyNotification mPropertyNotification;   ///< Property notification
178 };
179
180 } // namespace Internal
181
182 // Helpers for public-api forwarding methods
183
184 inline Toolkit::Internal::ImageView& GetImpl(Toolkit::ImageView& pub)
185 {
186   DALI_ASSERT_ALWAYS(pub);
187
188   Dali::RefObject& handle = pub.GetImplementation();
189
190   return static_cast<Toolkit::Internal::ImageView&>(handle);
191 }
192
193 inline const Toolkit::Internal::ImageView& GetImpl(const Toolkit::ImageView& pub)
194 {
195   DALI_ASSERT_ALWAYS(pub);
196
197   const Dali::RefObject& handle = pub.GetImplementation();
198
199   return static_cast<const Toolkit::Internal::ImageView&>(handle);
200 }
201
202 } // namespace Toolkit
203
204 } // namespace Dali
205
206 #endif // __DALI_TOOLKIT_INTERNAL_ImageView_H__