X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=examples%2Frendering-textured-cube%2Frendering-textured-cube.cpp;h=cc20719d9348d933426d94b0d5bb9b0490df050b;hb=cc6ea8d9723ab3a5415bb550acfbf27501de7a62;hp=eeda48b96fe2c12b49bbe5164d0aa8aa507ece42;hpb=94d678d62ca15faaced5deaf379f9ea4a6f16b7d;p=platform%2Fcore%2Fuifw%2Fdali-demo.git diff --git a/examples/rendering-textured-cube/rendering-textured-cube.cpp b/examples/rendering-textured-cube/rendering-textured-cube.cpp index eeda48b..cc20719 100644 --- a/examples/rendering-textured-cube/rendering-textured-cube.cpp +++ b/examples/rendering-textured-cube/rendering-textured-cube.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 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. @@ -82,9 +82,9 @@ public: // The Init signal is received once (only) during the Application lifetime void Create( Application& application ) { - // Get a handle to the stage - Stage stage = Stage::GetCurrent(); - stage.SetBackgroundColor( Color::WHITE ); + // Get a handle to the window + Window window = application.GetWindow(); + window.SetBackgroundColor( Color::WHITE ); // Step 1. Create shader CreateCubeShader(); @@ -104,8 +104,11 @@ public: // Step 6. Play animation to rotate the cube PlayAnimation(); - // Respond to a click anywhere on the stage - stage.GetRootLayer().TouchSignal().Connect( this, &TexturedCubeController::OnTouch ); + // Respond to a click anywhere on the window + window.GetRootLayer().TouchSignal().Connect( this, &TexturedCubeController::OnTouch ); + + // Respond to key events + window.KeyEventSignal().Connect( this, &TexturedCubeController::OnKeyEvent ); } bool OnTouch( Actor actor, const TouchData& touch ) @@ -116,6 +119,23 @@ public: } /** + * @brief Called when any key event is received + * + * Will use this to quit the application if Back or the Escape key is received + * @param[in] event The key event information + */ + void OnKeyEvent( const KeyEvent& event ) + { + if( event.state == KeyEvent::Down ) + { + if ( IsKey( event, Dali::DALI_KEY_ESCAPE ) || IsKey( event, Dali::DALI_KEY_BACK ) ) + { + mApplication.Quit(); + } + } + } + + /** * @brief CreateCubeGeometry * This function creates a cube geometry including texture coordinates. * Also it demonstrates using the indexed draw feature by setting an index array. @@ -241,16 +261,16 @@ public: */ void CreateActor() { - Stage stage = Stage::GetCurrent(); + Window window = mApplication.GetWindow(); - float quarterStageWidth = stage.GetSize().x * 0.25f; + float quarterWindowWidth = window.GetSize().GetWidth() * 0.25f; mActor = Actor::New(); - mActor.SetAnchorPoint( AnchorPoint::CENTER ); - mActor.SetParentOrigin( ParentOrigin::CENTER ); - mActor.SetPosition( Vector3( 0.0f, 0.0f, 0.0f ) ); - mActor.SetSize( Vector3( quarterStageWidth, quarterStageWidth, quarterStageWidth ) ); + mActor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); + mActor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); + mActor.SetProperty( Actor::Property::POSITION, Vector3( 0.0f, 0.0f, 0.0f ) ); + mActor.SetProperty( Actor::Property::SIZE, Vector3( quarterWindowWidth, quarterWindowWidth, quarterWindowWidth ) ); mActor.AddRenderer( mRenderer ); - stage.Add( mActor ); + window.Add( mActor ); } /** @@ -277,20 +297,10 @@ private: Animation mAnimation; }; -void RunTest( Application& application ) -{ - TexturedCubeController test( application ); - - application.MainLoop(); -} - -// Entry point for Linux & Tizen applications -// int DALI_EXPORT_API main( int argc, char **argv ) { Application application = Application::New( &argc, &argv ); - - RunTest( application ); - + TexturedCubeController test( application ); + application.MainLoop(); return 0; }