e5e04e3236a86e3ec1d75932c566587e03988944
[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::MaskFinishedSignal
135    */
136   Dali::Toolkit::MaskedImageView::MaskedImageViewSignal& MaskFinishedSignal();
137
138 protected:
139
140   /**
141    * @copydoc Dali::CustomActorImpl::OnPropertySet()
142    */
143   void OnPropertySet( Property::Index index, Property::Value propertyValue );
144
145   /**
146    * Helper for edit mode.
147    */
148   void OnPan( Actor source, PanGesture gesture );
149
150   /**
151    * Helper for edit mode.
152    */
153   void OnPinch( Actor actor, PinchGesture pinch );
154
155   /**
156    * Construct a new MaskedImageView.
157    */
158   MaskedImageView();
159
160   /**
161    * 2nd-phase initialization.
162    */
163   void Initialize( unsigned int targetWidth,
164                    unsigned int targetHeight,
165                    Image sourceImage,
166                    Image maskImage );
167
168   /**
169    * Helper to apply the desired shader-effect for a given rotation.
170    * @param[in] rotation The rotation to apply to the source image.
171    */
172   void ApplyMaskedImageShader( ImageRotation rotation );
173
174   /**
175    * Helper to clamp the source image properties (only in edit mode).
176    */
177   void ClampSourceSizeAndOffset();
178
179   /**
180    * A reference counted object may only be deleted by calling Unreference()
181    */
182   virtual ~MaskedImageView();
183
184 private:
185
186   // Undefined
187   MaskedImageView(const MaskedImageView&);
188
189   // Undefined
190   MaskedImageView& operator=(const MaskedImageView& rhs);
191
192   /**
193    * Emit MaskFinishedSignal when the render task finished rendering
194    * @param[in] renderTask the off-screen render task
195    */
196   void OnRenderTaskFinished( Dali::RenderTask& renderTask );
197
198 private:
199
200   Vector2 mTargetSize;
201
202   Property::Index mCustomProperties[ Dali::Toolkit::MaskedImageView::CUSTOM_PROPERTY_COUNT ];
203
204   // Used for off-screen rendering
205   RenderTask mRenderTask;
206   ImageActor mSourceImageActor;
207   FrameBufferImage mDestinationImage;
208
209   // Create actor to display result of off-screen rendering
210   ImageActor mDestinationImageActor;
211
212   // Because ShaderEffect doesn't have a GetEffectImage()
213   Image mMaskImage;
214
215   // For edit mode
216   Dali::Toolkit::MaskedImageView::EditMode mEditMode;
217   PanGestureDetector mPanGestureDetector;
218   PinchGestureDetector mPinchDetector;
219   bool mSelfPropertySetting;
220
221   struct ImagePosition
222   {
223     Vector2 mPanOffset;
224     Vector2 mStartPinchSize;
225     Vector2 mCurrentPinchSize;
226   };
227   ImagePosition mSourcePosition;
228   ImagePosition mMaskPosition;
229
230   ImageRotation mSourceRotation;
231
232   // Limits for edit mode
233   float mWidthOverHeight;
234   float mMaximumSourceScale;
235
236   Dali::Toolkit::MaskedImageView::MaskedImageViewSignal mMaskFinishedSignal;
237 };
238
239 } // namespace Internal
240
241 // Helpers for public-api forwarding methods
242
243 inline Toolkit::Internal::MaskedImageView& GetImpl(Toolkit::MaskedImageView& pub)
244 {
245   DALI_ASSERT_ALWAYS(pub);
246
247   Dali::RefObject& handle = pub.GetImplementation();
248
249   return static_cast<Toolkit::Internal::MaskedImageView&>(handle);
250 }
251
252 inline const Toolkit::Internal::MaskedImageView& GetImpl(const Toolkit::MaskedImageView& pub)
253 {
254   DALI_ASSERT_ALWAYS(pub);
255
256   const Dali::RefObject& handle = pub.GetImplementation();
257
258   return static_cast<const Toolkit::Internal::MaskedImageView&>(handle);
259 }
260
261 } // namespace Toolkit
262
263 } // namespace Dali
264
265 #endif // __DALI_TOOLKIT_INTERNAL_MASKED_IMAGE_VIEW_H__