void DissolveEffectApp::StartTransition(Vector2 position, Vector2 displacement) { mAnimation = Animation::New(TRANSITION_DURATION); Dali::Toolkit::DissolveEffectSetCentralLine( mCurrentImage, position, displacement, 0.0f ); mCurrentImage.SetProperty( Toolkit::ImageView::Property::IMAGE, mDissolveEffect ); mAnimation.AnimateTo( Property( mCurrentImage, "uPercentage" ), 1.0f, AlphaFunction::LINEAR ); mNextImage.SetOpacity(0.0f); mAnimation.AnimateTo( Property( mNextImage, Actor::Property::COLOR_ALPHA ), 1.0f, AlphaFunction::LINEAR ); if(mUseHighPrecision) { Dali::Toolkit::DissolveEffectSetCentralLine( mNextImage, position, displacement, 1.0f ); mNextImage.SetProperty( Toolkit::ImageView::Property::IMAGE, mDissolveEffect ); mAnimation.AnimateTo( Property( mNextImage, "uPercentage" ), 0.0f, AlphaFunction::LINEAR ); } else { mAnimation.AnimateTo( Property( mNextImage, Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), AlphaFunction::LINEAR ); } mAnimation.FinishedSignal().Connect( this, &DissolveEffectApp::OnTransitionCompleted ); mAnimation.Play(); mIsTransiting = true; }
// signal handler, called when the pan gesture is detected void DissolveEffectApp::OnPanGesture( Actor actor, const PanGesture& gesture ) { // does not response when the animation has not finished if( mIsTransiting || mSlideshow ) { return; } if( gesture.state == Gesture::Continuing ) { if( gesture.displacement.x < 0) { mIndex = (mIndex + 1)%NUM_IMAGES; } else { mIndex = (mIndex + NUM_IMAGES -1)%NUM_IMAGES; } mNextImage = CreateStageFillingImageView( IMAGES[ mIndex ] ); mNextImage.SetParentOrigin( ParentOrigin::CENTER ); mNextImage.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); mNextImage.SetSizeScalePolicy( SizeScalePolicy::FIT_WITH_ASPECT_RATIO ); mNextImage.SetZ(INITIAL_DEPTH); mParent.Add( mNextImage ); Vector2 size = Vector2( mCurrentImage.GetCurrentSize() ); StartTransition( gesture.position / size, gesture.displacement * Vector2(1.0, size.x/size.y)); } }
void DissolveEffectApp::OnInit( Application& application ) { Stage::GetCurrent().KeyEventSignal().Connect(this, &DissolveEffectApp::OnKeyEvent); // Creates a default view with a default tool bar, the view is added to the stage. mContent = DemoHelper::CreateView( application, mView,mToolBar, "", TOOLBAR_IMAGE, "" ); // Add an effect-changing button on the right of the tool bar. mEffectChangeButton = Toolkit::PushButton::New(); mEffectChangeButton.SetProperty( Toolkit::Button::Property::UNSELECTED_STATE_IMAGE, EFFECT_HIGHP_IMAGE ); mEffectChangeButton.SetProperty( Toolkit::Button::Property::SELECTED_STATE_IMAGE, EFFECT_HIGHP_IMAGE_SELECTED ); mEffectChangeButton.ClickedSignal().Connect( this, &DissolveEffectApp::OnEffectButtonClicked ); mToolBar.AddControl( mEffectChangeButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalRight, DemoHelper::DEFAULT_MODE_SWITCH_PADDING ); // Add title to the tool bar. mTitleActor = DemoHelper::CreateToolBarLabel( APPLICATION_TITLE_HIGHP ); mToolBar.AddControl( mTitleActor, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarTitlePercentage, Toolkit::Alignment::HorizontalCenter ); // Add an slide-show button on the right of the title mPlayStopButton = Toolkit::PushButton::New(); mPlayStopButton.SetProperty( Toolkit::Button::Property::UNSELECTED_STATE_IMAGE, PLAY_ICON ); mPlayStopButton.SetProperty( Toolkit::Button::Property::SELECTED_STATE_IMAGE, PLAY_ICON_SELECTED ); mPlayStopButton.ClickedSignal().Connect( this, &DissolveEffectApp::OnSildeshowButtonClicked ); mToolBar.AddControl( mPlayStopButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalCenter, DemoHelper::DEFAULT_PLAY_PADDING ); // use pan gesture to detect the cursor or finger movement mPanGestureDetector = PanGestureDetector::New(); mPanGestureDetector.DetectedSignal().Connect( this, &DissolveEffectApp::OnPanGesture ); mViewTimer = Timer::New( VIEWINGTIME ); mViewTimer.TickSignal().Connect( this, &DissolveEffectApp::OnTimerTick ); mTimerReady = true; // Set size to stage size to avoid seeing a black border on transition mParent = Actor::New(); mParent.SetSize( Stage::GetCurrent().GetSize() ); mParent.SetParentOrigin( ParentOrigin::CENTER ); mContent.Add( mParent ); // show the first image mCurrentImage = CreateStageFillingImageView( IMAGES[mIndex] ); mCurrentImage.SetParentOrigin( ParentOrigin::CENTER ); mCurrentImage.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); mCurrentImage.SetSizeScalePolicy( SizeScalePolicy::FIT_WITH_ASPECT_RATIO ); mParent.Add( mCurrentImage ); mPanGestureDetector.Attach( mCurrentImage ); mDissolveEffect = Dali::Toolkit::CreateDissolveEffect( mUseHighPrecision ); Property::Map emptyShaderMap; mEmptyEffect.Insert( "shader", emptyShaderMap ); }
bool DissolveEffectApp::OnTimerTick() { mTimerReady = true; if(mSlideshow) { mIndex = (mIndex + 1)%NUM_IMAGES; mNextImage = CreateStageFillingImageView( IMAGES[ mIndex ] ); mNextImage.SetParentOrigin( ParentOrigin::CENTER ); mNextImage.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); mNextImage.SetSizeScalePolicy( SizeScalePolicy::FIT_WITH_ASPECT_RATIO ); mNextImage.SetZ(INITIAL_DEPTH); mParent.Add( mNextImage ); switch( mCentralLineIndex%4 ) { case 0: { StartTransition(Vector2(1.0f,0.5f), Vector2(-1.0f, 0.0f)); break; } case 1: { StartTransition(Vector2(0.5f,0.0f), Vector2(0.0f, 1.0f)); break; } case 2: { StartTransition(Vector2(0.0f,0.5f), Vector2(1.0f, 0.0f)); break; } default: { StartTransition(Vector2(0.5f,1.0f), Vector2(0.0f, -1.0f)); break; } } mCentralLineIndex++; } return false; //return false to stop the timer }
void DissolveEffectApp::OnTransitionCompleted( Animation& source ) { if(mUseHighPrecision) { mNextImage.SetProperty( Toolkit::ImageView::Property::IMAGE, mEmptyEffect ); } mParent.Remove( mCurrentImage ); mPanGestureDetector.Detach( mCurrentImage ); mCurrentImage = mNextImage; mPanGestureDetector.Attach( mCurrentImage ); mIsTransiting = false; if( mSlideshow) { mViewTimer.Start(); mTimerReady = false; } }
void Create( Application& application ) { // Get a handle to the stage Stage stage = Stage::GetCurrent(); stage.SetBackgroundColor(Color::YELLOW); // Respond to a click anywhere on the stage stage.KeyEventSignal().Connect(this, &AtlasController::OnKeyEvent); mApplication.GetWindow().ShowIndicator( Dali::Window::INVISIBLE ); mContentLayer = DemoHelper::CreateView( mApplication, mView, mToolBar, BACKGROUND_IMAGE, TOOLBAR_IMAGE, "Atlas" ); mLoseContextButton = Toolkit::PushButton::New(); mLoseContextButton.SetUnselectedImage( LOSE_CONTEXT_IMAGE ); mLoseContextButton.SetSelectedImage( LOSE_CONTEXT_IMAGE_SELECTED ); mLoseContextButton.ClickedSignal().Connect( this, &AtlasController::OnLoseContextButtonClicked ); mToolBar.AddControl( mLoseContextButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalRight, DemoHelper::DEFAULT_MODE_SWITCH_PADDING ); mAtlas = Atlas::New( 400,300, Pixel::RGBA8888); mAtlas.Clear(Vector4(0.f,0.5f,0.5f,0.5f)); mAtlas.Upload( DALI_IMAGE_DIR "icon-change.png", 50, 30 ); mAtlas.Upload( DALI_IMAGE_DIR "icon-cluster-carousel.png", 100, 30 ); mAtlas.Upload( DALI_IMAGE_DIR "icon-effects-on.png", 150, 30 ); mAtlas.Upload( DALI_IMAGE_DIR "icon-effect-cross.png", 100, 80 ); mAtlas.Upload( DALI_IMAGE_DIR "icon-effect-fold.png", 150, 80 ); mAtlas.Upload( DALI_IMAGE_DIR "icon-effect-wave.png", 200, 80 ); mAtlas.Upload( DALI_IMAGE_DIR "icon-item-view-layout-depth.png", 150, 130 ); mAtlas.Upload( DALI_IMAGE_DIR "icon-item-view-layout-grid.png", 200, 130 ); mAtlas.Upload( DALI_IMAGE_DIR "icon-item-view-layout-spiral.png", 250, 130 ); UploadBufferImages(); Toolkit::ImageView imageActor1 = Toolkit::ImageView::New( mAtlas ); imageActor1.SetY(-170.f); imageActor1.SetParentOrigin(ParentOrigin::CENTER); mContentLayer.Add( imageActor1 ); Atlas atlas2 = Atlas::New( 400,400, Pixel::RGB888); atlas2.Clear( Color::RED ); atlas2.Upload( DALI_IMAGE_DIR "gallery-small-1.jpg", 4, 4 ); atlas2.Clear( Color::BLUE ); atlas2.Upload( DALI_IMAGE_DIR "gallery-small-2.jpg", 136, 4 ); atlas2.Upload( DALI_IMAGE_DIR "gallery-small-3.jpg", 268, 4 ); atlas2.Upload( DALI_IMAGE_DIR "gallery-small-4.jpg", 4, 136 ); atlas2.Upload( DALI_IMAGE_DIR "gallery-small-5.jpg", 136, 136 ); atlas2.Upload( DALI_IMAGE_DIR "gallery-small-6.jpg", 268, 135 ); atlas2.Upload( DALI_IMAGE_DIR "gallery-small-7.jpg", 4, 268 ); atlas2.Upload( DALI_IMAGE_DIR "gallery-small-7.jpg", 136, 268 ); atlas2.Upload( DALI_IMAGE_DIR "gallery-small-7.jpg", 268, 268 ); Toolkit::ImageView imageView = Toolkit::ImageView::New( DALI_IMAGE_DIR "gallery-small-1.jpg" ); imageView.SetY(200.f); imageView.SetZ(-1.f); imageView.SetParentOrigin(ParentOrigin::CENTER); mContentLayer.Add( imageView ); mPanGestureDetector = PanGestureDetector::New(); mPanGestureDetector.DetectedSignal().Connect( this, &AtlasController::OnPanGesture ); mPanGestureDetector.Attach( imageActor1 ); mPanGestureDetector.Attach( imageView ); stage.ContextLostSignal().Connect( this, &AtlasController::OnContextLost ); stage.ContextRegainedSignal().Connect( this, &AtlasController::OnContextRegained ); }