Include required header files directly rather than through dali.h
[platform/core/uifw/dali-toolkit.git] / optional / dali-toolkit / internal / controls / image-view / masked-image-view-impl.h
1 #ifndef __DALI_TOOLKIT_INTERNAL_MASKED_IMAGE_VIEW_H__
2 #define __DALI_TOOLKIT_INTERNAL_MASKED_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 // EXTERNAL INCLUDES
22 #include <dali/public-api/actors/image-actor.h>
23 #include <dali/public-api/render-tasks/render-task.h>
24 #include <dali/public-api/images/frame-buffer-image.h>
25
26 // INTERNAL INCLUDES
27 #include <dali-toolkit/public-api/controls/control-impl.h>
28 #include <dali-toolkit/public-api/controls/image-view/masked-image-view.h>
29
30 namespace Dali
31 {
32
33 namespace Toolkit
34 {
35
36 namespace Internal
37 {
38
39 /**
40  * @copydoc Dali::Toolkit::MaskedImageView
41  */
42 class MaskedImageView : public Control
43 {
44 public:
45
46   typedef Dali::Toolkit::MaskedImageView::ImageRotation ImageRotation;
47
48   /**
49    * Create a new MaskedImageView.
50    * @return A public handle to the newly allocated MaskedImageView.
51    */
52   static Dali::Toolkit::MaskedImageView New( unsigned int targetWidth,
53                                              unsigned int targetHeight,
54                                              Image sourceImage,
55                                              Image maskImage );
56
57   /**
58    * @copydoc Dali::Toolkit::MaskedImageView::SetSourceImage()
59    */
60   void SetSourceImage( Image sourceImage );
61
62   /**
63    * @copydoc Dali::Toolkit::MaskedImageView::GetSourceImage()
64    */
65   Image GetSourceImage();
66
67   /**
68    * @copydoc Dali::Toolkit::MaskedImageView::SetMaskImage()
69    */
70   void SetMaskImage( Image maskImage );
71
72   /**
73    * @copydoc Dali::Toolkit::MaskedImageView::GetMaskImage()
74    */
75   Image GetMaskImage();
76
77   /**
78    * @copydoc Dali::Toolkit::MaskedImageView::GetPropertyIndex()
79    */
80   Property::Index GetPropertyIndex( Dali::Toolkit::MaskedImageView::CustomProperty customProperty ) const;
81
82   /**
83    * @copydoc Dali::Toolkit::MaskedImageView::Pause()
84    */
85   void Pause();
86
87   /**
88    * @copydoc Dali::Toolkit::MaskedImageView::Resume()
89    */
90   void Resume();
91
92   /**
93    * @copydoc Dali::Toolkit::MaskedImageView::IsPaused()
94    */
95   bool IsPaused() const;
96
97   /**
98    * @copydoc Dali::Toolkit::MaskedImageView::SetEditMode()
99    */
100   void SetEditMode( Dali::Toolkit::MaskedImageView::EditMode editMode );
101
102   /**
103    * @copydoc Dali::Toolkit::MaskedImageView::GetEditMode()
104    */
105   Dali::Toolkit::MaskedImageView::EditMode GetEditMode() const;
106
107   /**
108    * @copydoc Dali::Toolkit::MaskedImageView::SetSourceAspectRatio()
109    */
110   void SetSourceAspectRatio( float widthOverHeight );
111
112   /**
113    * @copydoc Dali::Toolkit::MaskedImageView::GetSourceAspectRatio()
114    */
115   float GetSourceAspectRatio() const;
116
117   /**
118    * @copydoc Dali::Toolkit::MaskedImageView::SetMaximumSourceScale()
119    */
120   void SetMaximumSourceScale( float scale );
121
122   /**
123    * @copydoc Dali::Toolkit::MaskedImageView::GetMaximumSourceScale()
124    */
125   float GetMaximumSourceScale() const;
126
127   /**
128    * @copydoc Dali::Toolkit::MaskedImageView::SetSourceRotation()
129    */
130   void SetSourceRotation( ImageRotation rotation );
131
132   /**
133    * @copydoc Dali::Toolkit::MaskedImageView::GetSourceRotation()
134    */
135   ImageRotation GetSourceRotation() const;
136
137   /**
138    * @copydoc Dali::Toolkit::MaskedImageView::MaskFinishedSignal
139    */
140   Dali::Toolkit::MaskedImageView::MaskedImageViewSignal& MaskFinishedSignal();
141
142 protected:
143
144   /**
145    * @copydoc Dali::CustomActorImpl::OnPropertySet()
146    */
147   void OnPropertySet( Property::Index index, Property::Value propertyValue );
148
149   /**
150    * Helper for edit mode.
151    */
152   void OnPan( Actor source, PanGesture gesture );
153
154   /**
155    * Helper for edit mode.
156    */
157   void OnPinch( Actor actor, PinchGesture pinch );
158
159   /**
160    * Construct a new MaskedImageView.
161    */
162   MaskedImageView();
163
164   /**
165    * 2nd-phase initialization.
166    */
167   void Initialize( unsigned int targetWidth,
168                    unsigned int targetHeight,
169                    Image sourceImage,
170                    Image maskImage );
171
172   /**
173    * Helper to apply the desired shader-effect for a given rotation.
174    * @param[in] rotation The rotation to apply to the source image.
175    */
176   void ApplyMaskedImageShader( ImageRotation rotation );
177
178   /**
179    * Helper to clamp the source image properties (only in edit mode).
180    */
181   void ClampSourceSizeAndOffset();
182
183   /**
184    * A reference counted object may only be deleted by calling Unreference()
185    */
186   virtual ~MaskedImageView();
187
188 private:
189
190   // Undefined
191   MaskedImageView(const MaskedImageView&);
192
193   // Undefined
194   MaskedImageView& operator=(const MaskedImageView& rhs);
195
196   /**
197    * Emit MaskFinishedSignal when the render task finished rendering
198    * @param[in] renderTask the off-screen render task
199    */
200   void OnRenderTaskFinished( Dali::RenderTask& renderTask );
201
202 private:
203
204   Vector2 mTargetSize;
205
206   Property::Index mCustomProperties[ Dali::Toolkit::MaskedImageView::CUSTOM_PROPERTY_COUNT ];
207
208   // Used for off-screen rendering
209   RenderTask mRenderTask;
210   ImageActor mSourceImageActor;
211   FrameBufferImage mDestinationImage;
212
213   // Create actor to display result of off-screen rendering
214   ImageActor mDestinationImageActor;
215
216   // Because ShaderEffect doesn't have a GetEffectImage()
217   Image mMaskImage;
218
219   // For edit mode
220   Dali::Toolkit::MaskedImageView::EditMode mEditMode;
221   PanGestureDetector mPanGestureDetector;
222   PinchGestureDetector mPinchDetector;
223   bool mSelfPropertySetting;
224
225   struct ImagePosition
226   {
227     Vector2 mPanOffset;
228     Vector2 mStartPinchSize;
229     Vector2 mCurrentPinchSize;
230   };
231   ImagePosition mSourcePosition;
232   ImagePosition mMaskPosition;
233
234   ImageRotation mSourceRotation;
235
236   // Limits for edit mode
237   float mWidthOverHeight;
238   float mMaximumSourceScale;
239
240   Dali::Toolkit::MaskedImageView::MaskedImageViewSignal mMaskFinishedSignal;
241 };
242
243 } // namespace Internal
244
245 // Helpers for public-api forwarding methods
246
247 inline Toolkit::Internal::MaskedImageView& GetImpl(Toolkit::MaskedImageView& pub)
248 {
249   DALI_ASSERT_ALWAYS(pub);
250
251   Dali::RefObject& handle = pub.GetImplementation();
252
253   return static_cast<Toolkit::Internal::MaskedImageView&>(handle);
254 }
255
256 inline const Toolkit::Internal::MaskedImageView& GetImpl(const Toolkit::MaskedImageView& pub)
257 {
258   DALI_ASSERT_ALWAYS(pub);
259
260   const Dali::RefObject& handle = pub.GetImplementation();
261
262   return static_cast<const Toolkit::Internal::MaskedImageView&>(handle);
263 }
264
265 } // namespace Toolkit
266
267 } // namespace Dali
268
269 #endif // __DALI_TOOLKIT_INTERNAL_MASKED_IMAGE_VIEW_H__