X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fcontrols%2Fscrollable%2Fbouncing-effect-actor.cpp;h=1cfbe5aa12466cef2fb4ad01c3b5d17a10747ef4;hb=HEAD;hp=19dc7cc69ff3a1813e4dc262784c1214c55401bb;hpb=bf362e39199631c5ecc65a79cd94eacba0063994;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 19dc7cc..1cfbe5a 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) 2024 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,56 +19,36 @@ #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 Vector3 LAYER_HEIGHTS( 1.f, 27.f/42.f, 13.f/42.f); - -#define MAKE_SHADER(A)#A - -// Modify the vertex position according to the bounce coefficient; -const char* MESH_VERTEX_SHADER = MAKE_SHADER( -attribute mediump vec3 aPosition1;\n -attribute mediump vec3 aPosition2;\n -uniform mediump mat4 uMvpMatrix;\n -uniform mediump vec3 uSize; -uniform mediump float uBounceCoefficient;\n -\n -void main()\n -{\n - gl_Position = uMvpMatrix * vec4(mix( aPosition1, aPosition2, abs(uBounceCoefficient) )*uSize, 1.0);\n -} -); - -// use the actor color to paint every layer -const char* MESH_FRAGMENT_SHADER = MAKE_SHADER( -uniform lowp vec4 uColor;\n -void main()\n -{\n - gl_FragColor = uColor;\n -}\n; -); +const float LAYER_HEIGHTS[5] = + { + 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) { // Create the bouncing mesh geometry struct VertexPosition @@ -77,53 +57,56 @@ Actor CreateBouncingEffectActor( Property::Index& bouncePropertyIndex ) Vector3 position2; }; // 4 vertices 2 triangles per layer. The depth interval between each layer is 0.01 - VertexPosition vertexData[12] = { - //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 ) }, + 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.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 ) }, + {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.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 ) } - }; + {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; - PropertyBuffer vertices = PropertyBuffer::New( PropertyBuffer::STATIC, vertexFormat, 12u ); - vertices.SetData( vertexData ); + VertexBuffer vertices = VertexBuffer::New(vertexFormat); + vertices.SetData(vertexData, 20u); - unsigned int indexData[18] = { 0,3,1,0,2,3,4,7,5,4,6,7,8,11,9,8,10,11 }; - Property::Map indexFormat; - indexFormat["indices"] = Property::UNSIGNED_INTEGER; - PropertyBuffer indices = PropertyBuffer::New( PropertyBuffer::STATIC, indexFormat, 18u ); - indices.SetData( indexData ); + 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( indices ); + meshGeometry.AddVertexBuffer(vertices); + meshGeometry.SetIndexBuffer(indexData, sizeof(indexData) / sizeof(indexData[0])); - // Create material - Shader shader = Shader::New( MESH_VERTEX_SHADER, MESH_FRAGMENT_SHADER ); - Material material = Material::New( shader ); + // Create the shader + Shader shader = Shader::New(SHADER_BOUNCING_EFFECT_MESH_SHADER_VERT, SHADER_BOUNCING_EFFECT_MESH_SHADER_FRAG, Shader::Hint::NONE, "BOUNCING_EFFECT"); // Create renderer - Renderer renderer = Renderer::New( meshGeometry, material ); + Renderer renderer = Renderer::New(meshGeometry, shader); // Create actor - Actor meshActor= Actor::New(); - meshActor.AddRenderer( renderer ); + Actor meshActor = Actor::New(); + meshActor.AddRenderer(renderer); // Register property - bouncePropertyIndex = meshActor.RegisterProperty("bounce-coefficient", 0.f); - meshActor.AddUniformMapping( bouncePropertyIndex, "uBounceCoefficient" ); + bouncePropertyIndex = meshActor.RegisterProperty("uBounceCoefficient", 0.f); return meshActor; }