X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=examples%2Fshadows-and-lights%2Fshadows-and-lights-example.cpp;h=157dcbc65176f23460d8901b8b8cd5a57ad081c7;hb=3818d79b8ecc810cca0300c83c49de0363582849;hp=4ae587760ab13264af30b06c1ea569abc687e10f;hpb=f95b1257053b875ed48d271889fb718f0b86805f;p=platform%2Fcore%2Fuifw%2Fdali-demo.git diff --git a/examples/shadows-and-lights/shadows-and-lights-example.cpp b/examples/shadows-and-lights/shadows-and-lights-example.cpp old mode 100644 new mode 100755 index 4ae5877..157dcbc --- a/examples/shadows-and-lights/shadows-and-lights-example.cpp +++ b/examples/shadows-and-lights/shadows-and-lights-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. @@ -56,7 +56,7 @@ const Vector3 LEFT_POINT( -R3_2, 0.5f, 0.0f); const Vector3 RIGHT_POINT( R3_2, 0.5f, 0.0f); const Vector3 FRONT_POINT( 0.0f, 0.0f, 20.0f); -const Vector2 DEFAULT_STAGE_SIZE( 480.0f, 800.0f ); +const Vector2 DEFAULT_WINDOW_SIZE( 480.0f, 800.0f ); const float X_ROTATION_DISPLACEMENT_FACTOR = 60.f; const float Y_ROTATION_DISPLACEMENT_FACTOR = 60.f; @@ -80,8 +80,24 @@ public: */ TestApp(Application &app) : mApp(app), - mPaused(false), - mTranslation(22.0f, -1.0f, 0.0f), + mView(), + mContents(), + mSceneActor(), + mAnimation(), + mSceneAnimation(), + mPaused( false ), + mShadowView(), + mShadowPlaneBg(), + mShadowPlane(), + mCastingLight(), + mLightAnchor(), + mImageActor1(), + mImageActor2(), + mImageActor3(), + mPanGestureDetector(), + mPinchGestureDetector(), + mTapGestureDetector(), + mTranslation( 22.0f, -1.0f, 0.0f ), mSceneXRotation( Degree(-6.0f) ), // Initial values give a reasonable off-straight view. mSceneYRotation( Degree(20.0f) ), mLightXRotation( Degree(-1.5f) ), @@ -90,7 +106,10 @@ public: mObjectYRotation(0.0f), mPinchScale(0.6f), mScaleAtPinchStart(0.6f), - mPanState(PAN_LIGHT) + mAngle1Index( Property::INVALID_INDEX ), + mAngle3Index( Property::INVALID_INDEX ), + mTitleActor(), + mPanState( PAN_LIGHT ) { app.InitSignal().Connect(this, &TestApp::Create); app.TerminateSignal().Connect(this, &TestApp::Terminate); @@ -126,7 +145,7 @@ public: { srand(0); // Want repeatable path - Stage::GetCurrent().KeyEventSignal().Connect(this, &TestApp::OnKeyEvent); + app.GetWindow().KeyEventSignal().Connect(this, &TestApp::OnKeyEvent); CreateToolbarAndView(app); CreateShadowViewAndLights(); @@ -136,7 +155,7 @@ public: void CreateToolbarAndView(Application& app) { // 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; mContents = DemoHelper::CreateView( app, mView, @@ -147,32 +166,32 @@ public: // Add an effect-changing button on the right of the tool bar. Toolkit::PushButton effectChangeButton = Toolkit::PushButton::New(); - effectChangeButton.SetUnselectedImage( CHANGE_EFFECT_IMAGE ); - effectChangeButton.SetSelectedImage( CHANGE_EFFECT_IMAGE_SELECTED ); + effectChangeButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, CHANGE_EFFECT_IMAGE ); + effectChangeButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, CHANGE_EFFECT_IMAGE_SELECTED ); effectChangeButton.ClickedSignal().Connect( this, &TestApp::OnEffectButtonClicked ); - toolBar.AddControl( effectChangeButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalRight, DemoHelper::DEFAULT_MODE_SWITCH_PADDING ); + toolBar.AddControl( effectChangeButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HORIZONTAL_RIGHT, DemoHelper::DEFAULT_MODE_SWITCH_PADDING ); // Add title to the tool bar. mTitleActor = DemoHelper::CreateToolBarLabel( "" ); - toolBar.AddControl( mTitleActor, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarTitlePercentage, Toolkit::Alignment::HorizontalCenter ); + toolBar.AddControl( mTitleActor, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarTitlePercentage, Toolkit::Alignment::HORIZONTAL_CENTER ); // Set Title text mTitleActor.SetProperty( TextLabel::Property::TEXT, std::string(APPLICATION_TITLE_PAN_LIGHT) ); //Add a reset button Toolkit::PushButton resetButton = Toolkit::PushButton::New(); - resetButton.SetUnselectedImage( RESET_ICON ); - resetButton.SetSelectedImage( RESET_ICON_SELECTED ); + resetButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, RESET_ICON ); + resetButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, RESET_ICON_SELECTED ); resetButton.ClickedSignal().Connect( this, &TestApp::OnResetPressed ); - toolBar.AddControl( resetButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalCenter, DemoHelper::DEFAULT_PLAY_PADDING ); + toolBar.AddControl( resetButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HORIZONTAL_CENTER, DemoHelper::DEFAULT_PLAY_PADDING ); // Setup - mView.SetPosition(Vector3(0.0f, 0.0f, 0.0f)); + mView.SetProperty( Actor::Property::POSITION, Vector3( 0.0f, 0.0f, 0.0f ) ); - mContents.SetBehavior(Layer::LAYER_3D); - mContents.SetPosition(mTranslation); - mContents.SetOrientation( CalculateWorldRotation( mSceneXRotation, mSceneYRotation ) ); - mContents.SetScale(mPinchScale, mPinchScale, mPinchScale); + mContents.SetProperty( Layer::Property::BEHAVIOR, Layer::LAYER_3D ); + mContents.SetProperty( Actor::Property::POSITION, mTranslation ); + mContents.SetProperty( Actor::Property::ORIENTATION, CalculateWorldRotation( mSceneXRotation, mSceneYRotation ) ); + mContents.SetProperty( Actor::Property::SCALE, Vector3( mPinchScale, mPinchScale, mPinchScale ) ); mPanGestureDetector = PanGestureDetector::New(); mPanGestureDetector.Attach( mView ); @@ -192,56 +211,56 @@ public: void CreateShadowViewAndLights() { mShadowView = Toolkit::ShadowView::New(); - mShadowView.SetName("Container"); - mShadowView.SetParentOrigin(ParentOrigin::CENTER); - mShadowView.SetAnchorPoint(AnchorPoint::CENTER); + mShadowView.SetProperty( Dali::Actor::Property::NAME,"Container"); + mShadowView.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER); + mShadowView.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::CENTER); mShadowView.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); mShadowView.SetPointLightFieldOfView( Math::PI / 2.0f); mContents.Add(mShadowView); mShadowPlaneBg = ImageView::New( DEMO_IMAGE_DIR "brick-wall.jpg" ); - mShadowPlaneBg.SetParentOrigin(ParentOrigin::CENTER); - mShadowPlaneBg.SetAnchorPoint(AnchorPoint::CENTER); - mShadowPlaneBg.SetName("Plane"); - mShadowPlaneBg.SetSize(1000.0f, 1000.0f); + mShadowPlaneBg.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER); + mShadowPlaneBg.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::CENTER); + mShadowPlaneBg.SetProperty( Dali::Actor::Property::NAME,"Plane"); + mShadowPlaneBg.SetProperty( Actor::Property::SIZE, Vector2(1000.0f, 1000.0f) ); mContents.Add(mShadowPlaneBg); - mShadowPlaneBg.SetPosition(Vector3(50.0f, 50.0f, -200.0f)); + mShadowPlaneBg.SetProperty( Actor::Property::POSITION, Vector3(50.0f, 50.0f, -200.0f)); mShadowView.SetShadowPlaneBackground(mShadowPlaneBg); mShadowView.Activate(); mLightAnchor = Actor::New(); - mLightAnchor.SetParentOrigin(ParentOrigin::CENTER); - mLightAnchor.SetAnchorPoint(AnchorPoint::CENTER); - mLightAnchor.SetOrientation( CalculateWorldRotation( mLightXRotation, mLightYRotation ) ); + mLightAnchor.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER); + mLightAnchor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::CENTER); + mLightAnchor.SetProperty( Actor::Property::ORIENTATION, CalculateWorldRotation( mLightXRotation, mLightYRotation ) ); // Work out a scaling factor as the initial light position was calculated for desktop - // Need to scale light position as scene actor size is based on stage size (i.e. much bigger on device) - Vector2 stageSize( Stage::GetCurrent().GetSize() ); - float scaleFactor = stageSize.x / DEFAULT_STAGE_SIZE.x; + // Need to scale light position as scene actor size is based on window size (i.e. much bigger on device) + Vector2 windowSize( mApp.GetWindow().GetSize() ); + float scaleFactor = windowSize.x / DEFAULT_WINDOW_SIZE.x; mCastingLight = Actor::New(); - mCastingLight.SetParentOrigin(ParentOrigin::CENTER); - mCastingLight.SetAnchorPoint(AnchorPoint::CENTER); - mCastingLight.SetPosition( Vector3( 0.0f, 0.0f, 800.0f ) * scaleFactor ); + mCastingLight.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER); + mCastingLight.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::CENTER); + mCastingLight.SetProperty( Actor::Property::POSITION, Vector3( 0.0f, 0.0f, 800.0f ) * scaleFactor ); TextLabel text = TextLabel::New( "Light" ); text.SetProperty( TextLabel::Property::POINT_SIZE, 20.0f ); text.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); - text.SetColor( Color::BLUE ); + text.SetProperty( Actor::Property::COLOR, Color::BLUE ); mCastingLight.Add(text); mLightAnchor.Add(mCastingLight); mShadowPlaneBg.Add(mLightAnchor); - text.SetParentOrigin(ParentOrigin::CENTER); + text.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER); mShadowView.SetPointLight(mCastingLight); } void CreateScene() { mSceneActor = Actor::New(); - mSceneActor.SetParentOrigin(ParentOrigin::CENTER); + mSceneActor.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER); // Create and add images to the scene actor: mImageActor1 = ImageView::New( SCENE_IMAGE_1 ); @@ -252,13 +271,13 @@ public: mImageActor2.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); mImageActor3.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); - mImageActor2.SetParentOrigin(ParentOrigin::CENTER); + mImageActor2.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER); - mImageActor1.SetParentOrigin(ParentOrigin::CENTER_LEFT); - mImageActor1.SetAnchorPoint(AnchorPoint::CENTER_RIGHT); + mImageActor1.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER_LEFT); + mImageActor1.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::CENTER_RIGHT); - mImageActor3.SetParentOrigin(ParentOrigin::CENTER_RIGHT); - mImageActor3.SetAnchorPoint(AnchorPoint::CENTER_LEFT); + mImageActor3.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER_RIGHT); + mImageActor3.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::CENTER_LEFT); mSceneActor.Add(mImageActor2); mImageActor2.Add(mImageActor1); @@ -284,8 +303,8 @@ public: mSceneAnimation.SetLooping(true); mSceneAnimation.Play(); - mSceneActor.SetSize(250.0f, 250.0f); - mSceneActor.SetPosition(0.0f, 0.0f, 130.0f); + mSceneActor.SetProperty( Actor::Property::SIZE, Vector2( 250.0f, 250.0f ) ); + mSceneActor.SetProperty( Actor::Property::POSITION, Vector3( 0.0f, 0.0f, 130.0f ) ); mShadowView.Add(mSceneActor); } @@ -316,44 +335,45 @@ public: void OnPan(Actor actor, const PanGesture& gesture) { - switch (gesture.state) + switch (gesture.GetState()) { case Gesture::Continuing: { + const Vector2& displacement = gesture.GetDisplacement(); switch(mPanState) { case PAN_LIGHT: { - mLightXRotation = mLightXRotation - gesture.displacement.y * LIGHT_PAN_X_DISPLACEMENT_FACTOR; // X displacement rotates around Y axis + mLightXRotation = mLightXRotation - displacement.y * LIGHT_PAN_X_DISPLACEMENT_FACTOR; // X displacement rotates around Y axis mLightXRotation = Clamp(mLightXRotation, -Dali::ANGLE_45, Dali::ANGLE_45 ); - mLightYRotation = mLightYRotation + gesture.displacement.x * LIGHT_PAN_Y_DISPLACEMENT_FACTOR; // Y displacement rotates around X axis + mLightYRotation = mLightYRotation + displacement.x * LIGHT_PAN_Y_DISPLACEMENT_FACTOR; // Y displacement rotates around X axis mLightYRotation = Clamp(mLightYRotation, -Dali::ANGLE_45, Dali::ANGLE_45 ); - mLightAnchor.SetOrientation( CalculateWorldRotation( mLightXRotation, mLightYRotation ) ); + mLightAnchor.SetProperty( Actor::Property::ORIENTATION, CalculateWorldRotation( mLightXRotation, mLightYRotation ) ); break; } case PAN_SCENE: { - mTranslation += Vector3(gesture.displacement.x, gesture.displacement.y, 0.f); - mContents.SetPosition(mTranslation); + mTranslation += Vector3(displacement.x, displacement.y, 0.f); + mContents.SetProperty( Actor::Property::POSITION, mTranslation ); break; } case ROTATE_SCENE: { - mSceneXRotation = mSceneXRotation - gesture.displacement.y / X_ROTATION_DISPLACEMENT_FACTOR; // X displacement rotates around Y axis + mSceneXRotation = mSceneXRotation - displacement.y / X_ROTATION_DISPLACEMENT_FACTOR; // X displacement rotates around Y axis mSceneXRotation = Clamp( mSceneXRotation, -Dali::ANGLE_90, Dali::ANGLE_90 ); - mSceneYRotation = mSceneYRotation + gesture.displacement.x / Y_ROTATION_DISPLACEMENT_FACTOR; // Y displacement rotates around X axis + mSceneYRotation = mSceneYRotation + displacement.x / Y_ROTATION_DISPLACEMENT_FACTOR; // Y displacement rotates around X axis mSceneYRotation = Clamp( mSceneYRotation, -Dali::ANGLE_90, Dali::ANGLE_90 ); - mContents.SetOrientation( CalculateWorldRotation( mSceneXRotation, mSceneYRotation ) ); + mContents.SetProperty( Actor::Property::ORIENTATION, CalculateWorldRotation( mSceneXRotation, mSceneYRotation ) ); break; } case ROTATE_OBJECT: { - mObjectXRotation = mObjectXRotation - gesture.displacement.y / X_ROTATION_DISPLACEMENT_FACTOR; // X displacement rotates around Y axis - mObjectYRotation = mObjectYRotation + gesture.displacement.x / Y_ROTATION_DISPLACEMENT_FACTOR; // Y displacement rotates around X axis - mSceneActor.SetOrientation( CalculateWorldRotation( mObjectXRotation, mObjectYRotation ) ); + mObjectXRotation = mObjectXRotation - displacement.y / X_ROTATION_DISPLACEMENT_FACTOR; // X displacement rotates around Y axis + mObjectYRotation = mObjectYRotation + displacement.x / Y_ROTATION_DISPLACEMENT_FACTOR; // Y displacement rotates around X axis + mSceneActor.SetProperty( Actor::Property::ORIENTATION, CalculateWorldRotation( mObjectXRotation, mObjectYRotation ) ); break; } } @@ -371,30 +391,30 @@ public: void OnPinch(Actor actor, const PinchGesture& gesture) { - if (gesture.state == Gesture::Started) + if (gesture.GetState() == Gesture::Started) { - mScaleAtPinchStart = mContents.GetCurrentScale().x; + mScaleAtPinchStart = mContents.GetCurrentProperty< Vector3 >( Actor::Property::SCALE ).x; } - mPinchScale = Clamp(mScaleAtPinchStart * gesture.scale, MIN_PINCH_SCALE, MAX_PINCH_SCALE); + mPinchScale = Clamp(mScaleAtPinchStart * gesture.GetScale(), MIN_PINCH_SCALE, MAX_PINCH_SCALE); - mContents.SetScale(mPinchScale, mPinchScale, mPinchScale); + mContents.SetProperty( Actor::Property::SCALE, Vector3( mPinchScale, mPinchScale, mPinchScale ) ); } void Terminate(Application& app) { if( mSceneActor ) { - Stage::GetCurrent().Remove(mSceneActor); + mApp.GetWindow().Remove(mSceneActor); } if( mView ) { - Stage::GetCurrent().Remove(mView); + mApp.GetWindow().Remove(mView); } } void OnKeyEvent(const KeyEvent& event) { - if(event.state == KeyEvent::Down) + if(event.GetState() == KeyEvent::DOWN) { if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) ) { @@ -434,12 +454,12 @@ public: { // Reset translation mTranslation = Vector3::ZERO; - mContents.SetPosition(mTranslation); + mContents.SetProperty( Actor::Property::POSITION, mTranslation ); // Align scene so that light anchor orientation is Z Axis mSceneXRotation = -mLightXRotation; mSceneYRotation = -mLightYRotation; - mContents.SetOrientation( CalculateWorldRotation( mSceneXRotation, mSceneYRotation ) ); + mContents.SetProperty( Actor::Property::ORIENTATION, CalculateWorldRotation( mSceneXRotation, mSceneYRotation ) ); return true; } @@ -491,20 +511,10 @@ private: /*****************************************************************************/ -static void -RunTest(Application& app) -{ - TestApp theApp(app); - app.MainLoop(); -} - -/*****************************************************************************/ - int DALI_EXPORT_API main(int argc, char **argv) { Application app = Application::New(&argc, &argv, DEMO_THEME_PATH); - - RunTest(app); - + TestApp theApp(app); + app.MainLoop(); return 0; }