Fixed an issue where the multi-tap did not work properly.
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / dali-toolkit-test-utils / test-actor-utils.cpp
1 /*
2  * Copyright (c) 2020 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
18 // CLASS HEADER
19 #include "test-actor-utils.h"
20
21 // EXTERNAL INCLUDES
22 #include <dali/public-api/dali-core.h>
23
24 // INTERNAL INCLUDES
25 #include "mesh-builder.h"
26
27 namespace Dali
28 {
29 namespace
30 {
31 const char* VERTEX_SHADER = DALI_COMPOSE_SHADER(
32   attribute mediump vec2   aPosition;\n
33     uniform mediump mat4   uMvpMatrix;\n
34       uniform mediump vec3 uSize;\n
35   \n void main()\n {
36         \n
37           mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);
38         \n
39           vertexPosition.xyz *= uSize;
40         \n
41           gl_Position = uMvpMatrix * vertexPosition;
42         \n
43       }\n);
44
45 const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER(
46   uniform lowp vec4 uColor;\n
47   \n void main()\n {
48     \n
49       gl_FragColor = uColor;
50     \n
51   }\n);
52
53 } // unnamed namespace
54
55 Actor CreateRenderableActor()
56 {
57   return CreateRenderableActor(Texture(), VERTEX_SHADER, FRAGMENT_SHADER);
58 }
59
60 Actor CreateRenderableActor(Texture texture)
61 {
62   return CreateRenderableActor(texture, VERTEX_SHADER, FRAGMENT_SHADER);
63 }
64
65 Actor CreateRenderableActor(Texture texture, const std::string& vertexShader, const std::string& fragmentShader)
66 {
67   // Create the geometry
68   Geometry geometry = CreateQuadGeometry();
69
70   // Create Shader
71   Shader shader = Shader::New(vertexShader, fragmentShader);
72
73   // Create renderer from geometry and material
74   Renderer renderer = Renderer::New(geometry, shader);
75
76   // Create actor and set renderer
77   Actor actor = Actor::New();
78   actor.AddRenderer(renderer);
79
80   // If we a texture, then create a texture-set and add to renderer
81   if(texture)
82   {
83     TextureSet textureSet = TextureSet::New();
84     textureSet.SetTexture(0u, texture);
85     renderer.SetTextures(textureSet);
86
87     // Set actor to the size of the texture if set
88     actor.SetProperty(Actor::Property::SIZE, Vector2(texture.GetWidth(), texture.GetHeight()));
89   }
90
91   return actor;
92 }
93
94 } // namespace Dali