X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=examples%2Fitem-view%2Fitem-view-example.cpp;h=95378a7eb7eab78d891068f5bf5dd19724f89c8b;hb=1b19fd140ff139b5854a1a62447faf31b175d8f6;hp=448735c084de8e71d63c249e1bee92421ae6fea9;hpb=3429cdb9f1fc3864dff4505bf42012e2f09fb6f4;p=platform%2Fcore%2Fuifw%2Fdali-demo.git diff --git a/examples/item-view/item-view-example.cpp b/examples/item-view/item-view-example.cpp index 448735c..95378a7 100644 --- a/examples/item-view/item-view-example.cpp +++ b/examples/item-view/item-view-example.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 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. @@ -16,22 +16,17 @@ */ #include -#include -#include -#include -#include -#include // rand #include "shared/view.h" -#include #include +#include +#include using namespace Dali; using namespace Dali::Toolkit; namespace { - enum AllImagesLayouts { SPIRAL_LAYOUT, @@ -42,153 +37,121 @@ enum AllImagesLayouts }; const char* IMAGE_PATHS[] = { - DALI_IMAGE_DIR "gallery-medium-1.jpg", - DALI_IMAGE_DIR "gallery-medium-2.jpg", - DALI_IMAGE_DIR "gallery-medium-3.jpg", - DALI_IMAGE_DIR "gallery-medium-4.jpg", - DALI_IMAGE_DIR "gallery-medium-5.jpg", - DALI_IMAGE_DIR "gallery-medium-6.jpg", - DALI_IMAGE_DIR "gallery-medium-7.jpg", - DALI_IMAGE_DIR "gallery-medium-8.jpg", - DALI_IMAGE_DIR "gallery-medium-9.jpg", - DALI_IMAGE_DIR "gallery-medium-10.jpg", - DALI_IMAGE_DIR "gallery-medium-11.jpg", - DALI_IMAGE_DIR "gallery-medium-12.jpg", - DALI_IMAGE_DIR "gallery-medium-13.jpg", - DALI_IMAGE_DIR "gallery-medium-14.jpg", - DALI_IMAGE_DIR "gallery-medium-15.jpg", - DALI_IMAGE_DIR "gallery-medium-16.jpg", - DALI_IMAGE_DIR "gallery-medium-17.jpg", - DALI_IMAGE_DIR "gallery-medium-18.jpg", - DALI_IMAGE_DIR "gallery-medium-19.jpg", - DALI_IMAGE_DIR "gallery-medium-20.jpg", - DALI_IMAGE_DIR "gallery-medium-21.jpg", - DALI_IMAGE_DIR "gallery-medium-22.jpg", - DALI_IMAGE_DIR "gallery-medium-23.jpg", - DALI_IMAGE_DIR "gallery-medium-24.jpg", - DALI_IMAGE_DIR "gallery-medium-25.jpg", - DALI_IMAGE_DIR "gallery-medium-26.jpg", - DALI_IMAGE_DIR "gallery-medium-27.jpg", - DALI_IMAGE_DIR "gallery-medium-28.jpg", - DALI_IMAGE_DIR "gallery-medium-29.jpg", - DALI_IMAGE_DIR "gallery-medium-30.jpg", - DALI_IMAGE_DIR "gallery-medium-31.jpg", - DALI_IMAGE_DIR "gallery-medium-32.jpg", - DALI_IMAGE_DIR "gallery-medium-33.jpg", - DALI_IMAGE_DIR "gallery-medium-34.jpg", - DALI_IMAGE_DIR "gallery-medium-35.jpg", - DALI_IMAGE_DIR "gallery-medium-36.jpg", - DALI_IMAGE_DIR "gallery-medium-37.jpg", - DALI_IMAGE_DIR "gallery-medium-38.jpg", - DALI_IMAGE_DIR "gallery-medium-39.jpg", - DALI_IMAGE_DIR "gallery-medium-40.jpg", - DALI_IMAGE_DIR "gallery-medium-41.jpg", - DALI_IMAGE_DIR "gallery-medium-42.jpg", - DALI_IMAGE_DIR "gallery-medium-43.jpg", - DALI_IMAGE_DIR "gallery-medium-44.jpg", - DALI_IMAGE_DIR "gallery-medium-45.jpg", - DALI_IMAGE_DIR "gallery-medium-46.jpg", - DALI_IMAGE_DIR "gallery-medium-47.jpg", - DALI_IMAGE_DIR "gallery-medium-48.jpg", - DALI_IMAGE_DIR "gallery-medium-49.jpg", - DALI_IMAGE_DIR "gallery-medium-50.jpg", - DALI_IMAGE_DIR "gallery-medium-51.jpg", - DALI_IMAGE_DIR "gallery-medium-52.jpg", - DALI_IMAGE_DIR "gallery-medium-53.jpg", + DEMO_IMAGE_DIR "gallery-medium-1.jpg", + DEMO_IMAGE_DIR "gallery-medium-2.jpg", + DEMO_IMAGE_DIR "gallery-medium-3.jpg", + DEMO_IMAGE_DIR "gallery-medium-4.jpg", + DEMO_IMAGE_DIR "gallery-medium-5.jpg", + DEMO_IMAGE_DIR "gallery-medium-6.jpg", + DEMO_IMAGE_DIR "gallery-medium-7.jpg", + DEMO_IMAGE_DIR "gallery-medium-8.jpg", + DEMO_IMAGE_DIR "gallery-medium-9.jpg", + DEMO_IMAGE_DIR "gallery-medium-10.jpg", + DEMO_IMAGE_DIR "gallery-medium-11.jpg", + DEMO_IMAGE_DIR "gallery-medium-12.jpg", + DEMO_IMAGE_DIR "gallery-medium-13.jpg", + DEMO_IMAGE_DIR "gallery-medium-14.jpg", + DEMO_IMAGE_DIR "gallery-medium-15.jpg", + DEMO_IMAGE_DIR "gallery-medium-16.jpg", + DEMO_IMAGE_DIR "gallery-medium-17.jpg", + DEMO_IMAGE_DIR "gallery-medium-18.jpg", + DEMO_IMAGE_DIR "gallery-medium-19.jpg", + DEMO_IMAGE_DIR "gallery-medium-20.jpg", + DEMO_IMAGE_DIR "gallery-medium-21.jpg", + DEMO_IMAGE_DIR "gallery-medium-22.jpg", + DEMO_IMAGE_DIR "gallery-medium-23.jpg", + DEMO_IMAGE_DIR "gallery-medium-24.jpg", + DEMO_IMAGE_DIR "gallery-medium-25.jpg", + DEMO_IMAGE_DIR "gallery-medium-26.jpg", + DEMO_IMAGE_DIR "gallery-medium-27.jpg", + DEMO_IMAGE_DIR "gallery-medium-28.jpg", + DEMO_IMAGE_DIR "gallery-medium-29.jpg", + DEMO_IMAGE_DIR "gallery-medium-30.jpg", + DEMO_IMAGE_DIR "gallery-medium-31.jpg", + DEMO_IMAGE_DIR "gallery-medium-32.jpg", + DEMO_IMAGE_DIR "gallery-medium-33.jpg", + DEMO_IMAGE_DIR "gallery-medium-34.jpg", + DEMO_IMAGE_DIR "gallery-medium-35.jpg", + DEMO_IMAGE_DIR "gallery-medium-36.jpg", + DEMO_IMAGE_DIR "gallery-medium-37.jpg", + DEMO_IMAGE_DIR "gallery-medium-38.jpg", + DEMO_IMAGE_DIR "gallery-medium-39.jpg", + DEMO_IMAGE_DIR "gallery-medium-40.jpg", + DEMO_IMAGE_DIR "gallery-medium-41.jpg", + DEMO_IMAGE_DIR "gallery-medium-42.jpg", + DEMO_IMAGE_DIR "gallery-medium-43.jpg", + DEMO_IMAGE_DIR "gallery-medium-44.jpg", + DEMO_IMAGE_DIR "gallery-medium-45.jpg", + DEMO_IMAGE_DIR "gallery-medium-46.jpg", + DEMO_IMAGE_DIR "gallery-medium-47.jpg", + DEMO_IMAGE_DIR "gallery-medium-48.jpg", + DEMO_IMAGE_DIR "gallery-medium-49.jpg", + DEMO_IMAGE_DIR "gallery-medium-50.jpg", + DEMO_IMAGE_DIR "gallery-medium-51.jpg", + DEMO_IMAGE_DIR "gallery-medium-52.jpg", + DEMO_IMAGE_DIR "gallery-medium-53.jpg", }; const unsigned int NUM_IMAGES = sizeof(IMAGE_PATHS) / sizeof(char*); -const unsigned int IMAGE_WIDTH = 256; -const unsigned int IMAGE_HEIGHT = 256; -const unsigned int NUM_IMAGE_PER_ROW_IN_ATLAS = 8; - -AlphaFunction ALPHA_FUNCTIONS[] = { AlphaFunctions::Linear, - AlphaFunctions::EaseIn, - AlphaFunctions::EaseOut }; - -const unsigned int NUM_ALPHA_FUNCTIONS = sizeof(ALPHA_FUNCTIONS) / sizeof(AlphaFunction); - -const char* ALPHA_FUNCTIONS_TEXT[] = { "Linear", - "EaseIn", - "EaseOut" }; - -const char* BACKGROUND_IMAGE( "" ); -const char* TOOLBAR_IMAGE( DALI_IMAGE_DIR "top-bar.png" ); -const char* EDIT_IMAGE( DALI_IMAGE_DIR "icon-edit.png" ); -const char* SPIRAL_LAYOUT_IMAGE( DALI_IMAGE_DIR "icon-item-view-layout-spiral.png" ); -const char* GRID_LAYOUT_IMAGE( DALI_IMAGE_DIR "icon-item-view-layout-grid.png" ); -const char* DEPTH_LAYOUT_IMAGE( DALI_IMAGE_DIR "icon-item-view-layout-depth.png" ); -const char* DELETE_IMAGE( DALI_IMAGE_DIR "icon-delete.png" ); -const char* REPLACE_IMAGE( DALI_IMAGE_DIR "icon-replace.png" ); -const char* INSERT_IMAGE( DALI_IMAGE_DIR "icon-insert.png" ); -const char* SELECTED_IMAGE( DALI_IMAGE_DIR "item-select-check.png" ); -const char* APPLICATION_TITLE( "ItemView" ); +const char* BACKGROUND_IMAGE(""); +const char* TOOLBAR_IMAGE(DEMO_IMAGE_DIR "top-bar.png"); +const char* EDIT_IMAGE(DEMO_IMAGE_DIR "icon-edit.png"); +const char* EDIT_IMAGE_SELECTED(DEMO_IMAGE_DIR "icon-edit-selected.png"); +const char* SPIRAL_LAYOUT_IMAGE(DEMO_IMAGE_DIR "icon-item-view-layout-spiral.png"); +const char* SPIRAL_LAYOUT_IMAGE_SELECTED(DEMO_IMAGE_DIR "icon-item-view-layout-spiral-selected.png"); +const char* GRID_LAYOUT_IMAGE(DEMO_IMAGE_DIR "icon-item-view-layout-grid.png"); +const char* GRID_LAYOUT_IMAGE_SELECTED(DEMO_IMAGE_DIR "icon-item-view-layout-grid-selected.png"); +const char* DEPTH_LAYOUT_IMAGE(DEMO_IMAGE_DIR "icon-item-view-layout-depth.png"); +const char* DEPTH_LAYOUT_IMAGE_SELECTED(DEMO_IMAGE_DIR "icon-item-view-layout-depth-selected.png"); +const char* DELETE_IMAGE(DEMO_IMAGE_DIR "icon-delete.png"); +const char* DELETE_IMAGE_SELECTED(DEMO_IMAGE_DIR "icon-delete-selected.png"); +const char* REPLACE_IMAGE(DEMO_IMAGE_DIR "icon-replace.png"); +const char* REPLACE_IMAGE_SELECTED(DEMO_IMAGE_DIR "icon-replace-selected.png"); +const char* INSERT_IMAGE(DEMO_IMAGE_DIR "icon-insert.png"); +const char* INSERT_IMAGE_SELECTED(DEMO_IMAGE_DIR "icon-insert-selected.png"); +const char* SELECTED_IMAGE(DEMO_IMAGE_DIR "item-select-check.png"); +const char* APPLICATION_TITLE("ItemView"); const char* SPIRAL_LABEL("Spiral"); const char* GRID_LABEL("Grid"); const char* DEPTH_LABEL("Depth"); -const char* ITEM_BORDER_IMAGE_PATH( DALI_IMAGE_DIR "frame-128x128.png" ); -const Vector3 ITEM_BORDER_MARGIN_SIZE(24, 24, 0); - -// These values depend on the border image -const float ITEM_IMAGE_BORDER_LEFT = 13.0f; -const float ITEM_IMAGE_BORDER_RIGHT = 13.0f; -const float ITEM_IMAGE_BORDER_TOP = 13.0f; -const float ITEM_IMAGE_BORDER_BOTTOM = 13.0f; - -const unsigned int DEPTH_LAYOUT_ROWS_PORTRAIT = 26; -const unsigned int DEPTH_LAYOUT_ROWS_LANDSCAPE = 16; -const float DEPTH_LAYOUT_TILT_ANGLE_PORTRAIT = 25.0f; -const float DEPTH_LAYOUT_TILT_ANGLE_LANDSCAPE = 21.0f; -const float DEPTH_LAYOUT_ROW_SPACING_FACTOR = 0.1f; -const float DEPTH_LAYOUT_ITEM_SIZE_FACTOR_PORTRAIT = 1.0f; -const float DEPTH_LAYOUT_ITEM_SIZE_FACTOR_LANDSCAPE = 0.8f; -const float DEPTH_LAYOUT_BOTTOM_MARGIN_FACTOR_PORTRAIT = 0.2f; -const float DEPTH_LAYOUT_BOTTOM_MARGIN_FACTOR_LANDSCAPE = 0.1f; +const float ITEM_BORDER_SIZE = 2.0f; -const float SPIRAL_LAYOUT_REVOLUTION_NUMBER_PORTRAIT = 4.5f; -const float SPIRAL_LAYOUT_REVOLUTION_NUMBER_LANDSCAPE = 2.5f; +const float DEPTH_LAYOUT_ITEM_SIZE_FACTOR_PORTRAIT = 1.0f; +const float DEPTH_LAYOUT_ITEM_SIZE_FACTOR_LANDSCAPE = 0.8f; +const float DEPTH_LAYOUT_COLUMNS = 3.0f; -const float DEPTH_LAYOUT_HEIGHT_SCALE = 20.0f; const float MIN_SWIPE_DISTANCE = 15.0f; -const float MIN_SWIPE_SPEED = 5.0f; +const float MIN_SWIPE_SPEED = 5.0f; const float SELECTION_BORDER_WIDTH = 3.0f; -const float BUTTON_BORDER = -10.0f; +const float BUTTON_BORDER = -10.0f; const float MENU_OPTION_HEIGHT(140.0f); const float LABEL_TEXT_SIZE_Y = 20.0f; -const Vector3 INITIAL_OFFSCREEN_POSITION( 1000.0f, 0, -1000.0f ); +const Vector3 INITIAL_OFFSCREEN_POSITION(1000.0f, 0, -1000.0f); + +const float SCROLL_TO_ITEM_ANIMATION_TIME = 5.f; -static Vector3 DepthLayoutItemSizeFunctionPortrait(unsigned int numberOfColumns, float layoutWidth) +static Vector3 DepthLayoutItemSizeFunctionPortrait(float layoutWidth) { - float width = (layoutWidth / static_cast(numberOfColumns + 1)) * DEPTH_LAYOUT_ITEM_SIZE_FACTOR_PORTRAIT; + float width = (layoutWidth / (DEPTH_LAYOUT_COLUMNS + 1.0f)) * DEPTH_LAYOUT_ITEM_SIZE_FACTOR_PORTRAIT; // 1x1 aspect ratio return Vector3(width, width, width); } -static Vector3 DepthLayoutItemSizeFunctionLandscape(unsigned int numberOfColumns, float layoutWidth) +static Vector3 DepthLayoutItemSizeFunctionLandscape(float layoutWidth) { - float width = (layoutWidth / static_cast(numberOfColumns + 1)) * DEPTH_LAYOUT_ITEM_SIZE_FACTOR_LANDSCAPE; + float width = (layoutWidth / (DEPTH_LAYOUT_COLUMNS + 1.0f)) * DEPTH_LAYOUT_ITEM_SIZE_FACTOR_LANDSCAPE; // 1x1 aspect ratio return Vector3(width, width, width); } -static float DepthLayoutBottomMarginFunctionPortrait(float layoutHeight) -{ - return layoutHeight * DEPTH_LAYOUT_BOTTOM_MARGIN_FACTOR_PORTRAIT; -} - -static float DepthLayoutBottomMarginFunctionLandscape(float layoutHeight) -{ - return layoutHeight * DEPTH_LAYOUT_BOTTOM_MARGIN_FACTOR_LANDSCAPE; -} - -} +} // unnamed namespace /** * This example shows how to use ItemView UI control. @@ -199,7 +162,6 @@ static float DepthLayoutBottomMarginFunctionLandscape(float layoutHeight) class ItemViewExample : public ConnectionTracker, public ItemFactory { public: - enum Mode { MODE_NORMAL, @@ -216,14 +178,12 @@ public: * Constructor * @param application class, stored as reference */ - ItemViewExample( Application& application ) - : mApplication( application ), - mMode( MODE_NORMAL ), - mMenuShown( false ), - mOrientation( 0 ), - mCurrentLayout( SPIRAL_LAYOUT ), - mDurationSeconds( 1.0f ), - mAlphaFuncIndex( 0u ) + ItemViewExample(Application& application) + : mApplication(application), + mMode(MODE_NORMAL), + mOrientation(0), + mCurrentLayout(SPIRAL_LAYOUT), + mDurationSeconds(0.25f) { // Connect to the Application's Init signal mApplication.InitSignal().Connect(this, &ItemViewExample::OnInit); @@ -234,97 +194,96 @@ public: */ void OnInit(Application& app) { - DemoHelper::RequestThemeChange(); - - Stage stage = Dali::Stage::GetCurrent(); - stage.KeyEventSignal().Connect(this, &ItemViewExample::OnKeyEvent); + Window window = app.GetWindow(); + window.KeyEventSignal().Connect(this, &ItemViewExample::OnKeyEvent); + window.GetRootLayer().SetProperty(Layer::Property::BEHAVIOR, Layer::LAYER_3D); - Vector2 stageSize = Stage::GetCurrent().GetSize(); - - // Create a border image shared by all the item actors - mBorderImage = ResourceImage::New(ITEM_BORDER_IMAGE_PATH); + Vector2 windowSize = window.GetSize(); // Creates a default view with a default tool bar. - // The view is added to the stage. - Layer contents = DemoHelper::CreateView( mApplication, - mView, - mToolBar, - BACKGROUND_IMAGE, - TOOLBAR_IMAGE, - "" ); + // The view is added to the window. - mView.OrientationAnimationStartedSignal().Connect( this, &ItemViewExample::OnOrientationChanged ); + Layer contents = DemoHelper::CreateView(mApplication, + mView, + mToolBar, + BACKGROUND_IMAGE, + TOOLBAR_IMAGE, + ""); // Create an edit mode button. (left of toolbar) Toolkit::PushButton editButton = Toolkit::PushButton::New(); - editButton.SetBackgroundImage( ResourceImage::New( EDIT_IMAGE ) ); - editButton.ClickedSignal().Connect( this, &ItemViewExample::OnModeButtonClicked); - editButton.SetLeaveRequired( true ); - mToolBar.AddControl( editButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalLeft, DemoHelper::DEFAULT_MODE_SWITCH_PADDING ); + editButton.SetProperty(Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, EDIT_IMAGE); + editButton.SetProperty(Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, EDIT_IMAGE_SELECTED); + editButton.ClickedSignal().Connect(this, &ItemViewExample::OnModeButtonClicked); + editButton.SetProperty(Actor::Property::LEAVE_REQUIRED, true); + mToolBar.AddControl(editButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HORIZONTAL_LEFT, DemoHelper::DEFAULT_MODE_SWITCH_PADDING); // Create a layout toggle button. (right of toolbar) mLayoutButton = Toolkit::PushButton::New(); - mLayoutButton.SetBackgroundImage( ResourceImage::New( SPIRAL_LAYOUT_IMAGE ) ); - mLayoutButton.ClickedSignal().Connect( this, &ItemViewExample::OnLayoutButtonClicked); - mLayoutButton.SetLeaveRequired( true ); - mToolBar.AddControl( mLayoutButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalRight, DemoHelper::DEFAULT_MODE_SWITCH_PADDING ); + mLayoutButton.SetProperty(Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, SPIRAL_LAYOUT_IMAGE); + mLayoutButton.SetProperty(Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, SPIRAL_LAYOUT_IMAGE_SELECTED); + mLayoutButton.ClickedSignal().Connect(this, &ItemViewExample::OnLayoutButtonClicked); + mLayoutButton.SetProperty(Actor::Property::LEAVE_REQUIRED, true); + mToolBar.AddControl(mLayoutButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HORIZONTAL_RIGHT, DemoHelper::DEFAULT_MODE_SWITCH_PADDING); // Create a delete button (bottom right of screen) mDeleteButton = Toolkit::PushButton::New(); - mDeleteButton.SetParentOrigin(ParentOrigin::BOTTOM_RIGHT); - mDeleteButton.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT); - mDeleteButton.SetPosition( BUTTON_BORDER, BUTTON_BORDER ); - mDeleteButton.SetDrawMode( DrawMode::OVERLAY ); - mDeleteButton.SetButtonImage( ResourceImage::New( DELETE_IMAGE ) ); - mDeleteButton.SetBackgroundImage( ResourceImage::New( TOOLBAR_IMAGE ) ); - mDeleteButton.SetSize( Vector2( stageSize.width * 0.15f, stageSize.width * 0.15f ) ); - mDeleteButton.ClickedSignal().Connect( this, &ItemViewExample::OnDeleteButtonClicked); - mDeleteButton.SetLeaveRequired( true ); - mDeleteButton.SetVisible( false ); - stage.Add( mDeleteButton ); + mDeleteButton.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_RIGHT); + mDeleteButton.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_RIGHT); + mDeleteButton.SetProperty(Actor::Property::POSITION, Vector2(BUTTON_BORDER, BUTTON_BORDER)); + mDeleteButton.SetProperty(Actor::Property::DRAW_MODE, DrawMode::OVERLAY_2D); + mDeleteButton.SetProperty(Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, DELETE_IMAGE); + mDeleteButton.SetProperty(Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, DELETE_IMAGE_SELECTED); + mDeleteButton.SetProperty(Toolkit::Control::Property::BACKGROUND, TOOLBAR_IMAGE); + mDeleteButton.SetProperty(Actor::Property::SIZE, Vector2(windowSize.width * 0.15f, windowSize.width * 0.15f)); + mDeleteButton.ClickedSignal().Connect(this, &ItemViewExample::OnDeleteButtonClicked); + mDeleteButton.SetProperty(Actor::Property::LEAVE_REQUIRED, true); + mDeleteButton.SetProperty(Actor::Property::VISIBLE, false); + window.Add(mDeleteButton); // Create an insert button (bottom right of screen) mInsertButton = Toolkit::PushButton::New(); - mInsertButton.SetParentOrigin(ParentOrigin::BOTTOM_RIGHT); - mInsertButton.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT); - mInsertButton.SetPosition( BUTTON_BORDER, BUTTON_BORDER ); - mInsertButton.SetDrawMode( DrawMode::OVERLAY ); - mInsertButton.SetButtonImage( ResourceImage::New( INSERT_IMAGE ) ); - mInsertButton.SetBackgroundImage( ResourceImage::New( TOOLBAR_IMAGE ) ); - mInsertButton.SetSize( stageSize.width * 0.15f, stageSize.width * 0.15f ); - mInsertButton.ClickedSignal().Connect( this, &ItemViewExample::OnInsertButtonClicked); - mInsertButton.SetLeaveRequired( true ); - mInsertButton.SetVisible( false ); - stage.Add( mInsertButton ); + mInsertButton.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_RIGHT); + mInsertButton.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_RIGHT); + mInsertButton.SetProperty(Actor::Property::POSITION, Vector2(BUTTON_BORDER, BUTTON_BORDER)); + mInsertButton.SetProperty(Actor::Property::DRAW_MODE, DrawMode::OVERLAY_2D); + mInsertButton.SetProperty(Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, INSERT_IMAGE); + mInsertButton.SetProperty(Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, INSERT_IMAGE_SELECTED); + mInsertButton.SetProperty(Toolkit::Control::Property::BACKGROUND, TOOLBAR_IMAGE); + mInsertButton.SetProperty(Actor::Property::SIZE, Vector2(windowSize.width * 0.15f, windowSize.width * 0.15f)); + mInsertButton.ClickedSignal().Connect(this, &ItemViewExample::OnInsertButtonClicked); + mInsertButton.SetProperty(Actor::Property::LEAVE_REQUIRED, true); + mInsertButton.SetProperty(Actor::Property::VISIBLE, false); + window.Add(mInsertButton); // Create an replace button (bottom right of screen) mReplaceButton = Toolkit::PushButton::New(); - mReplaceButton.SetParentOrigin(ParentOrigin::BOTTOM_RIGHT); - mReplaceButton.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT); - mReplaceButton.SetPosition( BUTTON_BORDER, BUTTON_BORDER ); - mReplaceButton.SetDrawMode( DrawMode::OVERLAY ); - mReplaceButton.SetButtonImage( ResourceImage::New( REPLACE_IMAGE ) ); - mReplaceButton.SetBackgroundImage( ResourceImage::New( TOOLBAR_IMAGE ) ); - mReplaceButton.SetSize( stageSize.width * 0.15f, stageSize.width * 0.15f ); - mReplaceButton.ClickedSignal().Connect( this, &ItemViewExample::OnReplaceButtonClicked); - mReplaceButton.SetLeaveRequired( true ); - mReplaceButton.SetVisible( false ); - stage.Add( mReplaceButton ); + mReplaceButton.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_RIGHT); + mReplaceButton.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_RIGHT); + mReplaceButton.SetProperty(Actor::Property::POSITION, Vector2(BUTTON_BORDER, BUTTON_BORDER)); + mReplaceButton.SetProperty(Actor::Property::DRAW_MODE, DrawMode::OVERLAY_2D); + mReplaceButton.SetProperty(Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, REPLACE_IMAGE); + mReplaceButton.SetProperty(Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, REPLACE_IMAGE_SELECTED); + mReplaceButton.SetProperty(Toolkit::Control::Property::BACKGROUND, TOOLBAR_IMAGE); + mReplaceButton.SetProperty(Actor::Property::SIZE, Vector2(windowSize.width * 0.15f, windowSize.width * 0.15f)); + mReplaceButton.ClickedSignal().Connect(this, &ItemViewExample::OnReplaceButtonClicked); + mReplaceButton.SetProperty(Actor::Property::LEAVE_REQUIRED, true); + mReplaceButton.SetProperty(Actor::Property::VISIBLE, false); + window.Add(mReplaceButton); // Create the item view actor - mImageAtlas = CreateImageAtlas(); mItemView = ItemView::New(*this); - mItemView.SetRelayoutEnabled( false ); - mItemView.SetParentOrigin(ParentOrigin::CENTER); - mItemView.SetAnchorPoint(AnchorPoint::CENTER); + mItemView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mItemView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); - // Display item view on the stage - stage.Add( mItemView ); + // Display item view on the window + window.Add(mItemView); + window.GetRootLayer().SetProperty(Layer::Property::BEHAVIOR, Layer::LAYER_3D); // Create the layouts - mSpiralLayout = SpiralLayout::New(); - mDepthLayout = DepthLayout::New(); - mGridLayout = GridLayout::New(); + mSpiralLayout = DefaultItemLayout::New(DefaultItemLayout::SPIRAL); + mDepthLayout = DefaultItemLayout::New(DefaultItemLayout::DEPTH); + mGridLayout = DefaultItemLayout::New(DefaultItemLayout::GRID); // Add the layouts to item view mItemView.AddLayout(*mSpiralLayout); @@ -335,21 +294,22 @@ public: mItemView.SetMinimumSwipeSpeed(MIN_SWIPE_SPEED); // Activate the spiral layout - UseLayout(mCurrentLayout, 0.0f); - mItemView.SetKeyboardFocusable( true ); - KeyboardFocusManager::Get().PreFocusChangeSignal().Connect( this, &ItemViewExample::OnKeyboardPreFocusChange ); + SetLayout(mCurrentLayout); + mItemView.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true); + KeyboardFocusManager::Get().PreFocusChangeSignal().Connect(this, &ItemViewExample::OnKeyboardPreFocusChange); // Set the title and icon to the current layout SetLayoutTitle(); SetLayoutImage(); - // Store one 1x1 white image for multiple items to share for backgrounds: - mWhiteImage = BufferImage::WHITE(); + mLongPressDetector = LongPressGestureDetector::New(); + mLongPressDetector.Attach(mItemView); + mLongPressDetector.DetectedSignal().Connect(this, &ItemViewExample::OnLongPress); } - Actor OnKeyboardPreFocusChange( Actor current, Actor proposed, Control::KeyboardFocusNavigationDirection direction ) + Actor OnKeyboardPreFocusChange(Actor current, Actor proposed, Control::KeyboardFocus::Direction direction) { - if ( !current && !proposed ) + if(!current && !proposed) { return mItemView; } @@ -358,49 +318,61 @@ public: } /** - * Switch to a different item view layout + * Animate to a different layout */ - void UseLayout(int layoutId, float duration) + void ChangeLayout() { - // Set the new orientation to the layout - mItemView.GetLayout(layoutId)->SetOrientation(static_cast(mOrientation / 90)); + Animation animation = Animation::New(mDurationSeconds); + animation.FinishedSignal().Connect(this, &ItemViewExample::AnimationFinished); + animation.AnimateTo(Property(mItemView, Actor::Property::COLOR_ALPHA), 0.0f); + animation.Play(); + } - Vector2 stageSize = Stage::GetCurrent().GetSize(); + void AnimationFinished(Animation&) + { + SetLayout(mCurrentLayout); + + Animation animation = Animation::New(mDurationSeconds); + animation.AnimateTo(Property(mItemView, Actor::Property::COLOR_ALPHA), 1.0f); + animation.Play(); + } - if(layoutId == SPIRAL_LAYOUT) + /** + * Switch to a different item view layout + */ + void SetLayout(int layoutId) + { + Window window = mApplication.GetWindow(); + switch(mCurrentLayout) { - mSpiralLayout->SetRevolutionDistance(stageSize.height / Stage::GetCurrent().GetDpi().y * 45.0f); + case SPIRAL_LAYOUT: + case DEPTH_LAYOUT: + { + window.GetRootLayer().SetProperty(Layer::Property::BEHAVIOR, Layer::LAYER_3D); + break; + } + case GRID_LAYOUT: + { + window.GetRootLayer().SetProperty(Layer::Property::BEHAVIOR, Layer::LAYER_UI); + break; + } } - if(layoutId == GRID_LAYOUT) - { - // Set up the grid layout according to the new orientation - float layoutWidth = Toolkit::IsHorizontal(mGridLayout->GetOrientation()) ? stageSize.height : stageSize.width; - float gridItemSize = (layoutWidth / mGridLayout->GetNumberOfColumns()) * 0.5f; - mGridLayout->SetScrollSpeedFactor(mGridLayout->GetNumberOfColumns() / gridItemSize); + // Set the new orientation to the layout + mItemView.GetLayout(layoutId)->SetOrientation(static_cast(mOrientation / 90)); - float toolbarHeight = mToolBar.GetCurrentSize().y; - mGridLayout->SetTopMargin(toolbarHeight + mGridLayout->GetRowSpacing()); - } + Vector2 windowSize = window.GetSize(); if(layoutId == DEPTH_LAYOUT) { // Set up the depth layout according to the new orientation if(Toolkit::IsVertical(mDepthLayout->GetOrientation())) { - mDepthLayout->SetRowSpacing(stageSize.height * DEPTH_LAYOUT_ROW_SPACING_FACTOR); - mDepthLayout->SetNumberOfRows(DEPTH_LAYOUT_ROWS_PORTRAIT); - mDepthLayout->SetTiltAngle( Degree( DEPTH_LAYOUT_TILT_ANGLE_PORTRAIT - mDepthLayout->GetNumberOfColumns() ) ); - mDepthLayout->SetItemSizeFunction(DepthLayoutItemSizeFunctionPortrait); - mDepthLayout->SetBottomMarginFunction(DepthLayoutBottomMarginFunctionPortrait); + mDepthLayout->SetItemSize(DepthLayoutItemSizeFunctionPortrait(windowSize.width)); } else { - mDepthLayout->SetRowSpacing(stageSize.width * DEPTH_LAYOUT_ROW_SPACING_FACTOR); - mDepthLayout->SetNumberOfRows(DEPTH_LAYOUT_ROWS_LANDSCAPE); - mDepthLayout->SetTiltAngle( Degree( DEPTH_LAYOUT_TILT_ANGLE_LANDSCAPE - mDepthLayout->GetNumberOfColumns() ) ); - mDepthLayout->SetItemSizeFunction(DepthLayoutItemSizeFunctionLandscape); - mDepthLayout->SetBottomMarginFunction(DepthLayoutBottomMarginFunctionLandscape); + mDepthLayout->SetItemSize(DepthLayoutItemSizeFunctionLandscape(windowSize.height)); } } @@ -408,33 +380,15 @@ public: mItemView.SetAnchoring(layoutId == DEPTH_LAYOUT); // Activate the layout - mItemView.ActivateLayout(layoutId, Vector3(stageSize.x, stageSize.y, stageSize.x), duration); + mItemView.ActivateLayout(layoutId, Vector3(windowSize.x, windowSize.y, windowSize.x), 0.0f); } - /** - * Orientation changed signal callback - * @param orientation - */ - void OnOrientationChanged( View view, Animation& animation, const Orientation& orientation ) - { - const unsigned int angle = orientation.GetDegrees(); - - // If orientation really changed - if( mOrientation != angle ) - { - // Remember orientation - mOrientation = angle; - - UseLayout(mCurrentLayout, mDurationSeconds); - } - } - - bool OnLayoutButtonClicked( Toolkit::Button button ) + bool OnLayoutButtonClicked(Toolkit::Button button) { // Switch to the next layout mCurrentLayout = (mCurrentLayout + 1) % mItemView.GetLayoutCount(); - UseLayout(mCurrentLayout, mDurationSeconds); + ChangeLayout(); SetLayoutTitle(); SetLayoutImage(); @@ -442,7 +396,7 @@ public: return true; } - bool OnModeButtonClicked( Toolkit::Button button ) + bool OnModeButtonClicked(Toolkit::Button button) { SwitchToNextMode(); @@ -451,7 +405,7 @@ public: void SwitchToNextMode() { - switch( mMode ) + switch(mMode) { case MODE_REMOVE: { @@ -517,12 +471,12 @@ public: mTapDetector = TapGestureDetector::New(); - for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i ) + for(unsigned int i = 0u; i < mItemView.GetChildCount(); ++i) { mTapDetector.Attach(mItemView.GetChildAt(i)); } - mTapDetector.DetectedSignal().Connect( this, &ItemViewExample::RemoveOnTap ); + mTapDetector.DetectedSignal().Connect(this, &ItemViewExample::RemoveOnTap); } void ExitRemoveMode() @@ -530,85 +484,114 @@ public: mTapDetector.Reset(); } - void RemoveOnTap( Actor actor, const TapGesture& tap ) + void RemoveOnTap(Actor actor, const TapGesture& tap) { - mItemView.RemoveItem( mItemView.GetItemId(actor), 0.5f ); + mItemView.RemoveItem(mItemView.GetItemId(actor), 0.5f); } void EnterRemoveManyMode() { SetTitle("Edit: Remove Many"); - mDeleteButton.SetVisible( true ); + mDeleteButton.SetProperty(Actor::Property::VISIBLE, true); mTapDetector = TapGestureDetector::New(); - for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i ) + for(unsigned int i = 0u; i < mItemView.GetChildCount(); ++i) { - Actor child = mItemView.GetChildAt( i ); - Actor box = child.FindChildByName( "CheckBox" ); + Actor child = mItemView.GetChildAt(i); + Actor box = child.FindChildByName("CheckBox"); - if( box ) + if(box) { - mTapDetector.Attach( child ); - box.SetVisible( true ); + mTapDetector.Attach(child); + box.SetProperty(Actor::Property::VISIBLE, true); } } - mTapDetector.DetectedSignal().Connect( this, &ItemViewExample::SelectOnTap ); + mTapDetector.DetectedSignal().Connect(this, &ItemViewExample::SelectOnTap); } void ExitRemoveManyMode() { - for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i ) + for(unsigned int i = 0u; i < mItemView.GetChildCount(); ++i) { - Actor child = mItemView.GetChildAt( i ); - Actor box = child.FindChildByName( "CheckBox" ); + Actor child = mItemView.GetChildAt(i); + Actor box = child.FindChildByName("CheckBox"); - if( box ) + if(box) { - box.SetVisible( false ); + box.SetProperty(Actor::Property::VISIBLE, false); - Actor tick = box.FindChildByName( "Tick" ); - if( tick ) + Actor tick = box.FindChildByName("Tick"); + if(tick) { - tick.SetVisible( false ); + tick.SetProperty(Actor::Property::VISIBLE, false); } } } mTapDetector.Reset(); - mDeleteButton.SetVisible( false ); + mDeleteButton.SetProperty(Actor::Property::VISIBLE, false); + } + + void SelectOnTap(Actor actor, const TapGesture& tap) + { + Actor tick = actor.FindChildByName("Tick"); + if(tick) + { + tick.SetProperty(Actor::Property::VISIBLE, !tick.GetCurrentProperty(Actor::Property::VISIBLE)); + } } - void SelectOnTap( Actor actor, const TapGesture& tap ) + void OnLongPress(Actor actor, const LongPressGesture& gesture) { - Actor tick = actor.FindChildByName( "Tick" ); - if( tick ) + switch(gesture.GetState()) { - tick.SetVisible( !tick.IsVisible() ); + case GestureState::STARTED: + { + const Size& size = mApplication.GetWindow().GetSize(); + + ItemRange range(0u, 0u); + mItemView.GetItemsRange(range); + + const unsigned int item = (gesture.GetScreenPoint().y < 0.5f * size.height) ? range.begin : range.end; + mItemView.ScrollToItem(item, SCROLL_TO_ITEM_ANIMATION_TIME); + + break; + } + case GestureState::FINISHED: + { + Property::Map attributes; + mItemView.DoAction("stopScrolling", attributes); + break; + } + default: + { + break; + } } } - bool OnDeleteButtonClicked( Toolkit::Button button ) + bool OnDeleteButtonClicked(Toolkit::Button button) { ItemIdContainer removeList; - for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i ) + for(unsigned int i = 0u; i < mItemView.GetChildCount(); ++i) { - Actor child = mItemView.GetChildAt( i ); - Actor tick = child.FindChildByName( "Tick" ); + Actor child = mItemView.GetChildAt(i); + Actor tick = child.FindChildByName("Tick"); - if( tick && tick.IsVisible() ) + if(tick && tick.GetCurrentProperty(Actor::Property::VISIBLE)) { - removeList.push_back( mItemView.GetItemId(child) ); + removeList.push_back(mItemView.GetItemId(child)); } } - if( ! removeList.empty() ) + if(!removeList.empty()) { - mItemView.RemoveItems( removeList, 0.5f ); + mItemView.RemoveItems(removeList, 0.5f); } return true; @@ -620,12 +603,12 @@ public: mTapDetector = TapGestureDetector::New(); - for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i ) + for(unsigned int i = 0u; i < mItemView.GetChildCount(); ++i) { - mTapDetector.Attach( mItemView.GetChildAt(i) ); + mTapDetector.Attach(mItemView.GetChildAt(i)); } - mTapDetector.DetectedSignal().Connect( this, &ItemViewExample::InsertOnTap ); + mTapDetector.DetectedSignal().Connect(this, &ItemViewExample::InsertOnTap); } void ExitInsertMode() @@ -633,80 +616,80 @@ public: mTapDetector.Reset(); } - void InsertOnTap( Actor actor, const TapGesture& tap ) + void InsertOnTap(Actor actor, const TapGesture& tap) { - ItemId id = mItemView.GetItemId( actor ); + ItemId id = mItemView.GetItemId(actor); - Actor newActor = NewItem( rand() ); + Actor newActor = NewItem(rand()); - mItemView.InsertItem( Item(id,newActor), 0.5f ); + mItemView.InsertItem(Item(id, newActor), 0.5f); } void EnterInsertManyMode() { SetTitle("Edit: Insert Many"); - mInsertButton.SetVisible( true ); + mInsertButton.SetProperty(Actor::Property::VISIBLE, true); mTapDetector = TapGestureDetector::New(); - for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i ) + for(unsigned int i = 0u; i < mItemView.GetChildCount(); ++i) { - Actor child = mItemView.GetChildAt( i ); - Actor box = child.FindChildByName( "CheckBox" ); + Actor child = mItemView.GetChildAt(i); + Actor box = child.FindChildByName("CheckBox"); - if( box ) + if(box) { - mTapDetector.Attach( child ); - box.SetVisible( true ); + mTapDetector.Attach(child); + box.SetProperty(Actor::Property::VISIBLE, true); } } - mTapDetector.DetectedSignal().Connect( this, &ItemViewExample::SelectOnTap ); + mTapDetector.DetectedSignal().Connect(this, &ItemViewExample::SelectOnTap); } void ExitInsertManyMode() { - for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i ) + for(unsigned int i = 0u; i < mItemView.GetChildCount(); ++i) { - Actor child = mItemView.GetChildAt( i ); - Actor box = child.FindChildByName( "CheckBox" ); + Actor child = mItemView.GetChildAt(i); + Actor box = child.FindChildByName("CheckBox"); - if( box ) + if(box) { - box.SetVisible( false ); + box.SetProperty(Actor::Property::VISIBLE, false); - Actor tick = box.FindChildByName( "Tick" ); - if( tick ) + Actor tick = box.FindChildByName("Tick"); + if(tick) { - tick.SetVisible( false ); + tick.SetProperty(Actor::Property::VISIBLE, false); } } } mTapDetector.Reset(); - mInsertButton.SetVisible( false ); + mInsertButton.SetProperty(Actor::Property::VISIBLE, false); } - bool OnInsertButtonClicked( Toolkit::Button button ) + bool OnInsertButtonClicked(Toolkit::Button button) { ItemContainer insertList; - for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i ) + for(unsigned int i = 0u; i < mItemView.GetChildCount(); ++i) { - Actor child = mItemView.GetChildAt( i ); - Actor tick = child.FindChildByName( "Tick" ); + Actor child = mItemView.GetChildAt(i); + Actor tick = child.FindChildByName("Tick"); - if( tick && tick.IsVisible() ) + if(tick && tick.GetCurrentProperty(Actor::Property::VISIBLE)) { - insertList.push_back( Item( mItemView.GetItemId(child), NewItem(rand()) ) ); + insertList.push_back(Item(mItemView.GetItemId(child), NewItem(rand()))); } } - if( ! insertList.empty() ) + if(!insertList.empty()) { - mItemView.InsertItems( insertList, 0.5f ); + mItemView.InsertItems(insertList, 0.5f); } return true; @@ -718,17 +701,17 @@ public: mTapDetector = TapGestureDetector::New(); - for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i ) + for(unsigned int i = 0u; i < mItemView.GetChildCount(); ++i) { mTapDetector.Attach(mItemView.GetChildAt(i)); } - mTapDetector.DetectedSignal().Connect( this, &ItemViewExample::ReplaceOnTap ); + mTapDetector.DetectedSignal().Connect(this, &ItemViewExample::ReplaceOnTap); } - void ReplaceOnTap( Actor actor, const TapGesture& tap ) + void ReplaceOnTap(Actor actor, const TapGesture& tap) { - mItemView.ReplaceItem( Item( mItemView.GetItemId(actor), NewItem(rand()) ), 0.5f ); + mItemView.ReplaceItem(Item(mItemView.GetItemId(actor), NewItem(rand())), 0.5f); } void ExitReplaceMode() @@ -740,67 +723,67 @@ public: { SetTitle("Edit: Replace Many"); - mReplaceButton.SetVisible( true ); + mReplaceButton.SetProperty(Actor::Property::VISIBLE, true); mTapDetector = TapGestureDetector::New(); - for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i ) + for(unsigned int i = 0u; i < mItemView.GetChildCount(); ++i) { - Actor child = mItemView.GetChildAt( i ); - Actor box = child.FindChildByName( "CheckBox" ); + Actor child = mItemView.GetChildAt(i); + Actor box = child.FindChildByName("CheckBox"); - if( box ) + if(box) { - mTapDetector.Attach( child ); - box.SetVisible( true ); + mTapDetector.Attach(child); + box.SetProperty(Actor::Property::VISIBLE, true); } } - mTapDetector.DetectedSignal().Connect( this, &ItemViewExample::SelectOnTap ); + mTapDetector.DetectedSignal().Connect(this, &ItemViewExample::SelectOnTap); } void ExitReplaceManyMode() { - for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i ) + for(unsigned int i = 0u; i < mItemView.GetChildCount(); ++i) { - Actor child = mItemView.GetChildAt( i ); - Actor box = child.FindChildByName( "CheckBox" ); + Actor child = mItemView.GetChildAt(i); + Actor box = child.FindChildByName("CheckBox"); - if( box ) + if(box) { - box.SetVisible( false ); + box.SetProperty(Actor::Property::VISIBLE, false); - Actor tick = box.FindChildByName( "Tick" ); - if( tick ) + Actor tick = box.FindChildByName("Tick"); + if(tick) { - tick.SetVisible( false ); + tick.SetProperty(Actor::Property::VISIBLE, false); } } } mTapDetector.Reset(); - mReplaceButton.SetVisible( false ); + mReplaceButton.SetProperty(Actor::Property::VISIBLE, false); } - bool OnReplaceButtonClicked( Toolkit::Button button ) + bool OnReplaceButtonClicked(Toolkit::Button button) { ItemContainer replaceList; - for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i ) + for(unsigned int i = 0u; i < mItemView.GetChildCount(); ++i) { - Actor child = mItemView.GetChildAt( i ); - Actor tick = child.FindChildByName( "Tick" ); + Actor child = mItemView.GetChildAt(i); + Actor tick = child.FindChildByName("Tick"); - if( tick && tick.IsVisible() ) + if(tick && tick.GetCurrentProperty(Actor::Property::VISIBLE)) { - replaceList.push_back( Item( mItemView.GetItemId(child), NewItem(rand()) ) ); + replaceList.push_back(Item(mItemView.GetItemId(child), NewItem(rand()))); } } - if( ! replaceList.empty() ) + if(!replaceList.empty()) { - mItemView.ReplaceItems( replaceList, 0.5f ); + mItemView.ReplaceItems(replaceList, 0.5f); } return true; @@ -808,22 +791,22 @@ public: void SetLayoutTitle() { - if( MODE_NORMAL == mMode ) + if(MODE_NORMAL == mMode) { std::stringstream ss(APPLICATION_TITLE); switch(mCurrentLayout) { - case SPIRAL_LAYOUT: - ss << APPLICATION_TITLE << ": " << SPIRAL_LABEL; - break; - case GRID_LAYOUT: - ss << APPLICATION_TITLE << ": " << GRID_LABEL; - break; - case DEPTH_LAYOUT: - ss << APPLICATION_TITLE << ": " << DEPTH_LABEL; - break; - default: - break; + case SPIRAL_LAYOUT: + ss << APPLICATION_TITLE << ": " << SPIRAL_LABEL; + break; + case GRID_LAYOUT: + ss << APPLICATION_TITLE << ": " << GRID_LABEL; + break; + case DEPTH_LAYOUT: + ss << APPLICATION_TITLE << ": " << DEPTH_LABEL; + break; + default: + break; } SetTitle(ss.str()); } @@ -831,25 +814,28 @@ public: void SetLayoutImage() { - if( mLayoutButton ) + if(mLayoutButton) { - switch( mCurrentLayout ) + switch(mCurrentLayout) { case SPIRAL_LAYOUT: { - mLayoutButton.SetBackgroundImage( ResourceImage::New( SPIRAL_LAYOUT_IMAGE ) ); + mLayoutButton.SetProperty(Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, SPIRAL_LAYOUT_IMAGE); + mLayoutButton.SetProperty(Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, SPIRAL_LAYOUT_IMAGE_SELECTED); break; } case GRID_LAYOUT: { - mLayoutButton.SetBackgroundImage( ResourceImage::New( GRID_LAYOUT_IMAGE ) ); + mLayoutButton.SetProperty(Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, GRID_LAYOUT_IMAGE); + mLayoutButton.SetProperty(Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, GRID_LAYOUT_IMAGE_SELECTED); break; } case DEPTH_LAYOUT: { - mLayoutButton.SetBackgroundImage( ResourceImage::New( DEPTH_LAYOUT_IMAGE ) ); + mLayoutButton.SetProperty(Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, DEPTH_LAYOUT_IMAGE); + mLayoutButton.SetProperty(Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, DEPTH_LAYOUT_IMAGE_SELECTED); break; } @@ -860,7 +846,6 @@ public: } public: // From ItemFactory - /** * Query the number of items available from the factory. * The maximum available item has an ID of GetNumberOfItems() - 1. @@ -877,89 +862,82 @@ public: // From ItemFactory */ virtual Actor NewItem(unsigned int itemId) { - // Create an image actor for this item - unsigned int imageId = itemId % NUM_IMAGES; - ImageActor::PixelArea pixelArea( (imageId%NUM_IMAGE_PER_ROW_IN_ATLAS)*IMAGE_WIDTH, - (imageId/NUM_IMAGE_PER_ROW_IN_ATLAS)*IMAGE_HEIGHT, - IMAGE_WIDTH, - IMAGE_HEIGHT ); - Actor actor = ImageActor::New(mImageAtlas, pixelArea); - actor.SetPosition( INITIAL_OFFSCREEN_POSITION ); + // Create an image view for this item + Property::Map propertyMap; + propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE); + propertyMap.Insert(ImageVisual::Property::URL, IMAGE_PATHS[itemId % NUM_IMAGES]); + propertyMap.Insert(DevelVisual::Property::VISUAL_FITTING_MODE, DevelVisual::FILL); + ImageView actor = ImageView::New(); + actor.SetProperty(Toolkit::ImageView::Property::IMAGE, propertyMap); + actor.SetProperty(Actor::Property::POSITION_Z, 0.0f); + actor.SetProperty(Actor::Property::POSITION, INITIAL_OFFSCREEN_POSITION); // Add a border image child actor - ImageActor borderActor = ImageActor::New(mBorderImage); - borderActor.SetParentOrigin( ParentOrigin::CENTER ); - borderActor.SetAnchorPoint( AnchorPoint::CENTER ); - borderActor.SetPosition( 0.f, 0.f, 1.f ); - borderActor.SetStyle( ImageActor::STYLE_NINE_PATCH ); - borderActor.SetNinePatchBorder( Vector4( ITEM_IMAGE_BORDER_LEFT, ITEM_IMAGE_BORDER_TOP, ITEM_IMAGE_BORDER_RIGHT, ITEM_IMAGE_BORDER_BOTTOM ) ); - borderActor.SetColorMode( USE_OWN_MULTIPLY_PARENT_COLOR ); // darken with parent image-actor - borderActor.SetResizePolicy( SIZE_FIXED_OFFSET_FROM_PARENT, ALL_DIMENSIONS ); - borderActor.SetSizeModeFactor( ITEM_BORDER_MARGIN_SIZE ); + ImageView borderActor = ImageView::New(); + borderActor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + borderActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + borderActor.SetResizePolicy(ResizePolicy::SIZE_FIXED_OFFSET_FROM_PARENT, Dimension::ALL_DIMENSIONS); + borderActor.SetProperty(Actor::Property::SIZE_MODE_FACTOR, Vector3(2.0f * ITEM_BORDER_SIZE, 2.0f * ITEM_BORDER_SIZE, 0.0f)); + borderActor.SetProperty(Actor::Property::COLOR_MODE, USE_PARENT_COLOR); + + Property::Map borderProperty; + borderProperty.Insert(Toolkit::Visual::Property::TYPE, Visual::BORDER); + borderProperty.Insert(BorderVisual::Property::COLOR, Color::WHITE); + borderProperty.Insert(BorderVisual::Property::SIZE, ITEM_BORDER_SIZE); + borderProperty.Insert(BorderVisual::Property::ANTI_ALIASING, true); + borderActor.SetProperty(ImageView::Property::IMAGE, borderProperty); + actor.Add(borderActor); - actor.SetKeyboardFocusable( true ); + + actor.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true); Vector3 spiralItemSize; - static_cast(*mSpiralLayout).GetItemSize( 0u, Vector3( Stage::GetCurrent().GetSize() ), spiralItemSize ); + Vector2 windowSize = mApplication.GetWindow().GetSize(); + static_cast(*mSpiralLayout).GetItemSize(0u, Vector3(windowSize), spiralItemSize); // Add a checkbox child actor; invisible until edit-mode is enabled - - ImageActor checkbox = ImageActor::New( mWhiteImage ); - checkbox.SetRelayoutEnabled( false ); - checkbox.SetName( "CheckBox" ); - checkbox.SetColor( Vector4(0.0f,0.0f,0.0f,0.6f) ); - checkbox.SetParentOrigin( ParentOrigin::TOP_RIGHT ); - checkbox.SetAnchorPoint( AnchorPoint::TOP_RIGHT ); - checkbox.SetSize( spiralItemSize.width * 0.2f, spiralItemSize.width * 0.2f ); - checkbox.SetPosition( -SELECTION_BORDER_WIDTH, SELECTION_BORDER_WIDTH ); - checkbox.SetZ( 1.0f ); - if( MODE_REMOVE_MANY != mMode && - MODE_INSERT_MANY != mMode && - MODE_REPLACE_MANY != mMode ) - { - checkbox.SetVisible( false ); - } - actor.Add( checkbox ); - - ImageActor tick = ImageActor::New( ResourceImage::New(SELECTED_IMAGE) ); - tick.SetRelayoutEnabled( false ); - tick.SetColorMode( USE_OWN_COLOR ); - tick.SetName( "Tick" ); - tick.SetParentOrigin( ParentOrigin::TOP_RIGHT ); - tick.SetAnchorPoint( AnchorPoint::TOP_RIGHT ); - tick.SetSize( spiralItemSize.width * 0.2f, spiralItemSize.width * 0.2f ); - tick.SetZ( 1.0f ); - tick.SetVisible( false ); - checkbox.Add( tick ); + ImageView checkbox = ImageView::New(); + checkbox.SetProperty(Dali::Actor::Property::NAME, "CheckBox"); + checkbox.SetProperty(Actor::Property::COLOR_MODE, USE_PARENT_COLOR); + checkbox.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_RIGHT); + checkbox.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_RIGHT); + checkbox.SetProperty(Actor::Property::SIZE, Vector2(spiralItemSize.width * 0.2f, spiralItemSize.width * 0.2f)); + checkbox.SetProperty(Actor::Property::POSITION, Vector2(-SELECTION_BORDER_WIDTH, SELECTION_BORDER_WIDTH)); + checkbox.SetProperty(Actor::Property::POSITION_Z, 0.1f); + + Property::Map solidColorProperty; + solidColorProperty.Insert(Toolkit::Visual::Property::TYPE, Visual::COLOR); + solidColorProperty.Insert(ColorVisual::Property::MIX_COLOR, Vector4(0.f, 0.f, 0.f, 0.6f)); + checkbox.SetProperty(ImageView::Property::IMAGE, solidColorProperty); + + if(MODE_REMOVE_MANY != mMode && + MODE_INSERT_MANY != mMode && + MODE_REPLACE_MANY != mMode) + { + checkbox.SetProperty(Actor::Property::VISIBLE, false); + } + borderActor.Add(checkbox); + + ImageView tick = ImageView::New(SELECTED_IMAGE); + tick.SetProperty(Dali::Actor::Property::NAME, "Tick"); + tick.SetProperty(Actor::Property::COLOR_MODE, USE_PARENT_COLOR); + tick.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_RIGHT); + tick.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_RIGHT); + tick.SetProperty(Actor::Property::SIZE, Vector2(spiralItemSize.width * 0.2f, spiralItemSize.width * 0.2f)); + tick.SetProperty(Actor::Property::POSITION_Z, 0.2f); + tick.SetProperty(Actor::Property::VISIBLE, false); + checkbox.Add(tick); // Connect new items for various editing modes - if( mTapDetector ) + if(mTapDetector) { - mTapDetector.Attach( actor ); + mTapDetector.Attach(actor); } return actor; } private: - - /** - * Create an Atlas to tile the images inside. - */ - Atlas CreateImageAtlas() - { - const unsigned int atlas_width = IMAGE_WIDTH*NUM_IMAGE_PER_ROW_IN_ATLAS; - const unsigned int atlas_height = IMAGE_HEIGHT*ceil( static_cast(NUM_IMAGES)/ static_cast(NUM_IMAGE_PER_ROW_IN_ATLAS)); - Atlas atlas = Atlas::New(atlas_width, atlas_height, Pixel::RGB888); - - for( unsigned int i = 0; i < NUM_IMAGES; i++ ) - { - atlas.Upload( IMAGE_PATHS[i], (i%NUM_IMAGE_PER_ROW_IN_ATLAS)*IMAGE_WIDTH, (i/NUM_IMAGE_PER_ROW_IN_ATLAS)*IMAGE_HEIGHT ); - } - - return atlas; - } - /** * Sets/Updates the title of the View * @param[in] title The new title for the view. @@ -968,108 +946,12 @@ private: { if(!mTitleActor) { - mTitleActor = DemoHelper::CreateToolBarLabel( "" ); + mTitleActor = DemoHelper::CreateToolBarLabel(""); // Add title to the tool bar. - mToolBar.AddControl( mTitleActor, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarTitlePercentage, Alignment::HorizontalCenter ); - } - - mTitleActor.SetProperty( TextLabel::Property::TEXT, title ); - } - - void ShowMenu() - { - Stage stage = Stage::GetCurrent(); - const float popupWidth = stage.GetSize().x * 0.75f; - - mMenu = Toolkit::Popup::New(); - mMenu.SetParentOrigin( ParentOrigin::BOTTOM_LEFT ); - mMenu.SetAnchorPoint( AnchorPoint::BOTTOM_LEFT ); - mMenu.SetSize( popupWidth, MENU_OPTION_HEIGHT * 2 ); - mMenu.OutsideTouchedSignal().Connect( this, &ItemViewExample::HideMenu ); - - TableView tableView = TableView::New( 0, 0 ); - tableView.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS ); - mMenu.Add( tableView ); - - Slider slider = Slider::New(); - slider.SetProperty( Slider::Property::LOWER_BOUND, 0.0f ); - slider.SetProperty( Slider::Property::UPPER_BOUND, 3.0f ); - slider.SetProperty( Slider::Property::VALUE, mDurationSeconds ); - slider.SetProperty( Slider::Property::VALUE_PRECISION, 2 ); - slider.SetProperty( Slider::Property::SHOW_POPUP, true ); - slider.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS ); - slider.ValueChangedSignal().Connect( this, &ItemViewExample::SliderValueChange ); - tableView.AddChild( slider, TableView::CellPosition( 0, 0 ) ); - - TextLabel text = TextLabel::New( "Duration" ); - text.SetAnchorPoint( ParentOrigin::TOP_LEFT ); - text.SetParentOrigin( ParentOrigin::TOP_LEFT ); - text.SetResizePolicy( FILL_TO_PARENT, WIDTH ); - text.SetResizePolicy( FIXED, HEIGHT ); - text.SetSize( Vector2( 0.0f, LABEL_TEXT_SIZE_Y ) ); - slider.Add( text ); - - Actor textContainer = Actor::New(); - textContainer.SetRelayoutEnabled( true ); - textContainer.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS ); - mAlphaFunctionText = TextLabel::New( ALPHA_FUNCTIONS_TEXT[mAlphaFuncIndex] ); - mAlphaFunctionText.SetAnchorPoint( ParentOrigin::CENTER ); - mAlphaFunctionText.SetParentOrigin( ParentOrigin::CENTER ); - textContainer.Add( mAlphaFunctionText ); - tableView.AddChild( textContainer, TableView::CellPosition( 1, 0 ) ); - - mTapDetector = TapGestureDetector::New(); - mTapDetector.Attach(mAlphaFunctionText); - mTapDetector.DetectedSignal().Connect( this, &ItemViewExample::ChangeAlphaFunctionOnTap ); - - text = TextLabel::New( "Alpha Function" ); - text.SetAnchorPoint( ParentOrigin::TOP_LEFT ); - text.SetParentOrigin( ParentOrigin::TOP_LEFT ); - text.SetResizePolicy( FILL_TO_PARENT, WIDTH ); - text.SetSize( 0.0f, LABEL_TEXT_SIZE_Y ); - textContainer.Add( text ); - - mMenu.MarkDirtyForRelayout(); - mMenu.Show(); - mMenuShown = true; - } - - bool SliderValueChange( Toolkit::Slider slider, float value ) - { - mDurationSeconds = value; - - return true; - } - - void ChangeAlphaFunctionOnTap( Actor actor, const TapGesture& tap ) - { - if( NUM_ALPHA_FUNCTIONS <= ++mAlphaFuncIndex ) - { - mAlphaFuncIndex = 0; - } - - if( mAlphaFunctionText ) - { - mAlphaFunctionText.SetProperty( TextLabel::Property::TEXT, std::string(ALPHA_FUNCTIONS_TEXT[mAlphaFuncIndex]) ); - } - - if( mItemView ) - { - mItemView.GetActiveLayout()->SetAlphaFunction( ALPHA_FUNCTIONS[mAlphaFuncIndex] ); - } - } - - void HideMenu() - { - mTapDetector.Reset(); - - if( mMenu ) - { - mMenu.Hide(); - mMenu.Reset(); + mToolBar.AddControl(mTitleActor, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarTitlePercentage, Alignment::HORIZONTAL_CENTER); } - mMenuShown = false; + mTitleActor.SetProperty(TextLabel::Property::TEXT, title); } /** @@ -1077,80 +959,46 @@ private: */ void OnKeyEvent(const KeyEvent& event) { - if(event.state == KeyEvent::Down) + if(event.GetState() == KeyEvent::DOWN) { - if( IsKey( event, DALI_KEY_MENU ) ) + if(IsKey(event, DALI_KEY_ESCAPE) || IsKey(event, DALI_KEY_BACK)) { - if( mMenuShown ) - { - HideMenu(); - } - else - { - ShowMenu(); - } - } - else if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) ) - { - if( mMenuShown ) - { - HideMenu(); - } - else - { - mApplication.Quit(); - } + mApplication.Quit(); } } } private: - Application& mApplication; - Mode mMode; - bool mMenuShown; + Mode mMode; - Toolkit::View mView; - unsigned int mOrientation; + Toolkit::Control mView; + unsigned int mOrientation; Toolkit::ToolBar mToolBar; - TextLabel mTitleActor; ///< The Toolbar's Title. + TextLabel mTitleActor; ///< The Toolbar's Title. - ItemView mItemView; - Image mBorderImage; - Atlas mImageAtlas; + ItemView mItemView; unsigned int mCurrentLayout; - float mDurationSeconds; - - SpiralLayoutPtr mSpiralLayout; - DepthLayoutPtr mDepthLayout; - GridLayoutPtr mGridLayout; + float mDurationSeconds; - Toolkit::Popup mMenu; + ItemLayoutPtr mSpiralLayout; + ItemLayoutPtr mDepthLayout; + ItemLayoutPtr mGridLayout; - TapGestureDetector mTapDetector; + TapGestureDetector mTapDetector; Toolkit::PushButton mLayoutButton; Toolkit::PushButton mDeleteButton; Toolkit::PushButton mInsertButton; Toolkit::PushButton mReplaceButton; - unsigned int mAlphaFuncIndex; - TextLabel mAlphaFunctionText; - BufferImage mWhiteImage; + LongPressGestureDetector mLongPressDetector; }; -void RunTest(Application& app) +int DALI_EXPORT_API main(int argc, char** argv) { + Application app = Application::New(&argc, &argv, DEMO_THEME_PATH); ItemViewExample test(app); - app.MainLoop(); -} - -int main(int argc, char **argv) -{ - Application app = Application::New(&argc, &argv); - - RunTest(app); - return 0; }