Merge "Do not reposition the text's popup when buttons are pressed." into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / renderers / renderer-factory-cache.cpp
1  /*
2  * Copyright (c) 2015 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 // CLASS HEADER
18 #include "renderer-factory-cache.h"
19
20 // Internal HEADER
21 #include <dali-toolkit/internal/controls/renderers/color/color-renderer.h>
22
23 namespace Dali
24 {
25
26 namespace Toolkit
27 {
28
29 namespace Internal
30 {
31
32 RendererFactoryCache::RendererFactoryCache()
33 {
34 }
35
36 RendererFactoryCache::~RendererFactoryCache()
37 {
38   for( int i=0; i<= SHADER_TYPE_MAX; i++)
39   {
40     if(mShader[i])
41     {
42       mShader[i].Reset();
43     }
44   }
45
46   for( int i=0; i<= GEOMETRY_TYPE_MAX; i++)
47   {
48     if(mGeometry[i])
49     {
50       mGeometry[i].Reset();
51     }
52   }
53 }
54
55
56 Geometry RendererFactoryCache::GetGeometry( GeometryType type )
57 {
58   return mGeometry[type];
59 }
60
61 void RendererFactoryCache::SaveGeometry( GeometryType type, Geometry geometry )
62 {
63   mGeometry[type] = geometry;
64 }
65
66 Shader RendererFactoryCache::GetShader( ShaderType type )
67 {
68   return mShader[type];
69 }
70
71 void RendererFactoryCache::SaveShader( ShaderType type, Shader shader )
72 {
73   mShader[type] = shader;
74 }
75
76 Geometry RendererFactoryCache::CreateQuadGeometry()
77 {
78   const float halfWidth = 0.5f;
79   const float halfHeight = 0.5f;
80   struct QuadVertex { Vector2 position;};
81   QuadVertex quadVertexData[4] =
82   {
83       { Vector2(-halfWidth, -halfHeight) },
84       { Vector2( halfWidth, -halfHeight) },
85       { Vector2(-halfWidth, halfHeight)  },
86       { Vector2( halfWidth, halfHeight)  }
87   };
88
89   Property::Map quadVertexFormat;
90   quadVertexFormat["aPosition"] = Property::VECTOR2;
91   PropertyBuffer quadVertices = PropertyBuffer::New( quadVertexFormat, 4 );
92   quadVertices.SetData(quadVertexData);
93
94   // Create indices
95   //TODO: replace with triangle strip when Geometry supports it
96   unsigned int indexData[6] = { 0, 3, 1, 0, 2, 3 };
97   Property::Map indexFormat;
98   indexFormat["indices"] = Property::INTEGER;
99   PropertyBuffer indices = PropertyBuffer::New( indexFormat, 6 );
100   indices.SetData(indexData);
101
102   // Create the geometry object
103   Geometry geometry = Geometry::New();
104   geometry.AddVertexBuffer( quadVertices );
105   geometry.SetIndexBuffer( indices );
106
107   return geometry;
108 }
109
110 } // namespace Internal
111
112 } // namespace Toolkit
113
114 } // namespace Dali
115