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 ),
47 mActionIndex( Property::INVALID_INDEX )
49 application.InitSignal().Connect( this, &TransitionApplication::Create );
52 TransitionApplication::~TransitionApplication()
56 void TransitionApplication::Create( Application& application )
58 Stage stage = Stage::GetCurrent();
59 stage.KeyEventSignal().Connect(this, &TransitionApplication::OnKeyEvent);
60 stage.SetBackgroundColor( Vector4( 0.1f, 0.1f, 0.1f, 1.0f ) );
62 // Hide the indicator bar
63 application.GetWindow().ShowIndicator( Dali::Window::INVISIBLE );
66 TableView contentLayout = TableView::New( 3, 1 );
67 contentLayout.SetName("ContentLayout");
68 contentLayout.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
69 contentLayout.SetAnchorPoint( AnchorPoint::TOP_LEFT );
70 contentLayout.SetParentOrigin( ParentOrigin::TOP_LEFT );
71 contentLayout.SetCellPadding( Size( 10, 10 ) );
73 // Assign all rows the size negotiation property of fitting to children
75 stage.Add( contentLayout );
77 mTitle = TextLabel::New( "Custom Control Transition Example" );
78 mTitle.SetName( "Title" );
79 mTitle.SetStyleName("Title");
80 mTitle.SetAnchorPoint( AnchorPoint::TOP_CENTER );
81 mTitle.SetParentOrigin( ParentOrigin::TOP_CENTER );
82 mTitle.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
83 mTitle.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
84 mTitle.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
85 contentLayout.Add( mTitle );
86 contentLayout.SetFitHeight(0);
88 mBeatControl = BeatControl::New();
89 mBeatControl.SetName("BeatControl");
90 mBeatControl.SetAnchorPoint( AnchorPoint::CENTER );
91 mBeatControl.SetParentOrigin( ParentOrigin::CENTER );
92 mBeatControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
93 contentLayout.Add( mBeatControl );
94 // beat control should fill the tableview cell, so no change to default parameters
96 TableView actionButtonLayout = TableView::New( 1, 4 );
97 actionButtonLayout.SetName("ThemeButtonsLayout");
98 actionButtonLayout.SetCellPadding( Vector2( 6.0f, 0.0f ) );
100 actionButtonLayout.SetAnchorPoint( AnchorPoint::CENTER );
101 actionButtonLayout.SetParentOrigin( ParentOrigin::CENTER );
102 actionButtonLayout.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
103 actionButtonLayout.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::HEIGHT );
104 actionButtonLayout.SetCellPadding( Size( 10, 10 ) );
105 actionButtonLayout.SetFitHeight( 0 );
107 TextLabel label = TextLabel::New( "Action: ");
108 label.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
109 label.SetStyleName("ActionLabel");
110 label.SetAnchorPoint( AnchorPoint::TOP_CENTER );
111 label.SetParentOrigin( ParentOrigin::TOP_CENTER );
112 actionButtonLayout.AddChild( label, TableView::CellPosition( 0, 0 ) );
113 actionButtonLayout.SetCellAlignment( TableView::CellPosition( 0, 0 ), HorizontalAlignment::LEFT, VerticalAlignment::CENTER );
115 for( int i=0; i<3; ++i )
117 mActionButtons[i] = PushButton::New();
118 mActionButtons[i].SetName("ActionButton");
119 mActionButtons[i].SetStyleName("ActionButton");
120 mActionButtons[i].SetParentOrigin( ParentOrigin::CENTER );
121 mActionButtons[i].SetAnchorPoint( ParentOrigin::CENTER );
122 mActionButtons[i].SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
123 mActionButtons[i].SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
124 mActionIndex = mActionButtons[i].RegisterProperty( "actionId", i, Property::READ_WRITE );
125 mActionButtons[i].ClickedSignal().Connect( this, &TransitionApplication::OnActionButtonClicked );
126 actionButtonLayout.AddChild( mActionButtons[i], TableView::CellPosition( 0, 1+i ) );
128 mActionButtons[0].SetLabelText( "Bounce" );
129 mActionButtons[1].SetLabelText( "X" );
130 mActionButtons[2].SetLabelText( "Y" );
132 contentLayout.Add( actionButtonLayout );
133 contentLayout.SetFitHeight(2);
137 bool TransitionApplication::OnActionButtonClicked( Button button )
139 int action = button.GetProperty<int>( mActionIndex );
144 mBeatControl.StartBounceAnimation();
149 mBeatControl.StartXAnimation();
154 mBeatControl.StartYAnimation();
162 void TransitionApplication::OnKeyEvent( const KeyEvent& keyEvent )
164 static int keyPressed = 0;
166 if( keyEvent.state == KeyEvent::Down)
168 if( keyPressed == 0 ) // Is this the first down event?
170 printf("Key pressed: %s %d\n", keyEvent.keyPressedName.c_str(), keyEvent.keyCode );
172 if( IsKey( keyEvent, DALI_KEY_ESCAPE) || IsKey( keyEvent, DALI_KEY_BACK ) )
176 else if( keyEvent.keyPressedName.compare("Return") == 0 )
182 else if( keyEvent.state == KeyEvent::Up )