2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
23 #include <cstdlib> // rand
24 #include "../shared/view.h"
26 #include <dali/dali.h>
27 #include <dali-toolkit/dali-toolkit.h>
31 using namespace Dali::Toolkit;
45 const char* IMAGE_PATHS[] = {
46 DALI_IMAGE_DIR "gallery-medium-1.jpg",
47 DALI_IMAGE_DIR "gallery-medium-2.jpg",
48 DALI_IMAGE_DIR "gallery-medium-3.jpg",
49 DALI_IMAGE_DIR "gallery-medium-4.jpg",
50 DALI_IMAGE_DIR "gallery-medium-5.jpg",
51 DALI_IMAGE_DIR "gallery-medium-6.jpg",
52 DALI_IMAGE_DIR "gallery-medium-7.jpg",
53 DALI_IMAGE_DIR "gallery-medium-8.jpg",
54 DALI_IMAGE_DIR "gallery-medium-9.jpg",
55 DALI_IMAGE_DIR "gallery-medium-10.jpg",
56 DALI_IMAGE_DIR "gallery-medium-11.jpg",
57 DALI_IMAGE_DIR "gallery-medium-12.jpg",
58 DALI_IMAGE_DIR "gallery-medium-13.jpg",
59 DALI_IMAGE_DIR "gallery-medium-14.jpg",
60 DALI_IMAGE_DIR "gallery-medium-15.jpg",
61 DALI_IMAGE_DIR "gallery-medium-16.jpg",
62 DALI_IMAGE_DIR "gallery-medium-17.jpg",
63 DALI_IMAGE_DIR "gallery-medium-18.jpg",
64 DALI_IMAGE_DIR "gallery-medium-19.jpg",
65 DALI_IMAGE_DIR "gallery-medium-20.jpg",
66 DALI_IMAGE_DIR "gallery-medium-21.jpg",
67 DALI_IMAGE_DIR "gallery-medium-22.jpg",
68 DALI_IMAGE_DIR "gallery-medium-23.jpg",
69 DALI_IMAGE_DIR "gallery-medium-24.jpg",
70 DALI_IMAGE_DIR "gallery-medium-25.jpg",
71 DALI_IMAGE_DIR "gallery-medium-26.jpg",
72 DALI_IMAGE_DIR "gallery-medium-27.jpg",
73 DALI_IMAGE_DIR "gallery-medium-28.jpg",
74 DALI_IMAGE_DIR "gallery-medium-29.jpg",
75 DALI_IMAGE_DIR "gallery-medium-30.jpg",
76 DALI_IMAGE_DIR "gallery-medium-31.jpg",
77 DALI_IMAGE_DIR "gallery-medium-32.jpg",
78 DALI_IMAGE_DIR "gallery-medium-33.jpg",
79 DALI_IMAGE_DIR "gallery-medium-34.jpg",
80 DALI_IMAGE_DIR "gallery-medium-35.jpg",
81 DALI_IMAGE_DIR "gallery-medium-36.jpg",
82 DALI_IMAGE_DIR "gallery-medium-37.jpg",
83 DALI_IMAGE_DIR "gallery-medium-38.jpg",
84 DALI_IMAGE_DIR "gallery-medium-39.jpg",
85 DALI_IMAGE_DIR "gallery-medium-40.jpg",
86 DALI_IMAGE_DIR "gallery-medium-41.jpg",
87 DALI_IMAGE_DIR "gallery-medium-42.jpg",
88 DALI_IMAGE_DIR "gallery-medium-43.jpg",
89 DALI_IMAGE_DIR "gallery-medium-44.jpg",
90 DALI_IMAGE_DIR "gallery-medium-45.jpg",
91 DALI_IMAGE_DIR "gallery-medium-46.jpg",
92 DALI_IMAGE_DIR "gallery-medium-47.jpg",
93 DALI_IMAGE_DIR "gallery-medium-48.jpg",
94 DALI_IMAGE_DIR "gallery-medium-49.jpg",
95 DALI_IMAGE_DIR "gallery-medium-50.jpg",
96 DALI_IMAGE_DIR "gallery-medium-51.jpg",
97 DALI_IMAGE_DIR "gallery-medium-52.jpg",
98 DALI_IMAGE_DIR "gallery-medium-53.jpg",
101 const unsigned int NUM_IMAGES = sizeof(IMAGE_PATHS) / sizeof(char*);
103 AlphaFunction ALPHA_FUNCTIONS[] = { AlphaFunctions::Linear,
104 AlphaFunctions::EaseIn,
105 AlphaFunctions::EaseOut };
107 const unsigned int NUM_ALPHA_FUNCTIONS = sizeof(ALPHA_FUNCTIONS) / sizeof(AlphaFunction);
109 const char* ALPHA_FUNCTIONS_TEXT[] = { "Linear",
113 const char* BACKGROUND_IMAGE( "" );
114 const char* TOOLBAR_IMAGE( DALI_IMAGE_DIR "top-bar.png" );
115 const char* EDIT_IMAGE( DALI_IMAGE_DIR "icon-edit.png" );
116 const char* SPIRAL_LAYOUT_IMAGE( DALI_IMAGE_DIR "icon-item-view-layout-spiral.png" );
117 const char* GRID_LAYOUT_IMAGE( DALI_IMAGE_DIR "icon-item-view-layout-grid.png" );
118 const char* DEPTH_LAYOUT_IMAGE( DALI_IMAGE_DIR "icon-item-view-layout-depth.png" );
119 const char* DELETE_IMAGE( DALI_IMAGE_DIR "icon-delete.png" );
120 const char* REPLACE_IMAGE( DALI_IMAGE_DIR "icon-replace.png" );
121 const char* INSERT_IMAGE( DALI_IMAGE_DIR "icon-insert.png" );
122 const char* SELECTED_IMAGE( DALI_IMAGE_DIR "item-select-check.png" );
123 const char* APPLICATION_TITLE( "ItemView" );
125 const char* SPIRAL_LABEL("Spiral");
126 const char* GRID_LABEL("Grid");
127 const char* DEPTH_LABEL("Depth");
129 const char* ITEM_BORDER_IMAGE_PATH( DALI_IMAGE_DIR "frame-128x128.png" );
130 const Vector3 ITEM_BORDER_MARGIN_SIZE(24, 24, 0);
132 // These values depend on the border image
133 const float ITEM_IMAGE_BORDER_LEFT = 13.0f;
134 const float ITEM_IMAGE_BORDER_RIGHT = 13.0f;
135 const float ITEM_IMAGE_BORDER_TOP = 13.0f;
136 const float ITEM_IMAGE_BORDER_BOTTOM = 13.0f;
138 const unsigned int DEPTH_LAYOUT_ROWS_PORTRAIT = 26;
139 const unsigned int DEPTH_LAYOUT_ROWS_LANDSCAPE = 16;
140 const float DEPTH_LAYOUT_TILT_ANGLE_PORTRAIT = 25.0f;
141 const float DEPTH_LAYOUT_TILT_ANGLE_LANDSCAPE = 21.0f;
142 const float DEPTH_LAYOUT_ROW_SPACING_FACTOR = 0.1f;
143 const float DEPTH_LAYOUT_ITEM_SIZE_FACTOR_PORTRAIT = 1.0f;
144 const float DEPTH_LAYOUT_ITEM_SIZE_FACTOR_LANDSCAPE = 0.8f;
145 const float DEPTH_LAYOUT_BOTTOM_MARGIN_FACTOR_PORTRAIT = 0.2f;
146 const float DEPTH_LAYOUT_BOTTOM_MARGIN_FACTOR_LANDSCAPE = 0.1f;
148 const float SPIRAL_LAYOUT_REVOLUTION_NUMBER_PORTRAIT = 4.5f;
149 const float SPIRAL_LAYOUT_REVOLUTION_NUMBER_LANDSCAPE = 2.5f;
151 const float DEPTH_LAYOUT_HEIGHT_SCALE = 20.0f;
152 const float MIN_SWIPE_DISTANCE = 15.0f;
153 const float MIN_SWIPE_SPEED = 5.0f;
155 const float SELECTION_BORDER_WIDTH = 3.0f;
156 const float BUTTON_BORDER = -10.0f;
157 const float MENU_OPTION_HEIGHT(140.0f);
158 const float LABEL_TEXT_SIZE_Y = 20.0f;
160 const char* DEFAULT_TEXT_STYLE_FONT_FAMILY("HelveticaNue");
161 const char* DEFAULT_TEXT_STYLE_FONT_STYLE("Regular");
162 const PointSize DEFAULT_TEXT_STYLE_POINT_SIZE( 5.0f );
163 const TextStyle::Weight DEFAULT_TEXT_STYLE_WEIGHT(Dali::TextStyle::MEDIUM);
164 const Vector4 DEFAULT_TEXT_STYLE_COLOR(1.0f, 1.0f, 1.0f, 1.0f);
166 const Vector3 INITIAL_OFFSCREEN_POSITION( 1000.0f, 0, -1000.0f );
168 struct BorderSizeConstraintFunction
170 Vector3 operator()(const Vector3& current,
171 const PropertyInput& parentSize)
173 return parentSize.GetVector3() + ITEM_BORDER_MARGIN_SIZE;
177 static Vector3 DepthLayoutItemSizeFunctionPortrait(unsigned int numberOfColumns, float layoutWidth)
179 float width = (layoutWidth / static_cast<float>(numberOfColumns + 1)) * DEPTH_LAYOUT_ITEM_SIZE_FACTOR_PORTRAIT;
182 return Vector3(width, width, width);
185 static Vector3 DepthLayoutItemSizeFunctionLandscape(unsigned int numberOfColumns, float layoutWidth)
187 float width = (layoutWidth / static_cast<float>(numberOfColumns + 1)) * DEPTH_LAYOUT_ITEM_SIZE_FACTOR_LANDSCAPE;
190 return Vector3(width, width, width);
193 static float DepthLayoutBottomMarginFunctionPortrait(float layoutHeight)
195 return layoutHeight * DEPTH_LAYOUT_BOTTOM_MARGIN_FACTOR_PORTRAIT;
198 static float DepthLayoutBottomMarginFunctionLandscape(float layoutHeight)
200 return layoutHeight * DEPTH_LAYOUT_BOTTOM_MARGIN_FACTOR_LANDSCAPE;
206 * This example shows how to use ItemView UI control.
207 * There are three layouts created for ItemView, i.e., Spiral, Depth and Grid.
208 * There is one button in the upper-left corner for quitting the application and
209 * another button in the upper-right corner for switching between different layouts.
211 class ItemViewExample : public ConnectionTracker, public ItemFactory
229 * @param application class, stored as reference
231 ItemViewExample( Application& application )
232 : mApplication( application ),
233 mMode( MODE_NORMAL ),
236 mCurrentLayout( SPIRAL_LAYOUT ),
237 mDurationSeconds( 1.0f ),
238 mAlphaFuncIndex( 0u )
240 // Connect to the Application's Init signal
241 mApplication.InitSignal().Connect(this, &ItemViewExample::OnInit);
245 * This method gets called once the main loop of application is up and running
247 void OnInit(Application& app)
249 Stage stage = Dali::Stage::GetCurrent();
250 stage.KeyEventSignal().Connect(this, &ItemViewExample::OnKeyEvent);
252 Vector2 stageSize = Stage::GetCurrent().GetSize();
254 // Create a border image shared by all the item actors
255 mBorderImage = Image::New(ITEM_BORDER_IMAGE_PATH);
257 // Creates a default view with a default tool bar.
258 // The view is added to the stage.
259 Layer contents = DemoHelper::CreateView( mApplication,
266 mView.OrientationAnimationStartedSignal().Connect( this, &ItemViewExample::OnOrientationChanged );
268 // Create an edit mode button. (left of toolbar)
269 Toolkit::PushButton editButton = Toolkit::PushButton::New();
270 editButton.SetBackgroundImage( Image::New( EDIT_IMAGE ) );
271 editButton.ClickedSignal().Connect( this, &ItemViewExample::OnModeButtonClicked);
272 editButton.SetLeaveRequired( true );
273 mToolBar.AddControl( editButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalLeft, DemoHelper::DEFAULT_MODE_SWITCH_PADDING );
275 // Create a layout toggle button. (right of toolbar)
276 mLayoutButton = Toolkit::PushButton::New();
277 mLayoutButton.SetBackgroundImage( Image::New( SPIRAL_LAYOUT_IMAGE ) );
278 mLayoutButton.ClickedSignal().Connect( this, &ItemViewExample::OnLayoutButtonClicked);
279 mLayoutButton.SetLeaveRequired( true );
280 mToolBar.AddControl( mLayoutButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalRight, DemoHelper::DEFAULT_MODE_SWITCH_PADDING );
282 // Create a delete button (bottom right of screen)
283 mDeleteButton = Toolkit::PushButton::New();
284 mDeleteButton.SetParentOrigin(ParentOrigin::BOTTOM_RIGHT);
285 mDeleteButton.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
286 mDeleteButton.SetPosition( BUTTON_BORDER, BUTTON_BORDER );
287 mDeleteButton.SetDrawMode( DrawMode::OVERLAY );
288 mDeleteButton.SetBackgroundImage( Image::New( TOOLBAR_IMAGE ) );
289 mDeleteButton.SetButtonImage( Image::New( DELETE_IMAGE ) );
290 mDeleteButton.SetSize( stageSize.width * 0.15f, stageSize.width * 0.15f );
291 mDeleteButton.ClickedSignal().Connect( this, &ItemViewExample::OnDeleteButtonClicked);
292 mDeleteButton.SetLeaveRequired( true );
293 mDeleteButton.SetVisible( false );
294 stage.Add( mDeleteButton );
296 // Create an insert button (bottom right of screen)
297 mInsertButton = Toolkit::PushButton::New();
298 mInsertButton.SetParentOrigin(ParentOrigin::BOTTOM_RIGHT);
299 mInsertButton.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
300 mInsertButton.SetPosition( BUTTON_BORDER, BUTTON_BORDER );
301 mInsertButton.SetDrawMode( DrawMode::OVERLAY );
302 mInsertButton.SetBackgroundImage( Image::New( TOOLBAR_IMAGE ) );
303 mInsertButton.SetButtonImage( Image::New( INSERT_IMAGE ) );
304 mInsertButton.SetSize( stageSize.width * 0.15f, stageSize.width * 0.15f );
305 mInsertButton.ClickedSignal().Connect( this, &ItemViewExample::OnInsertButtonClicked);
306 mInsertButton.SetLeaveRequired( true );
307 mInsertButton.SetVisible( false );
308 stage.Add( mInsertButton );
310 // Create an replace button (bottom right of screen)
311 mReplaceButton = Toolkit::PushButton::New();
312 mReplaceButton.SetParentOrigin(ParentOrigin::BOTTOM_RIGHT);
313 mReplaceButton.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
314 mReplaceButton.SetPosition( BUTTON_BORDER, BUTTON_BORDER );
315 mReplaceButton.SetDrawMode( DrawMode::OVERLAY );
316 mReplaceButton.SetBackgroundImage( Image::New( TOOLBAR_IMAGE ) );
317 mReplaceButton.SetButtonImage( Image::New( REPLACE_IMAGE ) );
318 mReplaceButton.SetSize( stageSize.width * 0.15f, stageSize.width * 0.15f );
319 mReplaceButton.ClickedSignal().Connect( this, &ItemViewExample::OnReplaceButtonClicked);
320 mReplaceButton.SetLeaveRequired( true );
321 mReplaceButton.SetVisible( false );
322 stage.Add( mReplaceButton );
324 // Create the item view actor
325 mItemView = ItemView::New(*this);
326 mItemView.SetParentOrigin(ParentOrigin::CENTER);
327 mItemView.SetAnchorPoint(AnchorPoint::CENTER);
329 // Display item view on the stage
330 stage.Add( mItemView );
332 // Create the layouts
333 mSpiralLayout = SpiralLayout::New();
334 mDepthLayout = DepthLayout::New();
335 mGridLayout = GridLayout::New();
337 // Add the layouts to item view
338 mItemView.AddLayout(*mSpiralLayout);
339 mItemView.AddLayout(*mDepthLayout);
340 mItemView.AddLayout(*mGridLayout);
342 mItemView.SetMinimumSwipeDistance(MIN_SWIPE_DISTANCE);
343 mItemView.SetMinimumSwipeSpeed(MIN_SWIPE_SPEED);
345 // Activate the spiral layout
346 UseLayout(mCurrentLayout, 0.0f);
347 mItemView.SetKeyboardFocusable( true );
348 KeyboardFocusManager::Get().PreFocusChangeSignal().Connect( this, &ItemViewExample::OnKeyboardPreFocusChange );
350 // Set the title and icon to the current layout
355 Actor OnKeyboardPreFocusChange( Actor current, Actor proposed, Control::KeyboardFocusNavigationDirection direction )
357 if ( !current && !proposed )
366 * Switch to a different item view layout
368 void UseLayout(int layoutId, float duration)
370 // Set the new orientation to the layout
371 mItemView.GetLayout(layoutId)->SetOrientation(static_cast<ControlOrientation::Type>(mOrientation / 90));
373 Vector2 stageSize = Stage::GetCurrent().GetSize();
375 if(layoutId == SPIRAL_LAYOUT)
377 mSpiralLayout->SetRevolutionDistance(stageSize.height / Stage::GetCurrent().GetDpi().y * 45.0f);
380 if(layoutId == GRID_LAYOUT)
382 // Set up the grid layout according to the new orientation
383 float layoutWidth = Toolkit::IsHorizontal(mGridLayout->GetOrientation()) ? stageSize.height : stageSize.width;
384 float gridItemSize = (layoutWidth / mGridLayout->GetNumberOfColumns()) * 0.5f;
385 mGridLayout->SetScrollSpeedFactor(mGridLayout->GetNumberOfColumns() / gridItemSize);
387 float toolbarHeight = mToolBar.GetCurrentSize().y;
388 mGridLayout->SetTopMargin(toolbarHeight + mGridLayout->GetRowSpacing());
391 if(layoutId == DEPTH_LAYOUT)
393 // Set up the depth layout according to the new orientation
394 if(Toolkit::IsVertical(mDepthLayout->GetOrientation()))
396 mDepthLayout->SetRowSpacing(stageSize.height * DEPTH_LAYOUT_ROW_SPACING_FACTOR);
397 mDepthLayout->SetNumberOfRows(DEPTH_LAYOUT_ROWS_PORTRAIT);
398 mDepthLayout->SetTiltAngle( Degree( DEPTH_LAYOUT_TILT_ANGLE_PORTRAIT - mDepthLayout->GetNumberOfColumns() ) );
399 mDepthLayout->SetItemSizeFunction(DepthLayoutItemSizeFunctionPortrait);
400 mDepthLayout->SetBottomMarginFunction(DepthLayoutBottomMarginFunctionPortrait);
404 mDepthLayout->SetRowSpacing(stageSize.width * DEPTH_LAYOUT_ROW_SPACING_FACTOR);
405 mDepthLayout->SetNumberOfRows(DEPTH_LAYOUT_ROWS_LANDSCAPE);
406 mDepthLayout->SetTiltAngle( Degree( DEPTH_LAYOUT_TILT_ANGLE_LANDSCAPE - mDepthLayout->GetNumberOfColumns() ) );
407 mDepthLayout->SetItemSizeFunction(DepthLayoutItemSizeFunctionLandscape);
408 mDepthLayout->SetBottomMarginFunction(DepthLayoutBottomMarginFunctionLandscape);
412 // Enable anchoring for depth layout only
413 mItemView.SetAnchoring(layoutId == DEPTH_LAYOUT);
415 // Activate the layout
416 mItemView.ActivateLayout(layoutId, Vector3(stageSize.x, stageSize.y, stageSize.x), duration);
420 * Orientation changed signal callback
423 void OnOrientationChanged( View view, Animation& animation, const Orientation& orientation )
425 const unsigned int angle = orientation.GetDegrees();
427 // If orientation really changed
428 if( mOrientation != angle )
430 // Remember orientation
431 mOrientation = angle;
433 UseLayout(mCurrentLayout, mDurationSeconds);
437 bool OnLayoutButtonClicked( Toolkit::Button button )
439 // Switch to the next layout
440 mCurrentLayout = (mCurrentLayout + 1) % mItemView.GetLayoutCount();
442 UseLayout(mCurrentLayout, mDurationSeconds);
450 bool OnModeButtonClicked( Toolkit::Button button )
457 void SwitchToNextMode()
464 mMode = MODE_REMOVE_MANY;
465 EnterRemoveManyMode();
469 case MODE_REMOVE_MANY:
471 ExitRemoveManyMode();
480 mMode = MODE_INSERT_MANY;
481 EnterInsertManyMode();
485 case MODE_INSERT_MANY:
487 ExitInsertManyMode();
488 mMode = MODE_REPLACE;
496 mMode = MODE_REPLACE_MANY;
497 EnterReplaceManyMode();
501 case MODE_REPLACE_MANY:
503 ExitReplaceManyMode();
519 void EnterRemoveMode()
521 SetTitle("Edit: Remove");
523 mTapDetector = TapGestureDetector::New();
525 for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i )
527 mTapDetector.Attach(mItemView.GetChildAt(i));
530 mTapDetector.DetectedSignal().Connect( this, &ItemViewExample::RemoveOnTap );
533 void ExitRemoveMode()
535 mTapDetector.Reset();
538 void RemoveOnTap( Actor actor, TapGesture tap )
540 mItemView.RemoveItem( mItemView.GetItemId(actor), 0.5f );
543 void EnterRemoveManyMode()
545 SetTitle("Edit: Remove Many");
547 mDeleteButton.SetVisible( true );
549 mTapDetector = TapGestureDetector::New();
551 for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i )
553 Actor child = mItemView.GetChildAt( i );
554 Actor box = child.FindChildByName( "CheckBox" );
558 mTapDetector.Attach( child );
559 box.SetVisible( true );
563 mTapDetector.DetectedSignal().Connect( this, &ItemViewExample::SelectOnTap );
566 void ExitRemoveManyMode()
568 for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i )
570 Actor child = mItemView.GetChildAt( i );
571 Actor box = child.FindChildByName( "CheckBox" );
575 box.SetVisible( false );
577 Actor tick = box.FindChildByName( "Tick" );
580 tick.SetVisible( false );
585 mTapDetector.Reset();
587 mDeleteButton.SetVisible( false );
590 void SelectOnTap( Actor actor, TapGesture tap )
592 Actor tick = actor.FindChildByName( "Tick" );
595 tick.SetVisible( !tick.IsVisible() );
599 bool OnDeleteButtonClicked( Toolkit::Button button )
601 ItemIdContainer removeList;
603 for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i )
605 Actor child = mItemView.GetChildAt( i );
606 Actor tick = child.FindChildByName( "Tick" );
608 if( tick && tick.IsVisible() )
610 removeList.push_back( mItemView.GetItemId(child) );
614 if( ! removeList.empty() )
616 mItemView.RemoveItems( removeList, 0.5f );
622 void EnterInsertMode()
624 SetTitle("Edit: Insert");
626 mTapDetector = TapGestureDetector::New();
628 for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i )
630 mTapDetector.Attach( mItemView.GetChildAt(i) );
633 mTapDetector.DetectedSignal().Connect( this, &ItemViewExample::InsertOnTap );
636 void ExitInsertMode()
638 mTapDetector.Reset();
641 void InsertOnTap( Actor actor, TapGesture tap )
643 ItemId id = mItemView.GetItemId( actor );
645 Actor newActor = NewItem( rand() );
647 mItemView.InsertItem( Item(id,newActor), 0.5f );
650 void EnterInsertManyMode()
652 SetTitle("Edit: Insert Many");
654 mInsertButton.SetVisible( true );
656 mTapDetector = TapGestureDetector::New();
658 for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i )
660 Actor child = mItemView.GetChildAt( i );
661 Actor box = child.FindChildByName( "CheckBox" );
665 mTapDetector.Attach( child );
666 box.SetVisible( true );
670 mTapDetector.DetectedSignal().Connect( this, &ItemViewExample::SelectOnTap );
673 void ExitInsertManyMode()
675 for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i )
677 Actor child = mItemView.GetChildAt( i );
678 Actor box = child.FindChildByName( "CheckBox" );
682 box.SetVisible( false );
684 Actor tick = box.FindChildByName( "Tick" );
687 tick.SetVisible( false );
692 mTapDetector.Reset();
694 mInsertButton.SetVisible( false );
697 bool OnInsertButtonClicked( Toolkit::Button button )
699 ItemContainer insertList;
701 for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i )
703 Actor child = mItemView.GetChildAt( i );
704 Actor tick = child.FindChildByName( "Tick" );
706 if( tick && tick.IsVisible() )
708 insertList.push_back( Item( mItemView.GetItemId(child), NewItem(rand()) ) );
712 if( ! insertList.empty() )
714 mItemView.InsertItems( insertList, 0.5f );
720 void EnterReplaceMode()
722 SetTitle("Edit: Replace");
724 mTapDetector = TapGestureDetector::New();
726 for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i )
728 mTapDetector.Attach(mItemView.GetChildAt(i));
731 mTapDetector.DetectedSignal().Connect( this, &ItemViewExample::ReplaceOnTap );
734 void ReplaceOnTap( Actor actor, TapGesture tap )
736 mItemView.ReplaceItem( Item( mItemView.GetItemId(actor), NewItem(rand()) ), 0.5f );
739 void ExitReplaceMode()
741 mTapDetector.Reset();
744 void EnterReplaceManyMode()
746 SetTitle("Edit: Replace Many");
748 mReplaceButton.SetVisible( true );
750 mTapDetector = TapGestureDetector::New();
752 for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i )
754 Actor child = mItemView.GetChildAt( i );
755 Actor box = child.FindChildByName( "CheckBox" );
759 mTapDetector.Attach( child );
760 box.SetVisible( true );
764 mTapDetector.DetectedSignal().Connect( this, &ItemViewExample::SelectOnTap );
767 void ExitReplaceManyMode()
769 for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i )
771 Actor child = mItemView.GetChildAt( i );
772 Actor box = child.FindChildByName( "CheckBox" );
776 box.SetVisible( false );
778 Actor tick = box.FindChildByName( "Tick" );
781 tick.SetVisible( false );
786 mTapDetector.Reset();
788 mReplaceButton.SetVisible( false );
791 bool OnReplaceButtonClicked( Toolkit::Button button )
793 ItemContainer replaceList;
795 for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i )
797 Actor child = mItemView.GetChildAt( i );
798 Actor tick = child.FindChildByName( "Tick" );
800 if( tick && tick.IsVisible() )
802 replaceList.push_back( Item( mItemView.GetItemId(child), NewItem(rand()) ) );
806 if( ! replaceList.empty() )
808 mItemView.ReplaceItems( replaceList, 0.5f );
814 void SetLayoutTitle()
816 if( MODE_NORMAL == mMode )
818 std::stringstream ss(APPLICATION_TITLE);
819 switch(mCurrentLayout)
822 ss << APPLICATION_TITLE << ": " << SPIRAL_LABEL;
825 ss << APPLICATION_TITLE << ": " << GRID_LABEL;
828 ss << APPLICATION_TITLE << ": " << DEPTH_LABEL;
837 void SetLayoutImage()
841 switch( mCurrentLayout )
845 mLayoutButton.SetBackgroundImage( Image::New( SPIRAL_LAYOUT_IMAGE ) );
851 mLayoutButton.SetBackgroundImage( Image::New( GRID_LAYOUT_IMAGE ) );
857 mLayoutButton.SetBackgroundImage( Image::New( DEPTH_LAYOUT_IMAGE ) );
867 public: // From ItemFactory
870 * Query the number of items available from the factory.
871 * The maximum available item has an ID of GetNumberOfItems() - 1.
873 virtual unsigned int GetNumberOfItems()
875 return NUM_IMAGES * 10;
879 * Create an Actor to represent a visible item.
881 * @return the created actor.
883 virtual Actor NewItem(unsigned int itemId)
885 // Create an image actor for this item
886 Image image = Image::New( IMAGE_PATHS[itemId % NUM_IMAGES] );
887 Actor actor = ImageActor::New(image);
888 actor.SetPosition( INITIAL_OFFSCREEN_POSITION );
890 // Add a border image child actor
891 ImageActor borderActor = ImageActor::New(mBorderImage);
892 borderActor.SetParentOrigin( ParentOrigin::CENTER );
893 borderActor.SetAnchorPoint( AnchorPoint::CENTER );
894 borderActor.SetPosition( 0.f, 0.f, 1.f );
895 borderActor.SetStyle( ImageActor::STYLE_NINE_PATCH );
896 borderActor.SetNinePatchBorder( Vector4( ITEM_IMAGE_BORDER_LEFT, ITEM_IMAGE_BORDER_TOP, ITEM_IMAGE_BORDER_RIGHT, ITEM_IMAGE_BORDER_BOTTOM ) );
897 borderActor.SetColorMode( USE_OWN_MULTIPLY_PARENT_COLOR ); // darken with parent image-actor
899 Constraint constraint = Constraint::New<Vector3>( Actor::SIZE, ParentSource( Actor::SIZE ), BorderSizeConstraintFunction() );
900 borderActor.ApplyConstraint(constraint);
901 actor.Add(borderActor);
902 actor.SetKeyboardFocusable( true );
904 Vector3 spiralItemSize;
905 static_cast<ItemLayout&>(*mSpiralLayout).GetItemSize( 0u, Vector3( Stage::GetCurrent().GetSize() ), spiralItemSize );
907 // Add a checkbox child actor; invisible until edit-mode is enabled
909 ImageActor checkbox = ImageActor::New( BitmapImage::WHITE() );
910 checkbox.SetName( "CheckBox" );
911 checkbox.SetColor( Vector4(0.0f,0.0f,0.0f,0.6f) );
912 checkbox.SetParentOrigin( ParentOrigin::TOP_RIGHT );
913 checkbox.SetAnchorPoint( AnchorPoint::TOP_RIGHT );
914 checkbox.SetSize( spiralItemSize.width * 0.2f, spiralItemSize.width * 0.2f );
915 checkbox.SetPosition( -SELECTION_BORDER_WIDTH, SELECTION_BORDER_WIDTH );
916 checkbox.SetZ( 1.0f );
917 if( MODE_REMOVE_MANY != mMode &&
918 MODE_INSERT_MANY != mMode &&
919 MODE_REPLACE_MANY != mMode )
921 checkbox.SetVisible( false );
923 actor.Add( checkbox );
925 ImageActor tick = ImageActor::New( Image::New(SELECTED_IMAGE) );
926 tick.SetColorMode( USE_OWN_COLOR );
927 tick.SetName( "Tick" );
928 tick.SetParentOrigin( ParentOrigin::TOP_RIGHT );
929 tick.SetAnchorPoint( AnchorPoint::TOP_RIGHT );
930 tick.SetSize( spiralItemSize.width * 0.2f, spiralItemSize.width * 0.2f );
932 tick.SetVisible( false );
933 checkbox.Add( tick );
935 // Connect new items for various editing modes
938 mTapDetector.Attach( actor );
947 * Sets/Updates the title of the View
948 * @param[in] title The new title for the view.
950 void SetTitle(const std::string& title)
954 mTitleActor = TextView::New();
955 // Add title to the tool bar.
956 mToolBar.AddControl( mTitleActor, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarTitlePercentage, Alignment::HorizontalCenter );
959 Font font = Font::New();
960 mTitleActor.SetText( title );
961 mTitleActor.SetSize( font.MeasureText( title ) );
962 mTitleActor.SetStyleToCurrentText(DemoHelper::GetDefaultTextStyle());
967 Stage stage = Stage::GetCurrent();
968 const float popupWidth = stage.GetSize().x * 0.75f;
970 mMenu = Toolkit::Popup::New();
971 mMenu.SetParentOrigin( ParentOrigin::BOTTOM_LEFT );
972 mMenu.SetAnchorPoint( AnchorPoint::BOTTOM_LEFT );
973 mMenu.OutsideTouchedSignal().Connect( this, &ItemViewExample::HideMenu );
976 TableView tableView = TableView::New( 0, 0 );
977 Vector2 tableSize = Vector2( popupWidth, MENU_OPTION_HEIGHT * 2 );
978 tableView.SetSize( tableSize );
979 mMenu.Add( tableView );
981 Slider slider = Slider::New();
982 slider.SetProperty( Slider::LOWER_BOUND_PROPERTY, 0.0f );
983 slider.SetProperty( Slider::UPPER_BOUND_PROPERTY, 3.0f );
984 slider.SetProperty( Slider::VALUE_PROPERTY, mDurationSeconds );
985 slider.SetProperty( Slider::VALUE_PRECISION_PROPERTY, 2 );
986 slider.SetProperty( Slider::SHOW_POPUP_PROPERTY, true );
987 slider.ValueChangedSignal().Connect( this, &ItemViewExample::SliderValueChange );
988 tableView.AddChild( slider, TableView::CellPosition( 0, 0 ) );
989 tableView.SetRelativeHeight( 0, 0.5f );
991 TextStyle defaultTextStyle;
992 defaultTextStyle.SetFontName(DEFAULT_TEXT_STYLE_FONT_FAMILY);
993 defaultTextStyle.SetFontStyle(DEFAULT_TEXT_STYLE_FONT_STYLE);
994 defaultTextStyle.SetFontPointSize(DEFAULT_TEXT_STYLE_POINT_SIZE);
995 defaultTextStyle.SetWeight(DEFAULT_TEXT_STYLE_WEIGHT);
996 defaultTextStyle.SetTextColor(DEFAULT_TEXT_STYLE_COLOR);
998 TextView text = TextView::New( "Duration" );
999 text.SetAnchorPoint( ParentOrigin::TOP_LEFT );
1000 text.SetParentOrigin( ParentOrigin::TOP_LEFT );
1001 text.SetTextAlignment( Dali::Toolkit::Alignment::HorizontalLeft );
1002 text.SetStyleToCurrentText( defaultTextStyle );
1003 text.SetSize( 0.0f, LABEL_TEXT_SIZE_Y );
1004 text.ApplyConstraint( Dali::Constraint::New<float>( Dali::Actor::SIZE_WIDTH, Dali::ParentSource( Dali::Actor::SIZE_WIDTH ), Dali::EqualToConstraint() ) );
1008 Actor textContainer = Actor::New();
1009 mAlphaFunctionText = TextView::New( ALPHA_FUNCTIONS_TEXT[mAlphaFuncIndex] );
1010 mAlphaFunctionText.SetAnchorPoint( ParentOrigin::CENTER );
1011 mAlphaFunctionText.SetParentOrigin( ParentOrigin::CENTER );
1012 mAlphaFunctionText.SetTextAlignment( Toolkit::Alignment::VerticalCenter );
1013 textContainer.Add( mAlphaFunctionText );
1014 tableView.AddChild( textContainer, TableView::CellPosition( 1, 0 ) );
1015 tableView.SetRelativeHeight( 0, 0.5f );
1017 mTapDetector = TapGestureDetector::New();
1018 mTapDetector.Attach(mAlphaFunctionText);
1019 mTapDetector.DetectedSignal().Connect( this, &ItemViewExample::ChangeAlphaFunctionOnTap );
1021 text = TextView::New( "Alpha Function" );
1022 text.SetAnchorPoint( ParentOrigin::TOP_LEFT );
1023 text.SetParentOrigin( ParentOrigin::TOP_LEFT );
1024 text.SetTextAlignment( Dali::Toolkit::Alignment::HorizontalLeft );
1025 text.SetStyleToCurrentText( defaultTextStyle );
1026 text.SetSize( 0.0f, LABEL_TEXT_SIZE_Y );
1027 text.ApplyConstraint( Dali::Constraint::New<float>( Dali::Actor::SIZE_WIDTH, Dali::ParentSource( Dali::Actor::SIZE_WIDTH ), Dali::EqualToConstraint() ) );
1028 textContainer.Add( text );
1034 bool SliderValueChange( Toolkit::Slider slider, float value )
1036 mDurationSeconds = value;
1041 void ChangeAlphaFunctionOnTap( Actor actor, TapGesture tap )
1043 if( NUM_ALPHA_FUNCTIONS <= ++mAlphaFuncIndex )
1045 mAlphaFuncIndex = 0;
1048 if( mAlphaFunctionText )
1050 mAlphaFunctionText.SetText( ALPHA_FUNCTIONS_TEXT[mAlphaFuncIndex] );
1055 mItemView.GetActiveLayout()->SetAlphaFunction( ALPHA_FUNCTIONS[mAlphaFuncIndex] );
1061 mTapDetector.Reset();
1073 * Main key event handler
1075 void OnKeyEvent(const KeyEvent& event)
1077 if(event.state == KeyEvent::Down)
1079 if( IsKey( event, DALI_KEY_MENU ) )
1090 else if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) )
1098 mApplication.Quit();
1106 Application& mApplication;
1110 Toolkit::View mView;
1111 unsigned int mOrientation;
1113 Toolkit::ToolBar mToolBar;
1114 TextView mTitleActor; ///< The Toolbar's Title.
1118 unsigned int mCurrentLayout;
1119 float mDurationSeconds;
1121 SpiralLayoutPtr mSpiralLayout;
1122 DepthLayoutPtr mDepthLayout;
1123 GridLayoutPtr mGridLayout;
1125 Toolkit::Popup mMenu;
1127 TapGestureDetector mTapDetector;
1128 Toolkit::PushButton mLayoutButton;
1129 Toolkit::PushButton mDeleteButton;
1130 Toolkit::PushButton mInsertButton;
1131 Toolkit::PushButton mReplaceButton;
1133 unsigned int mAlphaFuncIndex;
1134 TextView mAlphaFunctionText;
1137 void RunTest(Application& app)
1139 ItemViewExample test(app);
1144 int main(int argc, char **argv)
1146 Application app = Application::New(&argc, &argv);