diff --git a/build/tizen/examples/Makefile.am b/build/tizen/examples/Makefile.am index bb61a9c..a207c14 100644 --- a/build/tizen/examples/Makefile.am +++ b/build/tizen/examples/Makefile.am @@ -37,8 +37,9 @@ bin_PROGRAMS = \ image-scaling-irregular-grid.example \ buttons.example \ text-view.example \ - logging.example - + logging.example \ + bloom-view.example \ + gaussian-blur-view.example daliimagedir = $(appdatadir)/images/ dalimodeldir = $(appdatadir)/models/ @@ -176,3 +177,13 @@ logging_example_SOURCES = $(examples_src_dir)/logging/logging-example.cpp logging_example_CXXFLAGS = $(EXAMPLE_CXXFLAGS) logging_example_DEPENDENCIES = $(EXAMPLE_DEPS) logging_example_LDADD = $(EXAMPLE_LDADD) + +bloom_view_example_SOURCES = $(examples_src_dir)/bloom-view/bloom-view-example.cpp +bloom_view_example_CXXFLAGS = $(EXAMPLE_CXXFLAGS) +bloom_view_example_DEPENDENCIES = $(EXAMPLE_DEPS) +bloom_view_example_LDADD = $(EXAMPLE_LDADD) + +gaussian_blur_view_example_SOURCES = $(examples_src_dir)/gaussian-blur-view/gaussian-blur-view-example.cpp +gaussian_blur_view_example_CXXFLAGS = $(EXAMPLE_CXXFLAGS) +gaussian_blur_view_example_DEPENDENCIES = $(EXAMPLE_DEPS) +gaussian_blur_view_example_LDADD = $(EXAMPLE_LDADD) diff --git a/com.samsung.dali-demo.xml b/com.samsung.dali-demo.xml index 14fe3a3..00bb88d 100644 --- a/com.samsung.dali-demo.xml +++ b/com.samsung.dali-demo.xml @@ -76,4 +76,10 @@ + + + + + + diff --git a/demo/images/GreyThinLine30x30-76x78.png b/demo/images/GreyThinLine30x30-76x78.png new file mode 100644 index 0000000..4ec3364 --- /dev/null +++ b/demo/images/GreyThinLine30x30-76x78.png diff --git a/demo/images/UI-Leather-DIFF.png b/demo/images/UI-Leather-DIFF.png new file mode 100644 index 0000000..b04d0ac --- /dev/null +++ b/demo/images/UI-Leather-DIFF.png diff --git a/demo/images/desktop_background_1440x2560.png b/demo/images/desktop_background_1440x2560.png new file mode 100644 index 0000000..738703d --- /dev/null +++ b/demo/images/desktop_background_1440x2560.png diff --git a/examples/bloom-view/bloom-view-example.cpp b/examples/bloom-view/bloom-view-example.cpp new file mode 100644 index 0000000..d47347e --- /dev/null +++ b/examples/bloom-view/bloom-view-example.cpp @@ -0,0 +1,526 @@ +// +// Copyright (c) 2014 Samsung Electronics Co., Ltd. +// +// Licensed under the Flora License, Version 1.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://floralicense.org/license/ +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an AS IS BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +#include +#include + +using namespace Dali; +using namespace Dali::Toolkit; + +namespace +{ + +//#define ADD_REMOVE_FROM_STAGE_TEST + +const char* BACKGROUND_IMAGE_PATH = DALI_IMAGE_DIR "desktop_background_1440x2560.png"; +const char* UI_DIFFUSE_IMAGE( DALI_IMAGE_DIR "UI-Leather-DIFF.png" ); + +const Rect UI_PIXEL_AREA( 0, 0, 720, 1280 ); + +const Rect PANEL1_PIXEL_AREA( 0, 0, 720, 39 ); +const Rect PANEL2_PIXEL_AREA( 0, 39, 720, 100 ); + +const unsigned int NUM_MOVEMENT_ANIMATIONS = 2; + +// for animating bloom intensity on tap gesture +const float PULSE_BLOOM_INCREASE_ANIM_TIME = 1.175; +const float PULSE_BLOOM_DECREASE_ANIM_TIME = 2.4; +const float PULSE_BLOOM_TOTAL_ANIM_TIME = PULSE_BLOOM_INCREASE_ANIM_TIME + PULSE_BLOOM_DECREASE_ANIM_TIME; +const float PULSE_BLOOM_INTENSITY_DEFAULT = 1.0f; +const float PULSE_BLOOM_INTENSITY_INCREASE = 3.0f; + + + +// buttons +const char* BUTTON_BACKGROUND_IMAGE_PATH = DALI_IMAGE_DIR "GreyThinLine30x30-76x78.png"; + +// These values depend on the button background image +const Vector4 BUTTON_IMAGE_BORDER(16.0f, 16.0f, 16.0f, 20.0f); + + +const float UI_MARGIN = 4.0f; ///< Screen Margin for placement of UI buttons +const Vector3 BUTTON_SIZE_CONSTRAINT( 0.24f, 0.09f, 1.0f ); +const char * BUTTON_QUIT = "Quit"; + +} // namespace + + + +/** + * This example demonstrates a bloom effect. + */ +class TestApp : public ConnectionTracker +{ +public: + + TestApp( Application &application ) + : mApplication(application) + , mCurrentAnimation(0) + { + application.InitSignal().Connect(this, &TestApp::Create); + } + + ~TestApp() + { + } + +public: + + void Create(Application& application) + { + // Preload images + mDiffuseImage = Image::New( UI_DIFFUSE_IMAGE ); + + // Creation is deferred until images have loaded + mDiffuseImage.LoadingFinishedSignal().Connect( this, &TestApp::Create2 ); + } + +#ifdef ADD_REMOVE_FROM_STAGE_TEST + void Create2(Image loadedImage) + { + Stage stage = Stage::GetCurrent(); + Vector2 stageSize = stage.GetSize(); + + mStageRootActor = Actor::New(); + mStageRootActor.SetParentOrigin(ParentOrigin::CENTER); + mStageRootActor.SetSize(stageSize); + stage.Add(mStageRootActor); + + // Create the object that will perform the blooming work + mBloomView = Dali::Toolkit::BloomView::New(); + mBloomView.SetParentOrigin(ParentOrigin::CENTER); + mBloomView.SetSize(stageSize * 0.75f); + mStageRootActor.Add(mBloomView); + mBloomView.Activate(); + + // Create the background image + Image background = Image::New(BACKGROUND_IMAGE_PATH); + ImageActor backgroundImage = ImageActor::New(background); + backgroundImage.SetParentOrigin(ParentOrigin::CENTER); + backgroundImage.ApplyConstraint( Constraint::New( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ) ); + + Layer backgroundLayer = Layer::New(); + backgroundLayer.ApplyConstraint( Constraint::New( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ) ); + backgroundLayer.SetParentOrigin( ParentOrigin::CENTER ); + mBloomView.Add( backgroundLayer ); + backgroundLayer.Add( backgroundImage ); + + Layer foregroundLayer = Layer::New(); + foregroundLayer.ApplyConstraint( Constraint::New( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ) ); + foregroundLayer.SetParentOrigin( ParentOrigin::CENTER ); + mBloomView.Add( foregroundLayer ); + + // Create visible actors + mObjectRootActor = Actor::New(); + mObjectRootActor.SetParentOrigin( ParentOrigin::CENTER ); + mObjectRootActor.ApplyConstraint( Constraint::New( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ) ); + foregroundLayer.Add( mObjectRootActor ); + + ImageActor imageActor = ImageActor::New( mDiffuseImage ); + imageActor.SetParentOrigin( ParentOrigin::CENTER ); + imageActor.SetSize( stageSize * 0.75f); + mObjectRootActor.Add( imageActor ); + + imageActor = ImageActor::New( mDiffuseImage ); + imageActor.SetParentOrigin( ParentOrigin::CENTER ); + imageActor.SetSize( stageSize * 0.5f ); + imageActor.SetPosition(0.0f, 0.0f, 100.0f); + mObjectRootActor.Add( imageActor ); + + AnimateBloomView(); + PulseBloomIntensity(); + + // Gesture detection + mTapGestureDetector = TapGestureDetector::New(); + mTapGestureDetector.Attach( mStageRootActor ); + mTapGestureDetector.DetectedSignal().Connect( this, &TestApp::OnTap ); + } + + void AnimateBloomView() + { + if(mRotationAnimation) + { + mRotationAnimation.Stop(); + } + if(mResizeAnimation) + { + mResizeAnimation.Stop(); + } + if(mTranslationAnimation) + { + mTranslationAnimation.Stop(); + } + if(mBlurAnimation) + { + mBlurAnimation.Stop(); + } + + // ROTATE + float animDuration = 10.0f; + mRotationAnimation = Animation::New(animDuration); + mRotationAnimation.RotateBy(mBloomView, Degree(720), Vector3::YAXIS, AlphaFunctions::EaseInOut); + mRotationAnimation.SetEndAction( Animation::Discard ); + mRotationAnimation.SetLooping( true ); + mRotationAnimation.Play(); + + // BLUR + mBlurAnimation = Animation::New( 4.0f ); + mBlurAnimation.AnimateTo( Property( mBloomView, mBloomView.GetBlurStrengthPropertyIndex() ), 0.0f, AlphaFunctions::Linear, TimePeriod(0.0f, 0.5f) ); + mBlurAnimation.AnimateTo( Property( mBloomView, mBloomView.GetBlurStrengthPropertyIndex() ), 1.0f, AlphaFunctions::Linear, TimePeriod(2.0f, 0.5f) ); + mBlurAnimation.SetEndAction( Animation::Discard ); + mBlurAnimation.SetLooping( true ); + mBlurAnimation.Play(); + } +#else //#ifdef ADD_REMOVE_FROM_STAGE_TEST + + void Create2(Image loadedImage) + { + Stage stage = Stage::GetCurrent(); + Vector2 stageSize = stage.GetSize(); + + mStageRootActor = Actor::New(); + mStageRootActor.SetParentOrigin(ParentOrigin::CENTER); + mStageRootActor.SetSize(stageSize); + stage.Add(mStageRootActor); + + // Create the object that will perform the blooming work + mBloomView = Dali::Toolkit::BloomView::New(); + mBloomView.SetParentOrigin(ParentOrigin::CENTER); + mBloomView.SetSize(stageSize * 0.75f); + mStageRootActor.Add(mBloomView); + mBloomView.Activate(); + + // Create the Quit button + PushButton button; + button = CreateButton(BUTTON_QUIT, BUTTON_QUIT, BUTTON_SIZE_CONSTRAINT); + button.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT); + button.SetParentOrigin(ParentOrigin::BOTTOM_RIGHT); + button.SetPosition(-UI_MARGIN, -UI_MARGIN); + + // Create the background image + Image background = Image::New(BACKGROUND_IMAGE_PATH); + ImageActor backgroundImage = ImageActor::New(background); + backgroundImage.SetParentOrigin(ParentOrigin::CENTER); + backgroundImage.ApplyConstraint( Constraint::New( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ) ); + + Layer backgroundLayer = Layer::New(); + backgroundLayer.ApplyConstraint( Constraint::New( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ) ); + backgroundLayer.SetParentOrigin( ParentOrigin::CENTER ); + mBloomView.Add( backgroundLayer ); + backgroundLayer.Add( backgroundImage ); + + Layer foregroundLayer = Layer::New(); + foregroundLayer.ApplyConstraint( Constraint::New( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ) ); + foregroundLayer.SetParentOrigin( ParentOrigin::CENTER ); + mBloomView.Add( foregroundLayer ); + + // Create visible actors + mObjectRootActor = Actor::New(); + mObjectRootActor.SetParentOrigin( ParentOrigin::CENTER ); + mObjectRootActor.ApplyConstraint( Constraint::New( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ) ); + foregroundLayer.Add( mObjectRootActor ); + + ImageActor imageActor = ImageActor::New( mDiffuseImage ); + imageActor.SetParentOrigin( ParentOrigin::CENTER ); + imageActor.SetSize( stageSize * 0.75f); + mObjectRootActor.Add( imageActor ); + + imageActor = ImageActor::New( mDiffuseImage ); + imageActor.SetParentOrigin( ParentOrigin::CENTER ); + imageActor.SetSize( stageSize * 0.5f ); + imageActor.SetPosition(0.0f, 0.0f, 100.0f); + mObjectRootActor.Add( imageActor ); + + ToggleAnimation(); + PulseBloomIntensity(); + + // Gesture detection + mTapGestureDetector = TapGestureDetector::New(); + mTapGestureDetector.Attach( mStageRootActor ); + mTapGestureDetector.DetectedSignal().Connect( this, &TestApp::OnTap ); + } + + PushButton CreateButton(const std::string& name, const std::string& label, const Vector3& sizeConstraint) + { + // Create the button + Image img = Image::New(BUTTON_BACKGROUND_IMAGE_PATH); + ImageActor background = ImageActor::New(img); + + background.SetStyle(ImageActor::STYLE_NINE_PATCH); + background.SetNinePatchBorder(BUTTON_IMAGE_BORDER); + + PushButton button = PushButton::New(); + button.SetName(name); + button.SetBackgroundImage(background); + + // Set the button's size + button.ApplyConstraint( Constraint::New( Actor::SIZE, ParentSource( Actor::SIZE ), RelativeToConstraint( sizeConstraint ) ) ); + + // Make sure the button only takes up its natural or allocated width. + button.SetSizePolicy( Toolkit::Control::Fixed, Toolkit::Control::Fixed ); + + mStageRootActor.Add(button); + + button.ClickedSignal().Connect(this, &TestApp::OnButtonTouchEvent); + + SetButtonLabel(button, label, TextView::Center); + + return button; + } + + void SetButtonLabel(PushButton button, const std::string& label, const TextView::LineJustification justification) + { + Font font = Font::New(); + Vector3 textSize = font.MeasureText(label); + + // Add a text label to the button + TextView textView = TextView::New( label ); + textView.SetAnchorPoint( AnchorPoint::CENTER ); + textView.SetParentOrigin( ParentOrigin::CENTER ); + textView.SetMultilinePolicy(TextView::SplitByWord); + textView.SetWidthExceedPolicy(TextView::Original); + textView.SetTextAlignment(static_cast< Alignment::Type >( Alignment::HorizontalCenter | Alignment::VerticalCenter )); + textView.SetLineJustification(justification); + textView.SetSize(textSize); + + Alignment align = Alignment::New(); + align.Add(textView); + align.SetScaling( Alignment::ShrinkToFitKeepAspect ); + + button.SetLabelText(align); + } + + /** + * Signal handler, called when the button is pressed + */ + bool OnButtonTouchEvent(Button button) + { + if(button.GetName() == BUTTON_QUIT) + { + // quit the application + mApplication.Quit(); + } + + return true; + } + + void AnimateBloomView() + { + if(mRotationAnimation) + { + mRotationAnimation.Stop(); + } + if(mResizeAnimation) + { + mResizeAnimation.Stop(); + } + if(mTranslationAnimation) + { + mTranslationAnimation.Stop(); + } + if(mBlurAnimation) + { + mBlurAnimation.Stop(); + } + + // ROTATE + float animDuration = 10.0f; + mRotationAnimation = Animation::New(animDuration); + mRotationAnimation.RotateBy(mBloomView, Degree(720), Vector3::YAXIS, AlphaFunctions::EaseInOut); + mRotationAnimation.SetEndAction( Animation::Discard ); + mRotationAnimation.SetLooping( true ); + mRotationAnimation.Play(); + + + // RESIZE + Stage stage = Stage::GetCurrent(); + Vector3 stageSize(stage.GetSize().width, stage.GetSize().height, 1.0f); + mResizeAnimation = Animation::New( 7.5f ); + mResizeAnimation.AnimateTo( Property(mBloomView, Actor::SIZE), stageSize * Vector3(0.5f, 0.5f, 1.0f), AlphaFunctions::Bounce, TimePeriod(2.5f) ); + mResizeAnimation.SetEndAction( Animation::Discard ); + mResizeAnimation.SetLooping( true ); + mResizeAnimation.Play(); + + + // TRANSLATE + mTranslationAnimation = Animation::New( 7.5f ); + mTranslationAnimation.AnimateBy( Property(mObjectRootActor, Actor::POSITION), Vector3(100.0f, 0.0f, 0.0f), AlphaFunctions::Bounce, TimePeriod(2.5f) ); + mTranslationAnimation.AnimateBy( Property(mObjectRootActor, Actor::POSITION), Vector3(300.0f, 0.0f, 0.0f), AlphaFunctions::Bounce, TimePeriod(2.5f, 2.5f) ); + mTranslationAnimation.AnimateBy( Property(mObjectRootActor, Actor::POSITION), Vector3(0.0f, 0.0f, 0.0f), AlphaFunctions::Bounce, TimePeriod(5.0f, 2.5f) ); + mTranslationAnimation.SetEndAction( Animation::Discard ); + mTranslationAnimation.SetLooping( true ); + mTranslationAnimation.Play(); + + + // BLUR + mBlurAnimation = Animation::New( 4.0f ); + mBlurAnimation.AnimateTo( Property( mBloomView, mBloomView.GetBlurStrengthPropertyIndex() ), 0.0f, AlphaFunctions::Linear, TimePeriod(0.0f, 0.5f) ); + mBlurAnimation.AnimateTo( Property( mBloomView, mBloomView.GetBlurStrengthPropertyIndex() ), 1.0f, AlphaFunctions::Linear, TimePeriod(2.0f, 0.5f) ); + mBlurAnimation.SetEndAction( Animation::Discard ); + mBlurAnimation.SetLooping( true ); + mBlurAnimation.Play(); + } + + void AnimateActorRoot() + { + if(mRotationAnimation) + { + mRotationAnimation.Stop(); + } + if(mResizeAnimation) + { + mResizeAnimation.Stop(); + } + if(mTranslationAnimation) + { + mTranslationAnimation.Stop(); + } + if(mBlurAnimation) + { + mBlurAnimation.Stop(); + } + + // ROTATE + float animDuration = 10.0f; + mRotationAnimation = Animation::New(animDuration); + mRotationAnimation.RotateBy(mObjectRootActor, Degree(720), Vector3::YAXIS, AlphaFunctions::EaseInOut); + mRotationAnimation.SetEndAction( Animation::Discard ); + mRotationAnimation.SetLooping( true ); + mRotationAnimation.Play(); + + + // RESIZE + Stage stage = Stage::GetCurrent(); + Vector3 stageSize(stage.GetSize().width, stage.GetSize().height, 1.0f); + mResizeAnimation = Animation::New( 7.5f ); + mResizeAnimation.AnimateTo( Property(mBloomView, Actor::SIZE), stageSize * Vector3(0.5f, 0.5f, 1.0f), AlphaFunctions::Bounce, TimePeriod(2.5f) ); + mResizeAnimation.SetEndAction( Animation::Discard ); + mResizeAnimation.SetLooping( true ); + mResizeAnimation.Play(); + + + // TRANSLATE + mTranslationAnimation = Animation::New( 7.5f ); + mTranslationAnimation.AnimateBy( Property(mObjectRootActor, Actor::POSITION), Vector3(100.0f, 0.0f, 0.0f), AlphaFunctions::Bounce, TimePeriod(2.5f) ); + mTranslationAnimation.AnimateBy( Property(mObjectRootActor, Actor::POSITION), Vector3(300.0f, 0.0f, 0.0f), AlphaFunctions::Bounce, TimePeriod(2.5f, 2.5f) ); + mTranslationAnimation.AnimateBy( Property(mObjectRootActor, Actor::POSITION), Vector3(0.0f, 0.0f, 0.0f), AlphaFunctions::Bounce, TimePeriod(5.0f, 2.5f) ); + mTranslationAnimation.SetEndAction( Animation::Discard ); + mTranslationAnimation.SetLooping( true ); + mTranslationAnimation.Play(); + + + // BLUR + mBlurAnimation = Animation::New( 4.0f ); + mBlurAnimation.AnimateTo( Property( mBloomView, mBloomView.GetBlurStrengthPropertyIndex() ), 0.0f, AlphaFunctions::Linear, TimePeriod(0.0f, 0.5f) ); + mBlurAnimation.AnimateTo( Property( mBloomView, mBloomView.GetBlurStrengthPropertyIndex() ), 1.0f, AlphaFunctions::Linear, TimePeriod(2.0f, 0.5f) ); + mBlurAnimation.SetEndAction( Animation::Discard ); + mBlurAnimation.SetLooping( true ); + mBlurAnimation.Play(); + } + + void ToggleAnimation() + { + mCurrentAnimation++; + if(mCurrentAnimation == NUM_MOVEMENT_ANIMATIONS) + { + mCurrentAnimation = 0; + } + + switch(mCurrentAnimation) + { + case 0: + AnimateActorRoot(); + break; + + case 1: + AnimateBloomView(); + break; + } + } +#endif //#ifdef ADD_REMOVE_FROM_STAGE_TEST + + void PulseBloomIntensity() + { + mPulseBloomIntensityAnim = Animation::New( 2.5f ); + mPulseBloomIntensityAnim.AnimateTo( Property(mBloomView, mBloomView.GetBloomIntensityPropertyIndex()), 3.0f, AlphaFunctions::Bounce, TimePeriod(2.5f) ); + mPulseBloomIntensityAnim.SetEndAction( Animation::Discard ); + mPulseBloomIntensityAnim.SetLooping( true ); + mPulseBloomIntensityAnim.Play(); + } + + void OnTap( Actor actor, const TapGesture& tapGesture ) + { + Stage stage = Stage::GetCurrent(); + +#ifdef ADD_REMOVE_FROM_STAGE_TEST + if(mBloomView.OnStage()) + { + mStageRootActor.Remove(mBloomView); + mBloomView.Deactivate(); + } + else + { + mStageRootActor.Add(mBloomView); + mBloomView.Activate(); + } +#else //#ifdef ADD_REMOVE_FROM_STAGE_TEST + ToggleAnimation(); +#endif //#ifdef ADD_REMOVE_FROM_STAGE_TEST + } + +private: + + Application& mApplication; + + TapGestureDetector mTapGestureDetector; + + Actor mStageRootActor; + + Actor mObjectRootActor; + Image mDiffuseImage; + + unsigned int mCurrentAnimation; + Animation mRotationAnimation; + Animation mResizeAnimation; + Animation mTranslationAnimation; + Animation mBlurAnimation; + Animation mPulseBloomIntensityAnim; + + // for rendering the blur / bloom + GaussianBlurView mGaussianBlurView; + BloomView mBloomView; +}; + +/*****************************************************************************/ + +static void +RunTest( Application& application ) +{ + TestApp theApp(application); + application.MainLoop(); +} + +/*****************************************************************************/ + +int +main(int argc, char **argv) +{ + Application application = Application::New(&argc, &argv); + + RunTest(application); + + return 0; +} diff --git a/examples/gaussian-blur-view/gaussian-blur-view-example.cpp b/examples/gaussian-blur-view/gaussian-blur-view-example.cpp new file mode 100644 index 0000000..7fce8a6 --- /dev/null +++ b/examples/gaussian-blur-view/gaussian-blur-view-example.cpp @@ -0,0 +1,521 @@ +// +// Copyright (c) 2014 Samsung Electronics Co., Ltd. +// +// Licensed under the Flora License, Version 1.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://floralicense.org/license/ +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an AS IS BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +#include +#include + +using namespace Dali; +using namespace Dali::Toolkit; + +namespace +{ + +//#define ADD_REMOVE_FROM_STAGE_TEST + +const char* BACKGROUND_IMAGE_PATH = DALI_IMAGE_DIR "desktop_background_1440x2560.png"; +const char* UI_DIFFUSE_IMAGE( DALI_IMAGE_DIR "UI-Leather-DIFF.png" ); + +const Rect UI_PIXEL_AREA( 0, 0, 720, 1280 ); + +const Rect PANEL1_PIXEL_AREA( 0, 0, 720, 39 ); +const Rect PANEL2_PIXEL_AREA( 0, 39, 720, 100 ); + +const unsigned int NUM_MOVEMENT_ANIMATIONS = 2; + +// for animating bloom intensity on tap gesture +const float PULSE_BLOOM_INCREASE_ANIM_TIME = 1.175; +const float PULSE_BLOOM_DECREASE_ANIM_TIME = 2.4; +const float PULSE_BLOOM_TOTAL_ANIM_TIME = PULSE_BLOOM_INCREASE_ANIM_TIME + PULSE_BLOOM_DECREASE_ANIM_TIME; +const float PULSE_BLOOM_INTENSITY_DEFAULT = 1.0f; +const float PULSE_BLOOM_INTENSITY_INCREASE = 3.0f; + + +// buttons +const char* BUTTON_BACKGROUND_IMAGE_PATH = DALI_IMAGE_DIR "GreyThinLine30x30-76x78.png"; + +// These values depend on the button background image +const float BUTTON_IMAGE_BORDER_LEFT = 16.0f; +const float BUTTON_IMAGE_BORDER_RIGHT = 16.0f; +const float BUTTON_IMAGE_BORDER_TOP = 13.0f; +const float BUTTON_IMAGE_BORDER_BOTTOM = 20.0f; + +const Vector4 BUTTON_IMAGE_BORDER( BUTTON_IMAGE_BORDER_LEFT, BUTTON_IMAGE_BORDER_TOP, BUTTON_IMAGE_BORDER_RIGHT, BUTTON_IMAGE_BORDER_BOTTOM ); + +const float UI_MARGIN = 4.0f; ///< Screen Margin for placement of UI buttons +const Vector3 BUTTON_SIZE_CONSTRAINT( 0.24f, 0.09f, 1.0f ); +const char * BUTTON_QUIT = "Quit"; +const char * BUTTON_QUIT_LABEL ="Quit"; + +} // namespace + + + +/** + * This example demonstrates a blur effect. + */ +class TestApp : public ConnectionTracker +{ +public: + + TestApp( Application &application ) + : mApplication(application) + , mCurrentAnimation(0) + { + application.InitSignal().Connect(this, &TestApp::Create); + application.TerminateSignal().Connect(this, &TestApp::Terminate); + } + + ~TestApp() + { + } + +public: + + void Create(Application& application) + { + // Preload images + mDiffuseImage = Image::New( UI_DIFFUSE_IMAGE ); + + // Creation is deferred until images have loaded + mDiffuseImage.LoadingFinishedSignal().Connect( this, &TestApp::Create2 ); + } + +#ifdef ADD_REMOVE_FROM_STAGE_TEST + void Create2(Image loadedImage) + { + Stage stage = Stage::GetCurrent(); + Vector2 stageSize = stage.GetSize(); + + mStageRootActor = Actor::New(); + mStageRootActor.SetParentOrigin(ParentOrigin::CENTER); + mStageRootActor.SetSize(stageSize); + stage.Add(mStageRootActor); + + // Create the object that will perform the blurring work + mGaussianBlurView = Dali::Toolkit::GaussianBlurView::New(); + mGaussianBlurView.SetParentOrigin(ParentOrigin::CENTER); + mGaussianBlurView.SetSize(stageSize * 0.75f); + mStageRootActor.Add(mGaussianBlurView); + mGaussianBlurView.Activate(); + + // Create the background image + Image background = Image::New(BACKGROUND_IMAGE_PATH); + ImageActor backgroundImage = ImageActor::New(background); + backgroundImage.SetParentOrigin(ParentOrigin::CENTER); + backgroundImage.ApplyConstraint( Constraint::New( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ) ); + + Layer backgroundLayer = Layer::New(); + backgroundLayer.ApplyConstraint( Constraint::New( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ) ); + backgroundLayer.SetParentOrigin( ParentOrigin::CENTER ); + mGaussianBlurView.Add( backgroundLayer ); + backgroundLayer.Add( backgroundImage ); + + Layer foregroundLayer = Layer::New(); + foregroundLayer.ApplyConstraint( Constraint::New( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ) ); + foregroundLayer.SetParentOrigin( ParentOrigin::CENTER ); + mGaussianBlurView.Add( foregroundLayer ); + + // Create visible actors + mObjectRootActor = Actor::New(); + mObjectRootActor.SetParentOrigin( ParentOrigin::CENTER ); + mObjectRootActor.ApplyConstraint( Constraint::New( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ) ); + foregroundLayer.Add( mObjectRootActor ); + + ImageActor imageActor = ImageActor::New( mDiffuseImage ); + imageActor.SetParentOrigin( ParentOrigin::CENTER ); + imageActor.SetSize( stageSize * 0.75f); + mObjectRootActor.Add( imageActor ); + + imageActor = ImageActor::New( mDiffuseImage ); + imageActor.SetParentOrigin( ParentOrigin::CENTER ); + imageActor.SetSize( stageSize * 0.5f ); + imageActor.SetPosition(0.0f, 0.0f, 100.0f); + mObjectRootActor.Add( imageActor ); + + AnimateGaussianBlurView(); + + // Gesture detection + mTapGestureDetector = TapGestureDetector::New(); + mTapGestureDetector.Attach( mStageRootActor ); + mTapGestureDetector.DetectedSignal().Connect( this, &TestApp::OnTap ); + } + + void AnimateGaussianBlurView() + { + if(mRotationAnimation) + { + mRotationAnimation.Stop(); + } + if(mResizeAnimation) + { + mResizeAnimation.Stop(); + } + if(mTranslationAnimation) + { + mTranslationAnimation.Stop(); + } + if(mBlurAnimation) + { + mBlurAnimation.Stop(); + } + + // ROTATE + float animDuration = 10.0f; + mRotationAnimation = Animation::New(animDuration); + mRotationAnimation.RotateBy(mGaussianBlurView, Degree(720), Vector3::YAXIS, AlphaFunctions::EaseInOut); + mRotationAnimation.SetEndAction( Animation::Discard ); + mRotationAnimation.SetLooping( true ); + mRotationAnimation.Play(); + + // BLUR + mBlurAnimation = Animation::New( 4.0f ); + mBlurAnimation.AnimateTo( Property( mGaussianBlurView, mGaussianBlurView.GetBlurStrengthPropertyIndex() ), 0.0f, AlphaFunctions::Linear, TimePeriod(0.0f, 0.5f) ); + mBlurAnimation.AnimateTo( Property( mGaussianBlurView, mGaussianBlurView.GetBlurStrengthPropertyIndex() ), 1.0f, AlphaFunctions::Linear, TimePeriod(2.0f, 0.5f) ); + mBlurAnimation.SetEndAction( Animation::Discard ); + mBlurAnimation.SetLooping( true ); + mBlurAnimation.Play(); + } +#else //#ifdef ADD_REMOVE_FROM_STAGE_TEST + + void Create2(Image loadedImage) + { + Stage stage = Stage::GetCurrent(); + Vector2 stageSize = stage.GetSize(); + + mStageRootActor = Actor::New(); + mStageRootActor.SetParentOrigin(ParentOrigin::CENTER); + mStageRootActor.SetSize(stageSize); + stage.Add(mStageRootActor); + + // Create the object that will perform the blurring work + mGaussianBlurView = Dali::Toolkit::GaussianBlurView::New(); + mGaussianBlurView.SetParentOrigin(ParentOrigin::CENTER); + mGaussianBlurView.SetSize(stageSize * 0.75f); + mStageRootActor.Add(mGaussianBlurView); + mGaussianBlurView.Activate(); + + // Create the Quit button + PushButton button; + button = CreateButton(BUTTON_QUIT, BUTTON_QUIT_LABEL, BUTTON_SIZE_CONSTRAINT); + button.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT); + button.SetParentOrigin(ParentOrigin::BOTTOM_RIGHT); + button.SetPosition(-UI_MARGIN, -UI_MARGIN); + + // Create the background image + Image background = Image::New(BACKGROUND_IMAGE_PATH); + ImageActor backgroundImage = ImageActor::New(background); + backgroundImage.SetParentOrigin(ParentOrigin::CENTER); + backgroundImage.ApplyConstraint( Constraint::New( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ) ); + + Layer backgroundLayer = Layer::New(); + backgroundLayer.ApplyConstraint( Constraint::New( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ) ); + backgroundLayer.SetParentOrigin( ParentOrigin::CENTER ); + mGaussianBlurView.Add( backgroundLayer ); + backgroundLayer.Add( backgroundImage ); + + Layer foregroundLayer = Layer::New(); + foregroundLayer.ApplyConstraint( Constraint::New( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ) ); + foregroundLayer.SetParentOrigin( ParentOrigin::CENTER ); + mGaussianBlurView.Add( foregroundLayer ); + + // Create visible actors + mObjectRootActor = Actor::New(); + mObjectRootActor.SetParentOrigin( ParentOrigin::CENTER ); + mObjectRootActor.ApplyConstraint( Constraint::New( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ) ); + foregroundLayer.Add( mObjectRootActor ); + + ImageActor imageActor = ImageActor::New( mDiffuseImage ); + imageActor.SetParentOrigin( ParentOrigin::CENTER ); + imageActor.SetSize( stageSize * 0.75f); + mObjectRootActor.Add( imageActor ); + + imageActor = ImageActor::New( mDiffuseImage ); + imageActor.SetParentOrigin( ParentOrigin::CENTER ); + imageActor.SetSize( stageSize * 0.5f ); + imageActor.SetPosition(0.0f, 0.0f, 100.0f); + mObjectRootActor.Add( imageActor ); + + ToggleAnimation(); + + // Gesture detection + mTapGestureDetector = TapGestureDetector::New(); + mTapGestureDetector.Attach( mStageRootActor ); + mTapGestureDetector.DetectedSignal().Connect( this, &TestApp::OnTap ); + } + + PushButton CreateButton(const std::string& name, const std::string& label, const Vector3& sizeConstraint) + { + // Create the button + Image img = Image::New(BUTTON_BACKGROUND_IMAGE_PATH); + ImageActor background = ImageActor::New(img); + + background.SetStyle(ImageActor::STYLE_NINE_PATCH); + background.SetNinePatchBorder(BUTTON_IMAGE_BORDER); + + PushButton button = PushButton::New(); + button.SetName(name); + button.SetBackgroundImage(background); + + // Set the button's size + button.ApplyConstraint( Constraint::New( Actor::SIZE, ParentSource( Actor::SIZE ), RelativeToConstraint( sizeConstraint ) ) ); + + mStageRootActor.Add(button); + + button.ClickedSignal().Connect(this, &TestApp::OnButtonTouchEvent); + + SetButtonLabel(button, label, TextView::Center); + + return button; + } + + void SetButtonLabel(PushButton button, const std::string& label, const TextView::LineJustification justification) + { + Font font = Font::New(); + Vector3 textSize = font.MeasureText(label); + + // Add a text label to the button + TextView textView = TextView::New( label ); + textView.SetAnchorPoint( AnchorPoint::CENTER ); + textView.SetParentOrigin( ParentOrigin::CENTER ); + textView.SetMultilinePolicy(TextView::SplitByWord); + textView.SetWidthExceedPolicy(TextView::Original); + textView.SetTextAlignment(static_cast< Alignment::Type >( Alignment::HorizontalCenter | Alignment::VerticalCenter )); + textView.SetLineJustification(justification); + textView.SetSize(textSize); + + Alignment align = Alignment::New(); + align.Add(textView); + align.SetScaling( Alignment::ShrinkToFitKeepAspect ); + + button.SetLabelText(align); + } + + /** + * Signal handler, called when the button is pressed + */ + bool OnButtonTouchEvent(Button button) + { + if(button.GetName() == BUTTON_QUIT) + { + // quit the application + mApplication.Quit(); + } + + return true; + } + + void AnimateGaussianBlurView() + { + if(mRotationAnimation) + { + mRotationAnimation.Stop(); + } + if(mResizeAnimation) + { + mResizeAnimation.Stop(); + } + if(mTranslationAnimation) + { + mTranslationAnimation.Stop(); + } + if(mBlurAnimation) + { + mBlurAnimation.Stop(); + } + + // ROTATE + float animDuration = 10.0f; + mRotationAnimation = Animation::New(animDuration); + mRotationAnimation.RotateBy(mGaussianBlurView, Degree(720), Vector3::YAXIS, AlphaFunctions::EaseInOut); + mRotationAnimation.SetEndAction( Animation::Discard ); + mRotationAnimation.SetLooping( true ); + mRotationAnimation.Play(); + + + // RESIZE + Stage stage = Stage::GetCurrent(); + Vector3 stageSize(stage.GetSize().width, stage.GetSize().height, 1.0f); + mResizeAnimation = Animation::New( 7.5f ); + mResizeAnimation.AnimateTo( Property(mGaussianBlurView, Actor::SIZE), stageSize * Vector3(0.5f, 0.5f, 1.0f), AlphaFunctions::Bounce, TimePeriod(2.5f) ); + mResizeAnimation.SetEndAction( Animation::Discard ); + mResizeAnimation.SetLooping( true ); + mResizeAnimation.Play(); + + + // TRANSLATE + mTranslationAnimation = Animation::New( 7.5f ); + mTranslationAnimation.AnimateBy( Property(mObjectRootActor, Actor::POSITION), Vector3(100.0f, 0.0f, 0.0f), AlphaFunctions::Bounce, TimePeriod(2.5f) ); + mTranslationAnimation.AnimateBy( Property(mObjectRootActor, Actor::POSITION), Vector3(300.0f, 0.0f, 0.0f), AlphaFunctions::Bounce, TimePeriod(2.5f, 2.5f) ); + mTranslationAnimation.AnimateBy( Property(mObjectRootActor, Actor::POSITION), Vector3(0.0f, 0.0f, 0.0f), AlphaFunctions::Bounce, TimePeriod(5.0f, 2.5f) ); + mTranslationAnimation.SetEndAction( Animation::Discard ); + mTranslationAnimation.SetLooping( true ); + mTranslationAnimation.Play(); + + + // BLUR + mBlurAnimation = Animation::New( 4.0f ); + mBlurAnimation.AnimateTo( Property( mGaussianBlurView, mGaussianBlurView.GetBlurStrengthPropertyIndex() ), 0.0f, AlphaFunctions::Linear, TimePeriod(0.0f, 0.5f) ); + mBlurAnimation.AnimateTo( Property( mGaussianBlurView, mGaussianBlurView.GetBlurStrengthPropertyIndex() ), 1.0f, AlphaFunctions::Linear, TimePeriod(2.0f, 0.5f) ); + mBlurAnimation.SetEndAction( Animation::Discard ); + mBlurAnimation.SetLooping( true ); + mBlurAnimation.Play(); + } + + void AnimateActorRoot() + { + if(mRotationAnimation) + { + mRotationAnimation.Stop(); + } + if(mResizeAnimation) + { + mResizeAnimation.Stop(); + } + if(mTranslationAnimation) + { + mTranslationAnimation.Stop(); + } + if(mBlurAnimation) + { + mBlurAnimation.Stop(); + } + + // ROTATE + float animDuration = 10.0f; + mRotationAnimation = Animation::New(animDuration); + mRotationAnimation.RotateBy(mObjectRootActor, Degree(720), Vector3::YAXIS, AlphaFunctions::EaseInOut); + mRotationAnimation.SetEndAction( Animation::Discard ); + mRotationAnimation.SetLooping( true ); + mRotationAnimation.Play(); + + + // RESIZE + Stage stage = Stage::GetCurrent(); + Vector3 stageSize(stage.GetSize().width, stage.GetSize().height, 1.0f); + mResizeAnimation = Animation::New( 7.5f ); + mResizeAnimation.AnimateTo( Property(mGaussianBlurView, Actor::SIZE), stageSize * Vector3(0.5f, 0.5f, 1.0f), AlphaFunctions::Bounce, TimePeriod(2.5f) ); + mResizeAnimation.SetEndAction( Animation::Discard ); + mResizeAnimation.SetLooping( true ); + mResizeAnimation.Play(); + + + // TRANSLATE + mTranslationAnimation = Animation::New( 7.5f ); + mTranslationAnimation.AnimateBy( Property(mObjectRootActor, Actor::POSITION), Vector3(100.0f, 0.0f, 0.0f), AlphaFunctions::Bounce, TimePeriod(2.5f) ); + mTranslationAnimation.AnimateBy( Property(mObjectRootActor, Actor::POSITION), Vector3(300.0f, 0.0f, 0.0f), AlphaFunctions::Bounce, TimePeriod(2.5f, 2.5f) ); + mTranslationAnimation.AnimateBy( Property(mObjectRootActor, Actor::POSITION), Vector3(0.0f, 0.0f, 0.0f), AlphaFunctions::Bounce, TimePeriod(5.0f, 2.5f) ); + mTranslationAnimation.SetEndAction( Animation::Discard ); + mTranslationAnimation.SetLooping( true ); + mTranslationAnimation.Play(); + + + // BLUR + mBlurAnimation = Animation::New( 4.0f ); + mBlurAnimation.AnimateTo( Property( mGaussianBlurView, mGaussianBlurView.GetBlurStrengthPropertyIndex() ), 0.0f, AlphaFunctions::Linear, TimePeriod(0.0f, 0.5f) ); + mBlurAnimation.AnimateTo( Property( mGaussianBlurView, mGaussianBlurView.GetBlurStrengthPropertyIndex() ), 1.0f, AlphaFunctions::Linear, TimePeriod(2.0f, 0.5f) ); + mBlurAnimation.SetEndAction( Animation::Discard ); + mBlurAnimation.SetLooping( true ); + mBlurAnimation.Play(); + } + + void ToggleAnimation() + { + mCurrentAnimation++; + if(mCurrentAnimation == NUM_MOVEMENT_ANIMATIONS) + { + mCurrentAnimation = 0; + } + + switch(mCurrentAnimation) + { + case 0: + AnimateActorRoot(); + break; + + case 1: + AnimateGaussianBlurView(); + break; + } + } +#endif //#ifdef ADD_REMOVE_FROM_STAGE_TEST + + void Terminate( Application& app ) + { + } + + void OnTap( Actor actor, const TapGesture& tapGesture ) + { + Stage stage = Stage::GetCurrent(); + +#ifdef ADD_REMOVE_FROM_STAGE_TEST + if(mGaussianBlurView.OnStage()) + { + mStageRootActor.Remove(mGaussianBlurView); + mGaussianBlurView.Deactivate(); + } + else + { + mStageRootActor.Add(mGaussianBlurView); + mGaussianBlurView.Activate(); + } +#else //#ifdef ADD_REMOVE_FROM_STAGE_TEST + ToggleAnimation(); +#endif //#ifdef ADD_REMOVE_FROM_STAGE_TEST + } + +private: + + Application& mApplication; + + TapGestureDetector mTapGestureDetector; + + Actor mStageRootActor; + + Actor mObjectRootActor; + Image mDiffuseImage; + + unsigned int mCurrentAnimation; + Animation mRotationAnimation; + Animation mResizeAnimation; + Animation mTranslationAnimation; + Animation mBlurAnimation; + Animation mPulseBloomIntensityAnim; + + // for rendering the blur / bloom + GaussianBlurView mGaussianBlurView; + BloomView mBloomView; +}; + +/*****************************************************************************/ + +static void +RunTest( Application& application ) +{ + TestApp theApp(application); + application.MainLoop(); +} + +/*****************************************************************************/ + +int +main(int argc, char **argv) +{ + Application application = Application::New(&argc, &argv); + + RunTest(application); + + return 0; +} diff --git a/examples/magnifier/magnifier-example.cpp b/examples/magnifier/magnifier-example.cpp index 4302665..d916511 100644 --- a/examples/magnifier/magnifier-example.cpp +++ b/examples/magnifier/magnifier-example.cpp @@ -236,7 +236,7 @@ public: mMagnifier.SetSourceActor( mView.GetBackgroundLayer() ); mMagnifier.SetSize( MAGNIFIER_SIZE * mStageSize.width ); // Size of magnifier is in relation to stage width mMagnifier.SetMagnificationFactor( MAGNIFICATION_FACTOR ); - mMagnifier.SetFrameVisibility(false); + mMagnifier.SetFrameVisibility(true); mMagnifier.SetScale(Vector3::ZERO); overlay.Add( mMagnifier );