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 * @file transition-application.cpp
19 * @brief Application class for showing stylable transitions
23 #include "transition-application.h"
26 #include <dali-toolkit/dali-toolkit.h>
27 #include "beat-control.h"
34 using namespace Dali::Toolkit;
39 const char* TransitionApplication::DEMO_THEME_ONE_PATH( DEMO_STYLE_DIR "style-example-theme-one.json" );
42 TransitionApplication::TransitionApplication( Application& application )
43 : mApplication( application )
45 application.InitSignal().Connect( this, &TransitionApplication::Create );
48 TransitionApplication::~TransitionApplication()
52 void TransitionApplication::Create( Application& application )
54 Stage stage = Stage::GetCurrent();
55 stage.KeyEventSignal().Connect(this, &TransitionApplication::OnKeyEvent);
56 stage.SetBackgroundColor( Vector4( 0.1f, 0.1f, 0.1f, 1.0f ) );
58 // Hide the indicator bar
59 application.GetWindow().ShowIndicator( Dali::Window::INVISIBLE );
62 TableView contentLayout = TableView::New( 3, 1 );
63 contentLayout.SetName("ContentLayout");
64 contentLayout.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
65 contentLayout.SetAnchorPoint( AnchorPoint::TOP_LEFT );
66 contentLayout.SetParentOrigin( ParentOrigin::TOP_LEFT );
67 contentLayout.SetCellPadding( Size( 10, 10 ) );
69 // Assign all rows the size negotiation property of fitting to children
71 stage.Add( contentLayout );
73 mTitle = TextLabel::New( "Custom Control Transition Example" );
74 mTitle.SetName( "Title" );
75 mTitle.SetStyleName("Title");
76 mTitle.SetAnchorPoint( AnchorPoint::TOP_CENTER );
77 mTitle.SetParentOrigin( ParentOrigin::TOP_CENTER );
78 mTitle.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
79 mTitle.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
80 mTitle.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
81 contentLayout.Add( mTitle );
82 contentLayout.SetFitHeight(0);
84 mBeatControl = BeatControl::New();
85 mBeatControl.SetName("BeatControl");
86 mBeatControl.SetAnchorPoint( AnchorPoint::CENTER );
87 mBeatControl.SetParentOrigin( ParentOrigin::CENTER );
88 mBeatControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
89 contentLayout.Add( mBeatControl );
90 // beat control should fill the tableview cell, so no change to default parameters
92 TableView actionButtonLayout = TableView::New( 1, 4 );
93 actionButtonLayout.SetName("ThemeButtonsLayout");
94 actionButtonLayout.SetCellPadding( Vector2( 6.0f, 0.0f ) );
96 actionButtonLayout.SetAnchorPoint( AnchorPoint::CENTER );
97 actionButtonLayout.SetParentOrigin( ParentOrigin::CENTER );
98 actionButtonLayout.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
99 actionButtonLayout.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::HEIGHT );
100 actionButtonLayout.SetCellPadding( Size( 10, 10 ) );
101 actionButtonLayout.SetFitHeight( 0 );
103 TextLabel label = TextLabel::New( "Action: ");
104 label.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
105 label.SetStyleName("ActionLabel");
106 label.SetAnchorPoint( AnchorPoint::TOP_CENTER );
107 label.SetParentOrigin( ParentOrigin::TOP_CENTER );
108 actionButtonLayout.AddChild( label, TableView::CellPosition( 0, 0 ) );
109 actionButtonLayout.SetCellAlignment( TableView::CellPosition( 0, 0 ), HorizontalAlignment::LEFT, VerticalAlignment::CENTER );
111 for( int i=0; i<3; ++i )
113 mActionButtons[i] = PushButton::New();
114 mActionButtons[i].SetName("ActionButton");
115 mActionButtons[i].SetStyleName("ActionButton");
116 mActionButtons[i].SetParentOrigin( ParentOrigin::CENTER );
117 mActionButtons[i].SetAnchorPoint( ParentOrigin::CENTER );
118 mActionButtons[i].SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
119 mActionButtons[i].SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
120 mActionIndex = mActionButtons[i].RegisterProperty( "actionId", i, Property::READ_WRITE );
121 mActionButtons[i].ClickedSignal().Connect( this, &TransitionApplication::OnActionButtonClicked );
122 actionButtonLayout.AddChild( mActionButtons[i], TableView::CellPosition( 0, 1+i ) );
124 mActionButtons[0].SetLabelText( "Bounce" );
125 mActionButtons[1].SetLabelText( "X" );
126 mActionButtons[2].SetLabelText( "Y" );
128 contentLayout.Add( actionButtonLayout );
129 contentLayout.SetFitHeight(2);
133 bool TransitionApplication::OnActionButtonClicked( Button button )
135 int action = button.GetProperty<int>( mActionIndex );
140 mBeatControl.StartBounceAnimation();
145 mBeatControl.StartXAnimation();
150 mBeatControl.StartYAnimation();
158 void TransitionApplication::OnKeyEvent( const KeyEvent& keyEvent )
160 static int keyPressed = 0;
162 if( keyEvent.state == KeyEvent::Down)
164 if( keyPressed == 0 ) // Is this the first down event?
166 printf("Key pressed: %s %d\n", keyEvent.keyPressedName.c_str(), keyEvent.keyCode );
168 if( IsKey( keyEvent, DALI_KEY_ESCAPE) || IsKey( keyEvent, DALI_KEY_BACK ) )
172 else if( keyEvent.keyPressedName.compare("Return") == 0 )
178 else if( keyEvent.state == KeyEvent::Up )