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