X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=examples%2Fanimated-shapes%2Fanimated-shapes-example.cpp;h=7e865ce88c51ba27057dd54c0441a92f67d562de;hb=9d9a22fa08afb1572f4f66a02800c363df5ea219;hp=b4b8a390f870da6c034698445958e2f5f02fe2b9;hpb=c5e5d3a8637bdb9f31bced4558943d2965fdd37c;p=platform%2Fcore%2Fuifw%2Fdali-demo.git diff --git a/examples/animated-shapes/animated-shapes-example.cpp b/examples/animated-shapes/animated-shapes-example.cpp index b4b8a39..7e865ce 100644 --- a/examples/animated-shapes/animated-shapes-example.cpp +++ b/examples/animated-shapes/animated-shapes-example.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 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. @@ -91,28 +91,24 @@ public: AnimatedShapesExample( Application& application ) : mApplication( application ) { - // Connect to the Application's Init signal - mApplication.InitSignal().Connect( this, &AnimatedShapesExample::Create ); + // Connect to the Application's Init signal + mApplication.InitSignal().Connect( this, &AnimatedShapesExample::Create ); } - ~AnimatedShapesExample() - { - // Nothing to do here; - } + ~AnimatedShapesExample() = default; // The Init signal is received once (only) during the Application lifetime void Create( Application& application ) { - // Hide the indicator bar - application.GetWindow().ShowIndicator( Dali::Window::INVISIBLE ); - - Stage stage = Stage::GetCurrent(); + Window window = application.GetWindow(); + const Vector2 windowSize = window.GetSize(); // Creates the background gradient Toolkit::Control background = Dali::Toolkit::Control::New(); - background.SetAnchorPoint( Dali::AnchorPoint::CENTER ); - background.SetParentOrigin( Dali::ParentOrigin::CENTER ); + background[Actor::Property::ANCHOR_POINT] = Dali::AnchorPoint::CENTER; + background[Actor::Property::PARENT_ORIGIN] = Dali::ParentOrigin::CENTER; background.SetResizePolicy( Dali::ResizePolicy::FILL_TO_PARENT, Dali::Dimension::ALL_DIMENSIONS ); + Dali::Property::Map map; map.Insert( Toolkit::Visual::Property::TYPE, Visual::GRADIENT ); Property::Array stopOffsets; @@ -123,27 +119,27 @@ public: stopColors.PushBack( Vector4( 0.0f,0.0f,1.0f,1.0f ) ); stopColors.PushBack( Vector4( 1.0f,1.0f,1.0f,1.0f ) ); map.Insert( GradientVisual::Property::STOP_COLOR, stopColors ); - Vector2 halfStageSize = Stage::GetCurrent().GetSize()*0.5f; - map.Insert( GradientVisual::Property::START_POSITION, Vector2(0.0f,-halfStageSize.y) ); - map.Insert( GradientVisual::Property::END_POSITION, Vector2(0.0f,halfStageSize.y) ); + Vector2 halfWindowSize = windowSize * 0.5f; + map.Insert( GradientVisual::Property::START_POSITION, Vector2(0.0f,-halfWindowSize.y) ); + map.Insert( GradientVisual::Property::END_POSITION, Vector2(0.0f,halfWindowSize.y) ); map.Insert( GradientVisual::Property::UNITS, GradientVisual::Units::USER_SPACE ); - background.SetProperty( Dali::Toolkit::Control::Property::BACKGROUND, map ); - stage.Add( background ); + background[ Dali::Toolkit::Control::Property::BACKGROUND ] = map; + window.Add( background ); // Create a TextLabel for the application title. Toolkit::TextLabel label = Toolkit::TextLabel::New( APPLICATION_TITLE ); - label.SetAnchorPoint( AnchorPoint::TOP_CENTER ); - label.SetParentOrigin( Vector3( 0.5f, 0.0f, 0.5f ) ); - label.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" ); - label.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" ); - label.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) ); - stage.Add( label ); - - CreateTriangleMorph(Vector3( stage.GetSize().x*0.5f, stage.GetSize().y*0.15f, 0.0f), 100.0f ); - CreateCircleMorph( Vector3( stage.GetSize().x*0.5f, stage.GetSize().y*0.5f, 0.0f), 55.0f ); - CreateQuadMorph( Vector3( stage.GetSize().x*0.5f, stage.GetSize().y*0.85f, 0.0f), 60.0f ); - - stage.KeyEventSignal().Connect( this, &AnimatedShapesExample::OnKeyEvent ); + label[ Actor::Property::ANCHOR_POINT] = AnchorPoint::TOP_CENTER ; + label[ Actor::Property::PARENT_ORIGIN] = Vector3( 0.5f, 0.0f, 0.5f ); + label[ Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT ] = "CENTER"; + label[ Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT] = "CENTER"; + label[ Toolkit::TextLabel::Property::TEXT_COLOR ] = Color::WHITE; + window.Add( label ); + + CreateTriangleMorph(Vector3( windowSize.x*0.5f, windowSize.y*0.15f, 0.0f), 100.0f ); + CreateCircleMorph( Vector3( windowSize.x*0.5f, windowSize.y*0.5f, 0.0f), 55.0f ); + CreateQuadMorph( Vector3( windowSize.x*0.5f, windowSize.y*0.85f, 0.0f), 60.0f ); + + window.KeyEventSignal().Connect( this, &AnimatedShapesExample::OnKeyEvent ); } void CreateTriangleMorph( Vector3 center, float side ) @@ -159,21 +155,21 @@ public: Vector3 v5 = v2 + ( ( v0 - v2 ) * 0.5f ); Shader shader = CreateShader( 12 ); - shader.SetProperty( shader.GetPropertyIndex( "uPosition[0]"), v0 ); - shader.SetProperty( shader.GetPropertyIndex( "uPosition[1]"), v3 ); - shader.SetProperty( shader.GetPropertyIndex( "uPosition[2]"), v1 ); + shader[ "uPosition[0]"] = v0; + shader[ "uPosition[1]"] = v3; + shader[ "uPosition[2]"] = v1; - shader.SetProperty( shader.GetPropertyIndex( "uPosition[3]"), v1 ); - shader.SetProperty( shader.GetPropertyIndex( "uPosition[4]"), v4 ); - shader.SetProperty( shader.GetPropertyIndex( "uPosition[5]"), v2 ); + shader[ "uPosition[3]"] = v1; + shader[ "uPosition[4]"] = v4; + shader[ "uPosition[5]"] = v2; - shader.SetProperty( shader.GetPropertyIndex( "uPosition[6]"), v2 ); - shader.SetProperty( shader.GetPropertyIndex( "uPosition[7]"), v5 ); - shader.SetProperty( shader.GetPropertyIndex( "uPosition[8]"), v0 ); + shader[ "uPosition[6]"] = v2; + shader[ "uPosition[7]"] = v5; + shader[ "uPosition[8]"] = v0; - shader.SetProperty( shader.GetPropertyIndex( "uPosition[9]"), v0 ); - shader.SetProperty( shader.GetPropertyIndex( "uPosition[10]"), v1 ); - shader.SetProperty( shader.GetPropertyIndex( "uPosition[11]"), v2 ); + shader[ "uPosition[9]"] = v0; + shader[ "uPosition[10]"] = v1; + shader[ "uPosition[11]"] = v2; //Create geometry @@ -199,7 +195,7 @@ public: //Create a vertex buffer for vertex positions and texture coordinates Dali::Property::Map vertexFormat; vertexFormat["aCoefficient"] = Dali::Property::VECTOR3; - Dali::PropertyBuffer vertexBuffer = Dali::PropertyBuffer::New( vertexFormat ); + Dali::VertexBuffer vertexBuffer = Dali::VertexBuffer::New( vertexFormat ); vertexBuffer.SetData( vertexData, sizeof(vertexData)/sizeof(vertexData[0])); //Create the geometry @@ -208,17 +204,17 @@ public: geometry.SetIndexBuffer( indexData, sizeof(indexData)/sizeof(indexData[0]) ); Renderer renderer = Renderer::New( geometry, shader ); - renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::ON ); + renderer[Renderer::Property::BLEND_MODE] = BlendMode::ON; Actor actor = Actor::New(); - actor.SetSize( 400.0f, 400.0f ); - actor.SetPosition( center ); - actor.SetAnchorPoint( AnchorPoint::CENTER ); - actor.SetColor(Vector4(1.0f,1.0f,0.0f,1.0f) ); + actor[Actor::Property::SIZE ] = Vector2( 400.0f, 400.0f ); + actor[Actor::Property::POSITION ] = center; + actor[Actor::Property::ANCHOR_POINT] = AnchorPoint::CENTER; + actor[Actor::Property::COLOR] = Color::YELLOW; actor.AddRenderer( renderer ); - Stage stage = Stage::GetCurrent(); - stage.Add( actor ); + Window window = mApplication.GetWindow(); + window.Add( actor ); //Animation Animation animation = Animation::New(5.0f); @@ -246,28 +242,28 @@ public: void CreateCircleMorph( Vector3 center, float radius ) { Shader shader = CreateShader( 16 ); - shader.SetProperty( shader.GetPropertyIndex("uPosition[0]"), Vector3( -radius, -radius, 0.0f ) ); - shader.SetProperty( shader.GetPropertyIndex("uPosition[1]"), Vector3( 0.0f, -radius, 0.0f ) ); - shader.SetProperty( shader.GetPropertyIndex("uPosition[2]"), Vector3( radius, -radius, 0.0f ) ); + shader["uPosition[0]"] = Vector3( -radius, -radius, 0.0f ); + shader["uPosition[1]"] = Vector3( 0.0f, -radius, 0.0f ); + shader["uPosition[2]"] = Vector3( radius, -radius, 0.0f ); - shader.SetProperty( shader.GetPropertyIndex("uPosition[3]"), Vector3( radius, -radius, 0.0f ) ); - shader.SetProperty( shader.GetPropertyIndex("uPosition[4]"), Vector3( radius, 0.0f, 0.0f ) ); - shader.SetProperty( shader.GetPropertyIndex("uPosition[5]"), Vector3( radius, radius, 0.0f ) ); + shader["uPosition[3]"] = Vector3( radius, -radius, 0.0f ); + shader["uPosition[4]"] = Vector3( radius, 0.0f, 0.0f ); + shader["uPosition[5]"] = Vector3( radius, radius, 0.0f ); - shader.SetProperty( shader.GetPropertyIndex("uPosition[6]"), Vector3( radius, radius, 0.0f ) ); - shader.SetProperty( shader.GetPropertyIndex("uPosition[7]"), Vector3( 0.0f, radius, 0.0f ) ); - shader.SetProperty( shader.GetPropertyIndex("uPosition[8]"), Vector3( -radius, radius, 0.0f ) ); + shader["uPosition[6]"] = Vector3( radius, radius, 0.0f ); + shader["uPosition[7]"] = Vector3( 0.0f, radius, 0.0f ); + shader["uPosition[8]"] = Vector3( -radius, radius, 0.0f ); - shader.SetProperty( shader.GetPropertyIndex("uPosition[9]"), Vector3( -radius, radius, 0.0f ) ); - shader.SetProperty( shader.GetPropertyIndex("uPosition[10]"), Vector3( -radius, 0.0f, 0.0f ) ); - shader.SetProperty( shader.GetPropertyIndex("uPosition[11]"), Vector3( -radius, -radius, 0.0f ) ); + shader["uPosition[9]"] = Vector3( -radius, radius, 0.0f ); + shader["uPosition[10]"] = Vector3( -radius, 0.0f, 0.0f ); + shader["uPosition[11]"] = Vector3( -radius, -radius, 0.0f ); - shader.SetProperty( shader.GetPropertyIndex("uPosition[12]"), Vector3( -radius, -radius, 0.0f ) ); - shader.SetProperty( shader.GetPropertyIndex("uPosition[13]"), Vector3( radius, -radius, 0.0f ) ); - shader.SetProperty( shader.GetPropertyIndex("uPosition[14]"), Vector3( radius, radius, 0.0f ) ); - shader.SetProperty( shader.GetPropertyIndex("uPosition[15]"), Vector3( -radius, radius, 0.0f ) ); + shader["uPosition[12]"] = Vector3( -radius, -radius, 0.0f ); + shader["uPosition[13]"] = Vector3( radius, -radius, 0.0f ); + shader["uPosition[14]"] = Vector3( radius, radius, 0.0f ); + shader["uPosition[15]"] = Vector3( -radius, radius, 0.0f ); - //shader.SetProperty( shader.GetPropertyIndex("uLineWidth"), 2.0f ); + //shader["uLineWidth"), 2.0] ; static const Vector3 vertexData[] = { Vector3( 0.0f, 0.0f, 0.0f ), Vector3( 0.5f, 0.0f, 1.0f ), @@ -291,7 +287,7 @@ public: //Create a vertex buffer for vertex positions and texture coordinates Dali::Property::Map vertexFormat; vertexFormat["aCoefficient"] = Dali::Property::VECTOR3; - Dali::PropertyBuffer vertexBuffer = Dali::PropertyBuffer::New( vertexFormat ); + Dali::VertexBuffer vertexBuffer = Dali::VertexBuffer::New( vertexFormat ); vertexBuffer.SetData( vertexData, sizeof(vertexData)/sizeof(vertexData[0])); //Create the geometry @@ -300,16 +296,16 @@ public: geometry.SetIndexBuffer( indexData, sizeof(indexData)/sizeof(indexData[0]) ); Renderer renderer = Renderer::New( geometry, shader ); - renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::ON ); + renderer[ Renderer::Property::BLEND_MODE ] = BlendMode::ON; Actor actor = Actor::New(); - actor.SetSize( 400.0f, 400.0f ); - actor.SetPosition( center ); - actor.SetAnchorPoint( AnchorPoint::CENTER ); + actor[ Actor::Property::SIZE] = Vector2( 400.0f, 400.0f ); + actor[ Actor::Property::POSITION] = center; + actor[ Actor::Property::ANCHOR_POINT] = AnchorPoint::CENTER; actor.AddRenderer( renderer ); - Stage stage = Stage::GetCurrent(); - stage.Add( actor ); + Window window = mApplication.GetWindow(); + window.Add( actor ); //Animation Animation animation = Animation::New(5.0f); @@ -345,26 +341,26 @@ public: void CreateQuadMorph( Vector3 center, float radius ) { Shader shader = CreateShader( 16 ); - shader.SetProperty( shader.GetPropertyIndex("uPosition[0]"), Vector3( -radius, -radius, 0.0f ) ); - shader.SetProperty( shader.GetPropertyIndex("uPosition[1]"), Vector3( 0.0f, -radius, 0.0f ) ); - shader.SetProperty( shader.GetPropertyIndex("uPosition[2]"), Vector3( radius, -radius, 0.0f ) ); + shader["uPosition[0]"] = Vector3( -radius, -radius, 0.0f ); + shader["uPosition[1]"] = Vector3( 0.0f, -radius, 0.0f ); + shader["uPosition[2]"] = Vector3( radius, -radius, 0.0f ); - shader.SetProperty( shader.GetPropertyIndex("uPosition[3]"), Vector3( radius, -radius, 0.0f ) ); - shader.SetProperty( shader.GetPropertyIndex("uPosition[4]"), Vector3( radius, 0.0f, 0.0f ) ); - shader.SetProperty( shader.GetPropertyIndex("uPosition[5]"), Vector3( radius, radius, 0.0f ) ); + shader["uPosition[3]"] = Vector3( radius, -radius, 0.0f ); + shader["uPosition[4]"] = Vector3( radius, 0.0f, 0.0f ); + shader["uPosition[5]"] = Vector3( radius, radius, 0.0f ); - shader.SetProperty( shader.GetPropertyIndex("uPosition[6]"), Vector3( radius, radius, 0.0f ) ); - shader.SetProperty( shader.GetPropertyIndex("uPosition[7]"), Vector3( 0.0f, radius, 0.0f ) ); - shader.SetProperty( shader.GetPropertyIndex("uPosition[8]"), Vector3( -radius, radius, 0.0f ) ); + shader["uPosition[6]"] = Vector3( radius, radius, 0.0f ); + shader["uPosition[7]"] = Vector3( 0.0f, radius, 0.0f ); + shader["uPosition[8]"] = Vector3( -radius, radius, 0.0f ); - shader.SetProperty( shader.GetPropertyIndex("uPosition[9]"), Vector3( -radius, radius, 0.0f ) ); - shader.SetProperty( shader.GetPropertyIndex("uPosition[10]"), Vector3( -radius, 0.0f, 0.0f ) ); - shader.SetProperty( shader.GetPropertyIndex("uPosition[11]"), Vector3( -radius, -radius, 0.0f ) ); + shader["uPosition[9]"] = Vector3( -radius, radius, 0.0f ); + shader["uPosition[10]"] = Vector3( -radius, 0.0f, 0.0f ); + shader["uPosition[11]"] = Vector3( -radius, -radius, 0.0f ); - shader.SetProperty( shader.GetPropertyIndex("uPosition[12]"), Vector3( -radius, -radius, 0.0f ) ); - shader.SetProperty( shader.GetPropertyIndex("uPosition[13]"), Vector3( radius, -radius, 0.0f ) ); - shader.SetProperty( shader.GetPropertyIndex("uPosition[14]"), Vector3( radius, radius, 0.0f ) ); - shader.SetProperty( shader.GetPropertyIndex("uPosition[15]"), Vector3( -radius, radius, 0.0f ) ); + shader["uPosition[12]"] = Vector3( -radius, -radius, 0.0f ); + shader["uPosition[13]"] = Vector3( radius, -radius, 0.0f ); + shader["uPosition[14]"] = Vector3( radius, radius, 0.0f ); + shader["uPosition[15]"] = Vector3( -radius, radius, 0.0f ); static const Vector3 vertexData[] = { Dali::Vector3( 0.0f, 0.0f, 0.0f ), Dali::Vector3( 0.5f, 0.0f, 1.0f ), @@ -392,7 +388,7 @@ public: //Create a vertex buffer for vertex positions and texture coordinates Dali::Property::Map vertexFormat; vertexFormat["aCoefficient"] = Dali::Property::VECTOR3; - Dali::PropertyBuffer vertexBuffer = Dali::PropertyBuffer::New( vertexFormat ); + Dali::VertexBuffer vertexBuffer = Dali::VertexBuffer::New( vertexFormat ); vertexBuffer.SetData( vertexData, sizeof(vertexData)/sizeof(vertexData[0])); //Create the geometry @@ -401,17 +397,17 @@ public: geometry.SetIndexBuffer( indexData, sizeof(indexData)/sizeof(indexData[0]) ); Renderer renderer = Renderer::New( geometry, shader ); - renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::ON ); + renderer[Renderer::Property::BLEND_MODE] = BlendMode::ON; Actor actor = Actor::New(); - actor.SetSize( 400.0f, 400.0f ); - actor.SetPosition( center ); - actor.SetAnchorPoint( AnchorPoint::CENTER ); - actor.SetColor(Vector4(1.0f,0.0f,0.0f,1.0f) ); + actor[Actor::Property::SIZE] = Vector2( 400.0f, 400.0f ); + actor[Actor::Property::POSITION] = center; + actor[Actor::Property::ANCHOR_POINT] = AnchorPoint::CENTER; + actor[Actor::Property::COLOR] = Color::RED; actor.AddRenderer( renderer ); - Stage stage = Stage::GetCurrent(); - stage.Add( actor ); + Window window = mApplication.GetWindow(); + window.Add( actor ); //Animation Animation animation = Animation::New( 5.0f );