/*
- * 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,
toggleScalingButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, TOGGLE_SCALING_IMAGE );
toggleScalingButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, TOGGLE_SCALING_IMAGE_SELECTED );
toggleScalingButton.ClickedSignal().Connect( this, &ImageScalingIrregularGridController::OnToggleScalingTouched );
- mToolBar.AddControl( toggleScalingButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalRight, DemoHelper::DEFAULT_MODE_SWITCH_PADDING );
+ mToolBar.AddControl( toggleScalingButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HORIZONTAL_RIGHT, DemoHelper::DEFAULT_MODE_SWITCH_PADDING );
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 );
mGridActor = imageField;
// Create the scroll bar
- mScrollBarVertical = ScrollBar::New(Toolkit::ScrollBar::Vertical);
+ mScrollBarVertical = ScrollBar::New(Toolkit::ScrollBar::VERTICAL);
mScrollBarVertical.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::TOP_RIGHT);
mScrollBarVertical.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_RIGHT);
mScrollBarVertical.SetResizePolicy(Dali::ResizePolicy::FILL_TO_PARENT, Dali::Dimension::HEIGHT);
mScrollBarVertical.SetResizePolicy(Dali::ResizePolicy::FIT_TO_CHILDREN, Dali::Dimension::WIDTH);
mScrollView.Add(mScrollBarVertical);
- mScrollBarHorizontal = ScrollBar::New(Toolkit::ScrollBar::Horizontal);
+ mScrollBarHorizontal = ScrollBar::New(Toolkit::ScrollBar::HORIZONTAL);
mScrollBarHorizontal.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::BOTTOM_LEFT);
mScrollBarHorizontal.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
mScrollBarHorizontal.SetResizePolicy(Dali::ResizePolicy::FIT_TO_CHILDREN, Dali::Dimension::WIDTH);
- mScrollBarHorizontal.SetOrientation(Quaternion(Radian( 1.5f * Math::PI ), Vector3::ZAXIS));
+ mScrollBarHorizontal.SetProperty( Actor::Property::ORIENTATION, Quaternion( Quaternion( Radian( 1.5f * Math::PI ), Vector3::ZAXIS) ) );
mScrollView.Add(mScrollBarHorizontal);
mScrollView.OnRelayoutSignal().Connect( this, &ImageScalingIrregularGridController::OnScrollViewRelayout );
void OnScrollViewRelayout(Actor actor)
{
// Make the height of the horizontal scroll bar to be the same as the width of scroll view.
- mScrollBarHorizontal.SetSize(Vector2(0.0f, mScrollView.GetRelayoutSize( Dimension::WIDTH) ));
+ mScrollBarHorizontal.SetProperty( Actor::Property::SIZE, Vector2(0.0f, mScrollView.GetRelayoutSize( Dimension::WIDTH) ));
}
/**
}
}
// 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:
const Vector2 imagePosition = imageRegionCorner + Vector2( GRID_CELL_PADDING , GRID_CELL_PADDING ) + imageSize * 0.5f;
ImageView image = CreateImageView( imageSource.configuration.path, imageSize.x, imageSize.y, fittingMode );
- image.SetPosition( Vector3( imagePosition.x, imagePosition.y, 0 ) );
- image.SetSize( imageSize );
+ image.SetProperty( Actor::Property::POSITION, Vector3( imagePosition.x, imagePosition.y, 0 ) );
+ 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 ] );
{
mTitleActor = DemoHelper::CreateToolBarLabel( "" );
// Add title to the tool bar.
- mToolBar.AddControl( mTitleActor, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarTitlePercentage, Alignment::HorizontalCenter );
+ mToolBar.AddControl( mTitleActor, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarTitlePercentage, Alignment::HORIZONTAL_CENTER );
}
mTitleActor.SetProperty( TextLabel::Property::TEXT, title );
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;