1 #ifndef __DALI_TOOLKIT_INTERNAL_MASKED_IMAGE_VIEW_H__
2 #define __DALI_TOOLKIT_INTERNAL_MASKED_IMAGE_VIEW_H__
5 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
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>
27 #include <dali-toolkit/public-api/controls/control-impl.h>
28 #include <dali-toolkit/public-api/controls/image-view/masked-image-view.h>
40 * @copydoc Dali::Toolkit::MaskedImageView
42 class MaskedImageView : public Control
46 typedef Dali::Toolkit::MaskedImageView::ImageRotation ImageRotation;
49 * Create a new MaskedImageView.
50 * @return A public handle to the newly allocated MaskedImageView.
52 static Dali::Toolkit::MaskedImageView New( unsigned int targetWidth,
53 unsigned int targetHeight,
58 * @copydoc Dali::Toolkit::MaskedImageView::SetSourceImage()
60 void SetSourceImage( Image sourceImage );
63 * @copydoc Dali::Toolkit::MaskedImageView::GetSourceImage()
65 Image GetSourceImage();
68 * @copydoc Dali::Toolkit::MaskedImageView::SetMaskImage()
70 void SetMaskImage( Image maskImage );
73 * @copydoc Dali::Toolkit::MaskedImageView::GetMaskImage()
78 * @copydoc Dali::Toolkit::MaskedImageView::GetPropertyIndex()
80 Property::Index GetPropertyIndex( Dali::Toolkit::MaskedImageView::CustomProperty customProperty ) const;
83 * @copydoc Dali::Toolkit::MaskedImageView::Pause()
88 * @copydoc Dali::Toolkit::MaskedImageView::Resume()
93 * @copydoc Dali::Toolkit::MaskedImageView::IsPaused()
95 bool IsPaused() const;
98 * @copydoc Dali::Toolkit::MaskedImageView::SetEditMode()
100 void SetEditMode( Dali::Toolkit::MaskedImageView::EditMode editMode );
103 * @copydoc Dali::Toolkit::MaskedImageView::GetEditMode()
105 Dali::Toolkit::MaskedImageView::EditMode GetEditMode() const;
108 * @copydoc Dali::Toolkit::MaskedImageView::SetSourceAspectRatio()
110 void SetSourceAspectRatio( float widthOverHeight );
113 * @copydoc Dali::Toolkit::MaskedImageView::GetSourceAspectRatio()
115 float GetSourceAspectRatio() const;
118 * @copydoc Dali::Toolkit::MaskedImageView::SetMaximumSourceScale()
120 void SetMaximumSourceScale( float scale );
123 * @copydoc Dali::Toolkit::MaskedImageView::GetMaximumSourceScale()
125 float GetMaximumSourceScale() const;
128 * @copydoc Dali::Toolkit::MaskedImageView::SetSourceRotation()
130 void SetSourceRotation( ImageRotation rotation );
133 * @copydoc Dali::Toolkit::MaskedImageView::GetSourceRotation()
135 ImageRotation GetSourceRotation() const;
138 * @copydoc Dali::Toolkit::MaskedImageView::MaskFinishedSignal
140 Dali::Toolkit::MaskedImageView::MaskedImageViewSignal& MaskFinishedSignal();
145 * @copydoc Dali::CustomActorImpl::OnPropertySet()
147 void OnPropertySet( Property::Index index, Property::Value propertyValue );
150 * Helper for edit mode.
152 void OnPan( Actor source, const PanGesture& gesture );
155 * Helper for edit mode.
157 void OnPinch( Actor actor, const PinchGesture& pinch );
160 * Construct a new MaskedImageView.
165 * 2nd-phase initialization.
167 void Initialize( unsigned int targetWidth,
168 unsigned int targetHeight,
173 * Helper to apply the desired shader-effect for a given rotation.
174 * @param[in] rotation The rotation to apply to the source image.
176 void ApplyMaskedImageShader( ImageRotation rotation );
179 * Helper to clamp the source image properties (only in edit mode).
181 void ClampSourceSizeAndOffset();
184 * A reference counted object may only be deleted by calling Unreference()
186 virtual ~MaskedImageView();
190 * @copydoc Toolkit::Control::OnControlSizeSet( const Vector3& targetSize )
192 virtual void OnControlSizeSet( const Vector3& targetSize );
197 MaskedImageView(const MaskedImageView&);
200 MaskedImageView& operator=(const MaskedImageView& rhs);
203 * Emit MaskFinishedSignal when the render task finished rendering
204 * @param[in] renderTask the off-screen render task
206 void OnRenderTaskFinished( Dali::RenderTask& renderTask );
212 Property::Index mCustomProperties[ Dali::Toolkit::MaskedImageView::CUSTOM_PROPERTY_COUNT ];
214 // Used for off-screen rendering
215 RenderTask mRenderTask;
216 ImageActor mSourceImageActor;
217 FrameBufferImage mDestinationImage;
219 // Create actor to display result of off-screen rendering
220 ImageActor mDestinationImageActor;
222 // Because ShaderEffect doesn't have a GetEffectImage()
226 Dali::Toolkit::MaskedImageView::EditMode mEditMode;
227 PanGestureDetector mPanGestureDetector;
228 PinchGestureDetector mPinchDetector;
229 bool mSelfPropertySetting;
234 Vector2 mStartPinchSize;
235 Vector2 mCurrentPinchSize;
237 ImagePosition mSourcePosition;
238 ImagePosition mMaskPosition;
240 ImageRotation mSourceRotation;
242 // Limits for edit mode
243 float mWidthOverHeight;
244 float mMaximumSourceScale;
246 Dali::Toolkit::MaskedImageView::MaskedImageViewSignal mMaskFinishedSignal;
249 } // namespace Internal
251 // Helpers for public-api forwarding methods
253 inline Toolkit::Internal::MaskedImageView& GetImpl(Toolkit::MaskedImageView& pub)
255 DALI_ASSERT_ALWAYS(pub);
257 Dali::RefObject& handle = pub.GetImplementation();
259 return static_cast<Toolkit::Internal::MaskedImageView&>(handle);
262 inline const Toolkit::Internal::MaskedImageView& GetImpl(const Toolkit::MaskedImageView& pub)
264 DALI_ASSERT_ALWAYS(pub);
266 const Dali::RefObject& handle = pub.GetImplementation();
268 return static_cast<const Toolkit::Internal::MaskedImageView&>(handle);
271 } // namespace Toolkit
275 #endif // __DALI_TOOLKIT_INTERNAL_MASKED_IMAGE_VIEW_H__