X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=examples%2Fgaussian-blur-view%2Fgaussian-blur-view-example.cpp;h=e9ff1cc6c18d9af263a1bd8be4dd5589d33abfa5;hb=1b19fd140ff139b5854a1a62447faf31b175d8f6;hp=6c68f69cc27ffceac6a43f5764e79390217c1a64;hpb=3a3e8aa1e057bb6efb73368d390f394bf2e5e278;p=platform%2Fcore%2Fuifw%2Fdali-demo.git diff --git a/examples/gaussian-blur-view/gaussian-blur-view-example.cpp b/examples/gaussian-blur-view/gaussian-blur-view-example.cpp index 6c68f69..e9ff1cc 100644 --- a/examples/gaussian-blur-view/gaussian-blur-view-example.cpp +++ b/examples/gaussian-blur-view/gaussian-blur-view-example.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,16 +21,15 @@ #include using namespace Dali; -using Dali::Toolkit::TextLabel; using Dali::Toolkit::GaussianBlurView; +using Dali::Toolkit::TextLabel; namespace { +const char* const BACKGROUND_IMAGE(DEMO_IMAGE_DIR "lake_front.jpg"); +const float BACKGROUND_IMAGE_WIDTH = 2048.0f; -const char* const BACKGROUND_IMAGE( DEMO_IMAGE_DIR "lake_front.jpg" ); -const float BACKGROUND_IMAGE_WIDTH = 2048.0f; - -} +} // namespace /** * This example shows a scrolling background image which can be blurred (on/off) by tapping the screen @@ -38,119 +37,111 @@ const float BACKGROUND_IMAGE_WIDTH = 2048.0f; class GaussianBlurViewExample : public ConnectionTracker { public: - - GaussianBlurViewExample( Application& application ) - : mApplication( application ), - mExcessWidth( 0.0f ), - mStrength( 1.0f ) + GaussianBlurViewExample(Application& application) + : mApplication(application), + mExcessWidth(0.0f), + mStrength(1.0f), + mActivate(false) { - mApplication.InitSignal().Connect( this, &GaussianBlurViewExample::Create ); + mApplication.InitSignal().Connect(this, &GaussianBlurViewExample::Create); } ~GaussianBlurViewExample() = default; private: - - void Create( Application& application ) + void Create(Application& application) { - Stage stage = Stage::GetCurrent(); - Vector2 stageSize = stage.GetSize(); - stage.KeyEventSignal().Connect(this, &GaussianBlurViewExample::OnKeyEvent); + auto window = application.GetWindow(); + Vector2 windowSize = window.GetSize(); + window.KeyEventSignal().Connect(this, &GaussianBlurViewExample::OnKeyEvent); - mImageView = Toolkit::ImageView::New( BACKGROUND_IMAGE ); - mImageView.SetParentOrigin( ParentOrigin::CENTER ); - mImageView.SetAnchorPoint( AnchorPoint::CENTER ); + mImageView = Toolkit::ImageView::New(BACKGROUND_IMAGE); + mImageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mImageView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); - stage.Add( mImageView ); + float excessWidth = std::max(0.0f, (BACKGROUND_IMAGE_WIDTH - windowSize.width) * 0.5f); - float excessWidth = std::max( 0.0f, (BACKGROUND_IMAGE_WIDTH - stageSize.width) * 0.5f ); - - if( excessWidth > 0.0f ) + if(excessWidth > 0.0f) { // Move background image to show GaussianBlurView activity float pixelsPerSecond = 10.0f; - float duration = excessWidth / pixelsPerSecond; - float qDuration = duration * 0.25f; + float duration = excessWidth / pixelsPerSecond; + float qDuration = duration * 0.25f; - mAnimation = Animation::New( duration ); - mAnimation.AnimateTo( Property(mImageView, Actor::Property::POSITION_X), excessWidth, TimePeriod(0.0f , qDuration) ); - mAnimation.AnimateTo( Property(mImageView, Actor::Property::POSITION_X), 0.0f, TimePeriod(qDuration , qDuration) ); - mAnimation.AnimateTo( Property(mImageView, Actor::Property::POSITION_X), -excessWidth, TimePeriod(2.0f*qDuration, qDuration) ); - mAnimation.AnimateTo( Property(mImageView, Actor::Property::POSITION_X), 0.0f, TimePeriod(3.0f*qDuration, qDuration) ); + mAnimation = Animation::New(duration); + mAnimation.AnimateTo(Property(mImageView, Actor::Property::POSITION_X), excessWidth, TimePeriod(0.0f, qDuration)); + mAnimation.AnimateTo(Property(mImageView, Actor::Property::POSITION_X), 0.0f, TimePeriod(qDuration, qDuration)); + mAnimation.AnimateTo(Property(mImageView, Actor::Property::POSITION_X), -excessWidth, TimePeriod(2.0f * qDuration, qDuration)); + mAnimation.AnimateTo(Property(mImageView, Actor::Property::POSITION_X), 0.0f, TimePeriod(3.0f * qDuration, qDuration)); - mAnimation.SetLooping( true ); + mAnimation.SetLooping(true); mAnimation.Play(); } Layer onTop = Layer::New(); - onTop.SetParentOrigin( ParentOrigin::CENTER ); - onTop.SetAnchorPoint( AnchorPoint::CENTER ); - onTop.SetSize( stageSize ); - stage.Add( onTop ); + onTop.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + onTop.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + onTop.SetProperty(Actor::Property::SIZE, windowSize); + window.Add(onTop); onTop.RaiseToTop(); - mOnLabel = TextLabel::New( "Blur ON" ); - mOnLabel.SetAnchorPoint( AnchorPoint::TOP_LEFT ); - mOnLabel.SetProperty( TextLabel::Property::TEXT_COLOR, Color::GREEN ); - mOnLabel.SetVisible( false ); - onTop.Add( mOnLabel ); + mOnLabel = TextLabel::New("Blur ON"); + mOnLabel.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + mOnLabel.SetProperty(TextLabel::Property::TEXT_COLOR, Color::GREEN); + mOnLabel.SetProperty(Actor::Property::VISIBLE, false); + onTop.Add(mOnLabel); + + mOffLabel = TextLabel::New("Blur OFF"); + mOffLabel.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + mOffLabel.SetProperty(TextLabel::Property::TEXT_COLOR, Color::WHITE); + mOffLabel.SetProperty(Actor::Property::VISIBLE, true); + onTop.Add(mOffLabel); + + mGaussianBlurView = GaussianBlurView::New(30, 8.0f, Pixel::RGBA8888, 0.5f, 0.5f, false); + mGaussianBlurView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mGaussianBlurView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + mGaussianBlurView.SetProperty(Actor::Property::SIZE, windowSize); + window.Add(mGaussianBlurView); - mOffLabel = TextLabel::New( "Blur OFF" ); - mOffLabel.SetAnchorPoint( AnchorPoint::TOP_LEFT ); - mOffLabel.SetProperty( TextLabel::Property::TEXT_COLOR, Color::WHITE ); - mOffLabel.SetVisible( true ); - onTop.Add( mOffLabel ); + mGaussianBlurView.Add(mImageView); + mGaussianBlurView.SetProperty(mGaussianBlurView.GetBlurStrengthPropertyIndex(), mStrength); - stage.GetRootLayer().TouchSignal().Connect( this, &GaussianBlurViewExample::OnTouch ); + window.GetRootLayer().TouchedSignal().Connect(this, &GaussianBlurViewExample::OnTouch); } - bool OnTouch( Actor actor, const TouchData& touch ) + bool OnTouch(Actor actor, const TouchEvent& touch) { - const PointState::Type state = touch.GetState( 0 ); + const PointState::Type state = touch.GetState(0); - if( PointState::DOWN == state ) + if(PointState::DOWN == state) + { + if(!mActivate) { - Stage stage = Stage::GetCurrent(); - - // Enable/disable blur effect + mActivate = true; + mGaussianBlurView.Activate(); - if( !mGaussianBlurView ) - { - mGaussianBlurView = GaussianBlurView::New( 30, 8.0f, Pixel::RGBA8888, 0.5f, 0.5f, false ); - mGaussianBlurView.SetParentOrigin( ParentOrigin::CENTER ); - mGaussianBlurView.SetAnchorPoint( AnchorPoint::CENTER ); - mGaussianBlurView.SetSize( stage.GetSize() ); - stage.Add( mGaussianBlurView ); - - mGaussianBlurView.Add( mImageView ); - mGaussianBlurView.Activate(); - - mGaussianBlurView.SetProperty( mGaussianBlurView.GetBlurStrengthPropertyIndex(), mStrength ); - - mOnLabel.SetVisible( true ); - mOffLabel.SetVisible( false ); - } - else - { - stage.Add( mImageView ); - - UnparentAndReset( mGaussianBlurView ); - - mOnLabel.SetVisible( false ); - mOffLabel.SetVisible( true ); - } + mOnLabel.SetProperty(Actor::Property::VISIBLE, true); + mOffLabel.SetProperty(Actor::Property::VISIBLE, false); + } + else + { + mActivate = false; + mGaussianBlurView.Deactivate(); + mOnLabel.SetProperty(Actor::Property::VISIBLE, false); + mOffLabel.SetProperty(Actor::Property::VISIBLE, true); } + } return true; } void OnKeyEvent(const KeyEvent& event) { - if(event.state == KeyEvent::Down) + if(event.GetState() == KeyEvent::DOWN) { - if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) ) + if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK)) { mApplication.Quit(); } @@ -158,8 +149,7 @@ private: } private: - - Application& mApplication; + Application& mApplication; Toolkit::ImageView mImageView; @@ -172,13 +162,15 @@ private: float mExcessWidth; float mStrength; + + bool mActivate; }; -int DALI_EXPORT_API main( int argc, char **argv ) +int DALI_EXPORT_API main(int argc, char** argv) { - Application application = Application::New( &argc, &argv ); + Application application = Application::New(&argc, &argv); - GaussianBlurViewExample test( application ); + GaussianBlurViewExample test(application); application.MainLoop();