/* * Copyright (c) 2017 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * @file transition-application.cpp * @brief Application class for showing stylable transitions */ // Class include #include "transition-application.h" // External includes #include #include "beat-control.h" #include #include // Internal includes using namespace Dali; using namespace Dali::Toolkit; namespace { void SetLabelText( Button button, const char* label ) { button.SetProperty( Toolkit::Button::Property::LABEL, label ); } } namespace Demo { const char* TransitionApplication::DEMO_THEME_ONE_PATH( DEMO_STYLE_DIR "style-example-theme-one.json" ); const char* DALI_LOGO_PATH( DEMO_IMAGE_DIR "Logo-for-demo.png" ); const char* DALI_ROBOT_MODEL_PATH( DEMO_MODEL_DIR "ToyRobot-Metal.obj" ); const char* DALI_ROBOT_MATERIAL_PATH( DEMO_MODEL_DIR "ToyRobot-Metal.mtl" ); TransitionApplication::TransitionApplication( Application& application ) : mApplication( application ), mTitle(), mBeatControl(), mActionButtons(), mVisualIndex( Property::INVALID_INDEX ), mActionIndex( Property::INVALID_INDEX ) { application.InitSignal().Connect( this, &TransitionApplication::Create ); } TransitionApplication::~TransitionApplication() { } void TransitionApplication::Create( Application& application ) { Stage stage = Stage::GetCurrent(); stage.KeyEventSignal().Connect(this, &TransitionApplication::OnKeyEvent); stage.SetBackgroundColor( Vector4( 0.1f, 0.1f, 0.1f, 1.0f ) ); // Hide the indicator bar application.GetWindow().ShowIndicator( Dali::Window::INVISIBLE ); // Content panes: TableView contentLayout = TableView::New( 4, 1 ); contentLayout.SetName("ContentLayout"); contentLayout.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); contentLayout.SetAnchorPoint( AnchorPoint::TOP_LEFT ); contentLayout.SetParentOrigin( ParentOrigin::TOP_LEFT ); contentLayout.SetCellPadding( Vector2( 0.0f, 5.0f ) ); // Assign all rows the size negotiation property of fitting to children stage.Add( contentLayout ); mTitle = TextLabel::New( "Custom Control Transition Example" ); mTitle.SetName( "Title" ); mTitle.SetStyleName("Title"); mTitle.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); mTitle.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT ); mTitle.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" ); contentLayout.Add( mTitle ); contentLayout.SetFitHeight(0); // Fill width mBeatControl = BeatControl::New(); mBeatControl.SetName("BeatControl"); mBeatControl.SetProperty( BeatControl::Property::BEAT_VISUAL, Property::Map() .Add( Visual::Property::TRANSFORM, Property::Map() .Add( Visual::Transform::Property::SIZE, Vector2(0.5f, 0.5f) ) ) ); mBeatControl.SetAnchorPoint( AnchorPoint::CENTER ); mBeatControl.SetParentOrigin( ParentOrigin::CENTER ); mBeatControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); contentLayout.Add( mBeatControl ); // beat control should fill the tableview cell, so no change to default parameters TableView visualTypeLayout = TableView::New( 1, NUMBER_OF_VISUAL_BUTTONS ); visualTypeLayout.SetName("VisualTypeLayout"); visualTypeLayout.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); visualTypeLayout.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::HEIGHT ); visualTypeLayout.SetFitHeight( 0 ); contentLayout.Add( visualTypeLayout ); contentLayout.SetFitHeight(2); for( int i=0; i( mVisualIndex ); Property::Map map; CreateVisualMap( visual, map ); map.Add( Visual::Property::TRANSFORM, Property::Map() .Add( Visual::Transform::Property::SIZE, Vector2( 0.5f, 0.5f ) ) ); mBeatControl.SetProperty( BeatControl::Property::BEAT_VISUAL, map ); } return true; } bool TransitionApplication::OnActionButtonClicked( Button button ) { int action = button.GetProperty( mActionIndex ); switch( action ) { case 0: { mBeatControl.StartBounceAnimation(); break; } case 1: { mBeatControl.StartXAnimation(); break; } case 2: { mBeatControl.StartYAnimation(); break; } case 3: { mBeatControl.StartFadeAnimation(); break; } } return true; } void TransitionApplication::OnKeyEvent( const KeyEvent& keyEvent ) { static int keyPressed = 0; if( keyEvent.state == KeyEvent::Down) { if( keyPressed == 0 ) // Is this the first down event? { printf("Key pressed: %s %d\n", keyEvent.keyPressedName.c_str(), keyEvent.keyCode ); if( IsKey( keyEvent, DALI_KEY_ESCAPE) || IsKey( keyEvent, DALI_KEY_BACK ) ) { mApplication.Quit(); } else if( keyEvent.keyPressedName.compare("Return") == 0 ) { } } keyPressed = 1; } else if( keyEvent.state == KeyEvent::Up ) { keyPressed = 0; } } } // namespace Demo