Removed Atlas example
[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) 2016 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/devel-api/adaptor-framework/bitmap-loader.h>
23 #include <dali/public-api/rendering/geometry.h>
24 #include <dali/public-api/rendering/texture.h>
25
26 namespace DemoHelper
27 {
28
29 Dali::PixelData LoadPixelData( const char* imagePath,
30                                Dali::ImageDimensions size,
31                                Dali::FittingMode::Type fittingMode,
32                                Dali::SamplingMode::Type samplingMode )
33 {
34   Dali::BitmapLoader loader = Dali::BitmapLoader::New( imagePath, size, fittingMode, samplingMode );
35   loader.Load();
36   return loader.GetPixelData();
37 }
38
39 /**
40  * @deprecated, dont use this anymore
41  */
42 Dali::Image LoadImage( const char* imagePath,
43                        Dali::ImageDimensions size = Dali::ImageDimensions(),
44                        Dali::FittingMode::Type fittingMode = Dali::FittingMode::DEFAULT,
45                        Dali::SamplingMode::Type samplingMode = Dali::SamplingMode::DEFAULT )
46 {
47   return Dali::ResourceImage::New( imagePath, size, fittingMode, samplingMode );
48 }
49
50 Dali::Texture LoadTexture( const char* imagePath,
51                            Dali::ImageDimensions size = Dali::ImageDimensions(),
52                            Dali::FittingMode::Type fittingMode = Dali::FittingMode::DEFAULT,
53                            Dali::SamplingMode::Type samplingMode = Dali::SamplingMode::DEFAULT )
54 {
55   Dali::PixelData pixelData = LoadPixelData(imagePath, size, fittingMode, samplingMode);
56   Dali::Texture texture  = Dali::Texture::New( Dali::TextureType::TEXTURE_2D,
57                                                pixelData.GetPixelFormat(),
58                                                pixelData.GetWidth(),
59                                                pixelData.GetHeight() );
60   texture.Upload( pixelData );
61
62   return texture;
63 }
64
65 /**
66  * @brief Load an bitmap resource.
67  * @deprecated, dont use this anymore
68  *
69  * If it is required to scaled-down to no more than the stage dimensions,
70  * uses image scaling mode FittingMode::SCALE_TO_FILL to resize the image at
71  * load time to cover the entire stage with pixels with no borders,
72  * and filter mode BOX_THEN_LINEAR to sample the image with
73  * maximum quality.
74  */
75
76 Dali::Image LoadStageFillingImage( const char* imagePath )
77 {
78   Dali::Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
79   return LoadImage( imagePath, Dali::ImageDimensions( stageSize.x, stageSize.y ), Dali::FittingMode::SCALE_TO_FILL, Dali::SamplingMode::BOX_THEN_LINEAR );
80 }
81
82 Dali::Texture LoadStageFillingTexture( const char* imagePath )
83 {
84   Dali::Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
85   return LoadTexture( imagePath, Dali::ImageDimensions( stageSize.x, stageSize.y ), Dali::FittingMode::SCALE_TO_FILL, Dali::SamplingMode::BOX_THEN_LINEAR );
86 }
87
88 Dali::Geometry CreateTexturedQuad()
89 {
90   struct Vertex
91   {
92     Dali::Vector2 position;
93     Dali::Vector2 texCoord;
94   };
95
96   static const Vertex data[] = {{ Dali::Vector2( -0.5f, -0.5f ), Dali::Vector2( 0.0f, 0.0f ) },
97                                 { Dali::Vector2(  0.5f, -0.5f ), Dali::Vector2( 1.0f, 0.0f ) },
98                                 { Dali::Vector2( -0.5f,  0.5f ), Dali::Vector2( 0.0f, 1.0f ) },
99                                 { Dali::Vector2(  0.5f,  0.5f ), Dali::Vector2( 1.0f, 1.0f ) }};
100
101   Dali::PropertyBuffer vertexBuffer;
102   Dali::Property::Map vertexFormat;
103   vertexFormat["aPosition"] = Dali::Property::VECTOR2;
104   vertexFormat["aTexCoord"] = Dali::Property::VECTOR2;
105
106   //Create a vertex buffer for vertex positions and texture coordinates
107   vertexBuffer = Dali::PropertyBuffer::New( vertexFormat );
108   vertexBuffer.SetData( data, 4u );
109
110   //Create the geometry
111   Dali::Geometry geometry = Dali::Geometry::New();
112   geometry.AddVertexBuffer( vertexBuffer );
113   geometry.SetType(Dali::Geometry::TRIANGLE_STRIP );
114
115   return geometry;
116 }
117 } // DemoHelper
118
119 #endif // DALI_DEMO_UTILITY_H