X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fcontrols%2Fscrollable%2Fbouncing-effect-actor.cpp;h=2d61cfaaee2419143813755385e9c7b9fde21f21;hb=8ce82d79da52fcd0ca29ce20b85ba625da067fcf;hp=5ea57534cd053e87cad855bf3509cb0eadfe3ae8;hpb=d04c5bdbb95cc98f90848c7a98b0b2804df6e5b8;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git diff --git a/dali-toolkit/internal/controls/scrollable/bouncing-effect-actor.cpp b/dali-toolkit/internal/controls/scrollable/bouncing-effect-actor.cpp index 5ea5753..2d61cfa 100644 --- a/dali-toolkit/internal/controls/scrollable/bouncing-effect-actor.cpp +++ b/dali-toolkit/internal/controls/scrollable/bouncing-effect-actor.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Copyright (c) 2021 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,100 +19,94 @@ #include // EXTERNAL INCLUDES -#include -#include -#include -#include -#include #include +#include +#include +#include +#include +#include + +// INTERNAL INCLUDES +#include namespace Dali { - namespace Toolkit { - namespace Internal { - namespace { // Bouncing effect is presented by stacked three layers with same color and opacity -const size_t NUM_LAYERS( 3 ); -const Vector3 LAYER_HEIGHTS( 1.f, 27.f/42.f, 13.f/42.f); - -// use the actor color to paint every layer -const char* MESH_FRAGMENT_SHADER = -"void main()\n" -"{\n" -" gl_FragColor = uColor;\n" -"}\n"; - -// Constraint to move the vertices vertically -struct VertexPositionConstraint -{ - VertexPositionConstraint( float initialY, float range ) - : mInitialY( initialY ), - mRange( range ) - { - } - - void operator()( Vector3& current, const PropertyInputContainer& inputs ) +const float LAYER_HEIGHTS[5] = { - current.y = mInitialY + mRange * fabsf( inputs[0]->GetFloat() ); - } - - float mInitialY; - float mRange; -}; + 1.f, + 26.f * 4.f / 130.f, + 26.f * 3.f / 130.f, + 26.f * 2.f / 130.f, + 26.f / 130.f}; -} // namespace Anon +} // namespace -Actor CreateBouncingEffectActor( Property::Index& bouncePropertyIndex ) +Actor CreateBouncingEffectActor(Property::Index& bouncePropertyIndex) { - Dali::AnimatableMesh mesh; - Dali::MeshActor meshActor; - - Dali::AnimatableMesh::Faces faces; - faces.reserve( NUM_LAYERS * 6 ); // 2 triangles per layer - for( size_t i=0; i( i ); // the interval between each layer is 0.01 - mesh[j ].SetPosition( Vector3( -0.5f, -0.5f, positionZ ) ); - mesh[j+1].SetPosition( Vector3( 0.5f, -0.5f, positionZ ) ); - mesh[j+2].SetPosition( Vector3( -0.5f, -0.5f, positionZ ) ); - mesh[j+3].SetPosition( Vector3( 0.5f, -0.5f, positionZ ) ); - } - - meshActor = Dali::MeshActor::New(mesh); - - Dali::ShaderEffect shaderEffect = Dali::ShaderEffect::New( "", MESH_FRAGMENT_SHADER, - GEOMETRY_TYPE_UNTEXTURED_MESH, - Dali::ShaderEffect::HINT_BLENDING ); - meshActor.SetShaderEffect(shaderEffect); - - // To control the movement of all vertices with one custom property - bouncePropertyIndex = meshActor.RegisterProperty("BounceCoeffcient", 0.f); - for( size_t i=0;i( mesh, mesh.GetPropertyIndex(j+2, AnimatableVertex::Property::POSITION ), VertexPositionConstraint(-0.5f, LAYER_HEIGHTS[i]) ); - constraint.AddSource( Source(meshActor, bouncePropertyIndex) ); - constraint.Apply(); - - constraint = Constraint::New( mesh, mesh.GetPropertyIndex(j+3, AnimatableVertex::Property::POSITION), VertexPositionConstraint(-0.5f, LAYER_HEIGHTS[i]) ); - constraint.AddSource( Source(meshActor, bouncePropertyIndex) ); - constraint.Apply(); - } + Vector3 position1; + Vector3 position2; + }; + // 4 vertices 2 triangles per layer. The depth interval between each layer is 0.01 + VertexPosition vertexData[20] = { + // bottom layer + {Vector3(-0.5f, -0.5f, 0.f), Vector3(-0.5f, -0.5f, 0.f)}, + {Vector3(0.5f, -0.5f, 0.f), Vector3(0.5f, -0.5f, 0.f)}, + {Vector3(-0.5f, -0.5f, 0.f), Vector3(-0.5f, -0.5f + LAYER_HEIGHTS[0], 0.f)}, + {Vector3(0.5f, -0.5f, 0.f), Vector3(0.5f, -0.5f + LAYER_HEIGHTS[0], 0.f)}, + // mid-bottom layer + {Vector3(-0.5f, -0.5f, 0.01f), Vector3(-0.5f, -0.5f, 0.01f)}, + {Vector3(0.5f, -0.5f, 0.01f), Vector3(0.5f, -0.5f, 0.01f)}, + {Vector3(-0.5f, -0.5f, 0.01f), Vector3(-0.5f, -0.5f + LAYER_HEIGHTS[1], 0.01f)}, + {Vector3(0.5f, -0.5f, 0.01f), Vector3(0.5f, -0.5f + LAYER_HEIGHTS[1], 0.01f)}, + // middle layer + {Vector3(-0.5f, -0.5f, 0.02f), Vector3(-0.5f, -0.5f, 0.02f)}, + {Vector3(0.5f, -0.5f, 0.02f), Vector3(0.5f, -0.5f, 0.02f)}, + {Vector3(-0.5f, -0.5f, 0.02f), Vector3(-0.5f, -0.5f + LAYER_HEIGHTS[2], 0.02f)}, + {Vector3(0.5f, -0.5f, 0.02f), Vector3(0.5f, -0.5f + LAYER_HEIGHTS[2], 0.02f)}, + // mid-top layer + {Vector3(-0.5f, -0.5f, 0.03f), Vector3(-0.5f, -0.5f, 0.03f)}, + {Vector3(0.5f, -0.5f, 0.03f), Vector3(0.5f, -0.5f, 0.03f)}, + {Vector3(-0.5f, -0.5f, 0.03f), Vector3(-0.5f, -0.5f + LAYER_HEIGHTS[3], 0.03f)}, + {Vector3(0.5f, -0.5f, 0.03f), Vector3(0.5f, -0.5f + LAYER_HEIGHTS[3], 0.03f)}, + // top layer + {Vector3(-0.5f, -0.5f, 0.04f), Vector3(-0.5f, -0.5f, 0.04f)}, + {Vector3(0.5f, -0.5f, 0.04f), Vector3(0.5f, -0.5f, 0.04f)}, + {Vector3(-0.5f, -0.5f, 0.04f), Vector3(-0.5f, -0.5f + LAYER_HEIGHTS[4], 0.04f)}, + {Vector3(0.5f, -0.5f, 0.04f), Vector3(0.5f, -0.5f + LAYER_HEIGHTS[4], 0.04f)}}; + Property::Map vertexFormat; + vertexFormat["aPosition1"] = Property::VECTOR3; + vertexFormat["aPosition2"] = Property::VECTOR3; + VertexBuffer vertices = VertexBuffer::New(vertexFormat); + vertices.SetData(vertexData, 20u); + + unsigned short indexData[30] = {0, 3, 1, 0, 2, 3, 4, 7, 5, 4, 6, 7, 8, 11, 9, 8, 10, 11, 12, 15, 13, 12, 14, 15, 16, 19, 17, 16, 18, 19}; + + Geometry meshGeometry = Geometry::New(); + meshGeometry.AddVertexBuffer(vertices); + meshGeometry.SetIndexBuffer(indexData, sizeof(indexData) / sizeof(indexData[0])); + + // Create the shader + Shader shader = Shader::New(SHADER_BOUNCING_EFFECT_MESH_SHADER_VERT, SHADER_BOUNCING_EFFECT_MESH_SHADER_FRAG); + + // Create renderer + Renderer renderer = Renderer::New(meshGeometry, shader); + + // Create actor + Actor meshActor = Actor::New(); + meshActor.AddRenderer(renderer); + + // Register property + bouncePropertyIndex = meshActor.RegisterProperty("uBounceCoefficient", 0.f); return meshActor; }