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 = DALI_IMAGE_DIR "tx-etc1.ktx";
24 const char* IMAGE_FILENAME_ASTC_LINEAR = DALI_IMAGE_DIR "tx-astc-4x4-linear.ktx";
25 const char* IMAGE_FILENAME_ASTC_SRGB = DALI_IMAGE_DIR "tx-astc-4x4-srgb.ktx";
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.SetFitHeight( 0u );
61 table.SetFitHeight( 1u );
62 table.SetFitHeight( 2u );
63 table.SetRelativeWidth( 0u, 0.5f );
64 table.SetRelativeWidth( 1u, 0.5f );
67 TextLabel textLabel = TextLabel::New( "ETC1:" );
68 textLabel.SetAnchorPoint( AnchorPoint::CENTER );
69 textLabel.SetParentOrigin( ParentOrigin::CENTER );
70 table.AddChild( textLabel, Toolkit::TableView::CellPosition( 0u, 0u ) );
71 table.SetCellAlignment( Toolkit::TableView::CellPosition( 0u, 0u ), HorizontalAlignment::LEFT, VerticalAlignment::CENTER );
73 textLabel = TextLabel::New( "ASTC 4x4 linear:" );
74 textLabel.SetAnchorPoint( AnchorPoint::CENTER );
75 textLabel.SetParentOrigin( ParentOrigin::CENTER );
76 table.AddChild( textLabel, Toolkit::TableView::CellPosition( 1u, 0u ) );
77 table.SetCellAlignment( Toolkit::TableView::CellPosition( 1u, 0u ), HorizontalAlignment::LEFT, VerticalAlignment::CENTER );
79 textLabel = TextLabel::New( "ASTC 4x4 sRGB:" );
80 textLabel.SetAnchorPoint( AnchorPoint::CENTER );
81 textLabel.SetParentOrigin( ParentOrigin::CENTER );
82 table.AddChild( textLabel, Toolkit::TableView::CellPosition( 2u, 0u ) );
83 table.SetCellAlignment( Toolkit::TableView::CellPosition( 2u, 0u ), HorizontalAlignment::LEFT, VerticalAlignment::CENTER );
86 Toolkit::ImageView imageView = Toolkit::ImageView::New( ResourceImage::New( IMAGE_FILENAME_ETC ) );
87 imageView.SetAnchorPoint( AnchorPoint::CENTER );
88 imageView.SetParentOrigin( ParentOrigin::CENTER );
89 table.AddChild( imageView, Toolkit::TableView::CellPosition( 0u, 1u ) );
91 imageView = Toolkit::ImageView::New( ResourceImage::New( IMAGE_FILENAME_ASTC_LINEAR ) );
92 imageView.SetAnchorPoint( AnchorPoint::CENTER );
93 imageView.SetParentOrigin( ParentOrigin::CENTER );
94 table.AddChild( imageView, Toolkit::TableView::CellPosition( 1u, 1u ) );
96 imageView = Toolkit::ImageView::New( ResourceImage::New( IMAGE_FILENAME_ASTC_SRGB ) );
97 imageView.SetAnchorPoint( AnchorPoint::CENTER );
98 imageView.SetParentOrigin( ParentOrigin::CENTER );
99 table.AddChild( imageView, Toolkit::TableView::CellPosition( 2u, 1u ) );
103 // Respond to a click anywhere on the stage
104 stage.GetRootLayer().TouchedSignal().Connect( this, &CompressedTextureFormatsController::OnTouch );
107 bool OnTouch( Actor actor, const TouchEvent& touch )
109 // quit the application
115 Application& mApplication;
118 void RunTest( Application& application )
120 CompressedTextureFormatsController test( application );
122 application.MainLoop();
125 // Entry point for Linux & Tizen applications
127 int main( int argc, char **argv )
129 Application application = Application::New( &argc, &argv );
131 RunTest( application );