(AnimatedVectorImageVisual) Render frames based on content's fps
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / dali-toolkit-test-utils / layout-utils.cpp
1 /*
2  * Copyright (c) 2018 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 // FILE HEADER
19 #include "layout-utils.h"
20
21 // EXTERNAL INCLUDES
22 #include <dali-toolkit/dali-toolkit.h>
23 #include <dali/devel-api/adaptor-framework/pixel-buffer.h>
24 #include <dali-toolkit/devel-api/image-loader/texture-manager.h>
25 #include <dali-toolkit/devel-api/controls/control-devel.h>
26 #include <dali-toolkit/devel-api/layouting/flex-layout.h>
27
28 // INTERNAL INCLUDES
29
30 namespace Dali
31 {
32
33 namespace Toolkit
34 {
35
36 std::string CreateImageURL( Vector4 color, ImageDimensions size )
37 {
38   auto pixelBuffer = Devel::PixelBuffer::New( size.GetWidth(), size.GetHeight(), Pixel::RGB888 );
39   unsigned char* pixels = pixelBuffer.GetBuffer();
40   pixels[0] = static_cast<unsigned char>( color.r );
41   pixels[1] = static_cast<unsigned char>( color.g );
42   pixels[2] = static_cast<unsigned char>( color.b );
43   auto texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGB888, size.GetWidth(), size.GetHeight() );
44   auto pixelData = Devel::PixelBuffer::Convert( pixelBuffer );
45   texture.Upload( pixelData );
46   return TextureManager::AddTexture( texture );
47 }
48
49 Control CreateLeafControl( int width, int height )
50 {
51   auto control = Control::New();
52   control.SetName( "Leaf" );
53   std::string url = CreateImageURL( Vector4( 255, 0, 0, 255 ), ImageDimensions( 1, 1 ) );
54
55   Property::Map map;
56   map[ Visual::Property::TYPE ] = Visual::IMAGE;
57   map[ ImageVisual::Property::URL ] = url;
58   map[ ImageVisual::Property::DESIRED_WIDTH ] = (float) width;
59   map[ ImageVisual::Property::DESIRED_HEIGHT ] = (float) height;
60   control.SetProperty( Control::Property::BACKGROUND, map );
61   return control;
62 }
63
64 TextLabel CreateTextLabel( const char* text )
65 {
66   TextLabel textLabel = TextLabel::New(text);
67   textLabel.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
68   textLabel.SetProperty( TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
69   textLabel.SetName( "TextLabel" );
70   textLabel.SetAnchorPoint( AnchorPoint::TOP_LEFT );
71   return textLabel;
72 }
73
74 ImageView CreateImageView( std::string& url, ImageDimensions size )
75 {
76   ImageView imageView = ImageView::New( url, size );
77   imageView.SetName( "ImageView" );
78   imageView.SetAnchorPoint( AnchorPoint::TOP_LEFT );
79   return imageView;
80 }
81
82 } // namespace Toolkit
83
84 } // namespace Dali