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