X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=examples%2Fbubble-effect%2Fbubble-effect-example.cpp;h=a668384efc387661067b6e16c723f582c06bb19c;hb=1a473d5189ca7e7d55aca3a64a8a4ff2dc3b6c67;hp=5e4e304bd9ecffb10d5818a88eb76aae4b311680;hpb=a1ecdd9dc7348be0dccf85345ddb4c339f9bb93f;p=platform%2Fcore%2Fuifw%2Fdali-demo.git diff --git a/examples/bubble-effect/bubble-effect-example.cpp b/examples/bubble-effect/bubble-effect-example.cpp index 5e4e304..a668384 100644 --- a/examples/bubble-effect/bubble-effect-example.cpp +++ b/examples/bubble-effect/bubble-effect-example.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 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. @@ -19,65 +19,64 @@ #include #include #include "shared/view.h" +#include "shared/utility.h" using namespace Dali; namespace { -const char * const TOOLBAR_IMAGE( DALI_IMAGE_DIR "top-bar.png" ); +const char * const TOOLBAR_IMAGE( DEMO_IMAGE_DIR "top-bar.png" ); const char * const APPLICATION_TITLE( "Bubble Effect" ); -const char * const CHANGE_BACKGROUND_ICON( DALI_IMAGE_DIR "icon-change.png" ); -const char * const CHANGE_BUBBLE_SHAPE_ICON( DALI_IMAGE_DIR "icon-replace.png" ); +const char * const CHANGE_BACKGROUND_ICON( DEMO_IMAGE_DIR "icon-change.png" ); +const char * const CHANGE_BACKGROUND_ICON_SELECTED( DEMO_IMAGE_DIR "icon-change-selected.png" ); +const char * const CHANGE_BUBBLE_SHAPE_ICON( DEMO_IMAGE_DIR "icon-replace.png" ); +const char * const CHANGE_BUBBLE_SHAPE_ICON_SELECTED( DEMO_IMAGE_DIR "icon-replace-selected.png" ); const char* BACKGROUND_IMAGES[]= { - DALI_IMAGE_DIR "background-1.jpg", - DALI_IMAGE_DIR "background-2.jpg", - DALI_IMAGE_DIR "background-3.jpg", - DALI_IMAGE_DIR "background-4.jpg", - DALI_IMAGE_DIR "background-5.jpg", + DEMO_IMAGE_DIR "background-1.jpg", + DEMO_IMAGE_DIR "background-2.jpg", + DEMO_IMAGE_DIR "background-3.jpg", + DEMO_IMAGE_DIR "background-4.jpg", + DEMO_IMAGE_DIR "background-5.jpg", }; const unsigned int NUM_BACKGROUND_IMAGES( sizeof( BACKGROUND_IMAGES ) / sizeof( BACKGROUND_IMAGES[0] ) ); const char* BUBBLE_SHAPE_IMAGES[] = { - DALI_IMAGE_DIR "bubble-ball.png", - DALI_IMAGE_DIR "icon-item-view-layout-spiral.png", - DALI_IMAGE_DIR "icon-replace.png", - DALI_IMAGE_DIR "icon-effect-cross.png" + DEMO_IMAGE_DIR "bubble-ball.png", + DEMO_IMAGE_DIR "icon-effect-cross.png", + DEMO_IMAGE_DIR "icon-item-view-layout-spiral.png", + DEMO_IMAGE_DIR "icon-replace.png" }; const unsigned int NUM_BUBBLE_SHAPE_IMAGES( sizeof( BUBBLE_SHAPE_IMAGES ) / sizeof( BUBBLE_SHAPE_IMAGES[0] ) ); const Vector2 DEFAULT_BUBBLE_SIZE( 10.f, 30.f ); const unsigned int DEFAULT_NUMBER_OF_BUBBLES( 1000 ); -/** - * @brief Load an image, scaled-down to no more than the stage dimensions. - * - * Uses image scaling mode FittingMode::SCALE_TO_FILL to resize the image at - * load time to cover the entire stage with pixels with no borders, - * and filter mode BOX_THEN_LINEAR to sample the image with - * maximum quality. - */ -ResourceImage LoadStageFillingImage( const char * const imagePath ) -{ - Size stageSize = Stage::GetCurrent().GetSize(); - return ResourceImage::New( imagePath, Dali::ImageDimensions( stageSize.x, stageSize.y ), Dali::FittingMode::SCALE_TO_FILL, Dali::SamplingMode::BOX_THEN_LINEAR ); -} - }// end LOCAL_STUFF -// This example shows the usage of BubbleEmitter which displays lots of moving bubbles on the stage. +// This example shows the usage of BubbleEmitter which displays lots of moving bubbles on the window. class BubbleEffectExample : public ConnectionTracker { public: BubbleEffectExample(Application &app) : mApp(app), + mBackground(), + mBubbleEmitter(), + mEmitAnimation(), + mChangeBackgroundButton(), + mChangeBubbleShapeButton(), + mTimerForBubbleEmission(), mHSVDelta( Vector3( 0.f, 0.f, 0.5f ) ), - mNeedNewAnimation( true ), + mCurrentTouchPosition(), + mEmitPosition(), + mAnimateComponentCount( 0 ), + mNonMovementCount( 0 ), mTimerInterval( 16 ), mCurrentBackgroundImageId( 0 ), - mCurrentBubbleShapeImageId( 0 ) + mCurrentBubbleShapeImageId( 0 ), + mNeedNewAnimation( true ) { // Connect to the Application's Init signal app.InitSignal().Connect(this, &BubbleEffectExample::Create); @@ -92,13 +91,13 @@ private: // The Init signal is received once (only) during the Application lifetime void Create(Application& app) { - Stage stage = Stage::GetCurrent(); - Vector2 stageSize = stage.GetSize(); + Window window = app.GetWindow(); + Vector2 windowSize = window.GetSize(); - stage.KeyEventSignal().Connect(this, &BubbleEffectExample::OnKeyEvent); + window.KeyEventSignal().Connect(this, &BubbleEffectExample::OnKeyEvent); // Creates a default view with a default tool bar. - // The view is added to the stage. + // The view is added to the window. Toolkit::ToolBar toolBar; Layer content = DemoHelper::CreateView( app, mBackground, @@ -109,37 +108,39 @@ private: // Add a button to change background. (right of toolbar) mChangeBackgroundButton = Toolkit::PushButton::New(); - mChangeBackgroundButton.SetBackgroundImage( ResourceImage::New( CHANGE_BACKGROUND_ICON ) ); + mChangeBackgroundButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, CHANGE_BACKGROUND_ICON ); + mChangeBackgroundButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, CHANGE_BACKGROUND_ICON_SELECTED ); mChangeBackgroundButton.ClickedSignal().Connect( this, &BubbleEffectExample::OnChangeIconClicked ); toolBar.AddControl( mChangeBackgroundButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, - Toolkit::Alignment::HorizontalRight, + Toolkit::Alignment::HORIZONTAL_RIGHT, DemoHelper::DEFAULT_MODE_SWITCH_PADDING ); // Add a button to change bubble shape. ( left of bar ) mChangeBubbleShapeButton = Toolkit::PushButton::New(); - mChangeBubbleShapeButton.SetBackgroundImage( ResourceImage::New( CHANGE_BUBBLE_SHAPE_ICON ) ); + mChangeBubbleShapeButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, CHANGE_BUBBLE_SHAPE_ICON ); + mChangeBubbleShapeButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, CHANGE_BUBBLE_SHAPE_ICON_SELECTED ); mChangeBubbleShapeButton.ClickedSignal().Connect( this, &BubbleEffectExample::OnChangeIconClicked ); toolBar.AddControl( mChangeBubbleShapeButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, - Toolkit::Alignment::HorizontalLeft, + Toolkit::Alignment::HORIZONTAL_LEFT, DemoHelper::DEFAULT_MODE_SWITCH_PADDING ); // Create and initialize the BubbleEmitter object - mBubbleEmitter = Toolkit::BubbleEmitter::New( stageSize, - ResourceImage::New( BUBBLE_SHAPE_IMAGES[mCurrentBubbleShapeImageId] ), + mBubbleEmitter = Toolkit::BubbleEmitter::New( windowSize, + DemoHelper::LoadTexture( BUBBLE_SHAPE_IMAGES[mCurrentBubbleShapeImageId] ), DEFAULT_NUMBER_OF_BUBBLES, DEFAULT_BUBBLE_SIZE); - mBackgroundImage = LoadStageFillingImage( BACKGROUND_IMAGES[mCurrentBackgroundImageId] ); - mBubbleEmitter.SetBackground( mBackgroundImage, mHSVDelta ); - // Get the root actor of all bubbles, and add it to stage. + mBubbleEmitter.SetBackground( DemoHelper::LoadWindowFillingTexture( window.GetSize(), BACKGROUND_IMAGES[mCurrentBackgroundImageId] ), mHSVDelta ); + + // Get the root actor of all bubbles, and add it to window. Actor bubbleRoot = mBubbleEmitter.GetRootActor(); - bubbleRoot.SetParentOrigin(ParentOrigin::CENTER); - bubbleRoot.SetZ(0.1f); // Make sure the bubbles displayed on top og the background. + bubbleRoot.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER); + bubbleRoot.SetProperty( Actor::Property::POSITION_Z, 0.1f); // Make sure the bubbles displayed on top og the background. content.Add( bubbleRoot ); - // Add the background image actor to stage - mBackground.SetBackgroundImage( mBackgroundImage ); + // Set the application background + mBackground.SetProperty( Toolkit::Control::Property::BACKGROUND, BACKGROUND_IMAGES[ mCurrentBackgroundImageId ] ); // Set up the timer to emit bubble regularly when the finger is touched down but not moved mTimerForBubbleEmission = Timer::New( mTimerInterval ); @@ -154,7 +155,7 @@ private: * Emit bubbles *****************/ - // Set up the animation of emitting bubbles, to be efficient, every animation controls multiple bubbles ( 4 here ) + // Set up the animation of emitting bubbles, to be efficient, every animation controls multiple emission ( 4 here ) void SetUpAnimation( Vector2 emitPosition, Vector2 direction ) { if( mNeedNewAnimation ) @@ -203,22 +204,20 @@ private: // Callback function of the touch signal on the background bool OnTouch(Dali::Actor actor, const Dali::TouchEvent& event) { - const TouchPoint &point = event.GetPoint(0); - switch(point.state) + switch( event.GetState( 0 ) ) { - case TouchPoint::Down: + case PointState::DOWN: { - mCurrentTouchPosition = point.screen; - mEmitPosition = point.screen; + mCurrentTouchPosition = mEmitPosition = event.GetScreenPosition( 0 ); mTimerForBubbleEmission.Start(); mNonMovementCount = 0; break; } - case TouchPoint::Motion: + case PointState::MOTION: { - Vector2 displacement = point.screen - mCurrentTouchPosition; - mCurrentTouchPosition = point.screen; + Vector2 displacement = event.GetScreenPosition( 0 ) - mCurrentTouchPosition; + mCurrentTouchPosition = event.GetScreenPosition( 0 ); //emit multiple bubbles along the moving direction when the finger moves quickly float step = std::min(5.f, displacement.Length()); for( float i=0.25f; i