Revert "Updates following rename of PropertyBuffer"
[platform/core/uifw/dali-demo.git] / shared / utility.h
1 #ifndef DALI_DEMO_UTILITY_H
2 #define DALI_DEMO_UTILITY_H
3
4 /*
5  * Copyright (c) 2020 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 #include <dali/dali.h>
22 #include <dali/public-api/rendering/geometry.h>
23 #include <dali/public-api/rendering/texture.h>
24 #include <dali/public-api/math/uint-16-pair.h>
25 #include <dali/devel-api/adaptor-framework/image-loading.h>
26
27 namespace DemoHelper
28 {
29
30 Dali::Texture LoadTexture( const char* imagePath,
31                            Dali::ImageDimensions size = Dali::ImageDimensions(),
32                            Dali::FittingMode::Type fittingMode = Dali::FittingMode::DEFAULT,
33                            Dali::SamplingMode::Type samplingMode = Dali::SamplingMode::DEFAULT,
34                            bool orientationCorrection = true )
35 {
36   Dali::Devel::PixelBuffer pixelBuffer = LoadImageFromFile(imagePath, size, fittingMode, samplingMode, orientationCorrection );
37   Dali::Texture texture  = Dali::Texture::New( Dali::TextureType::TEXTURE_2D,
38                                                pixelBuffer.GetPixelFormat(),
39                                                pixelBuffer.GetWidth(),
40                                                pixelBuffer.GetHeight() );
41
42   Dali::PixelData pixelData = Dali::Devel::PixelBuffer::Convert(pixelBuffer);
43   texture.Upload( pixelData );
44
45   return texture;
46 }
47
48 Dali::Texture LoadWindowFillingTexture( Dali::Uint16Pair size, const char* imagePath )
49 {
50   return LoadTexture( imagePath, size, Dali::FittingMode::SCALE_TO_FILL, Dali::SamplingMode::BOX_THEN_LINEAR );
51 }
52
53 Dali::Geometry CreateTexturedQuad()
54 {
55   struct Vertex
56   {
57     Dali::Vector2 position;
58     Dali::Vector2 texCoord;
59   };
60
61   static const Vertex data[] = {{ Dali::Vector2( -0.5f, -0.5f ), Dali::Vector2( 0.0f, 0.0f ) },
62                                 { Dali::Vector2(  0.5f, -0.5f ), Dali::Vector2( 1.0f, 0.0f ) },
63                                 { Dali::Vector2( -0.5f,  0.5f ), Dali::Vector2( 0.0f, 1.0f ) },
64                                 { Dali::Vector2(  0.5f,  0.5f ), Dali::Vector2( 1.0f, 1.0f ) }};
65
66   Dali::PropertyBuffer vertexBuffer;
67   Dali::Property::Map vertexFormat;
68   vertexFormat["aPosition"] = Dali::Property::VECTOR2;
69   vertexFormat["aTexCoord"] = Dali::Property::VECTOR2;
70
71   //Create a vertex buffer for vertex positions and texture coordinates
72   vertexBuffer = Dali::PropertyBuffer::New( vertexFormat );
73   vertexBuffer.SetData( data, 4u );
74
75   //Create the geometry
76   Dali::Geometry geometry = Dali::Geometry::New();
77   geometry.AddVertexBuffer( vertexBuffer );
78   geometry.SetType(Dali::Geometry::TRIANGLE_STRIP );
79
80   return geometry;
81 }
82 } // DemoHelper
83
84 #endif // DALI_DEMO_UTILITY_H