X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=examples%2Fhomescreen-benchmark%2Fhomescreen-benchmark.cpp;h=f710406cd64cb05f5d024315438ca242bde09590;hb=1a473d5189ca7e7d55aca3a64a8a4ff2dc3b6c67;hp=4cc62ee92f065d5b6a48cd90ac157bc6dcc1f661;hpb=9c07eea9b135baf8b85b1096fccedf4cf1711bd5;p=platform%2Fcore%2Fuifw%2Fdali-demo.git diff --git a/examples/homescreen-benchmark/homescreen-benchmark.cpp b/examples/homescreen-benchmark/homescreen-benchmark.cpp index 4cc62ee..f710406 100644 --- a/examples/homescreen-benchmark/homescreen-benchmark.cpp +++ b/examples/homescreen-benchmark/homescreen-benchmark.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 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. @@ -21,6 +21,9 @@ #include #include +#include +#include + using namespace Dali; using Dali::Toolkit::TextLabel; @@ -45,9 +48,9 @@ const float DEFAULT_OPT_ROW_COUNT ( 5 ); const float DEFAULT_OPT_COL_COUNT ( 4 ); const float DEFAULT_OPT_PAGE_COUNT ( 10 ); const bool DEFAULT_OPT_USE_TABLEVIEW ( true ); -const bool DEFAULT_OPT_BATCHING_ENABLED ( true ); const bool DEFAULT_OPT_ICON_LABELS ( true ); const IconType DEFAULT_OPT_ICON_TYPE ( IMAGEVIEW ); +const bool DEFAULT_OPT_USE_TEXT_LABEL ( false ); // The image/label area tries to make sure the positioning will be relative to previous sibling const float IMAGE_AREA ( 0.60f ); @@ -111,9 +114,9 @@ public: mCols( DEFAULT_OPT_COL_COUNT ), mPageCount( DEFAULT_OPT_PAGE_COUNT ), mTableViewEnabled( DEFAULT_OPT_USE_TABLEVIEW ), - mBatchingEnabled( DEFAULT_OPT_BATCHING_ENABLED ), mIconLabelsEnabled( DEFAULT_OPT_ICON_LABELS ), - mIconType( DEFAULT_OPT_ICON_TYPE ) + mIconType( DEFAULT_OPT_ICON_TYPE ), + mUseTextLabel( DEFAULT_OPT_USE_TEXT_LABEL ) { } @@ -121,9 +124,9 @@ public: int mCols; int mPageCount; bool mTableViewEnabled; - bool mBatchingEnabled; bool mIconLabelsEnabled; IconType mIconType; + bool mUseTextLabel; }; // animation script data @@ -161,30 +164,33 @@ public: // Create benchmark script CreateScript(); - // Get a handle to the stage - Stage stage = Stage::GetCurrent(); + // Get a handle to the window + Window window = application.GetWindow(); mScrollParent = Actor::New(); mScrollParent.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - mScrollParent.SetAnchorPoint( AnchorPoint::CENTER ); - mScrollParent.SetParentOrigin( ParentOrigin::CENTER ); + mScrollParent.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); + mScrollParent.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); // create background Toolkit::ImageView background = Toolkit::ImageView::New( BACKGROUND_IMAGE ); - Stage::GetCurrent().Add( background ); + window.Add( background ); background.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - background.SetAnchorPoint( AnchorPoint::CENTER ); - background.SetParentOrigin( ParentOrigin::CENTER ); + background.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); + background.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); PopulatePages(); - stage.Add( mScrollParent ); + window.Add( mScrollParent ); + + // Respond to a click anywhere on the window. + window.GetRootLayer().TouchedSignal().Connect( this, &HomescreenBenchmark::OnTouch ); - // Respond to a click anywhere on the stage. - stage.GetRootLayer().TouchSignal().Connect( this, &HomescreenBenchmark::OnTouch ); + // Respond to key events + window.KeyEventSignal().Connect( this, &HomescreenBenchmark::OnKeyEvent ); } - bool OnTouch( Actor actor, const TouchData& touch ) + bool OnTouch( Actor actor, const TouchEvent& touch ) { // Quit the application. mApplication.Quit(); @@ -194,26 +200,22 @@ public: Actor AddPage() { // Create root page actor. - Actor pageActor; + Toolkit::Control pageActor; if( mConfig.mTableViewEnabled ) { - Toolkit::TableView tableView = Toolkit::TableView::New( mConfig.mRows, mConfig.mCols ); - - // Create geometry batcher for table view. - tableView.SetBackgroundColor( Vector4( 0.0f, 0.0f, 0.0f, 0.5f ) ); - pageActor = tableView; + pageActor = Toolkit::TableView::New( mConfig.mRows, mConfig.mCols ); } else { pageActor = Toolkit::Control::New(); - pageActor.SetProperty( Toolkit::Control::Property::BACKGROUND_COLOR, Vector4( 0.0f, 0.0f, 0.0f, 0.5f ) ); } - pageActor.SetParentOrigin( ParentOrigin::CENTER ); - pageActor.SetAnchorPoint( AnchorPoint::CENTER ); + pageActor.SetBackgroundColor( Vector4( 0.0f, 0.0f, 0.0f, 0.5f ) ); + pageActor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); + pageActor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); pageActor.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS ); - pageActor.SetSizeModeFactor( Vector3( PAGE_SCALE_FACTOR_X, PAGE_SCALE_FACTOR_Y, 1.0f ) ); + pageActor.SetProperty( Actor::Property::SIZE_MODE_FACTOR, Vector3( PAGE_SCALE_FACTOR_X, PAGE_SCALE_FACTOR_Y, 1.0f ) ); return pageActor; } @@ -228,15 +230,12 @@ public: imagePath << IMAGE_PATH_PREFIX << currentIconIndex << IMAGE_PATH_POSTFIX; map[ Dali::Toolkit::ImageVisual::Property::URL ] = imagePath.str(); - // Enable/disable batching - map[ Toolkit::ImageVisual::Property::BATCHING_ENABLED ] = mConfig.mBatchingEnabled; - imageView.SetProperty( Toolkit::ImageView::Property::IMAGE, map ); imageView.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS ); - imageView.SetSizeScalePolicy( SizeScalePolicy::FIT_WITH_ASPECT_RATIO ); - imageView.SetAnchorPoint( AnchorPoint::CENTER ); - imageView.SetParentOrigin( ParentOrigin::CENTER ); - imageView.SetSizeModeFactor( Vector3( IMAGE_AREA, IMAGE_AREA, 1.0f ) ); + imageView.SetProperty( Actor::Property::SIZE_SCALE_POLICY, SizeScalePolicy::FIT_WITH_ASPECT_RATIO ); + imageView.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); + imageView.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); + imageView.SetProperty( Actor::Property::SIZE_MODE_FACTOR, Vector3( IMAGE_AREA, IMAGE_AREA, 1.0f ) ); return imageView; } @@ -245,24 +244,26 @@ public: { Toolkit::CheckBoxButton button = Toolkit::CheckBoxButton::New(); button.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS ); - button.SetSizeScalePolicy( SizeScalePolicy::FIT_WITH_ASPECT_RATIO ); - button.SetAnchorPoint( AnchorPoint::CENTER ); - button.SetParentOrigin( ParentOrigin::CENTER ); + button.SetProperty( Actor::Property::SIZE_SCALE_POLICY, SizeScalePolicy::FIT_WITH_ASPECT_RATIO ); + button.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); + button.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); button.SetProperty( Toolkit::Button::Property::SELECTED, ( currentIconIndex % 2 == 0 ) ); // Select half the button return button; } - void AddIconsToPage( Actor page ) + void AddIconsToPage( Actor page, bool useTextLabel ) { - Size stageSize( Stage::GetCurrent().GetSize() ); - const float scaledHeight = stageSize.y * PAGE_SCALE_FACTOR_Y; - const float scaledWidth = stageSize.x * PAGE_SCALE_FACTOR_X; - const float PADDING = stageSize.y / 64.0f; + Window window = mApplication.GetWindow(); + + Size windowSize( window.GetSize() ); + const float scaledHeight = windowSize.y * PAGE_SCALE_FACTOR_Y; + const float scaledWidth = windowSize.x * PAGE_SCALE_FACTOR_X; + const float PADDING = windowSize.y / 64.0f; const float ROW_HEIGHT = ( scaledHeight - (PADDING*2.0f) ) / static_cast( mConfig.mRows ); const float COL_WIDTH = ( scaledWidth - (PADDING*2.0f) ) / static_cast( mConfig.mCols ); - Vector2 dpi = Stage::GetCurrent().GetDpi(); + Vector2 dpi = window.GetDpi(); static int currentIconIndex = 0; @@ -272,20 +273,20 @@ public: { // Create parent icon view Toolkit::Control iconView = Toolkit::Control::New(); - iconView.SetAnchorPoint( AnchorPoint::TOP_LEFT ); - iconView.SetParentOrigin( ParentOrigin::TOP_LEFT ); + iconView.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); + iconView.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT ); if( !mConfig.mTableViewEnabled ) { float rowX = x * COL_WIDTH + PADDING; float rowY = y * ROW_HEIGHT + PADDING; - iconView.SetSize( Vector3( COL_WIDTH, ROW_HEIGHT, 1.0f ) ); - iconView.SetPosition( Vector3( rowX, rowY, 0.0f ) ); + iconView.SetProperty( Actor::Property::SIZE, Vector3( COL_WIDTH, ROW_HEIGHT, 1.0f ) ); + iconView.SetProperty( Actor::Property::POSITION, Vector3( rowX, rowY, 0.0f ) ); } else { iconView.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS ); - iconView.SetSizeScalePolicy( SizeScalePolicy::FIT_WITH_ASPECT_RATIO ); + iconView.SetProperty( Actor::Property::SIZE_SCALE_POLICY, SizeScalePolicy::FIT_WITH_ASPECT_RATIO ); } Actor icon; @@ -307,15 +308,34 @@ public: if( mConfig.mIconLabelsEnabled ) { // create label - Toolkit::TextLabel textLabel = Toolkit::TextLabel::New( DEMO_APPS_NAMES[currentIconIndex] ); - textLabel.SetAnchorPoint( AnchorPoint::TOP_CENTER ); - textLabel.SetParentOrigin( ParentOrigin::BOTTOM_CENTER ); - textLabel.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); - textLabel.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) ); // White. - textLabel.SetProperty( Toolkit::TextLabel::Property::POINT_SIZE, ( ( static_cast( ROW_HEIGHT * LABEL_AREA ) * 72.0f ) / dpi.y ) * 0.25f ); - textLabel.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" ); - textLabel.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "TOP" ); - icon.Add( textLabel ); + if( useTextLabel ) + { + Toolkit::TextLabel textLabel = Toolkit::TextLabel::New( DEMO_APPS_NAMES[currentIconIndex] ); + textLabel.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER ); + textLabel.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER ); + textLabel.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); + textLabel.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) ); // White. + textLabel.SetProperty( Toolkit::TextLabel::Property::POINT_SIZE, ( ( static_cast( ROW_HEIGHT * LABEL_AREA ) * 72.0f ) / dpi.y ) * 0.25f ); + textLabel.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" ); + textLabel.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "TOP" ); + icon.Add( textLabel ); + } + else + { + Property::Map map; + map.Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::TEXT ). + Add( Toolkit::TextVisual::Property::TEXT, DEMO_APPS_NAMES[currentIconIndex] ). + Add( Toolkit::TextVisual::Property::TEXT_COLOR, Color::WHITE ). + Add( Toolkit::TextVisual::Property::POINT_SIZE, ( ( static_cast( ROW_HEIGHT * LABEL_AREA ) * 72.0f ) / dpi.y ) * 0.25f ). + Add( Toolkit::TextVisual::Property::HORIZONTAL_ALIGNMENT, "CENTER" ). + Add( Toolkit::TextVisual::Property::VERTICAL_ALIGNMENT, "TOP" ); + + Toolkit::Control control = Toolkit::Control::New(); + control.SetProperty( Toolkit::Control::Property::BACKGROUND, map ); + control.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER ); + control.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER ); + icon.Add( control ); + } } iconView.Add( icon ); @@ -355,7 +375,7 @@ public: void PopulatePages() { - Vector3 stageSize( Stage::GetCurrent().GetSize() ); + Vector3 windowSize( mApplication.GetWindow().GetSize() ); for( int i = 0; i < mConfig.mPageCount; ++i ) { @@ -363,22 +383,17 @@ public: Actor page = AddPage(); // Populate icons. - AddIconsToPage( page ); + AddIconsToPage( page, mConfig.mUseTextLabel ); // Move page 'a little bit up'. - page.SetParentOrigin( ParentOrigin::CENTER ); - page.SetAnchorPoint( AnchorPoint::CENTER ); - page.SetPosition( Vector3( stageSize.x * i, 0.0f, 0.0f ) ); + page.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); + page.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); + page.SetProperty( Actor::Property::POSITION, Vector3( windowSize.x * i, 0.0f, 0.0f ) ); mScrollParent.Add( page ); - - if( mConfig.mTableViewEnabled && mConfig.mBatchingEnabled ) - { - page.SetProperty( DevelActor::Property::BATCH_PARENT, true ); - } } - mScrollParent.SetOpacity( 1.0f ); - mScrollParent.SetScale( Vector3::ONE ); + mScrollParent.SetProperty( Actor::Property::OPACITY, 1.0f ); + mScrollParent.SetProperty( Actor::Property::SCALE, Vector3::ONE ); // Fade in. ShowAnimation(); @@ -396,18 +411,18 @@ public: void ScrollPages(int pages, float duration, bool flick) { duration *= PAGE_DURATION_SCALE_FACTOR; - Vector3 stageSize( Stage::GetCurrent().GetSize() ); + Vector3 windowSize( mApplication.GetWindow().GetSize() ); mScrollAnimation = Animation::New( duration ); if( flick ) { - mScrollAnimation.AnimateBy( Property( mScrollParent, Actor::Property::POSITION ), Vector3( -stageSize.x * pages, 0.0f, 0.0f ), AlphaFunction::EASE_IN_OUT ); + mScrollAnimation.AnimateBy( Property( mScrollParent, Actor::Property::POSITION ), Vector3( -windowSize.x * pages, 0.0f, 0.0f ), AlphaFunction::EASE_IN_OUT ); } else { int totalPages = abs( pages ); for( int i = 0; i < totalPages; ++i ) { - mScrollAnimation.AnimateBy( Property( mScrollParent, Actor::Property::POSITION ), Vector3( pages < 0 ? stageSize.x : -stageSize.x, 0.0f, 0.0f ), AlphaFunction::EASE_IN_OUT, TimePeriod( duration * i, duration ) ); + mScrollAnimation.AnimateBy( Property( mScrollParent, Actor::Property::POSITION ), Vector3( pages < 0 ? windowSize.x : -windowSize.x, 0.0f, 0.0f ), AlphaFunction::EASE_IN_OUT, TimePeriod( duration * i, duration ) ); } } mScrollAnimation.FinishedSignal().Connect( this, &HomescreenBenchmark::OnAnimationEnd ); @@ -429,6 +444,17 @@ public: } } + void OnKeyEvent( const KeyEvent& event ) + { + if( event.GetState() == KeyEvent::DOWN ) + { + if ( IsKey( event, Dali::DALI_KEY_ESCAPE ) || IsKey( event, Dali::DALI_KEY_BACK ) ) + { + mApplication.Quit(); + } + } + } + private: Application& mApplication; @@ -441,26 +467,6 @@ private: int mCurrentPage; }; -void RunTest( Application& application, const HomescreenBenchmark::Config& config, bool printHelpAndExit ) -{ - HomescreenBenchmark test( application, config ); - - if( printHelpAndExit ) - { - PrintHelp( "c", " Number of columns" ); - PrintHelp( "r", " Number of rows" ); - PrintHelp( "p", " Number of pages ( must be greater than 1 )" ); - PrintHelp( "-disable-tableview", " Disables the use of TableView for layouting (must be enabled for batching)" ); - PrintHelp( "-disable-batching", " Disables geometry batching" ); - PrintHelp( "-disable-icon-labels", " Disables labels for each icon" ); - PrintHelp( "-use-checkbox", " Uses checkboxes for icons" ); - return; - } - - application.MainLoop(); -} - -// Entry point for Linux & Tizen applications. int DALI_EXPORT_API main( int argc, char **argv ) { // Default settings. @@ -487,10 +493,6 @@ int DALI_EXPORT_API main( int argc, char **argv ) { config.mTableViewEnabled = false; } - else if( arg.compare( "--disable-batching" ) == 0 ) - { - config.mBatchingEnabled = false; - } else if( arg.compare( "--disable-icon-labels" ) == 0 ) { config.mIconLabelsEnabled = false; @@ -499,15 +501,32 @@ int DALI_EXPORT_API main( int argc, char **argv ) { config.mIconType = CHECKBOX; } - else if ( arg.compare( "--help" ) == 0 ) + else if( arg.compare("--use-text-label" ) == 0) + { + config.mUseTextLabel = true; + } + else if( arg.compare( "--help" ) == 0 ) { printHelpAndExit = true; } } Application application = Application::New( &argc, &argv ); + HomescreenBenchmark test( application, config ); + + if( printHelpAndExit ) + { + PrintHelp( "c", " Number of columns" ); + PrintHelp( "r", " Number of rows" ); + PrintHelp( "p", " Number of pages ( must be greater than 1 )" ); + PrintHelp( "-disable-tableview", " Disables the use of TableView for layouting" ); + PrintHelp( "-disable-icon-labels", " Disables labels for each icon" ); + PrintHelp( "-use-checkbox", " Uses checkboxes for icons" ); + PrintHelp( "-use-text-label", " Uses TextLabel instead of a TextVisual" ); + return 0; + } - RunTest( application, config, printHelpAndExit ); + application.MainLoop(); return 0; }