diff --git a/com.samsung.dali-demo.xml b/com.samsung.dali-demo.xml index 4dbcc91..4a58819 100644 --- a/com.samsung.dali-demo.xml +++ b/com.samsung.dali-demo.xml @@ -55,9 +55,6 @@ - - - @@ -172,4 +169,7 @@ + + + diff --git a/demo/dali-demo.cpp b/demo/dali-demo.cpp index 28b1082..f413590 100644 --- a/demo/dali-demo.cpp +++ b/demo/dali-demo.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Copyright (c) 2016 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. @@ -46,7 +46,6 @@ int DALI_EXPORT_API main(int argc, char **argv) demo.AddExample(Example("motion-blur.example", DALI_DEMO_STR_TITLE_MOTION_BLUR)); demo.AddExample(Example("motion-stretch.example", DALI_DEMO_STR_TITLE_MOTION_STRETCH)); demo.AddExample(Example("page-turn-view.example", DALI_DEMO_STR_TITLE_PAGE_TURN_VIEW)); - demo.AddExample(Example("radial-menu.example", DALI_DEMO_STR_TITLE_RADIAL_MENU)); demo.AddExample(Example("refraction-effect.example", DALI_DEMO_STR_TITLE_REFRACTION)); demo.AddExample(Example("scroll-view.example", DALI_DEMO_STR_TITLE_SCROLL_VIEW)); demo.AddExample(Example("shadow-bone-lighting.example", DALI_DEMO_STR_TITLE_LIGHTS_AND_SHADOWS)); @@ -81,6 +80,8 @@ int DALI_EXPORT_API main(int argc, char **argv) demo.AddExample(Example("mesh-visual.example", DALI_DEMO_STR_TITLE_MESH_VISUAL)); demo.AddExample(Example("primitive-shapes.example", DALI_DEMO_STR_TITLE_PRIMITIVE_SHAPES)); demo.AddExample(Example("styling.example", DALI_DEMO_STR_TITLE_STYLING)); + demo.AddExample(Example("sparkle.example", DALI_DEMO_STR_TITLE_SPARKLE)); + demo.AddExample(Example("progress-bar.example", DALI_DEMO_STR_TITLE_PROGRESS_BAR)); demo.SortAlphabetically( true ); diff --git a/examples/mesh-visual/mesh-visual-example.cpp b/examples/mesh-visual/mesh-visual-example.cpp index 8376f61..e8674c9 100644 --- a/examples/mesh-visual/mesh-visual-example.cpp +++ b/examples/mesh-visual/mesh-visual-example.cpp @@ -95,25 +95,19 @@ public: Stage stage = Stage::GetCurrent(); stage.SetBackgroundColor( Vector4( 0.0, 0.5, 1.0, 1.0 ) ); - //Set up layer to place objects on. - Layer baseLayer = Layer::New(); - baseLayer.SetParentOrigin( ParentOrigin::CENTER ); - baseLayer.SetAnchorPoint( AnchorPoint::CENTER ); - baseLayer.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - baseLayer.SetBehavior( Layer::LAYER_2D ); //We use a 2D layer as this is closer to UI work than full 3D scene creation. - baseLayer.SetDepthTestDisabled( false ); //Enable depth testing, as otherwise the 2D layer would not do so. - baseLayer.RegisterProperty( "Tag", LAYER_TAG ); //Used to differentiate between different kinds of actor. - baseLayer.TouchedSignal().Connect( this, &MeshVisualController::OnTouch ); - stage.Add( baseLayer ); + //Set up root layer to receive touch gestures. + Layer rootLayer = stage.GetRootLayer(); + rootLayer.RegisterProperty( "Tag", LAYER_TAG ); //Used to differentiate between different kinds of actor. + rootLayer.TouchSignal().Connect( this, &MeshVisualController::OnTouch ); //Place models on the scene. - SetupModels( baseLayer ); + SetupModels( rootLayer ); //Place buttons on the scene. - SetupButtons( baseLayer ); + SetupButtons( rootLayer ); //Add a light to the scene. - SetupLight( baseLayer ); + SetupLight( rootLayer ); //Allow for exiting of the application via key presses. stage.KeyEventSignal().Connect( this, &MeshVisualController::OnKeyEvent ); @@ -129,7 +123,7 @@ public: mContainers[i].SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS ); mContainers[i].RegisterProperty( "Tag", MODEL_TAG ); //Used to differentiate between different kinds of actor. mContainers[i].RegisterProperty( "Model", Property::Value( i ) ); //Used to index into the model. - mContainers[i].TouchedSignal().Connect( this, &MeshVisualController::OnTouch ); + mContainers[i].TouchSignal().Connect( this, &MeshVisualController::OnTouch ); layer.Add( mContainers[i] ); } @@ -284,7 +278,7 @@ public: SetLightImage(); //Connect to touch signal for dragging. - mLightSource.TouchedSignal().Connect( this, &MeshVisualController::OnTouch ); + mLightSource.TouchSignal().Connect( this, &MeshVisualController::OnTouch ); //Place the light source on a layer above the base, so that it is rendered above everything else. Layer upperLayer = Layer::New(); @@ -396,14 +390,11 @@ public: //If the light source is touched, move it by dragging it. //If a model is touched, rotate it by panning around. - bool OnTouch( Actor actor, const TouchEvent& event ) + bool OnTouch( Actor actor, const TouchData& touch ) { - //Get primary touch point. - const Dali::TouchPoint& point = event.GetPoint( 0 ); - - switch( point.state ) + switch( touch.GetState( 0 ) ) { - case TouchPoint::Down: + case PointState::DOWN: { //Determine what was touched. actor.GetProperty( actor.GetPropertyIndex( "Tag" ) ).Get( mTag ); @@ -417,13 +408,13 @@ public: mModels[mSelectedModelIndex].rotationAnimation.Pause(); //Store start points. - mPanStart = point.screen; + mPanStart = touch.GetScreenPosition( 0 ); mRotationStart = mModels[mSelectedModelIndex].rotation; } break; } - case TouchPoint::Motion: + case PointState::MOTION: { //Switch on the kind of actor we're interacting with. switch( mTag ) @@ -431,7 +422,7 @@ public: case MODEL_TAG: //Rotate model { //Calculate displacement and corresponding rotation. - Vector2 displacement = point.screen - mPanStart; + Vector2 displacement = touch.GetScreenPosition( 0 ) - mPanStart; mModels[mSelectedModelIndex].rotation = Vector2( mRotationStart.x - displacement.y / Y_ROTATION_DISPLACEMENT_FACTOR, // Y displacement rotates around X axis mRotationStart.y + displacement.x / X_ROTATION_DISPLACEMENT_FACTOR ); // X displacement rotates around Y axis Quaternion rotation = Quaternion( Radian( mModels[mSelectedModelIndex].rotation.x ), Vector3::XAXIS) * @@ -445,7 +436,7 @@ public: case LIGHT_TAG: //Drag light { //Set light source to new position and update the models accordingly. - mLightSource.SetPosition( Vector3( point.screen ) ); + mLightSource.SetPosition( Vector3( touch.GetScreenPosition( 0 ) ) ); UpdateLight(); break; @@ -454,8 +445,8 @@ public: break; } - case TouchPoint::Interrupted: //Same as finished. - case TouchPoint::Finished: + case PointState::INTERRUPTED: //Same as finished. + case PointState::FINISHED: { if( mTag == MODEL_TAG ) { diff --git a/examples/model3d-view/model3d-view-example.cpp b/examples/model3d-view/model3d-view-example.cpp index 5adb945..40cf6eb 100644 --- a/examples/model3d-view/model3d-view-example.cpp +++ b/examples/model3d-view/model3d-view-example.cpp @@ -76,18 +76,10 @@ public: Vector2 screenSize = stage.GetSize(); //Add background - Toolkit::ImageView backView = Toolkit::ImageView::New(BACKGROUND_IMAGE); - backView.SetAnchorPoint( AnchorPoint::TOP_LEFT ); - stage.Add(backView); - - //Add 3D model control - m3DLayer = Layer::New(); - stage.GetRootLayer().Add(m3DLayer); - - //3D models require 3D based rendering method, so it can use depth buffer, etc. - m3DLayer.SetBehavior(Layer::LAYER_3D); - m3DLayer.SetParentOrigin( ParentOrigin::CENTER ); - m3DLayer.SetAnchorPoint( AnchorPoint::CENTER ); + Toolkit::ImageView backView = Toolkit::ImageView::New( BACKGROUND_IMAGE ); + backView.SetParentOrigin( ParentOrigin::CENTER ); + backView.SetAnchorPoint( AnchorPoint::CENTER ); + stage.Add( backView ); mModelCounter = 0; @@ -100,7 +92,7 @@ public: mModel3dView.SetProperty(Model3dView::Property::LIGHT_POSITION, Vector3(5,10.,0)); - m3DLayer.Add( mModel3dView ); + backView.Add( mModel3dView ); mIlluminationShader = Model3dView::IlluminationType(mModel3dView.GetProperty(Model3dView::Property::ILLUMINATION_TYPE)); @@ -108,7 +100,7 @@ public: mButtonLayer.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); mButtonLayer.SetParentOrigin( ParentOrigin::CENTER ); mButtonLayer.SetAnchorPoint( AnchorPoint::CENTER ); - stage.GetRootLayer().Add(mButtonLayer); + stage.Add(mButtonLayer); // Create button for model changing Toolkit::PushButton editButton = Toolkit::PushButton::New(); @@ -281,7 +273,6 @@ private: int mModelCounter; Model3dView mModel3dView; - Layer m3DLayer; Layer mButtonLayer; TapGestureDetector mTapDetector; diff --git a/examples/progress-bar/progress-bar-example.cpp b/examples/progress-bar/progress-bar-example.cpp new file mode 100644 index 0000000..593e297 --- /dev/null +++ b/examples/progress-bar/progress-bar-example.cpp @@ -0,0 +1,193 @@ +/* + * Copyright (c) 2016 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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 "shared/view.h" +#include +#include + +using namespace Dali; +using namespace Dali::Toolkit; +using Dali::Toolkit::ProgressBar; + +namespace +{ + +const char* const BACKGROUND_IMAGE = DEMO_IMAGE_DIR "background-gradient.jpg"; +const char* const TOOLBAR_IMAGE = DEMO_IMAGE_DIR "top-bar.png"; +const char* const TOOLBAR_TITLE = "Progress Bar"; + +const Vector4 BACKGROUND_COLOUR( 1.0f, 1.0f, 1.0f, 0.15f ); + +// Layout sizes +const int MARGIN_SIZE = 10; +const int TOP_MARGIN = 85; + +} // namespace + +/** This example shows how to create and use PROGRESS BAR. + */ + +class ProgressBarExample: public ConnectionTracker +{ +public: + + ProgressBarExample( Application& application ) + : mApplication( application ) + { + // Connect to the Application's Init signal + mProgressValue = 0.0f; + mApplication.InitSignal().Connect( this, &ProgressBarExample::Create ); + } + + ~ProgressBarExample() + { + // Nothing to do here + } + + void Create( Application& application ) + { + // The Init signal is received once (only) during the Application lifetime + + // Respond to key events + Stage::GetCurrent().KeyEventSignal().Connect( this, &ProgressBarExample::OnKeyEvent ); + + // Creates a default view with a default tool bar. + // The view is added to the stage. + + mContentLayer = DemoHelper::CreateView( application, + mView, + mToolBar, + BACKGROUND_IMAGE, + TOOLBAR_IMAGE, + TOOLBAR_TITLE ); + + mProgressBar = ProgressBar::New(); + mProgressBar.SetParentOrigin(ParentOrigin::TOP_CENTER); + mProgressBar.SetAnchorPoint(AnchorPoint::TOP_CENTER); + mProgressBar.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); + mProgressBar.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT); + + Toolkit::TableView contentTable = Toolkit::TableView::New(2, 1); + contentTable.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); + contentTable.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT); + contentTable.SetAnchorPoint(AnchorPoint::TOP_LEFT); + contentTable.SetParentOrigin(ParentOrigin::TOP_LEFT); + contentTable.SetCellPadding(Size(MARGIN_SIZE, MARGIN_SIZE * 0.5f)); + + for( unsigned int i = 0; i < contentTable.GetRows(); ++i ) + { + contentTable.SetFitHeight( i ); + } + + contentTable.SetPosition( 0.0f, TOP_MARGIN ); + mContentLayer.Add( contentTable ); + + // Image selector for progress bar + Toolkit::TableView progressBackground = Toolkit::TableView::New( 1, 1 ); + progressBackground.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); + progressBackground.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT ); + progressBackground.SetBackgroundColor( BACKGROUND_COLOUR ); + progressBackground.SetCellPadding( Size( MARGIN_SIZE, MARGIN_SIZE ) ); + progressBackground.SetRelativeWidth( 0, 1.0f ); + progressBackground.SetFitHeight( 0 ); + contentTable.Add( progressBackground ); + progressBackground.Add( mProgressBar ); + + // Create buttons + Toolkit::TableView buttonBackground = Toolkit::TableView::New( 2, 1 ); + buttonBackground.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); + buttonBackground.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT ); + buttonBackground.SetBackgroundColor( BACKGROUND_COLOUR ); + buttonBackground.SetCellPadding( Size( MARGIN_SIZE, MARGIN_SIZE ) ); + + for( unsigned int i = 0; i < buttonBackground.GetRows(); ++i ) + { + buttonBackground.SetFitHeight( i ); + } + + contentTable.Add( buttonBackground ); + + mSetProgressButton = Toolkit::PushButton::New(); + mSetProgressButton.SetLabelText( "Set Progress" ); + mSetProgressButton.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); + mSetProgressButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT ); + mSetProgressButton.ClickedSignal().Connect( this, &ProgressBarExample::OnSetProgressButtonSelected ); + + buttonBackground.Add( mSetProgressButton ); + + mResetProgressButton = Toolkit::PushButton::New(); + mResetProgressButton.SetLabelText( "Reset Progress" ); + mResetProgressButton.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); + mResetProgressButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT ); + mResetProgressButton.ClickedSignal().Connect( this, &ProgressBarExample::OnResetProgressButtonSelected ); + + buttonBackground.Add( mResetProgressButton ); + } + + bool OnResetProgressButtonSelected( Toolkit::Button button ) + { + mProgressValue = 0.0f; + mProgressBar.SetProperty(ProgressBar::Property::PROGRESS_VALUE, 0.0f); + return true; + } + + bool OnSetProgressButtonSelected( Toolkit::Button button ) + { + mProgressValue += 0.1f; + mProgressBar.SetProperty(ProgressBar::Property::PROGRESS_VALUE, mProgressValue); + return true; + } + + void OnKeyEvent( const KeyEvent& event ) + { + if( event.state == KeyEvent::Down ) + { + if( IsKey( event, Dali::DALI_KEY_ESCAPE ) || IsKey( event, Dali::DALI_KEY_BACK ) ) + { + // Exit application when click back or escape. + mApplication.Quit(); + } + } + } + +private: + + Application& mApplication; + Toolkit::Control mView; ///< The View instance. + Toolkit::ToolBar mToolBar; ///< The View's Toolbar. + Layer mContentLayer; ///< Content layer. + ProgressBar mProgressBar; + Toolkit::PushButton mSetProgressButton; + Toolkit::PushButton mResetProgressButton; + float mProgressValue; +}; + +void RunTest( Application& application ) +{ + ProgressBarExample test( application ); + application.MainLoop(); +} + +// Entry point for Linux & Tizen applications +int DALI_EXPORT_API main( int argc, char **argv ) +{ + Application application = Application::New( &argc, &argv, DEMO_THEME_PATH ); + + RunTest( application ); + + return 0; +} diff --git a/examples/radial-menu/radial-menu-example.cpp b/examples/radial-menu/radial-menu-example.cpp deleted file mode 100644 index 13be24a..0000000 --- a/examples/radial-menu/radial-menu-example.cpp +++ /dev/null @@ -1,307 +0,0 @@ -/* - * Copyright (c) 2015 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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 -#include "shared/view.h" -#include "radial-sweep-view.h" -#include "radial-sweep-view-impl.h" - -using namespace Dali; -using namespace Dali::Toolkit; - -namespace -{ -const char* TEST_OUTER_RING_FILENAME = DEMO_IMAGE_DIR "layer2.png"; // Image to be masked -const char* TEST_INNER_RING_FILENAME = DEMO_IMAGE_DIR "layer1.png"; // Image to be masked -const char* TEST_MENU_FILENAME = DEMO_IMAGE_DIR "layer3.png"; // Image to be masked -const char* TEST_DIAL_FILENAME = DEMO_IMAGE_DIR "layer4.png"; // Image to be masked -const char* TOOLBAR_IMAGE( DEMO_IMAGE_DIR "top-bar.png" ); // Background for toolbar -const char* APPLICATION_TITLE( "Radial Menu" ); -const char * const PLAY_ICON( DEMO_IMAGE_DIR "icon-play.png" ); -const char * const PLAY_ICON_SELECTED( DEMO_IMAGE_DIR "icon-play-selected.png" ); -const char * const STOP_ICON( DEMO_IMAGE_DIR "icon-stop.png" ); -const char * const STOP_ICON_SELECTED( DEMO_IMAGE_DIR "icon-stop-selected.png" ); -} - - -/******************************************************************************** - * Application controller class - */ - -// This example shows how to create a mesh actor for use as a stencil buffer -class RadialMenuExample : public ConnectionTracker -{ -public: - /** - * Constructor - * @param[in] app The application handle - */ - RadialMenuExample(Application app); - - /** - * Destructor - */ - ~RadialMenuExample(); - -private: - - /** - * Initialization signal handler - all actor initialization should happen here - * @param[in] app The application handle - */ - void OnInit(Application& app); - - /** - * Create a sweep view with the given image and parameters - */ - RadialSweepView CreateSweepView( std::string imageName, Degree initial, Degree final ); - - /** - * Start the sweep animation on the menu - */ - void StartAnimation(); - - /** - * Play or pause the animation when the button is clicked - */ - bool OnButtonClicked( Toolkit::Button button ); - - /** - * Update the state flag and change the button icon when the animation is finished - */ - void OnAnimationFinished( Animation& source ); - - /** - * Main key event handler - * - * @param[in] event The key event to respond to - */ - void OnKeyEvent(const KeyEvent& event); - -private: // Member variables - enum AnimState - { - STOPPED, - PAUSED, - PLAYING - }; - - Application mApplication; ///< The application handle - Toolkit::Control mView; ///< The toolbar view - Layer mContents; ///< The toolbar contents pane - ImageView mImageView; ///< Image view shown by stencil mask - Animation mAnimation; - AnimState mAnimationState; - - Toolkit::PushButton mPlayStopButton; - ImageView mDialView; - RadialSweepView mRadialSweepView1; - RadialSweepView mRadialSweepView2; - RadialSweepView mRadialSweepView3; -}; - -RadialMenuExample::RadialMenuExample(Application app) -: mApplication( app ), - mAnimationState(STOPPED) -{ - // Connect to the Application's Init signal - app.InitSignal().Connect(this, &RadialMenuExample::OnInit); -} - -RadialMenuExample::~RadialMenuExample() -{ - // Nothing to do here; actor handles will clean up themselves. -} - -void RadialMenuExample::OnInit(Application& app) -{ - Stage stage = Dali::Stage::GetCurrent(); - - // The Init signal is received once (only) during the Application lifetime - stage.KeyEventSignal().Connect(this, &RadialMenuExample::OnKeyEvent); - - // Create toolbar & view - Toolkit::ToolBar toolBar; - mContents = DemoHelper::CreateView( mApplication, - mView, - toolBar, - "", - TOOLBAR_IMAGE, - APPLICATION_TITLE ); - - mPlayStopButton = Toolkit::PushButton::New(); - mPlayStopButton.SetUnselectedImage( STOP_ICON ); - mPlayStopButton.SetSelectedImage( STOP_ICON_SELECTED ); - - mPlayStopButton.ClickedSignal().Connect( this, &RadialMenuExample::OnButtonClicked ); - - toolBar.AddControl( mPlayStopButton, - DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, - Toolkit::Alignment::HorizontalRight, - DemoHelper::DEFAULT_PLAY_PADDING ); - - - const ImageDimensions intImgSize = ResourceImage::GetImageSize(TEST_OUTER_RING_FILENAME); - Vector2 imgSize = Vector2( intImgSize.GetWidth(), intImgSize.GetHeight() ); - Vector2 stageSize = stage.GetSize(); - float scale = stageSize.width / imgSize.width; - float availableHeight = stageSize.height - DemoHelper::DEFAULT_VIEW_STYLE.mToolBarHeight * 2.0f; - if(availableHeight <= stageSize.width) - { - scale = availableHeight / imgSize.width; - } - - mRadialSweepView1 = CreateSweepView( TEST_OUTER_RING_FILENAME, Degree(-90.0f), Degree(-90.0f)); - mRadialSweepView2 = CreateSweepView( TEST_INNER_RING_FILENAME, Degree(90.0f), Degree(0.0f)); - mRadialSweepView3 = CreateSweepView( TEST_MENU_FILENAME, Degree(100.0f), Degree(0.0f)); - mRadialSweepView3.SetInitialActorAngle(Degree(-110)); - mRadialSweepView3.SetFinalActorAngle(Degree(0)); - - mDialView = ImageView::New( TEST_DIAL_FILENAME ); - mDialView.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); - mDialView.SetParentOrigin( ParentOrigin::CENTER ); - mDialView.SetScale(scale); - Layer dialLayer = Layer::New(); - - dialLayer.Add( mDialView ); - dialLayer.SetParentOrigin( ParentOrigin::CENTER ); - dialLayer.SetSize(stage.GetSize()); - mContents.Add(dialLayer); - - mRadialSweepView1.SetScale(scale); - mRadialSweepView2.SetScale(scale); - mRadialSweepView3.SetScale(scale); - - StartAnimation(); -} - -void RadialMenuExample::StartAnimation() -{ - mDialView.SetOpacity(0.0f); - mRadialSweepView1.SetOpacity(0.0f); - mAnimation = Animation::New(6.0f); - mRadialSweepView1.Activate(mAnimation, 0.0f, 3.0f); - mRadialSweepView2.Activate(mAnimation, 1.5f, 3.0f); - mRadialSweepView3.Activate(mAnimation, 3.0f, 3.0f); - mAnimation.AnimateTo( Property( mDialView, Actor::Property::COLOR_ALPHA ), 1.0f, AlphaFunction::EASE_IN, TimePeriod( 0.0f, 0.8f ) ); - mAnimation.AnimateTo( Property( mRadialSweepView1, Actor::Property::COLOR_ALPHA ), 1.0f, AlphaFunction::EASE_IN, TimePeriod( 0.0f, 0.5f ) ); - mAnimation.FinishedSignal().Connect( this, &RadialMenuExample::OnAnimationFinished ); - - mAnimationState = PLAYING; - mAnimation.Play(); -} - -bool RadialMenuExample::OnButtonClicked( Toolkit::Button button ) -{ - switch( mAnimationState ) - { - case PLAYING: - { - mAnimation.Pause(); - mAnimationState = PAUSED; - mPlayStopButton.SetUnselectedImage( PLAY_ICON ); - mPlayStopButton.SetSelectedImage( PLAY_ICON_SELECTED ); - } - break; - - case PAUSED: - { - mAnimation.Play(); - mAnimationState = PLAYING; - mPlayStopButton.SetUnselectedImage( STOP_ICON ); - mPlayStopButton.SetSelectedImage( STOP_ICON_SELECTED ); - } - break; - - case STOPPED: - { - mPlayStopButton.SetUnselectedImage( STOP_ICON ); - mPlayStopButton.SetSelectedImage( STOP_ICON_SELECTED ); - mRadialSweepView1.Deactivate(); - mRadialSweepView2.Deactivate(); - mRadialSweepView3.Deactivate(); - StartAnimation(); - } - } - return false; -} - -void RadialMenuExample::OnAnimationFinished( Animation& source ) -{ - mAnimationState = STOPPED; - mPlayStopButton.SetUnselectedImage( PLAY_ICON ); - mPlayStopButton.SetSelectedImage( PLAY_ICON_SELECTED ); -} - -RadialSweepView RadialMenuExample::CreateSweepView( std::string imageName, - Degree initialAngle, - Degree finalAngle) -{ - // Create the image - mImageView = ImageView::New(imageName); - mImageView.SetParentOrigin(ParentOrigin::CENTER); - mImageView.SetAnchorPoint(AnchorPoint::CENTER); - mImageView.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); - - // Create the stencil - const ImageDimensions imageSize = ResourceImage::GetImageSize(imageName); - float diameter = std::max(imageSize.GetWidth(), imageSize.GetHeight()); - RadialSweepView radialSweepView = RadialSweepView::New(); - radialSweepView.SetDiameter( diameter ); - radialSweepView.SetInitialAngle( initialAngle ); - radialSweepView.SetFinalAngle( finalAngle ); - radialSweepView.SetInitialSector( Degree(0.0f) ); - radialSweepView.SetFinalSector( Degree(359.999f) ); - radialSweepView.SetSize( Stage::GetCurrent().GetSize()); - radialSweepView.SetEasingFunction( Dali::AlphaFunction::EASE_IN_OUT ); - radialSweepView.SetParentOrigin( ParentOrigin::CENTER ); - mContents.Add(radialSweepView); - radialSweepView.Add( mImageView ); - mImageView.SetParentOrigin( ParentOrigin::CENTER ); - - return radialSweepView; -} - - -void RadialMenuExample::OnKeyEvent(const KeyEvent& event) -{ - if(event.state == KeyEvent::Down) - { - if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) ) - { - mApplication.Quit(); - } - } -} - -void RunTest(Application app) -{ - RadialMenuExample test(app); - - app.MainLoop(); -} - -// Entry point for Linux & Tizen applications -int DALI_EXPORT_API main(int argc, char **argv) -{ - Application app = Application::New(&argc, &argv, DEMO_THEME_PATH); - - RunTest(app); - - return 0; -} diff --git a/examples/radial-menu/radial-sweep-view-impl.cpp b/examples/radial-menu/radial-sweep-view-impl.cpp deleted file mode 100644 index 34bbe7c..0000000 --- a/examples/radial-menu/radial-sweep-view-impl.cpp +++ /dev/null @@ -1,357 +0,0 @@ -/* - * Copyright (c) 2016 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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 "radial-sweep-view-impl.h" - -#include -#include - -using namespace Dali; - -namespace -{ - -const char* VERTEX_SHADER_PREFIX( "#define MATH_PI_2 1.570796\n#define MATH_PI_4 0.785398\n" ); - -const char* VERTEX_SHADER = DALI_COMPOSE_SHADER( -attribute mediump float aAngleIndex;\n -attribute mediump vec2 aPosition1;\n -attribute mediump vec2 aPosition2;\n -uniform mediump mat4 uMvpMatrix;\n -uniform mediump float uStartAngle;\n -uniform mediump float uRotationAngle;\n -\n -void main()\n -{\n - float currentAngle = uStartAngle + uRotationAngle;\n - float angleInterval1 = MATH_PI_4 * aAngleIndex;\n - vec4 vertexPosition = vec4(0.0, 0.0, 0.0, 1.0);\n - if( currentAngle >= angleInterval1)\n - {\n - float angleInterval2 = angleInterval1 + MATH_PI_2;\n - float angle = currentAngle < angleInterval2 ? currentAngle : angleInterval2;\n - float delta;\n - if( mod( aAngleIndex+4.0, 4.0) < 2.0 )\n - {\n - delta = 0.5 - 0.5*cos(angle) / sin(angle);\n - }\n - else\n - {\n - delta = 0.5 + 0.5*sin(angle) / cos(angle);\n - }\n - vertexPosition.xy = mix( aPosition1, aPosition2, delta );\n - }\n - gl_Position = uMvpMatrix * vertexPosition;\n -} -); - -const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER( -uniform lowp vec4 uColor;\n -\n -void main()\n -{\n - gl_FragColor = uColor;\n -}\n -); - -float HoldZeroFastEaseInOutHoldOne(float progress) -{ - if( progress < 0.2f) - { - return 0.0f; - } - else if(progress < 0.5f) - { - progress = (progress-0.2) / 0.3f; - return progress*progress*progress*0.5f; - } - else if(progress < 0.8f) - { - progress = ((progress - 0.5f) / 0.3f) - 1.0f; - return (progress*progress*progress+1.0f) * 0.5f + 0.5f; - } - else - { - return 1.0f; - } -} - -} // anonymous namespace - - -RadialSweepView RadialSweepViewImpl::New( ) -{ - return New( 2.0f, 100.0f, ANGLE_0, ANGLE_0, ANGLE_0, ANGLE_360 ); -} - - -RadialSweepView RadialSweepViewImpl::New( float duration, float diameter, Radian initialAngle, Radian finalAngle, Radian initialSector, Radian finalSector ) -{ - RadialSweepViewImpl* impl= new RadialSweepViewImpl(duration, diameter, initialAngle, finalAngle, initialSector, finalSector); - RadialSweepView handle = RadialSweepView(*impl); - return handle; -} - -RadialSweepViewImpl::RadialSweepViewImpl( float duration, float diameter, Radian initialAngle, Radian finalAngle, Radian initialSector, Radian finalSector ) -: Control( ControlBehaviour( ACTOR_BEHAVIOUR_NONE ) ), - mDuration(duration), - mDiameter(diameter), - mInitialAngle(initialAngle), - mFinalAngle(finalAngle), - mInitialSector(initialSector), - mFinalSector(finalSector), - mInitialActorAngle(0), - mFinalActorAngle(0), - mEasingFunction(HoldZeroFastEaseInOutHoldOne), - mStartAngleIndex(Property::INVALID_INDEX), - mRotationAngleIndex(Property::INVALID_INDEX), - mRotateActorsWithStencil(false), - mRotateActors(false) -{ -} - -void RadialSweepViewImpl::SetDuration(float duration) -{ - mDuration = duration; -} - -void RadialSweepViewImpl::SetEasingFunction( Dali::AlphaFunction easingFunction ) -{ - mEasingFunction = easingFunction; -} - -void RadialSweepViewImpl::SetDiameter(float diameter) -{ - mDiameter = diameter; -} - -void RadialSweepViewImpl::SetInitialAngle( Dali::Radian initialAngle) -{ - mInitialAngle = initialAngle; -} - -void RadialSweepViewImpl::SetFinalAngle( Dali::Radian finalAngle) -{ - mFinalAngle = finalAngle; -} - -void RadialSweepViewImpl::SetInitialSector( Dali::Radian initialSector) -{ - mInitialSector = initialSector; -} - -void RadialSweepViewImpl::SetFinalSector( Dali::Radian finalSector) -{ - mFinalSector = finalSector; -} - -void RadialSweepViewImpl::SetInitialActorAngle( Dali::Radian initialAngle ) -{ - mInitialActorAngle = initialAngle; - mRotateActors = true; -} - -void RadialSweepViewImpl::SetFinalActorAngle( Dali::Radian finalAngle ) -{ - mFinalActorAngle = finalAngle; - mRotateActors = true; -} - -float RadialSweepViewImpl::GetDuration( ) -{ - return mDuration; -} - -float RadialSweepViewImpl::GetDiameter( ) -{ - return mDiameter; -} - -Dali::Radian RadialSweepViewImpl::GetInitialAngle( ) -{ - return mInitialAngle; -} - -Dali::Radian RadialSweepViewImpl::GetFinalAngle( ) -{ - return mFinalAngle; -} - -Dali::Radian RadialSweepViewImpl::GetInitialSector( ) -{ - return mInitialSector; -} - -Dali::Radian RadialSweepViewImpl::GetFinalSector( ) -{ - return mFinalSector; -} - -Dali::Radian RadialSweepViewImpl::GetInitialActorAngle( ) -{ - return mInitialActorAngle; -} - -Dali::Radian RadialSweepViewImpl::GetFinalActorAngle( ) -{ - return mFinalActorAngle; -} - -void RadialSweepViewImpl::RotateActorsWithStencil(bool rotate) -{ - mRotateActorsWithStencil = rotate; -} - -void RadialSweepViewImpl::Add(Actor actor) -{ - if( ! mLayer ) - { - mLayer = Layer::New(); - Self().Add(mLayer); - mLayer.SetSize( Stage::GetCurrent().GetSize() ); - mLayer.SetParentOrigin( ParentOrigin::CENTER ); - } - - mLayer.Add(actor); -} - -void RadialSweepViewImpl::Activate( Animation anim, float offsetTime, float duration ) -{ - bool startAnimation=false; - if( ! anim ) - { - mAnim = Animation::New( mDuration ); - anim = mAnim; - startAnimation = true; - } - - if( ! mStencilActor ) - { - CreateStencil( mInitialSector ); - mLayer.Add( mStencilActor ); - mStencilActor.SetScale(mDiameter); - } - - mStencilActor.SetOrientation( mInitialAngle, Vector3::ZAXIS ); - mStencilActor.SetProperty( mRotationAngleIndex, mInitialSector.radian ); - - if( mRotateActors ) - { - for(unsigned int i=0, count=mLayer.GetChildCount(); i -#include "radial-sweep-view.h" - - -/******************************************************************************** - * Class to implement a layer with a radial sweep stencil mask and an actor tree - */ -class RadialSweepViewImpl : public Dali::Toolkit::Internal::Control -{ -public: - static RadialSweepView New(); - - static RadialSweepView New( float duration, - float diameter, - Dali::Radian initialAngle, - Dali::Radian finalAngle, - Dali::Radian initialSector, - Dali::Radian finalSector ); - - RadialSweepViewImpl( float duration, - float diameter, - Dali::Radian initialAngle, - Dali::Radian finalAngle, - Dali::Radian initialSector, - Dali::Radian finalSector ); - - void SetDuration(float duration); - void SetEasingFunction( Dali::AlphaFunction easingFunction ); - - void SetDiameter(float diameter); - void SetInitialAngle( Dali::Radian initialAngle); - void SetFinalAngle( Dali::Radian finalAngle); - void SetInitialSector( Dali::Radian initialSector); - void SetFinalSector( Dali::Radian finalSector); - void SetInitialActorAngle( Dali::Radian initialAngle ); - void SetFinalActorAngle( Dali::Radian finalAngle ); - - float GetDuration( ); - float GetDiameter( ); - Dali::Radian GetInitialAngle( ); - Dali::Radian GetFinalAngle( ); - Dali::Radian GetInitialSector( ); - Dali::Radian GetFinalSector( ); - Dali::Radian GetInitialActorAngle( ); - Dali::Radian GetFinalActorAngle( ); - - void RotateActorsWithStencil(bool rotate); - - void Add( Dali::Actor actor ); - - void Activate( Dali::Animation anim = Dali::Animation(), float offsetTime=0, float duration=2.0f ); - - void Deactivate(); - -private: - - /** - * Create the stencil mask - */ - void CreateStencil(Dali::Radian initialSector ); - -private: - Dali::Layer mLayer; - Dali::Animation mAnim; - float mDuration; - float mDiameter; - Dali::Radian mInitialAngle; - Dali::Radian mFinalAngle; - Dali::Radian mInitialSector; - Dali::Radian mFinalSector; - Dali::Radian mInitialActorAngle; - Dali::Radian mFinalActorAngle; - Dali::AlphaFunction mEasingFunction; - Dali::Actor mStencilActor; ///< Stencil actor which generates mask - Dali::Property::Index mStartAngleIndex; ///< Index of start-angle property - Dali::Property::Index mRotationAngleIndex; ///< Index of rotation-angle property - bool mRotateActorsWithStencil:1; - bool mRotateActors; -}; - - -inline RadialSweepViewImpl& GetImpl( RadialSweepView& obj ) -{ - DALI_ASSERT_ALWAYS(obj); - Dali::RefObject& handle = obj.GetImplementation(); - return static_cast(handle); -} - -inline const RadialSweepViewImpl& GetImpl( const RadialSweepView& obj ) -{ - DALI_ASSERT_ALWAYS(obj); - const Dali::RefObject& handle = obj.GetImplementation(); - return static_cast(handle); -} - - - -#endif // DALI_DEMO_RADIAL_SWEEP_VIEW_IMPL_H diff --git a/examples/radial-menu/radial-sweep-view.cpp b/examples/radial-menu/radial-sweep-view.cpp deleted file mode 100644 index 46e2609..0000000 --- a/examples/radial-menu/radial-sweep-view.cpp +++ /dev/null @@ -1,184 +0,0 @@ -/* - * Copyright (c) 2015 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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 "radial-sweep-view.h" -#include "radial-sweep-view-impl.h" - -using namespace Dali; - -RadialSweepView::RadialSweepView() -{ -} - -RadialSweepView::RadialSweepView(const RadialSweepView& handle) -: Control(handle) -{ -} - -RadialSweepView& RadialSweepView::operator=(const RadialSweepView& rhs) -{ - if( &rhs != this ) - { - Control::operator=(rhs); - } - return *this; -} - -RadialSweepView::~RadialSweepView() -{ -} - -RadialSweepView RadialSweepView::DownCast( BaseHandle handle ) -{ - return Control::DownCast(handle); -} - -RadialSweepView RadialSweepView::New( ) -{ - return RadialSweepViewImpl::New(); -} - -RadialSweepView RadialSweepView::New( float duration, - float diameter, - Radian initialAngle, - Radian finalAngle, - Radian initialSector, - Radian finalSector ) -{ - return RadialSweepViewImpl::New(duration, diameter, initialAngle, finalAngle, initialSector, finalSector ); -} - -RadialSweepView::RadialSweepView( RadialSweepViewImpl& impl ) -: Control( impl ) -{ -} - -RadialSweepView::RadialSweepView( Dali::Internal::CustomActor* impl ) -: Control( impl ) -{ - VerifyCustomActorPointer(impl); -} - -void RadialSweepView::SetDuration(float duration) -{ - GetImpl(*this).SetDuration(duration); -} - -void RadialSweepView::SetEasingFunction( Dali::AlphaFunction easingFunction ) -{ - GetImpl(*this).SetEasingFunction( easingFunction ); -} - -void RadialSweepView::SetDiameter(float diameter) -{ - GetImpl(*this).SetDiameter(diameter); -} - -void RadialSweepView::SetInitialAngle( Dali::Radian initialAngle) -{ - GetImpl(*this).SetInitialAngle(initialAngle); -} - -void RadialSweepView::SetFinalAngle( Dali::Radian finalAngle) -{ - GetImpl(*this).SetFinalAngle(finalAngle); -} - -void RadialSweepView::SetInitialSector( Dali::Radian initialSector) -{ - GetImpl(*this).SetInitialSector(initialSector); -} - -void RadialSweepView::SetFinalSector( Dali::Radian finalSector) -{ - GetImpl(*this).SetFinalSector(finalSector); -} - -void RadialSweepView::SetInitialActorAngle( Dali::Radian initialAngle ) -{ - GetImpl(*this).SetInitialActorAngle(initialAngle); -} - -void RadialSweepView::SetFinalActorAngle( Dali::Radian finalAngle ) -{ - GetImpl(*this).SetFinalActorAngle(finalAngle); -} - -float RadialSweepView::GetDuration( ) -{ - return GetImpl(*this).GetDuration(); -} - -float RadialSweepView::GetDiameter( ) -{ - return GetImpl(*this).GetDiameter(); -} - -Dali::Radian RadialSweepView::GetInitialAngle( ) -{ - return GetImpl(*this).GetInitialAngle(); -} - -Dali::Radian RadialSweepView::GetFinalAngle( ) -{ - return GetImpl(*this).GetFinalAngle(); -} - -Dali::Radian RadialSweepView::GetInitialSector( ) -{ - return GetImpl(*this).GetInitialSector(); -} - -Dali::Radian RadialSweepView::GetFinalSector( ) -{ - return GetImpl(*this).GetFinalSector(); -} - -Dali::Radian RadialSweepView::GetInitialActorAngle( ) -{ - return GetImpl(*this).GetInitialActorAngle(); -} - -Dali::Radian RadialSweepView::GetFinalActorAngle( ) -{ - return GetImpl(*this).GetFinalActorAngle(); -} - -void RadialSweepView::RotateActorsWithStencil(bool rotate) -{ - GetImpl(*this).RotateActorsWithStencil(rotate); -} - -void RadialSweepView::Add(Actor actor) -{ - GetImpl(*this).Add(actor); -} - -void RadialSweepView::Activate() -{ - GetImpl(*this).Activate(); -} - -void RadialSweepView::Activate( Dali::Animation anim, float offsetTime, float duration ) -{ - GetImpl(*this).Activate(anim, offsetTime, duration); -} - -void RadialSweepView::Deactivate() -{ - GetImpl(*this).Deactivate(); -} diff --git a/examples/radial-menu/radial-sweep-view.h b/examples/radial-menu/radial-sweep-view.h deleted file mode 100644 index 3abdcb0..0000000 --- a/examples/radial-menu/radial-sweep-view.h +++ /dev/null @@ -1,150 +0,0 @@ -#ifndef DALI_DEMO_RADIAL_SWEEP_VIEW_H -#define DALI_DEMO_RADIAL_SWEEP_VIEW_H - -/* - * Copyright (c) 2015 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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 - -class RadialSweepViewImpl; - - -/******************************************************************************** - * Handle to RadialSweepView implementation - */ -class RadialSweepView : public Dali::Toolkit::Control -{ -public: - /** - * Create a new RadialSweepView with default parameters (2 second animation, - * no rotation, sweeping out a full circle). - */ - static RadialSweepView New( ); - - /** - * Create a new RadialSweepView. - * @param[in] duration The duration of the sweep animation - * @param[in] diameter The diameter of the stencil mask - * @param[in] initialAngle The initial angle of the anticlockwise line of the sweep sector - * @param[in] finalAngle The final angle of the anticlockwise line of the sweep sector - * @param[in] initialSector The angle of the starting sector - * @param[in] finalSector The angle of the sector at the end of the animation. - * Note, to cover the entire circle, use a value of 359.9999 degrees, not zero or 360 degrees. - * - * initial sector - * \ | . - * \ | . - * initialAngle \ | . final sector - * \| _| - * .________ - */ - static RadialSweepView New( float duration, - float diameter, - Dali::Radian initialAngle, - Dali::Radian finalAngle, - Dali::Radian initialSector, - Dali::Radian finalSector ); - - void SetDuration(float duration); - - void SetEasingFunction( Dali::AlphaFunction easingFunction ); - - void SetDiameter(float diameter); - - void SetInitialAngle( Dali::Radian initialAngle); - - void SetFinalAngle( Dali::Radian finalAngle); - - void SetInitialSector( Dali::Radian initialSector); - - void SetFinalSector( Dali::Radian finalSector); - - void SetInitialActorAngle( Dali::Radian initialAngle ); - - void SetFinalActorAngle( Dali::Radian finalAngle ); - - float GetDuration( ); - - float GetDiameter( ); - - Dali::Radian GetInitialAngle( ); - - Dali::Radian GetFinalAngle( ); - - Dali::Radian GetInitialSector( ); - - Dali::Radian GetFinalSector( ); - - Dali::Radian GetInitialActorAngle( ); - - Dali::Radian GetFinalActorAngle( ); - - /** - * @param[in] rotate True if the actors should rotate with the stencil - */ - void RotateActorsWithStencil(bool rotate); - - /** - * Add actors to the view - */ - void Add(Actor actor); - - /** - * Activate the sweep animation - */ - void Activate( ); - - void Activate( Dali::Animation anim, float offsetTime, float duration ); - - /** - * Deactivate the sweep animation - */ - void Deactivate(); - - /** - * Default constructor. Create an uninitialized handle. - */ - RadialSweepView(); - - /** - * Copy constructor - */ - RadialSweepView(const RadialSweepView& handle); - - /** - * Assignment operator - */ - RadialSweepView& operator=(const RadialSweepView& rhs); - - /** - * Destructor - */ - ~RadialSweepView(); - - /** - * Downcast method - */ - static RadialSweepView DownCast( BaseHandle handle ); - -public: // Not for use by application developers - - RadialSweepView( RadialSweepViewImpl& impl ); - - RadialSweepView( Dali::Internal::CustomActor* impl ); -}; - -#endif diff --git a/examples/renderer-stencil/renderer-stencil-example.cpp b/examples/renderer-stencil/renderer-stencil-example.cpp index 27385f0..37d6fe7 100644 --- a/examples/renderer-stencil/renderer-stencil-example.cpp +++ b/examples/renderer-stencil/renderer-stencil-example.cpp @@ -275,13 +275,10 @@ private: renderer.SetTextures( textureSet ); // Setup the renderer properties: - // We are writing to the color buffer & culling back faces. - renderer.SetProperty( Renderer::Property::WRITE_TO_COLOR_BUFFER, true ); + // We are writing to the color buffer & culling back faces (no stencil is used for the main cube). + renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::COLOR ); renderer.SetProperty( Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::BACK ); - // No stencil is used for the main cube. - renderer.SetProperty( Renderer::Property::STENCIL_MODE, StencilMode::OFF ); - // We do need to write to the depth buffer as other objects need to appear underneath this cube. renderer.SetProperty( Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::ON ); // We do not need to test the depth buffer as we are culling the back faces. @@ -316,13 +313,10 @@ private: renderer.SetTextures( planeTextureSet ); // Setup the renderer properties: - // We are writing to the color buffer & culling back faces (as we are NOT doing depth write). - renderer.SetProperty( Renderer::Property::WRITE_TO_COLOR_BUFFER, true ); + // We are writing to the color buffer & culling back faces as we are NOT doing depth write (no stencil is used for the floor). + renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::COLOR ); renderer.SetProperty( Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::BACK ); - // No stencil is used for the floor. - renderer.SetProperty( Renderer::Property::STENCIL_MODE, StencilMode::OFF ); - // We do not write to the depth buffer as its not needed. renderer.SetProperty( Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::OFF ); // We do need to test the depth buffer as we need the floor to be underneath the cube. @@ -360,11 +354,9 @@ private: Renderer renderer = CreateRenderer( planeGeometry, size, false, Vector4::ONE ); // Setup the renderer properties: - // The stencil plane is only for stencilling, so disable writing to color buffer. - renderer.SetProperty( Renderer::Property::WRITE_TO_COLOR_BUFFER, false ); + // The stencil plane is only for stencilling. + renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::STENCIL ); - // Enable stencil. Draw to the stencil buffer (only). - renderer.SetProperty( Renderer::Property::STENCIL_MODE, StencilMode::ON ); renderer.SetProperty( Renderer::Property::STENCIL_FUNCTION, StencilFunction::ALWAYS ); renderer.SetProperty( Renderer::Property::STENCIL_FUNCTION_REFERENCE, 1 ); renderer.SetProperty( Renderer::Property::STENCIL_FUNCTION_MASK, 0xFF ); @@ -410,8 +402,9 @@ private: renderer.SetTextures( textureSet ); // Setup the renderer properties: - // Write to color buffer so reflection is visible - renderer.SetProperty( Renderer::Property::WRITE_TO_COLOR_BUFFER, true ); + // Write to color buffer so reflection is visible. + // Also enable the stencil buffer, as we will be testing against it to only draw to areas within the stencil. + renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::COLOR_STENCIL ); // We cull to skip drawing the back faces. renderer.SetProperty( Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::BACK ); @@ -422,7 +415,6 @@ private: renderer.SetProperty( Renderer::Property::BLEND_FACTOR_DEST_RGB, BlendFactor::ONE ); // Enable stencil. Here we only draw to areas within the stencil. - renderer.SetProperty( Renderer::Property::STENCIL_MODE, StencilMode::ON ); renderer.SetProperty( Renderer::Property::STENCIL_FUNCTION, StencilFunction::EQUAL ); renderer.SetProperty( Renderer::Property::STENCIL_FUNCTION_REFERENCE, 1 ); renderer.SetProperty( Renderer::Property::STENCIL_FUNCTION_MASK, 0xff ); diff --git a/examples/renderer-stencil/renderer-stencil-shaders.h b/examples/renderer-stencil/renderer-stencil-shaders.h index fe9c461..fcf758f 100644 --- a/examples/renderer-stencil/renderer-stencil-shaders.h +++ b/examples/renderer-stencil/renderer-stencil-shaders.h @@ -29,7 +29,7 @@ const char * const POSITION( "aPosition"); const char * const NORMAL( "aNormal" ); const char * const TEXTURE( "aTexCoord" ); -// Shader for todor (vertex): +// Shader for basic, per-vertex lighting (vertex): const char* VERTEX_SHADER = DALI_COMPOSE_SHADER( attribute mediump vec3 aPosition; attribute highp vec3 aNormal; @@ -62,6 +62,7 @@ const char* VERTEX_SHADER = DALI_COMPOSE_SHADER( } ); +// Fragment shader. const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER( varying mediump vec2 vTexCoord; varying mediump vec3 vIllumination; @@ -74,6 +75,7 @@ const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER( } ); +// Shader for basic, per-vertex lighting with texture (vertex): const char* VERTEX_SHADER_TEXTURED = DALI_COMPOSE_SHADER( attribute mediump vec3 aPosition; attribute highp vec3 aNormal; @@ -107,6 +109,7 @@ const char* VERTEX_SHADER_TEXTURED = DALI_COMPOSE_SHADER( } ); +// Fragment shader. const char* FRAGMENT_SHADER_TEXTURED = DALI_COMPOSE_SHADER( varying mediump vec2 vTexCoord; varying mediump vec3 vIllumination; diff --git a/examples/size-negotiation/size-negotiation-example.cpp b/examples/size-negotiation/size-negotiation-example.cpp index 3c05fbd..5fe5daa 100644 --- a/examples/size-negotiation/size-negotiation-example.cpp +++ b/examples/size-negotiation/size-negotiation-example.cpp @@ -798,7 +798,7 @@ private: Layer mContentLayer; ///< Content layer. Toolkit::TextLabel mTitleActor; ///< Title text. - Toolkit::Popup mMenu; ///< The navigation menu todor. + Toolkit::Popup mMenu; ///< The navigation menu. Toolkit::Popup mPopup; ///< The current example popup. Toolkit::ItemView mItemView; ///< ItemView to hold test images. diff --git a/examples/sparkle/sparkle-effect-example.cpp b/examples/sparkle/sparkle-effect-example.cpp new file mode 100644 index 0000000..1cc465a --- /dev/null +++ b/examples/sparkle/sparkle-effect-example.cpp @@ -0,0 +1,568 @@ +/* + * Copyright (c) 2016 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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 + +#include +#include +#include + +#include "shared/utility.h" +#include "sparkle-effect.h" + +using namespace Dali; +using Dali::Toolkit::ImageView; + +using namespace SparkleEffect; + +namespace // unnamed namespace +{ + +//background image for normal status +const char * const CIRCLE_BACKGROUND_IMAGE( DEMO_IMAGE_DIR "sparkle_normal_background.png" ); +//particle shape image +const char * const PARTICLE_IMAGE( DEMO_IMAGE_DIR "sparkle_particle.png" ); + +float EaseOutSquare( float progress ) +{ + return 1.0f - (1.0f-progress) * (1.0f-progress); +} + +float CustomBounce( float progress ) +{ + float p = 1.f-progress; + p *=p; + return 17.68f*p*p*p*progress; +} + +float Mix( const Vector2& range, float a ) +{ + return range.x * a + range.y*(1.f-a)-0.001f; +} + +const Vector4 BACKGROUND_COLOR( 0.f, 0.f, 0.05f, 1.f ); + +} // unnamed namespace + +// This example shows a sparkle particle effect +// +class SparkleEffectExample : public ConnectionTracker +{ +public: + + /** + * Create the SparkleEffectExample + * @param[in] application The DALi application instance + */ + SparkleEffectExample( Application& application ) + : mApplication( application ), + mAnimationIndex( 0u ), + mShaking( false ) + { + mApplication.InitSignal().Connect( this, &SparkleEffectExample::OnInit ); + } + +private: + + /** + * Initialize the SparkleEffectExample + * @param[in] application The DALi application instance + */ + void OnInit( Application& application ) + { + Stage stage = Stage::GetCurrent(); + stage.KeyEventSignal().Connect(this, &SparkleEffectExample::OnKeyEvent); + stage.SetBackgroundColor( BACKGROUND_COLOR ); + + mCircleBackground = ImageView::New( CIRCLE_BACKGROUND_IMAGE ); + mCircleBackground.SetParentOrigin( ParentOrigin::CENTER ); + mCircleBackground.SetAnchorPoint( AnchorPoint::CENTER ); + + stage.Add( mCircleBackground ); + + mEffect = SparkleEffect::New(); + + mMeshActor = CreateMeshActor(); + + stage.Add( mMeshActor ); + + mMeshActor.SetPosition( ACTOR_POSITION ); + mMeshActor.SetScale( ACTOR_SCALE ); + + mTapDetector = TapGestureDetector::New(); + mTapDetector.Attach(mCircleBackground); + mTapDetector.DetectedSignal().Connect( this, &SparkleEffectExample::OnTap ); + + mPanGestureDetector = PanGestureDetector::New(); + mPanGestureDetector.DetectedSignal().Connect( this, &SparkleEffectExample::OnPan ); + mPanGestureDetector.Attach( mCircleBackground ); + + PlayWanderAnimation( 35.f ); + } + + /** + * Create the mesh representing all the particles + */ + Actor CreateMeshActor() + { + // shuffling to assign the color in random order + unsigned int* shuffleArray = new unsigned int[NUM_PARTICLE]; + for( unsigned int i = 0; i vertices; + std::vector< unsigned short > faces; + + for( unsigned int i = 0; i(thereshold-particleIndex)/PARTICLE_COLORS[i].numParticle ); + } + } + return NUM_COLOR-1; + } + + /** + * All a particle to the mesh by giving the moving path and color index + * + * Two triangles per particle + * 0---------3 + * |\ | + * | \ | + * | \ | + * | \| + * 1---------2 + * + * The information we need to pass in through attribute include: + * + * path which contains 12 integer + * ---- passed in 6 Vector2 attributes + * + * color index, particle index and textureCoor( (0,0) or (1,0) or (0,1) or (1,1) ) + * ---- package these info into texCood attribute as: (+-colorIndex, +-particleIndex) + */ + void AddParticletoMesh( std::vector< Vertex >& vertices, + std::vector< unsigned short >& faces, + MovingPath& movingPath, + float colorIndex ) + { + unsigned int idx = vertices.size(); + + // store the path into position and normal, which would be decoded inside the shader + Vector2 particlePath0( movingPath[0], movingPath[1] ); + Vector2 particlePath1( movingPath[2], movingPath[3] ); + Vector2 particlePath2( movingPath[4], movingPath[5] ); + Vector2 particlePath3( movingPath[6], movingPath[7] ); + Vector2 particlePath4( movingPath[8], movingPath[9] ); + Vector2 particlePath5( movingPath[10], movingPath[11] ); + + float particleIdx = static_cast(idx/4 + 1); // count from 1 + float colorIdx = colorIndex+1.f; // count from 1 + vertices.push_back( Vertex( Vector2(-colorIdx, -particleIdx), particlePath0, particlePath1, particlePath2, particlePath3, particlePath4, particlePath5 ) ); + vertices.push_back( Vertex( Vector2(-colorIdx, particleIdx), particlePath0, particlePath1, particlePath2, particlePath3, particlePath4, particlePath5 ) ); + vertices.push_back( Vertex( Vector2( colorIdx, particleIdx), particlePath0, particlePath1, particlePath2, particlePath3, particlePath4, particlePath5 ) ); + vertices.push_back( Vertex( Vector2( colorIdx, -particleIdx), particlePath0, particlePath1, particlePath2, particlePath3, particlePath4, particlePath5 ) ); + + faces.push_back(idx); + faces.push_back(idx+1); + faces.push_back(idx+2); + + faces.push_back(idx); + faces.push_back(idx+2); + faces.push_back(idx+3); + } + + /* + * Main key event handler + */ + void OnKeyEvent(const KeyEvent& event) + { + if(event.state == KeyEvent::Down) + { + if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) ) + { + mApplication.Quit(); + } + } + } + + /** + * Callback of the TapGesture + */ + void OnTap( Actor actor, const TapGesture& tap ) + { + { + PlayTapAnimation(5.f, tap.localPoint); + } + } + + /** + * Callback of the PanGesture + */ + void OnPan( Actor actor, const PanGesture& gesture ) + { + if( gesture.state == Gesture::Finished ) + { + switch(mAnimationIndex) + { + case 0: + { + PlayParticleFadeAnimation(0, NUM_PARTICLE, 0.f, 3.f ); + break; + } + case 1: + { + PlayBreakAnimation(2.0f); + break; + } + case 2: + { + PlayShakeAnimation(0.5f, 2.5f); + break; + } + default: + { + break; + } + } + + mAnimationIndex = (mAnimationIndex+1)%3; + } + } + + /** + * Animate the particle position to make them wandering on the screen with 'seemingly' random fade in/out + * @param[in] duration The duration for the particle to move a cycle on the path. the bigger this value the slower the floating movement. + * @param[in] looping Infinite playing or not + */ + void PlayWanderAnimation( float duration, bool looping = true ) + { + Animation wanderAnimation= Animation::New(duration); + wanderAnimation.AnimateTo( Property( mEffect, PERCENTAGE_UNIFORM_NAME ), 1.f ); + wanderAnimation.SetLooping(looping); // infinite playing + + wanderAnimation.Play(); + } + + /** + * Accelerate the particle moving speed + * @param[in] cycle How many extra cycles to move during the animation + * @param[in] duration The duration for the animation + */ + void PlayShakeAnimation( float cycle, float duration ) + { + if( mShaking ) + { + return; + } + DestroyAnimation( mTapAnimationAux ); + + float accelaration = GetFloatUniformValue( ACCELARATION_UNIFORM_NAME ); + mEffect.SetProperty( mEffect.GetPropertyIndex(ACCELARATION_UNIFORM_NAME), accelaration - int( accelaration) ); // Set the value as its fractional part + Animation shakeAnimation = Animation::New(duration); + shakeAnimation.AnimateBy( Property( mEffect, ACCELARATION_UNIFORM_NAME ), cycle, AlphaFunction::EASE_OUT ); + shakeAnimation.FinishedSignal().Connect( this, &SparkleEffectExample::OnShakeAnimationFinished ); + + shakeAnimation.Play(); + mShaking = true; + } + + /** + * Animate the particles to appear from center and spread all over around + * @param[in] duration The duration for the animation + */ + void PlayBreakAnimation( float duration ) + { + if( GetFloatUniformValue(BREAK_UNIFORM_NAME) > 0.f ) + { + return; + } + + // Stop the fading / tap animation before the breaking + DestroyAnimation( mFadeAnimation); + mTapIndices.x = mTapIndices.y; + mEffect.SetProperty( mEffect.GetPropertyIndex( TAP_INDICES_UNIFORM_NAME ), mTapIndices ); + mEffect.SetProperty( mEffect.GetPropertyIndex( ACCELARATION_UNIFORM_NAME ), 0.f ); + + // prepare the animation by setting the uniform to the required value + mEffect.SetProperty( mEffect.GetPropertyIndex( BREAK_UNIFORM_NAME ), 1.f ); + mMeshActor.SetScale(0.01f); + mEffect.SetProperty( mEffect.GetPropertyIndex( "uScale" ), 0.01f ); + mMeshActor.SetPosition( 0.f, 0.f, 1.f ); + + Animation breakAnimation = Animation::New(duration*1.5f); + breakAnimation.AnimateTo( Property(mMeshActor, Actor::Property::SCALE), Vector3(ACTOR_SCALE,ACTOR_SCALE,ACTOR_SCALE), EaseOutSquare); + breakAnimation.AnimateTo( Property( mEffect, "uScale" ), ACTOR_SCALE, EaseOutSquare); + breakAnimation.AnimateTo( Property(mMeshActor, Actor::Property::POSITION), ACTOR_POSITION, EaseOutSquare); + breakAnimation.FinishedSignal().Connect( this, &SparkleEffectExample::OnBreakAnimationFinished ); + + float timeUnit = duration/ (NUM_PARTICLE+1) /(NUM_PARTICLE+1) ; + std::ostringstream oss; + for(unsigned int i = 0; i 0.f ) + { + return; + } + + // start the opacity animation one particle after another gradually + float timeSlice = duration / (numParticle+1); + float fadeDuration = timeSlice>0.5f ? timeSlice : 0.5f; + + Animation fadeAnimation= Animation::New(duration+fadeDuration*2.f); + std::ostringstream oss; + for(unsigned int i = startIndex; i=NUM_PARTICLE ) break; // out of bound + + oss.str(""); + oss<< OPACITY_UNIFORM_NAME<< i << "]"; + fadeAnimation.AnimateTo(Property( mEffect, oss.str()), targetValue, TimePeriod( timeSlice*i, fadeDuration*2.f )); + } + + fadeAnimation.Play(); + mFadeAnimation = fadeAnimation; + mFadeAnimation.FinishedSignal().Connect( this, &SparkleEffectExample::OnFadeAnimationFinished ); + } + + /** + * Push the particles to the edge all around the circle then bounce back + * @param[in] duration The duration for the animation + * @param[in] tapPoint The position of the tap point + */ + void PlayTapAnimation(float duration, const Vector2& tapPoint ) + { + if( mTapIndices.y > mTapIndices.x && mTapAnimation.GetCurrentProgress() < 0.2f) + { + return; + } + + Animation animation= Animation::New(duration); + int idx = int(mTapIndices.y)%MAXIMUM_ANIMATION_COUNT; + mTapIndices.y += 1.f; + + std::ostringstream oss; + oss<< TAP_OFFSET_UNIFORM_NAME<< idx << "]"; + mEffect.SetProperty( mEffect.GetPropertyIndex( oss.str() ), 0.f); + animation.AnimateTo( Property( mEffect, oss.str() ), 0.75f, CustomBounce); + + oss.str(""); + oss<< TAP_POINT_UNIFORM_NAME<< idx << "]"; + mEffect.SetProperty( mEffect.GetPropertyIndex( oss.str() ), tapPoint/ACTOR_SCALE); + + mEffect.SetProperty( mEffect.GetPropertyIndex( TAP_INDICES_UNIFORM_NAME ), mTapIndices); + + if(!mShaking) + { + mTapAnimationAux = Animation::New(duration*0.2f); + mTapAnimationAux.AnimateBy( Property( mEffect, ACCELARATION_UNIFORM_NAME ), 0.15f, AlphaFunction::EASE_IN_OUT ); + mTapAnimationAux.Play(); + } + animation.Play(); + mTapAnimationIndexPair[animation] = static_cast(mTapIndices.y -1.f); + animation.FinishedSignal().Connect( this, &SparkleEffectExample::OnTapAnimationFinished ); + mTapAnimation = animation; + } + + /** + * Callback of the animation finished signal + */ + void OnShakeAnimationFinished( Animation& animation) + { + mShaking = false; + } + + /** + * Callback of the animation finished signal + */ + void OnFadeAnimationFinished( Animation& animation) + { + mFadeAnimation.Clear(); + mFadeAnimation.Reset(); + } + + /** + * Callback of the animation finished signal + */ + void OnBreakAnimationFinished( Animation& animation) + { + mEffect.SetProperty( mEffect.GetPropertyIndex( BREAK_UNIFORM_NAME ), 0.f ); + } + + /** + * Callback of the animation finished signal + */ + void OnTapAnimationFinished( Animation& animation ) + { + if( mTapAnimationIndexPair[animation] == static_cast(mTapIndices.x) ) + { + mTapIndices.x += 1.f; + if( mTapIndices.x >= mTapIndices.y ) + { + mTapIndices = Vector2::ZERO; + } + mEffect.SetProperty( mEffect.GetPropertyIndex( TAP_INDICES_UNIFORM_NAME ), mTapIndices); + } + + mTapAnimationIndexPair.erase( animation ); + if( mTapAnimationIndexPair.size() < 1 && mTapIndices != Vector2::ZERO) + { + mTapIndices = Vector2::ZERO; + mEffect.SetProperty( mEffect.GetPropertyIndex( TAP_INDICES_UNIFORM_NAME ), mTapIndices); + } + + animation.Clear(); + animation.Reset(); + } + + /** + * Helper retrieve a uniform value from the Sparkle effect shader + * @param[in] uniformName The uniform + * @return The float value + */ + float GetFloatUniformValue( const std::string& uniformName ) + { + float value; + mEffect.GetProperty(mEffect.GetPropertyIndex(uniformName)).Get(value); + return value; + } + + /** + * Terminate the given animation + */ + void DestroyAnimation( Animation& animation ) + { + if( animation ) + { + animation.Clear(); + animation.Reset(); + } + } + +private: + + Application& mApplication; + Shader mEffect; + ImageView mCircleBackground; + Actor mMeshActor; + + PanGestureDetector mPanGestureDetector; + TapGestureDetector mTapDetector; + + Animation mFadeAnimation; + Animation mTapAnimation; + Animation mTapAnimationAux; + + Vector2 mTapIndices; + unsigned int mAnimationIndex; + bool mShaking; + + std::map< Animation, int > mTapAnimationIndexPair; +}; + +void RunTest( Application& application ) +{ + SparkleEffectExample theApp( application ); + + application.MainLoop(); +} + +// Entry point for Linux & Tizen applications +// +int DALI_EXPORT_API main( int argc, char **argv ) +{ + Application application = Application::New( &argc, &argv ); + + RunTest( application ); + + return 0; +} + diff --git a/examples/sparkle/sparkle-effect.h b/examples/sparkle/sparkle-effect.h new file mode 100644 index 0000000..f37e1e6 --- /dev/null +++ b/examples/sparkle/sparkle-effect.h @@ -0,0 +1,393 @@ +#ifndef DALI_SPARKLE_EFFECT_H +#define DALI_SPARKLE_EFFECT_H + +/* + * Copyright (c) 2016 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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 Dali::Toolkit::ImageView; + +/************************************************************/ +/* Custom sparkle effect shader******************************/ +/************************************************************/ + +namespace SparkleEffect +{ + // uniform which controls the position of particle on the path + const std::string PERCENTAGE_UNIFORM_NAME( "uPercentage" ); + // uniform array of particle color, set their value as the PARTICLE_COLORS given below + const std::string PARTICLE_COLOR_UNIFORM_NAME("uParticleColors["); + // uniform array of particle opacity + const std::string OPACITY_UNIFORM_NAME("uOpacity["); + // uniform which offsets the path control point, with this values >=0, the paths are squeezed towards the GatheringPoint + const std::string ACCELARATION_UNIFORM_NAME("uAcceleration"); + // uniform which indicates the ongoing tap animations + const std::string TAP_INDICES_UNIFORM_NAME("uTapIndices"); + // uniform which controls how much the offset of the midpoints relative to the start/end points of the cubic bezier curve when the path is squeezed for tap animation + const std::string TAP_OFFSET_UNIFORM_NAME("uTapOffset["); + // uniform which gives the position of the tapping, in this way the particles will be pushed away from this point + const std::string TAP_POINT_UNIFORM_NAME("uTapPoint["); + // uniform which trigger the break animation, set to 1.0 when break animation is playing, otherwise set to 0.0 + const std::string BREAK_UNIFORM_NAME("uBreak"); + + /****************particle colors******************/ + + struct ParticleColor + { + Vector3 RGB; + Vector2 AlphaRange; + unsigned int numParticle; + }; + + ParticleColor PARTICLE_COLORS[]= + { + { Vector3( 0.f, 240.f, 255.f )/255.f, Vector2( 0.2f, 1.f ), 22 }, // 00f0ff, opacity 20%~100% + { Vector3( 89.f, 151.f, 239.f )/255.f, Vector2( 0.2f, 0.5f ), 12 }, // 5997ef, opacity 20%~50% + { Vector3( 181.f, 181.f, 207.f )/255.f, Vector2( 0.5f, 1.f ), 22 }, // b5b5cf, opacity 50%~100% + { Vector3( 147.f, 147.f, 170.f )/255.f, Vector2( 0.5f, 0.5f ), 22 }, // 9393aa, opacity 50%~50% + { Vector3( 145.f, 145.f, 201.f )/255.f, Vector2( 1.f, 1.f ), 12 }, // 91bdc9, opacity 100%~100% + { Vector3( 145.f, 145.f, 201.f )/255.f, Vector2( 0.2f, 0.2f ), 21 } // 91bdc9, opacity 20%~20% + }; + const unsigned int NUM_COLOR( sizeof( PARTICLE_COLORS ) / sizeof( PARTICLE_COLORS[0] ) ); + + /***************particle moving paths********************/ + + typedef int MovingPath[12]; + + // these paths are defined inside the circle which has the center at (250, 250) and the radius as 250 + MovingPath PATHS[]= + { // each path is composed of two cubic b-curves: (p0, p1, p2, p3) & (p3, p4, p5, p0) + // p0 p1 p2 p3 p4 p5 + { 280,273, 386,41, 489,141, 491,199, 494,256, 230,394 }, + { 129,226, 357,120, 150,491, 291,406, 433,320, 47,283 }, + { 96,264, 356,133, 446,196, 370,297, 294,399, -169,384 }, + { 345,110, 359,186, 14,393, 4,247, -6,101, 321,-28 }, + { 166,161, 128,353, 566,200, 487,304, 413,403, 203,-32 }, + { 193,286, 106,331, 206,569, 334,477, 462,385, 279,240 }, + { 336,247, 293,232, 301,465, 346,479, 390,493, 374,261 }, + { 250,72, 314,72, 332,495, 250,497, 168,499, 161,72 }, + { 48,387, 32,241, 452,558, 433,358, 411,121, 62,523 }, + { 300,32, 159,27, 442,568, 186,492, -70,415, 551,41 }, + { 479,150, 503,203, 216,403, 163,298, 110,193, 448,78 }, + { 346,75, 311,97, 336,196, 389,160, 442,123, 383,51 }, + { 90,61, 54,96, 218,373, 294,300, 370,227, 141,11 }, + { 126,225, 240,280, 378,29, 221,16, 64,4, 11,170 }, + { 308,101, 243,22, -10,271, 22,352, 49,422, 396,208 }, + { 193,188, 174,302, 502,389, 500,250, 498,111, 212,72 }, + { 227,3, 16,35, 577,309, 428,423, 279,537, 438,-28 }, + { 410,58, 387,18, 22,179, 154,277, 286,374, 459,142 }, + { 178,272, 109,299, 144,429, 218,396, 293,362, 221,254 }, + { 247,46, 98,5, -91,357, 160,431, 412,505, 397,88 }, + { 41,112, 22,144, 123,273, 158,187, 192,101, 75,56 }, + { 8,300, 23,340, 267,294, 238,218, 209,142, -20,226 }, + { 112,256, 24,270, -1,470, 154,433, 308,396, 201,242 }, + { 212,277, 267,346, 509,202, 452,103, 398,8, 150,199 }, + { 154,205, 146,287, 496,282, 492,194, 488,107, 160,140 }, + { 281,350, 365,318, 415,476, 332,482, 248,489, 204,379 }, + { 327,23, 346,81, 154,319, 123,207, 92,95, 313,-21 }, + { 323,233, 283,307, 454,420, 478,354, 501,288, 374,136 }, + { 318,186, 311,252, 488,248, 481,168, 474,87, 328,76 }, + { 7,192, -10,270, 249,398, 269,307, 290,216, 25,111 }, + { 148,22, 98,22, 25,458, 125,458, 225,458, 198,22 }, + { 349,32, 307,39, 492,416, 399,446, 305,477, 460,16 }, + { 147,474, 222,554, 392,154, 486,240, 581,325, 73,394 }, + { 57,186, 13,200, 51,398, 114,374, 178,349, 97,174 }, + { 257,192, 198,188, 162,345, 240,349, 319,354, 316,197 }, + { 242,4, 283,21, 30,172, 81,215, 133,257, 209,-10 }, + { 149,408, 165,442, 472,340, 444,275, 416,210, 120,348 }, + { 106,271, 136,359, 483,370, 422,186, 360,2, 76,186 }, + { 120,146, 29,224, 469,262, 346,390, 222,518, 393,-87 }, + { 318,265, 415,280, 398,537, 247,491, 96,446, 222,249 }, + { 171,275, 207,246, 274,469, 237,497, 199,525, 139,300 }, + { 196,84, 135,105, 256,510, 334,486, 412,462, 280,55 }, + { 485,314, 452,170, 158,606, 111,411, 55,179, 515,446 }, + { 134,54, 266,4, 175,607, 392,451, 609,296, -100,144 }, + { 3,229, -1,287, 334,383, 350,267, 366,150, 10,151 }, + { 105,115, 146,125, 154,227, 92,209, 30,192, 62,105 }, + { 343,20, 388,42, 323,357, 228,313, 132,269, 278,-10 }, + { 362,186, 271,274, 60,82, 204,19, 349,-44, 453,97 }, + { 145,128, 181,32, 501,185, 498,272, 495,347, 97,257 }, + { 286,172, 342,274, 59,463, 16,331, -27,198, 231,69 }, + { 194,7, 404,-32, -38,410, 140,469, 317,528, -16,45 }, + { 39,120, 48,74, 445,109, 352,244, 259,379, 20,215 }, + { 328,247, 402,250, 411,384, 330,377, 248,370, 281,244 }, + { 189,56, 317,-31, 610,240, 396,392, 183,543, 61,144 }, + { 402,53, 430,77, 376,231, 315,161, 255,91, 351,10 }, + { 496,218, 494,260, 249,296, 251,214, 254,133, 498,139 }, + { 381,210, 469,195, 557,376, 399,391, 241,407, 292,226 }, + { 297,263, 267,346, -8,289, 14,176, 35,69, 331,168 }, + { 329,187, 363,263, 30,371, 5,287, -19,203, 302,128 }, + { 257,354, 168,351, 171,516, 252,496, 333,475, 340,356 }, + { 106,60, 107,121, 366,284, 359,168, 352,52, 105,14 }, + { 178,257, 240,314, 115,476, 71,421, 28,367, 98,182 }, + { 163,213, 191,273, 22,327, 3,248, -17,170, 118,113 }, + { 459,117, 500,185, 297,390, 248,311, 199,232, 416,46 }, + { 270,3, 317,-14, 528,375, 434,407, 339,440, 223,19 }, + { 88,76, 130,68, 78,485, 176,483, 274,482, -22,96 }, + { 422,428, 378,528, 88,205, 26,317, -36,428, 467,328 }, + { 414,127, 460,125, 489,325, 421,322, 353,320, 372,128 }, + { 227,197, 281,174, 367,311, 294,340, 221,370, 173,220 }, + { 180,14, 147,44, 436,104, 401,161, 366,219, 207,-10 }, + { 400,367, 395,404, 71,406, 77,336, 82,265, 407,300 }, + { 396,222, 396,316, 71,439, 70,245, 68,51, 396,132 }, + { 342,109, 454,153, 49,332, 208,413, 367,494, 8,-23 }, + { 147,167, 222,137, 266,169, 231,199, 197,229, 129,178 }, + { 227,272, 310,243, 277,313, 322,266, 367,219, 207,313 }, + { 279,192, 339,233, 396,211, 367,182, 338,152, 228,194 }, + { 236,20, 283,75, 346,26, 338,71, 330,116, 207,17 }, + { 129,83, 164,23, 158,14, 179,11, 200,8, 91,78 }, + { 86,231, 129,293, 164,421, 104,348, 44,275, 66,200 }, + { 193,328, 197,278, 240,348, 276,305, 311,263, 199,354 }, + { 231,364, 241,209, 309,104, 326,236, 342,367, 225,424 }, + { 414,230, 398,328, 446,445, 467,363, 489,281, 373,254 }, + { 289,122, 332,123, 348,161, 322,158, 297,156, 275,125 }, + { 142,235, 199,308, 402,229, 283,218, 164,206, 130,206 }, + { 174,396, 210,387, 328,501, 246,455, 165,409, 138,394 }, + { 288,388, 366,357, 372,458, 393,400, 414,343, 249,431 }, + { 351,278, 409,369, 497,316, 437,288, 376,260, 351,243 }, + { 87,134, 181,77, 311,121, 206,140, 101,160, 61,159 }, + { 95,195, 126,208, 133,258, 110,236, 88,215, 95,195 }, + { 140,293, 158,330, 169,275, 184,299, 198,323, 126,313 }, + { 336,319, 383,357, 388,278, 393,333, 397,388, 311,325 }, + { 338,107, 434,209, -37,469, 151,287, 338,104, 285,50 }, + { 403,134, 446,182, 378,318, 386,233, 393,149, 360,98 }, + { 366,82, 413,93, 416,158, 390,118, 364,78, 336,75 }, + { 448,188, 448,230, 465,269, 470,225, 474,181, 448,177 }, + { 121,398, 142,418, 126,475, 111,436, 96,396, 100,382 }, + { 40,296, 90,352, 170,310, 143,350, 116,391, 7,300 }, + { 25,203, 45,241, 70,204, 45,248, 19,293, 4,204 }, + { 243,222, 225,275, 345,256, 296,237, 247,218, 249,199 }, + { 159,149, 282,133, 284,199, 226,191, 169,184, 147,160 }, + { 149,257, 290,322, 151,374, 166,338, 182,302, 116,263 }, + { 255,285, 354,327, 234,287, 279,327, 323,367, 193,290 }, + { 188,220, 353,190, 290,354, 348,293, 407,231, 152,248 }, + { 305,122, 382,174, 402,229, 366,198, 329,167, 297,127 }, + { 378,260, 406,267, 390,330, 384,293, 377,257, 366,263 }, + { 178,396, 357,365, 273,461, 248,431, 223,401, 157,412 }, + { 180,89, 258,88, 302,94, 255,115, 207,136, 166,96 }, + { 81,197, 139,232, 39,257, 94,259, 150,261, 58,200 }, + { 314,89, 378,40, 383,38, 389,42, 395,45, 267,90 }, + { 371,141, 482,233, 508,244, 498,272, 488,299, 307,157 }, + { 339,348, 361,465, 382,477, 406,442, 430,406, 269,369 } + }; + const unsigned int NUM_PARTICLE( sizeof( PATHS ) / sizeof( PATHS[0] ) ); + + const float PARTICLE_SIZE = 13.f; + + const float ACTOR_SCALE = 0.704f; // resize 500*500 to 352*352, a bit smaller than 360*360 + const Vector3 ACTOR_POSITION( -176.f, -176.f, 1.f); + + const int MAXIMUM_ANIMATION_COUNT = 30; + + // Geometry format used by the SparkeEffect + struct Vertex + { + Vertex( const Vector2& texCoord, + const Vector2& aParticlePath0, + const Vector2& aParticlePath1, + const Vector2& aParticlePath2, + const Vector2& aParticlePath3, + const Vector2& aParticlePath4, + const Vector2& aParticlePath5 ) + : aTexCoord( texCoord ), + aParticlePath0( aParticlePath0 ), + aParticlePath1( aParticlePath1 ), + aParticlePath2( aParticlePath2 ), + aParticlePath3( aParticlePath3 ), + aParticlePath4( aParticlePath4 ), + aParticlePath5( aParticlePath5 ) + { + } + + Vector2 aTexCoord; + Vector2 aParticlePath0; + Vector2 aParticlePath1; + Vector2 aParticlePath2; + Vector2 aParticlePath3; + Vector2 aParticlePath4; + Vector2 aParticlePath5; + }; + + /** + * Create a SparkleEffect object. + * @return A handle to a newly allocated SparkleEffect + */ + Shader New() + { + std::string vertexShader = DALI_COMPOSE_SHADER( + precision highp float;\n + \n + attribute vec2 aTexCoord;\n + uniform mat4 uMvpMatrix;\n + varying vec2 vTexCoord;\n + \n + attribute vec2 aParticlePath0;\n + attribute vec2 aParticlePath1;\n + attribute vec2 aParticlePath2;\n + attribute vec2 aParticlePath3;\n + attribute vec2 aParticlePath4;\n + attribute vec2 aParticlePath5;\n + \n + uniform float uPercentage;\n + uniform float uPercentageMarked;\n + uniform vec3 uParticleColors[NUM_COLOR];\n + uniform float uOpacity[NUM_PARTICLE];\n + uniform vec2 uTapIndices; + uniform float uTapOffset[MAXIMUM_ANIMATION_COUNT];\n + uniform vec2 uTapPoint[MAXIMUM_ANIMATION_COUNT];\n + uniform float uAcceleration;\n + uniform float uRadius;\n + uniform float uScale;\n + uniform float uBreak;\n + \n + varying lowp vec4 vColor;\n + \n + void main()\n + {\n + // we store the particle index inside texCoord attribute + float idx = abs(aTexCoord.y)-1.0;\n + \n + // early out if the particle is invisible + if(uOpacity[int(idx)]<1e-5)\n + {\n + gl_Position = vec4(0.0);\n + vColor = vec4(0.0);\n + return;\n + }\n + \n + // As the movement along the b-curve has nonuniform speed with a uniform increasing parameter 'uPercentage' + // we give different particles the different 'percentage' to make them looks more random + float increment = idx / float(NUM_PARTICLE)*5.0; + float percentage = mod(uPercentage +uAcceleration+increment, 1.0); + \n + vec2 p0; vec2 p1; vec2 p2; vec2 p3; + // calculate the particle position by using the cubic b-curve equation + if(percentage<0.5)\n // particle on the first b-curve + {\n + p0 = aParticlePath0;\n + p1 = aParticlePath1;\n + p2 = aParticlePath2;\n + p3 = aParticlePath3;\n + }\n + else\n + {\n + p0 = aParticlePath3;\n + p1 = aParticlePath4;\n + p2 = aParticlePath5;\n + p3 = aParticlePath0;\n + }\n + float t = mod( percentage*2.0, 1.0);\n + vec2 position = (1.0-t)*(1.0-t)*(1.0-t)*p0 + 3.0*(1.0-t)*(1.0-t)*t*p1+3.0*(1.0-t)*t*t*p2 + t*t*t*p3;\n + \n + vec2 referencePoint = mix(p0,p3,0.5);\n + float maxAnimationCount = float(MAXIMUM_ANIMATION_COUNT);\n + \n + for( float i=uTapIndices.x; i @@ -62,12 +62,13 @@ extern "C" #define DALI_DEMO_STR_TITLE_NEGOTIATE_SIZE dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_NEGOTIATE_SIZE") #define DALI_DEMO_STR_TITLE_PAGE_TURN_VIEW dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_PAGE_TURN_VIEW") #define DALI_DEMO_STR_TITLE_POPUP dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_POPUP") +#define DALI_DEMO_STR_TITLE_PROGRESS_BAR dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_PROGRESS_BAR") #define DALI_DEMO_STR_TITLE_PRIMITIVE_SHAPES dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_PRIMITIVE_SHAPES") -#define DALI_DEMO_STR_TITLE_RADIAL_MENU dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_RADIAL_MENU") #define DALI_DEMO_STR_TITLE_REFRACTION dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_REFRACTION") #define DALI_DEMO_STR_TITLE_RENDERER_STENCIL dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_RENDERER_STENCIL") #define DALI_DEMO_STR_TITLE_SCRIPT_BASED_UI dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_SCRIPT_BASED_UI") #define DALI_DEMO_STR_TITLE_SCROLL_VIEW dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_SCROLL_VIEW") +#define DALI_DEMO_STR_TITLE_SPARKLE dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_SPARKLE") #define DALI_DEMO_STR_TITLE_STYLING dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_STYLING") #define DALI_DEMO_STR_TITLE_SUPER_BLUR_BLOOM dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_SUPER_BLUR_BLOOM") #define DALI_DEMO_STR_TITLE_TEXTURED_MESH dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_TEXTURED_MESH") @@ -111,11 +112,11 @@ extern "C" #define DALI_DEMO_STR_TITLE_PAGE_TURN_VIEW "Page Turn View" #define DALI_DEMO_STR_TITLE_POPUP "Popup" #define DALI_DEMO_STR_TITLE_PRIMITIVE_SHAPES "Primitive Shapes" -#define DALI_DEMO_STR_TITLE_RADIAL_MENU "Radial Menu" #define DALI_DEMO_STR_TITLE_REFRACTION "Refract Effect" #define DALI_DEMO_STR_TITLE_RENDERER_STENCIL "Renderer Stencils" #define DALI_DEMO_STR_TITLE_SCRIPT_BASED_UI "Script Based UI" #define DALI_DEMO_STR_TITLE_SCROLL_VIEW "Scroll View" +#define DALI_DEMO_STR_TITLE_SPARKLE "Sparkle" #define DALI_DEMO_STR_TITLE_STYLING "Styling" #define DALI_DEMO_STR_TITLE_SUPER_BLUR_BLOOM "Super Blur and Bloom" #define DALI_DEMO_STR_TITLE_TEXTURED_MESH "Mesh Texture" @@ -125,6 +126,7 @@ extern "C" #define DALI_DEMO_STR_TITLE_TEXT_LABEL_MULTI_LANGUAGE "Text Scripts" #define DALI_DEMO_STR_TITLE_TEXT_SCROLLING "Text Scrolling" #define DALI_DEMO_STR_TITLE_TILT_SENSOR "Tilt Sensor" +#define DALI_DEMO_STR_TITLE_PROGRESS_BAR "Progress Bar" #endif @@ -132,4 +134,4 @@ extern "C" } #endif // __cplusplus -#endif // __DALI_DEMO_STRINGS_H__ +#endif // DALI_DEMO_STRINGS_H