X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=examples%2Fcontact-cards%2Fclipped-image.cpp;h=0de8617f0c948f96a648dee99b9b487b4127d920;hb=1b19fd140ff139b5854a1a62447faf31b175d8f6;hp=a4adbd338b96b7999797b0046d774fca00d42c19;hpb=cc86309efaef5f77c85ece1199f95e08534e4a32;p=platform%2Fcore%2Fuifw%2Fdali-demo.git diff --git a/examples/contact-cards/clipped-image.cpp b/examples/contact-cards/clipped-image.cpp index a4adbd3..0de8617 100644 --- a/examples/contact-cards/clipped-image.cpp +++ b/examples/contact-cards/clipped-image.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 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. @@ -23,14 +23,12 @@ namespace ClippedImage { - using namespace Dali; using namespace Dali::Toolkit; namespace { - -const char * const DELTA_PROPERTY_NAME( "uDelta" ); ///< Name of uniform used to mix the Circle and Quad geometries. +const char* const DELTA_PROPERTY_NAME("uDelta"); ///< Name of uniform used to mix the Circle and Quad geometries. /** * @brief This vertex-shader mixes in the quad and circle geometry depending on the value of uDelta. @@ -38,6 +36,7 @@ const char * const DELTA_PROPERTY_NAME( "uDelta" ); ///< Name of uniform used to * uDelta is used to mix in the Circle and the Quad positions. * If uDelta is 0.0f, then the circle position is adopted and if it is 1.0f, then the quad position is adopted. */ +// clang-format off const char * VERTEX_SHADER = DALI_COMPOSE_SHADER( attribute mediump vec2 aPositionCircle;\n attribute mediump vec2 aPositionQuad;\n @@ -62,6 +61,7 @@ const char * FRAGMENT_SHADER = DALI_COMPOSE_SHADER( gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0);\n }\n ); +// clang-format on /** * @brief Creates the shader required for the clipped image @@ -75,9 +75,9 @@ Shader& CreateShader() // be managed by the application writer. static Shader shader; - if( !shader ) + if(!shader) { - shader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER ); + shader = Shader::New(VERTEX_SHADER, FRAGMENT_SHADER); } return shader; @@ -95,7 +95,7 @@ Geometry& CreateGeometry() // be managed by the application writer. static Geometry geometry; - if ( !geometry ) + if(!geometry) { const int vertexCount = 34; // Needs to be 4n plus 2 where n is a positive integer above 4 @@ -103,87 +103,87 @@ Geometry& CreateGeometry() // Radius is bound to actor's dimensions so this should not be increased. // If a bigger circle is required then the actor size should be increased. - const float radius = 0.5f; + const float radius = 0.5f; const Vector2 center = Vector2::ZERO; // Create a buffer for vertex data Vector2 circleBuffer[vertexCount]; - int idx = 0; + int idx = 0; // Center vertex for triangle fan - circleBuffer[ idx++ ] = center; + circleBuffer[idx++] = center; // Outer vertices of the circle const int outerVertexCount = vertexCount - 1; - for ( int i = 0; i < outerVertexCount; ++i ) + for(int i = 0; i < outerVertexCount; ++i) { - const float percent = ( i / static_cast< float >( outerVertexCount - 1 ) ); - const float rad = percent * 2.0f * Math::PI; + const float percent = (i / static_cast(outerVertexCount - 1)); + const float rad = percent * 2.0f * Math::PI; // Vertex position Vector2 outer; - outer.x = center.x + radius * cos( rad ); - outer.y = center.y + radius * sin( rad ); + outer.x = center.x + radius * cos(rad); + outer.y = center.y + radius * sin(rad); - circleBuffer[ idx++ ] = outer; + circleBuffer[idx++] = outer; } Property::Map circleVertexFormat; circleVertexFormat["aPositionCircle"] = Property::VECTOR2; - PropertyBuffer circleVertices = PropertyBuffer::New( circleVertexFormat ); - circleVertices.SetData( circleBuffer, vertexCount ); + VertexBuffer circleVertices = VertexBuffer::New(circleVertexFormat); + circleVertices.SetData(circleBuffer, vertexCount); // Create the Quad Geometry Vector2 quadBuffer[vertexCount]; - idx = 0; - quadBuffer[ idx++ ] = center; + idx = 0; + quadBuffer[idx++] = center; - const size_t vertsPerSide = ( vertexCount - 2 ) / 4; - Vector2 outer( 0.5f, 0.0f ); - quadBuffer[ idx++ ] = outer; - float incrementPerBuffer = 1.0f / static_cast< float >( vertsPerSide ); + const size_t vertsPerSide = (vertexCount - 2) / 4; + Vector2 outer(0.5f, 0.0f); + quadBuffer[idx++] = outer; + float incrementPerBuffer = 1.0f / static_cast(vertsPerSide); - for( size_t i = 0; i < vertsPerSide && outer.y < 0.5f; ++i ) + for(size_t i = 0; i < vertsPerSide && outer.y < 0.5f; ++i) { outer.y += incrementPerBuffer; - quadBuffer[ idx++ ] = outer; + quadBuffer[idx++] = outer; } - for( size_t i = 0; i < vertsPerSide && outer.x > -0.5f; ++i ) + for(size_t i = 0; i < vertsPerSide && outer.x > -0.5f; ++i) { outer.x -= incrementPerBuffer; - quadBuffer[ idx++ ] = outer; + quadBuffer[idx++] = outer; } - for( size_t i = 0; i < vertsPerSide && outer.y > -0.5f; ++i ) + for(size_t i = 0; i < vertsPerSide && outer.y > -0.5f; ++i) { outer.y -= incrementPerBuffer; - quadBuffer[ idx++ ] = outer; + quadBuffer[idx++] = outer; } - for( size_t i = 0; i < vertsPerSide && outer.x < 0.5f; ++i ) + for(size_t i = 0; i < vertsPerSide && outer.x < 0.5f; ++i) { outer.x += incrementPerBuffer; - quadBuffer[ idx++ ] = outer; + quadBuffer[idx++] = outer; } - for( size_t i = 0; i < vertsPerSide && outer.y < 0.0f; ++i ) + for(size_t i = 0; i < vertsPerSide && outer.y < 0.0f; ++i) { outer.y += incrementPerBuffer; - quadBuffer[ idx++ ] = outer; + quadBuffer[idx++] = outer; } Property::Map vertexFormat; vertexFormat["aPositionQuad"] = Property::VECTOR2; - PropertyBuffer quadVertices2 = PropertyBuffer::New( vertexFormat ); - quadVertices2.SetData( quadBuffer, vertexCount ); + VertexBuffer quadVertices2 = VertexBuffer::New(vertexFormat); + quadVertices2.SetData(quadBuffer, vertexCount); // Create the geometry object itself geometry = Geometry::New(); - geometry.AddVertexBuffer( circleVertices ); - geometry.AddVertexBuffer( quadVertices2 ); - geometry.SetType( Geometry::TRIANGLE_FAN ); + geometry.AddVertexBuffer(circleVertices); + geometry.AddVertexBuffer(quadVertices2); + geometry.SetType(Geometry::TRIANGLE_FAN); } return geometry; @@ -192,28 +192,28 @@ Geometry& CreateGeometry() } // unnamed namespace const float CIRCLE_GEOMETRY = 0.0f; -const float QUAD_GEOMETRY = 1.0f; +const float QUAD_GEOMETRY = 1.0f; -Dali::Toolkit::Control Create( const std::string& imagePath, Property::Index& propertyIndex ) +Dali::Toolkit::Control Create(const std::string& imagePath, Property::Index& propertyIndex) { // Create a control which whose geometry will be morphed between a circle and a quad Control clippedImage = Control::New(); - clippedImage.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN ); + clippedImage.SetProperty(Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN); // Create the required renderer and add to the clipped image control - Renderer renderer = Renderer::New( CreateGeometry(), CreateShader() ); - renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::ON ); - clippedImage.AddRenderer( renderer ); + Renderer renderer = Renderer::New(CreateGeometry(), CreateShader()); + renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON); + clippedImage.AddRenderer(renderer); // Register the property on the clipped image control which will allow animations between a circle and a quad - propertyIndex = clippedImage.RegisterProperty( DELTA_PROPERTY_NAME, 0.0f ); + propertyIndex = clippedImage.RegisterProperty(DELTA_PROPERTY_NAME, 0.0f); // Add the actual image to the control - Control image = ImageView::New( imagePath ); - image.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - image.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - image.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - clippedImage.Add( image ); + Control image = ImageView::New(imagePath); + image.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + image.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + image.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + clippedImage.Add(image); return clippedImage; }