2 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include <dali-toolkit/dali-toolkit.h>
21 using Dali::Toolkit::TextLabel;
23 const char* IMAGE_FILENAME_ETC = DEMO_IMAGE_DIR "tx-etc1.ktx";
24 const char* IMAGE_FILENAME_ASTC_LINEAR = DEMO_IMAGE_DIR "tx-astc-4x4-linear.ktx";
25 const char* IMAGE_FILENAME_ASTC_LINEAR_NATIVE = DEMO_IMAGE_DIR "tx-astc-4x4-linear-native.astc";
28 * @brief This example shows 3 images, each of a different compressed texture type.
29 * If built and run on a OpenGL ES 3.1 compatable target, then all 3 images will display.
30 * Otherwise, the top image will display and the other 2 will appear as black squares.
32 class CompressedTextureFormatsController : public ConnectionTracker
36 CompressedTextureFormatsController( Application& application )
37 : mApplication( application )
39 // Connect to the Application's Init signal
40 mApplication.InitSignal().Connect( this, &CompressedTextureFormatsController::Create );
43 ~CompressedTextureFormatsController()
45 // Nothing to do here;
48 // The Init signal is received once (only) during the Application lifetime
49 void Create( Application& application )
51 // Get a handle to the stage
52 Stage stage = Stage::GetCurrent();
53 stage.SetBackgroundColor( Color::WHITE );
55 // Setup a TableView to hold a grid of images and labels.
56 Toolkit::TableView table = Toolkit::TableView::New( 3u, 2u );
57 table.SetAnchorPoint( AnchorPoint::CENTER );
58 table.SetParentOrigin( ParentOrigin::CENTER );
59 table.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
60 table.SetRelativeWidth( 0u, 0.5f );
61 table.SetRelativeWidth( 1u, 0.5f );
62 table.SetRelativeHeight( 0u, 1.0f / 3.0f );
63 table.SetRelativeHeight( 1u, 1.0f / 3.0f );
64 table.SetRelativeHeight( 2u, 1.0f / 3.0f );
68 TextLabel textLabel = TextLabel::New( "ETC1 (KTX):" );
69 textLabel.SetAnchorPoint( AnchorPoint::CENTER );
70 textLabel.SetParentOrigin( ParentOrigin::CENTER );
71 textLabel.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
72 textLabel.SetProperty( Toolkit::TextLabel::Property::MULTI_LINE, true );
73 table.AddChild( textLabel, Toolkit::TableView::CellPosition( 0u, 0u ) );
74 table.SetCellAlignment( Toolkit::TableView::CellPosition( 0u, 0u ), HorizontalAlignment::LEFT, VerticalAlignment::CENTER );
76 textLabel = TextLabel::New( "ASTC (KTX) 4x4 linear:" );
77 textLabel.SetAnchorPoint( AnchorPoint::CENTER );
78 textLabel.SetParentOrigin( ParentOrigin::CENTER );
79 textLabel.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
80 textLabel.SetProperty( Toolkit::TextLabel::Property::MULTI_LINE, true );
81 table.AddChild( textLabel, Toolkit::TableView::CellPosition( 1u, 0u ) );
82 table.SetCellAlignment( Toolkit::TableView::CellPosition( 1u, 0u ), HorizontalAlignment::LEFT, VerticalAlignment::CENTER );
84 textLabel = TextLabel::New( "ASTC (Native) 4x4 linear:" );
85 textLabel.SetAnchorPoint( AnchorPoint::CENTER );
86 textLabel.SetParentOrigin( ParentOrigin::CENTER );
87 textLabel.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
88 textLabel.SetProperty( Toolkit::TextLabel::Property::MULTI_LINE, true );
89 table.AddChild( textLabel, Toolkit::TableView::CellPosition( 2u, 0u ) );
90 table.SetCellAlignment( Toolkit::TableView::CellPosition( 2u, 0u ), HorizontalAlignment::LEFT, VerticalAlignment::CENTER );
93 Toolkit::ImageView imageView = Toolkit::ImageView::New( ResourceImage::New( IMAGE_FILENAME_ETC ) );
94 imageView.SetAnchorPoint( AnchorPoint::CENTER );
95 imageView.SetParentOrigin( ParentOrigin::CENTER );
96 table.AddChild( imageView, Toolkit::TableView::CellPosition( 0u, 1u ) );
98 imageView = Toolkit::ImageView::New( ResourceImage::New( IMAGE_FILENAME_ASTC_LINEAR ) );
99 imageView.SetAnchorPoint( AnchorPoint::CENTER );
100 imageView.SetParentOrigin( ParentOrigin::CENTER );
101 table.AddChild( imageView, Toolkit::TableView::CellPosition( 1u, 1u ) );
103 imageView = Toolkit::ImageView::New( ResourceImage::New( IMAGE_FILENAME_ASTC_LINEAR_NATIVE ) );
104 imageView.SetAnchorPoint( AnchorPoint::CENTER );
105 imageView.SetParentOrigin( ParentOrigin::CENTER );
106 table.AddChild( imageView, Toolkit::TableView::CellPosition( 2u, 1u ) );
110 // Respond to a click anywhere on the stage
111 stage.GetRootLayer().TouchedSignal().Connect( this, &CompressedTextureFormatsController::OnTouch );
114 bool OnTouch( Actor actor, const TouchEvent& touch )
116 // quit the application
122 Application& mApplication;
125 void RunTest( Application& application )
127 CompressedTextureFormatsController test( application );
129 application.MainLoop();
132 // Entry point for Linux & Tizen applications
134 int main( int argc, char **argv )
136 Application application = Application::New( &argc, &argv );
138 RunTest( application );