a1c828511898a4c285e8a4d0d47bfdde4bde2a31
[platform/core/uifw/dali-toolkit.git] / 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, const PanGesture& gesture );
153
154   /**
155    * Helper for edit mode.
156    */
157   void OnPinch( Actor actor, const 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   /**
189    *
190    * @copydoc Toolkit::Control::OnControlSizeSet( const Vector3& targetSize )
191    */
192   virtual void OnControlSizeSet( const Vector3& targetSize );
193
194 private:
195
196   // Undefined
197   MaskedImageView(const MaskedImageView&);
198
199   // Undefined
200   MaskedImageView& operator=(const MaskedImageView& rhs);
201
202   /**
203    * Emit MaskFinishedSignal when the render task finished rendering
204    * @param[in] renderTask the off-screen render task
205    */
206   void OnRenderTaskFinished( Dali::RenderTask& renderTask );
207
208 private:
209
210   Vector2 mTargetSize;
211
212   Property::Index mCustomProperties[ Dali::Toolkit::MaskedImageView::CUSTOM_PROPERTY_COUNT ];
213
214   // Used for off-screen rendering
215   RenderTask mRenderTask;
216   ImageActor mSourceImageActor;
217   FrameBufferImage mDestinationImage;
218
219   // Create actor to display result of off-screen rendering
220   ImageActor mDestinationImageActor;
221
222   // Because ShaderEffect doesn't have a GetEffectImage()
223   Image mMaskImage;
224
225   // For edit mode
226   Dali::Toolkit::MaskedImageView::EditMode mEditMode;
227   PanGestureDetector mPanGestureDetector;
228   PinchGestureDetector mPinchDetector;
229   bool mSelfPropertySetting;
230
231   struct ImagePosition
232   {
233     Vector2 mPanOffset;
234     Vector2 mStartPinchSize;
235     Vector2 mCurrentPinchSize;
236   };
237   ImagePosition mSourcePosition;
238   ImagePosition mMaskPosition;
239
240   ImageRotation mSourceRotation;
241
242   // Limits for edit mode
243   float mWidthOverHeight;
244   float mMaximumSourceScale;
245
246   Dali::Toolkit::MaskedImageView::MaskedImageViewSignal mMaskFinishedSignal;
247 };
248
249 } // namespace Internal
250
251 // Helpers for public-api forwarding methods
252
253 inline Toolkit::Internal::MaskedImageView& GetImpl(Toolkit::MaskedImageView& pub)
254 {
255   DALI_ASSERT_ALWAYS(pub);
256
257   Dali::RefObject& handle = pub.GetImplementation();
258
259   return static_cast<Toolkit::Internal::MaskedImageView&>(handle);
260 }
261
262 inline const Toolkit::Internal::MaskedImageView& GetImpl(const Toolkit::MaskedImageView& pub)
263 {
264   DALI_ASSERT_ALWAYS(pub);
265
266   const Dali::RefObject& handle = pub.GetImplementation();
267
268   return static_cast<const Toolkit::Internal::MaskedImageView&>(handle);
269 }
270
271 } // namespace Toolkit
272
273 } // namespace Dali
274
275 #endif // __DALI_TOOLKIT_INTERNAL_MASKED_IMAGE_VIEW_H__