/*
- * Copyright (c) 2019 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.
#include <dali-toolkit/dali-toolkit.h>
#include <iostream>
#include <dali-toolkit/devel-api/controls/control-devel.h>
+#include <dali-toolkit/devel-api/controls/scroll-bar/scroll-bar.h>
+#include <random> // std::default_random_engine
+#include <chrono> // std::chrono::system_clock
// INTERNAL INCLUDES
#include "grid-flags.h"
void ResourceReadySignal( Toolkit::Control control )
{
mImagesLoaded++;
- // To allow fast startup, we only place a small number of ImageViews on stage first
+ // To allow fast startup, we only place a small number of ImageViews on window first
if ( mImagesLoaded == INITIAL_IMAGES_TO_LOAD )
{
- // Adding the ImageViews to the stage will trigger loading of the Images
- mGridActor.Add( mOffStageImageViews );
+ // Adding the ImageViews to the window will trigger loading of the Images
+ mGridActor.Add( mOffWindowImageViews );
}
}
{
std::cout << "ImageScalingIrregularGridController::Create" << std::endl;
- // Get a handle to the stage:
- Stage stage = Stage::GetCurrent();
+ // Get a handle to the window:
+ Window window = application.GetWindow();
// Connect to input event signals:
- stage.KeyEventSignal().Connect(this, &ImageScalingIrregularGridController::OnKeyEvent);
-
- // Hide the indicator bar
- mApplication.GetWindow().ShowIndicator(Dali::Window::INVISIBLE);
+ window.KeyEventSignal().Connect(this, &ImageScalingIrregularGridController::OnKeyEvent);
// Create a default view with a default tool bar:
mContentLayer = DemoHelper::CreateView( mApplication,
SetTitle( APPLICATION_TITLE );
- mOffStageImageViews = Actor::New();
- mOffStageImageViews.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
- mOffStageImageViews.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER);
- mOffStageImageViews.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
+ mOffWindowImageViews = Actor::New();
+ mOffWindowImageViews.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
+ mOffWindowImageViews.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER);
+ mOffWindowImageViews.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
// Build the main content of the widow:
PopulateContentLayer( DEFAULT_SCALING_MODE );
*/
void PopulateContentLayer( const Dali::FittingMode::Type fittingMode )
{
- Stage stage = Stage::GetCurrent();
- Vector2 stageSize = stage.GetSize();
+ Window window = mApplication.GetWindow();
+ Vector2 windowSize = window.GetSize();
float fieldHeight;
- Actor imageField = BuildImageField( stageSize.x, GRID_WIDTH, GRID_MAX_HEIGHT, fittingMode, fieldHeight );
+ Actor imageField = BuildImageField( windowSize.x, GRID_WIDTH, GRID_MAX_HEIGHT, fittingMode, fieldHeight );
mScrollView = ScrollView::New();
// Restrict scrolling to mostly vertical only, but with some horizontal wiggle-room:
- RulerPtr rulerX = new FixedRuler( stageSize.width ); //< Pull the view back to the grid's centre-line when touch is release using a snapping ruler.
- rulerX->SetDomain( RulerDomain( stageSize.width * -0.125f, stageSize.width * 1.125f ) ); //< Scroll slightly left/right of image field.
+ RulerPtr rulerX = new FixedRuler( windowSize.width ); //< Pull the view back to the grid's centre-line when touch is release using a snapping ruler.
+ rulerX->SetDomain( RulerDomain( windowSize.width * -0.125f, windowSize.width * 1.125f ) ); //< Scroll slightly left/right of image field.
mScrollView.SetRulerX ( rulerX );
- RulerPtr rulerY = new DefaultRuler(); //< Snap in multiples of a screen / stage height
- rulerY->SetDomain( RulerDomain( - fieldHeight * 0.5f + stageSize.height * 0.5f - GRID_CELL_PADDING, fieldHeight * 0.5f + stageSize.height * 0.5f + GRID_CELL_PADDING ) );
+ RulerPtr rulerY = new DefaultRuler(); //< Snap in multiples of a screen / window height
+ rulerY->SetDomain( RulerDomain( - fieldHeight * 0.5f + windowSize.height * 0.5f - GRID_CELL_PADDING, fieldHeight * 0.5f + windowSize.height * 0.5f + GRID_CELL_PADDING ) );
mScrollView.SetRulerY ( rulerY );
mContentLayer.Add( mScrollView );
}
}
// Stir-up the list to get some nice irregularity in the generated field:
- std::random_shuffle( configurations.begin(), configurations.end() );
- std::random_shuffle( configurations.begin(), configurations.end() );
+ unsigned int seed = std::chrono::system_clock::now().time_since_epoch().count();
+ std::shuffle( configurations.begin(), configurations.end(), std::default_random_engine(seed) );
+ seed = std::chrono::system_clock::now().time_since_epoch().count();
+ std::shuffle( configurations.begin(), configurations.end(), std::default_random_engine(seed) );
// Place the images in the grid:
image.SetProperty( Actor::Property::SIZE, imageSize );
image.TouchSignal().Connect( this, &ImageScalingIrregularGridController::OnTouchImage );
image.ResourceReadySignal().Connect( this, &ImageScalingIrregularGridController::ResourceReadySignal );
- mFittingModes[image.GetId()] = fittingMode;
- mResourceUrls[image.GetId()] = imageSource.configuration.path;
- mSizes[image.GetId()] = imageSize;
+ mFittingModes[image.GetProperty< int >( Actor::Property::ID )] = fittingMode;
+ mResourceUrls[image.GetProperty< int >( Actor::Property::ID )] = imageSource.configuration.path;
+ mSizes[image.GetProperty< int >( Actor::Property::ID )] = imageSize;
if ( count < INITIAL_IMAGES_TO_LOAD )
{
gridActor.Add( image );
}
else
{
- // Store the ImageView in an offstage actor until the inital batch of ImageViews have finished loading their images
+ // Store the ImageView in an offwindow actor until the inital batch of ImageViews have finished loading their images
// Required
- mOffStageImageViews.Add( image );
+ mOffWindowImageViews.Add( image );
}
}
* @param[in] actor The actor touched
* @param[in] event The Touch information.
*/
- bool OnTouchImage( Actor actor, const TouchData& event )
+ bool OnTouchImage( Actor actor, const TouchEvent& event )
{
if( ( event.GetPointCount() > 0 ) && ( !mScrolling ) )
{
animation.Play();
// Change the scaling mode:
- const unsigned id = actor.GetId();
+ const unsigned id = actor.GetProperty< int >( Actor::Property::ID );
Dali::FittingMode::Type newMode = NextMode( mFittingModes[id] );
- const Vector2 imageSize = mSizes[actor.GetId()];
+ const Vector2 imageSize = mSizes[actor.GetProperty< int >( Actor::Property::ID )];
ImageView imageView = ImageView::DownCast( actor );
if( imageView)
*/
void OnKeyEvent(const KeyEvent& event)
{
- if( event.state == KeyEvent::Down )
+ if( event.GetState() == KeyEvent::Down )
{
if( IsKey( event, Dali::DALI_KEY_ESCAPE )
|| IsKey( event, Dali::DALI_KEY_BACK ) )
if( gridImageView )
{
// Cycle the scaling mode options:
- unsigned int id = gridImageView.GetId();
+ unsigned int id = gridImageView.GetProperty< int >( Actor::Property::ID );
const Vector2 imageSize = mSizes[ id ];
Dali::FittingMode::Type newMode = NextMode( mFittingModes[ id ] );
Toolkit::ToolBar mToolBar; ///< The View's Toolbar.
TextLabel mTitleActor; ///< The Toolbar's Title.
Actor mGridActor; ///< The container for the grid of images
- Actor mOffStageImageViews; ///< ImageViews held off stage until the inital batch have loaded their images
+ Actor mOffWindowImageViews; ///< ImageViews held off window until the inital batch have loaded their images
ScrollView mScrollView; ///< ScrollView UI Component
ScrollBar mScrollBarVertical;
ScrollBar mScrollBarHorizontal;