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