Updated all files to new format
[platform/core/uifw/dali-demo.git] / examples / color-transition / utils.cpp
1 /*
2  * Copyright (c) 2021 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 #include "utils.h"
18
19 #include <cstdarg>
20 #include <cstdio>
21
22 #include <cmath>
23
24 using namespace Dali;
25
26 Geometry CreateQuadGeometry()
27 {
28   // Create geometry -- unit square with whole of the texture mapped to it.
29   struct Vertex
30   {
31     Vector3 aPosition;
32   };
33
34   Vertex vertexData[] = {
35     {Vector3(-.5f, .5f, .0f)},
36     {Vector3(.5f, .5f, .0f)},
37     {Vector3(-.5f, -.5f, .0f)},
38     {Vector3(.5f, -.5f, .0f)},
39   };
40
41   VertexBuffer vertexBuffer = VertexBuffer::New(Property::Map()
42                                                   .Add("aPosition", Property::VECTOR3));
43   vertexBuffer.SetData(vertexData, std::extent<decltype(vertexData)>::value);
44
45   Geometry geometry = Geometry::New();
46   geometry.AddVertexBuffer(vertexBuffer);
47   geometry.SetType(Geometry::TRIANGLE_STRIP);
48   return geometry;
49 }
50
51 Renderer CreateRenderer(TextureSet textures, Geometry geometry, Shader shader, uint32_t options)
52 {
53   Renderer renderer = Renderer::New(geometry, shader);
54   renderer.SetProperty(Renderer::Property::BLEND_MODE,
55                        (options & RendererOptions::BLEND) ? BlendMode::ON : BlendMode::OFF);
56   renderer.SetProperty(Renderer::Property::DEPTH_TEST_MODE,
57                        (options & RendererOptions::DEPTH_TEST) ? DepthTestMode::ON : DepthTestMode::OFF);
58   renderer.SetProperty(Renderer::Property::DEPTH_WRITE_MODE,
59                        (options & RendererOptions::DEPTH_WRITE) ? DepthWriteMode::ON : DepthWriteMode::OFF);
60
61   int faceCulling = (((options & RendererOptions::CULL_BACK) != 0) << 1) |
62                     ((options & RendererOptions::CULL_FRONT) != 0);
63   renderer.SetProperty(Renderer::Property::FACE_CULLING_MODE, faceCulling);
64
65   if(!textures)
66   {
67     textures = TextureSet::New();
68   }
69
70   renderer.SetTextures(textures);
71   return renderer;
72 }
73
74 void CenterActor(Actor actor)
75 {
76   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
77   actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
78 }