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