2 * Copyright (c) 2017 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 namespace Dali::Toolkit;
23 const char* images[] = {
24 DEMO_IMAGE_DIR "gallery-small-1.jpg",
25 DEMO_IMAGE_DIR "gallery-small-2.jpg",
26 DEMO_IMAGE_DIR "gallery-small-3.jpg",
27 DEMO_IMAGE_DIR "gallery-small-4.jpg",
28 DEMO_IMAGE_DIR "gallery-small-5.jpg"
31 // This verification example confirms drawing order is the same, with or without clipping enabled.
32 class ClippingDrawOrderVerification : public ConnectionTracker
36 ClippingDrawOrderVerification( Application& application )
37 : mApplication( application )
39 // Connect to the Application's Init signal.
40 mApplication.InitSignal().Connect( this, &ClippingDrawOrderVerification::Create );
43 ~ClippingDrawOrderVerification()
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 // Create the title label.
56 TextLabel title = TextLabel::New( "Clipping draw order verification" );
57 title.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
58 title.SetProperty( TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
59 title.SetAnchorPoint( AnchorPoint::CENTER );
60 title.SetParentOrigin( ParentOrigin::CENTER );
62 // Create the description label.
63 TextLabel description = TextLabel::New( "The bottom tree should have the same draw order as the top tree.\nThey should look identical except \"C\" is clipped on the bottom tree." );
64 description.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
65 description.SetProperty( TextLabel::Property::MULTI_LINE, true );
66 description.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
67 description.SetParentOrigin( Vector3( 0.5f, 1.0f, 0.5f ) );
68 stage.Add( description );
71 * Create a 4-row TableView.
72 * It will be segmented as follows:
88 TableView view = TableView::New( 4, 1 );
89 view.SetAnchorPoint( AnchorPoint::CENTER );
90 view.SetParentOrigin( ParentOrigin::CENTER );
91 view.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
93 view.SetCellAlignment( Toolkit::TableView::CellPosition( 0, 0 ), HorizontalAlignment::CENTER, VerticalAlignment::CENTER );
94 view.SetCellAlignment( Toolkit::TableView::CellPosition( 1, 0 ), HorizontalAlignment::CENTER, VerticalAlignment::CENTER );
95 view.SetCellAlignment( Toolkit::TableView::CellPosition( 2, 0 ), HorizontalAlignment::CENTER, VerticalAlignment::CENTER );
96 view.SetCellAlignment( Toolkit::TableView::CellPosition( 3, 0 ), HorizontalAlignment::CENTER, VerticalAlignment::CENTER );
98 view.SetCellPadding( Vector2( 14.0f, 7.0f ) );
100 view.SetRelativeWidth( 0u, 1.0f );
102 view.SetFitHeight( 0u );
103 view.SetRelativeHeight( 1u, 0.5f );
104 view.SetRelativeHeight( 2u, 0.5f );
105 view.SetFitHeight( 3u );
107 // Add the title and description to the TableView.
108 view.AddChild( title, TableView::CellPosition( 0u, 0u ) );
109 view.AddChild( description, TableView::CellPosition( 3u, 0u ) );
112 For each of the 2 tree views, we create a small tree of actors as follows:
113 ( Note: Clipping is only enabled for B on the bottom tree ).
117 Clipping enabled -> B D
121 The correct draw order is "ABCDE" (the same as if clipping was not enabled).
123 const float treeYStart = 0.12f;
124 const float depthGap = 0.35f;
126 for( int tree = 0; tree < 2; ++tree )
128 Control container = Control::New();
129 container.SetAnchorPoint( AnchorPoint::TOP_CENTER );
130 container.SetParentOrigin( ParentOrigin::TOP_CENTER );
131 container.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
132 Vector4 backgroundColor = tree == 0 ? Vector4( 0.77f, 1.0f, 0.77f, 1.0f ) : Vector4( 0.8f, 0.8f, 1.0f, 1.0f );
133 container.SetProperty( Control::Property::BACKGROUND, backgroundColor );
136 // Loop for each of the 5 images & labels.
137 for( int i = 0; i < 5; ++i )
139 std::stringstream labelStream;
140 labelStream << static_cast<char>( static_cast<char>( i ) + 'A' );
141 TextLabel textLabel = TextLabel::New( labelStream.str() );
142 textLabel.SetAnchorPoint( AnchorPoint::TOP_CENTER );
144 image[i] = ImageView::New( images[i] );
145 image[i].SetAnchorPoint( AnchorPoint::TOP_CENTER );
147 // Calculate the relative positioning for the images and labels.
148 float depth = static_cast<float>( i == 0 ? 0 : ( ( i - 1 ) % 2 ) + 1 );
152 image[i].SetParentOrigin( Vector3( 0.5f, treeYStart, 0.5f ) );
153 textLabel.SetParentOrigin( Vector3( 1.0f, 0.05f * depth, 0.5f ) );
157 float b = i > 2 ? 1.0f : -1.0f;
158 image[i].SetParentOrigin( Vector3( 0.5f + ( 0.2f * b ), depthGap, 0.5f ) );
159 textLabel.SetParentOrigin( Vector3( 0.98f + 0.215f * b + ( 0.04f * b * depth ), treeYStart + 0.02f + ( 0.16f * depth ), 0.5f ) );
162 container.Add( textLabel );
165 // Create the title label.
166 std::string treeText = tree == 0 ? "Without Clipping" : "With Clipping";
167 TextLabel treeLabel = TextLabel::New( treeText );
168 treeLabel.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
169 treeLabel.SetProperty( TextLabel::Property::VERTICAL_ALIGNMENT, "BOTTOM" );
170 treeLabel.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
171 treeLabel.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
172 container.Add( treeLabel );
174 // Enable clipping for the 2nd tree.
177 image[1].SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
180 // Build the tree structure.
181 container.Add( image[0] );
183 image[0].Add( image[1] );
184 image[1].Add( image[2] );
186 image[0].Add( image[3] );
187 image[3].Add( image[4] );
189 // Add the finished tree to the TableView.
190 view.AddChild( container, TableView::CellPosition( 1u + tree, 0u ) );
193 // Add the finished TableView to the stage.
196 // Respond to a click anywhere on the stage
197 stage.GetRootLayer().TouchSignal().Connect( this, &ClippingDrawOrderVerification::OnTouch );
200 bool OnTouch( Actor actor, const TouchData& touch )
202 // Quit the application.
208 Application& mApplication;
211 void RunVerification( Application& application )
213 ClippingDrawOrderVerification verification( application );
215 application.MainLoop();
218 // Entry point for Linux & Tizen applications.
219 int DALI_EXPORT_API main( int argc, char **argv )
221 Application application = Application::New( &argc, &argv );
223 RunVerification( application );