/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2019 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 <algorithm>
#include <map>
#include <dali-toolkit/dali-toolkit.h>
-#include <dali-toolkit/devel-api/controls/buttons/button-devel.h>
#include <iostream>
+#include <dali-toolkit/devel-api/controls/control-devel.h>
// INTERNAL INCLUDES
#include "grid-flags.h"
NULL
};
const unsigned NUM_IMAGE_PATHS = sizeof(IMAGE_PATHS) / sizeof(IMAGE_PATHS[0]) - 1u;
-
+const unsigned int INITIAL_IMAGES_TO_LOAD = 10;
/**
map[Toolkit::ImageVisual::Property::FITTING_MODE] = fittingMode;
imageView.SetProperty( Toolkit::ImageView::Property::IMAGE, map );
- imageView.SetName( filename );
- imageView.SetParentOrigin(ParentOrigin::CENTER);
- imageView.SetAnchorPoint(AnchorPoint::CENTER);
+ imageView.SetProperty( Dali::Actor::Property::NAME, filename );
+ imageView.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER);
+ imageView.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::CENTER);
return imageView;
}
ImageScalingIrregularGridController( Application& application )
: mApplication( application ),
- mScrolling( false )
+ mScrolling( false ),
+ mImagesLoaded( 0 )
{
std::cout << "ImageScalingIrregularGridController::ImageScalingIrregularGridController" << std::endl;
}
/**
+ * Called everytime an ImageView has loaded it's image
+ */
+ void ResourceReadySignal( Toolkit::Control control )
+ {
+ mImagesLoaded++;
+ // To allow fast startup, we only place a small number of ImageViews on stage first
+ if ( mImagesLoaded == INITIAL_IMAGES_TO_LOAD )
+ {
+ // Adding the ImageViews to the stage will trigger loading of the Images
+ mGridActor.Add( mOffStageImageViews );
+ }
+ }
+
+
+ /**
* One-time setup in response to Application InitSignal.
*/
void Create( Application& application )
// Create an image scaling toggle button. (right of toolbar)
Toolkit::PushButton toggleScalingButton = Toolkit::PushButton::New();
- toggleScalingButton.SetProperty( Toolkit::DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL, TOGGLE_SCALING_IMAGE );
- toggleScalingButton.SetProperty( Toolkit::DevelButton::Property::SELECTED_BACKGROUND_VISUAL, TOGGLE_SCALING_IMAGE_SELECTED );
+ 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 );
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 );
+
// Build the main content of the widow:
PopulateContentLayer( DEFAULT_SCALING_MODE );
}
mScrollView.ScrollStartedSignal().Connect( this, &ImageScalingIrregularGridController::OnScrollStarted );
mScrollView.ScrollCompletedSignal().Connect( this, &ImageScalingIrregularGridController::OnScrollCompleted );
- mScrollView.SetAnchorPoint(AnchorPoint::CENTER);
- mScrollView.SetParentOrigin(ParentOrigin::CENTER);
+ mScrollView.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::CENTER);
+ mScrollView.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER);
mScrollView.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
// Create the scroll bar
mScrollBarVertical = ScrollBar::New(Toolkit::ScrollBar::Vertical);
- mScrollBarVertical.SetParentOrigin(ParentOrigin::TOP_RIGHT);
- mScrollBarVertical.SetAnchorPoint(AnchorPoint::TOP_RIGHT);
+ 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.SetParentOrigin(ParentOrigin::BOTTOM_LEFT);
- mScrollBarHorizontal.SetAnchorPoint(AnchorPoint::TOP_LEFT);
+ 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) ));
}
/**
Actor gridActor = Actor::New();
gridActor.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
- gridActor.SetParentOrigin( ParentOrigin::CENTER );
- gridActor.SetAnchorPoint( AnchorPoint::CENTER );
+ gridActor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
+ gridActor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
// Work out the constants of the grid and cell dimensions and positions:
const float cellWidth = fieldWidth / gridWidth;
outFieldHeight = actualGridHeight * cellHeight;
const Vector2 gridOrigin = Vector2( -fieldWidth * 0.5f, -outFieldHeight * 0.5 );
+ unsigned int count = 0;
// Build the image actors in their right locations in their parent's frame:
- for( std::vector<PositionedImage>::const_iterator i = placedImages.begin(), end = placedImages.end(); i != end; ++i )
+ for( std::vector<PositionedImage>::const_iterator i = placedImages.begin(), end = placedImages.end(); i != end; ++i, ++count )
{
const PositionedImage& imageSource = *i;
const Vector2 imageSize = imageSource.imageGridDims * cellSize - Vector2( GRID_CELL_PADDING * 2, GRID_CELL_PADDING * 2 );
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;
-
- gridActor.Add( image );
+ 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
+ // Required
+ mOffStageImageViews.Add( image );
+ }
}
return gridActor;
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
ScrollView mScrollView; ///< ScrollView UI Component
ScrollBar mScrollBarVertical;
ScrollBar mScrollBarHorizontal;
std::map<unsigned, Dali::FittingMode::Type> mFittingModes; ///< Stores the current scaling mode of each image, keyed by image actor id.
std::map<unsigned, std::string> mResourceUrls; ///< Stores the url of each image, keyed by image actor id.
std::map<unsigned, Vector2> mSizes; ///< Stores the current size of each image, keyed by image actor id.
+ unsigned int mImagesLoaded; ///< How many images have been loaded
};
-void RunTest( Application& application )
-{
- ImageScalingIrregularGridController 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, DEMO_THEME_PATH );
-
- RunTest( application );
-
+ ImageScalingIrregularGridController test( application );
+ application.MainLoop();
return 0;
}