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>
28 #include <dali/devel-api/images/atlas.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 const unsigned int IMAGE_WIDTH = 256;
104 const unsigned int IMAGE_HEIGHT = 256;
105 const unsigned int NUM_IMAGE_PER_ROW_IN_ATLAS = 8;
107 const char* BACKGROUND_IMAGE( "" );
108 const char* TOOLBAR_IMAGE( DALI_IMAGE_DIR "top-bar.png" );
109 const char* EDIT_IMAGE( DALI_IMAGE_DIR "icon-edit.png" );
110 const char* SPIRAL_LAYOUT_IMAGE( DALI_IMAGE_DIR "icon-item-view-layout-spiral.png" );
111 const char* GRID_LAYOUT_IMAGE( DALI_IMAGE_DIR "icon-item-view-layout-grid.png" );
112 const char* DEPTH_LAYOUT_IMAGE( DALI_IMAGE_DIR "icon-item-view-layout-depth.png" );
113 const char* DELETE_IMAGE( DALI_IMAGE_DIR "icon-delete.png" );
114 const char* REPLACE_IMAGE( DALI_IMAGE_DIR "icon-replace.png" );
115 const char* INSERT_IMAGE( DALI_IMAGE_DIR "icon-insert.png" );
116 const char* SELECTED_IMAGE( DALI_IMAGE_DIR "item-select-check.png" );
117 const char* APPLICATION_TITLE( "ItemView" );
119 const char* SPIRAL_LABEL("Spiral");
120 const char* GRID_LABEL("Grid");
121 const char* DEPTH_LABEL("Depth");
123 const char* ITEM_BORDER_IMAGE_PATH( DALI_IMAGE_DIR "frame-128x128.png" );
124 const Vector3 ITEM_BORDER_MARGIN_SIZE(24, 24, 0);
126 // These values depend on the border image
127 const float ITEM_IMAGE_BORDER_LEFT = 13.0f;
128 const float ITEM_IMAGE_BORDER_RIGHT = 13.0f;
129 const float ITEM_IMAGE_BORDER_TOP = 13.0f;
130 const float ITEM_IMAGE_BORDER_BOTTOM = 13.0f;
132 const float DEPTH_LAYOUT_ITEM_SIZE_FACTOR_PORTRAIT = 1.0f;
133 const float DEPTH_LAYOUT_ITEM_SIZE_FACTOR_LANDSCAPE = 0.8f;
134 const float DEPTH_LAYOUT_COLUMNS = 3.0f;
136 const float MIN_SWIPE_DISTANCE = 15.0f;
137 const float MIN_SWIPE_SPEED = 5.0f;
139 const float SELECTION_BORDER_WIDTH = 3.0f;
140 const float BUTTON_BORDER = -10.0f;
141 const float MENU_OPTION_HEIGHT(140.0f);
142 const float LABEL_TEXT_SIZE_Y = 20.0f;
144 const Vector3 INITIAL_OFFSCREEN_POSITION( 1000.0f, 0, -1000.0f );
146 static Vector3 DepthLayoutItemSizeFunctionPortrait( float layoutWidth )
148 float width = ( layoutWidth / ( DEPTH_LAYOUT_COLUMNS + 1.0f ) ) * DEPTH_LAYOUT_ITEM_SIZE_FACTOR_PORTRAIT;
151 return Vector3(width, width, width);
154 static Vector3 DepthLayoutItemSizeFunctionLandscape( float layoutWidth )
156 float width = ( layoutWidth / ( DEPTH_LAYOUT_COLUMNS + 1.0f ) ) * DEPTH_LAYOUT_ITEM_SIZE_FACTOR_LANDSCAPE;
159 return Vector3(width, width, width);
162 } // unnamed namespace
165 * This example shows how to use ItemView UI control.
166 * There are three layouts created for ItemView, i.e., Spiral, Depth and Grid.
167 * There is one button in the upper-left corner for quitting the application and
168 * another button in the upper-right corner for switching between different layouts.
170 class ItemViewExample : public ConnectionTracker, public ItemFactory
188 * @param application class, stored as reference
190 ItemViewExample( Application& application )
191 : mApplication( application ),
192 mMode( MODE_NORMAL ),
194 mCurrentLayout( SPIRAL_LAYOUT ),
195 mDurationSeconds( 0.25f )
197 // Connect to the Application's Init signal
198 mApplication.InitSignal().Connect(this, &ItemViewExample::OnInit);
202 * This method gets called once the main loop of application is up and running
204 void OnInit(Application& app)
206 DemoHelper::RequestThemeChange();
208 Stage stage = Dali::Stage::GetCurrent();
209 stage.KeyEventSignal().Connect(this, &ItemViewExample::OnKeyEvent);
211 Vector2 stageSize = Stage::GetCurrent().GetSize();
213 // Create a border image shared by all the item actors
214 mBorderImage = ResourceImage::New(ITEM_BORDER_IMAGE_PATH);
216 // Creates a default view with a default tool bar.
217 // The view is added to the stage.
218 Layer contents = DemoHelper::CreateView( mApplication,
225 app.GetWindow().GetOrientation().ChangedSignal().Connect( this, &ItemViewExample::OnOrientationChanged );
227 // Create an edit mode button. (left of toolbar)
228 Toolkit::PushButton editButton = Toolkit::PushButton::New();
229 editButton.SetBackgroundImage( ResourceImage::New( EDIT_IMAGE ) );
230 editButton.ClickedSignal().Connect( this, &ItemViewExample::OnModeButtonClicked);
231 editButton.SetLeaveRequired( true );
232 mToolBar.AddControl( editButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalLeft, DemoHelper::DEFAULT_MODE_SWITCH_PADDING );
234 // Create a layout toggle button. (right of toolbar)
235 mLayoutButton = Toolkit::PushButton::New();
236 mLayoutButton.SetBackgroundImage( ResourceImage::New( SPIRAL_LAYOUT_IMAGE ) );
237 mLayoutButton.ClickedSignal().Connect( this, &ItemViewExample::OnLayoutButtonClicked);
238 mLayoutButton.SetLeaveRequired( true );
239 mToolBar.AddControl( mLayoutButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalRight, DemoHelper::DEFAULT_MODE_SWITCH_PADDING );
241 // Create a delete button (bottom right of screen)
242 mDeleteButton = Toolkit::PushButton::New();
243 mDeleteButton.SetParentOrigin(ParentOrigin::BOTTOM_RIGHT);
244 mDeleteButton.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
245 mDeleteButton.SetPosition( BUTTON_BORDER, BUTTON_BORDER );
246 mDeleteButton.SetDrawMode( DrawMode::OVERLAY );
247 mDeleteButton.SetButtonImage( ResourceImage::New( DELETE_IMAGE ) );
248 mDeleteButton.SetBackgroundImage( ResourceImage::New( TOOLBAR_IMAGE ) );
249 mDeleteButton.SetSize( Vector2( stageSize.width * 0.15f, stageSize.width * 0.15f ) );
250 mDeleteButton.ClickedSignal().Connect( this, &ItemViewExample::OnDeleteButtonClicked);
251 mDeleteButton.SetLeaveRequired( true );
252 mDeleteButton.SetVisible( false );
253 stage.Add( mDeleteButton );
255 // Create an insert button (bottom right of screen)
256 mInsertButton = Toolkit::PushButton::New();
257 mInsertButton.SetParentOrigin(ParentOrigin::BOTTOM_RIGHT);
258 mInsertButton.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
259 mInsertButton.SetPosition( BUTTON_BORDER, BUTTON_BORDER );
260 mInsertButton.SetDrawMode( DrawMode::OVERLAY );
261 mInsertButton.SetButtonImage( ResourceImage::New( INSERT_IMAGE ) );
262 mInsertButton.SetBackgroundImage( ResourceImage::New( TOOLBAR_IMAGE ) );
263 mInsertButton.SetSize( stageSize.width * 0.15f, stageSize.width * 0.15f );
264 mInsertButton.ClickedSignal().Connect( this, &ItemViewExample::OnInsertButtonClicked);
265 mInsertButton.SetLeaveRequired( true );
266 mInsertButton.SetVisible( false );
267 stage.Add( mInsertButton );
269 // Create an replace button (bottom right of screen)
270 mReplaceButton = Toolkit::PushButton::New();
271 mReplaceButton.SetParentOrigin(ParentOrigin::BOTTOM_RIGHT);
272 mReplaceButton.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
273 mReplaceButton.SetPosition( BUTTON_BORDER, BUTTON_BORDER );
274 mReplaceButton.SetDrawMode( DrawMode::OVERLAY );
275 mReplaceButton.SetButtonImage( ResourceImage::New( REPLACE_IMAGE ) );
276 mReplaceButton.SetBackgroundImage( ResourceImage::New( TOOLBAR_IMAGE ) );
277 mReplaceButton.SetSize( stageSize.width * 0.15f, stageSize.width * 0.15f );
278 mReplaceButton.ClickedSignal().Connect( this, &ItemViewExample::OnReplaceButtonClicked);
279 mReplaceButton.SetLeaveRequired( true );
280 mReplaceButton.SetVisible( false );
281 stage.Add( mReplaceButton );
283 // Create the item view actor
284 mImageAtlas = CreateImageAtlas();
285 mItemView = ItemView::New(*this);
286 mItemView.SetParentOrigin(ParentOrigin::CENTER);
287 mItemView.SetAnchorPoint(AnchorPoint::CENTER);
289 // Display item view on the stage
290 stage.Add( mItemView );
292 // Create the layouts
293 mSpiralLayout = DefaultItemLayout::New( DefaultItemLayout::SPIRAL );
294 mDepthLayout = DefaultItemLayout::New( DefaultItemLayout::DEPTH );
295 mGridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
297 // Add the layouts to item view
298 mItemView.AddLayout(*mSpiralLayout);
299 mItemView.AddLayout(*mDepthLayout);
300 mItemView.AddLayout(*mGridLayout);
302 mItemView.SetMinimumSwipeDistance(MIN_SWIPE_DISTANCE);
303 mItemView.SetMinimumSwipeSpeed(MIN_SWIPE_SPEED);
305 // Activate the spiral layout
306 SetLayout( mCurrentLayout );
307 mItemView.SetKeyboardFocusable( true );
308 KeyboardFocusManager::Get().PreFocusChangeSignal().Connect( this, &ItemViewExample::OnKeyboardPreFocusChange );
310 // Set the title and icon to the current layout
314 // Store one 1x1 white image for multiple items to share for backgrounds:
315 mWhiteImage = BufferImage::WHITE();
318 Actor OnKeyboardPreFocusChange( Actor current, Actor proposed, Control::KeyboardFocusNavigationDirection direction )
320 if ( !current && !proposed )
329 * Animate to a different layout
333 Animation animation = Animation::New( mDurationSeconds );
334 animation.FinishedSignal().Connect( this, &ItemViewExample::AnimationFinished );
335 animation.AnimateTo( Property( mItemView, Actor::Property::COLOR_ALPHA ), 0.0f );
339 void AnimationFinished( Animation& )
341 SetLayout( mCurrentLayout );
343 Animation animation = Animation::New( mDurationSeconds );
344 animation.AnimateTo( Property( mItemView, Actor::Property::COLOR_ALPHA ), 1.0f );
349 * Switch to a different item view layout
351 void SetLayout( int layoutId )
353 // Set the new orientation to the layout
354 mItemView.GetLayout(layoutId)->SetOrientation(static_cast<ControlOrientation::Type>(mOrientation / 90));
356 Vector2 stageSize = Stage::GetCurrent().GetSize();
358 if(layoutId == DEPTH_LAYOUT)
360 // Set up the depth layout according to the new orientation
361 if(Toolkit::IsVertical(mDepthLayout->GetOrientation()))
363 mDepthLayout->SetItemSize( DepthLayoutItemSizeFunctionPortrait( stageSize.width ) );
367 mDepthLayout->SetItemSize( DepthLayoutItemSizeFunctionLandscape( stageSize.height ) );
371 // Enable anchoring for depth layout only
372 mItemView.SetAnchoring(layoutId == DEPTH_LAYOUT);
374 // Activate the layout
375 mItemView.ActivateLayout( layoutId, Vector3(stageSize.x, stageSize.y, stageSize.x), 0.0f );
379 * Orientation changed signal callback
382 void OnOrientationChanged( Orientation orientation )
384 const unsigned int angle = orientation.GetDegrees();
386 // If orientation really changed
387 if( mOrientation != angle )
389 // Remember orientation
390 mOrientation = angle;
392 SetLayout( mCurrentLayout );
396 bool OnLayoutButtonClicked( Toolkit::Button button )
398 // Switch to the next layout
399 mCurrentLayout = (mCurrentLayout + 1) % mItemView.GetLayoutCount();
409 bool OnModeButtonClicked( Toolkit::Button button )
416 void SwitchToNextMode()
423 mMode = MODE_REMOVE_MANY;
424 EnterRemoveManyMode();
428 case MODE_REMOVE_MANY:
430 ExitRemoveManyMode();
439 mMode = MODE_INSERT_MANY;
440 EnterInsertManyMode();
444 case MODE_INSERT_MANY:
446 ExitInsertManyMode();
447 mMode = MODE_REPLACE;
455 mMode = MODE_REPLACE_MANY;
456 EnterReplaceManyMode();
460 case MODE_REPLACE_MANY:
462 ExitReplaceManyMode();
478 void EnterRemoveMode()
480 SetTitle("Edit: Remove");
482 mTapDetector = TapGestureDetector::New();
484 for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i )
486 mTapDetector.Attach(mItemView.GetChildAt(i));
489 mTapDetector.DetectedSignal().Connect( this, &ItemViewExample::RemoveOnTap );
492 void ExitRemoveMode()
494 mTapDetector.Reset();
497 void RemoveOnTap( Actor actor, const TapGesture& tap )
499 mItemView.RemoveItem( mItemView.GetItemId(actor), 0.5f );
502 void EnterRemoveManyMode()
504 SetTitle("Edit: Remove Many");
506 mDeleteButton.SetVisible( true );
508 mTapDetector = TapGestureDetector::New();
510 for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i )
512 Actor child = mItemView.GetChildAt( i );
513 Actor box = child.FindChildByName( "CheckBox" );
517 mTapDetector.Attach( child );
518 box.SetVisible( true );
522 mTapDetector.DetectedSignal().Connect( this, &ItemViewExample::SelectOnTap );
525 void ExitRemoveManyMode()
527 for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i )
529 Actor child = mItemView.GetChildAt( i );
530 Actor box = child.FindChildByName( "CheckBox" );
534 box.SetVisible( false );
536 Actor tick = box.FindChildByName( "Tick" );
539 tick.SetVisible( false );
544 mTapDetector.Reset();
546 mDeleteButton.SetVisible( false );
549 void SelectOnTap( Actor actor, const TapGesture& tap )
551 Actor tick = actor.FindChildByName( "Tick" );
554 tick.SetVisible( !tick.IsVisible() );
558 bool OnDeleteButtonClicked( Toolkit::Button button )
560 ItemIdContainer removeList;
562 for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i )
564 Actor child = mItemView.GetChildAt( i );
565 Actor tick = child.FindChildByName( "Tick" );
567 if( tick && tick.IsVisible() )
569 removeList.push_back( mItemView.GetItemId(child) );
573 if( ! removeList.empty() )
575 mItemView.RemoveItems( removeList, 0.5f );
581 void EnterInsertMode()
583 SetTitle("Edit: Insert");
585 mTapDetector = TapGestureDetector::New();
587 for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i )
589 mTapDetector.Attach( mItemView.GetChildAt(i) );
592 mTapDetector.DetectedSignal().Connect( this, &ItemViewExample::InsertOnTap );
595 void ExitInsertMode()
597 mTapDetector.Reset();
600 void InsertOnTap( Actor actor, const TapGesture& tap )
602 ItemId id = mItemView.GetItemId( actor );
604 Actor newActor = NewItem( rand() );
606 mItemView.InsertItem( Item(id,newActor), 0.5f );
609 void EnterInsertManyMode()
611 SetTitle("Edit: Insert Many");
613 mInsertButton.SetVisible( true );
615 mTapDetector = TapGestureDetector::New();
617 for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i )
619 Actor child = mItemView.GetChildAt( i );
620 Actor box = child.FindChildByName( "CheckBox" );
624 mTapDetector.Attach( child );
625 box.SetVisible( true );
629 mTapDetector.DetectedSignal().Connect( this, &ItemViewExample::SelectOnTap );
632 void ExitInsertManyMode()
634 for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i )
636 Actor child = mItemView.GetChildAt( i );
637 Actor box = child.FindChildByName( "CheckBox" );
641 box.SetVisible( false );
643 Actor tick = box.FindChildByName( "Tick" );
646 tick.SetVisible( false );
651 mTapDetector.Reset();
653 mInsertButton.SetVisible( false );
656 bool OnInsertButtonClicked( Toolkit::Button button )
658 ItemContainer insertList;
660 for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i )
662 Actor child = mItemView.GetChildAt( i );
663 Actor tick = child.FindChildByName( "Tick" );
665 if( tick && tick.IsVisible() )
667 insertList.push_back( Item( mItemView.GetItemId(child), NewItem(rand()) ) );
671 if( ! insertList.empty() )
673 mItemView.InsertItems( insertList, 0.5f );
679 void EnterReplaceMode()
681 SetTitle("Edit: Replace");
683 mTapDetector = TapGestureDetector::New();
685 for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i )
687 mTapDetector.Attach(mItemView.GetChildAt(i));
690 mTapDetector.DetectedSignal().Connect( this, &ItemViewExample::ReplaceOnTap );
693 void ReplaceOnTap( Actor actor, const TapGesture& tap )
695 mItemView.ReplaceItem( Item( mItemView.GetItemId(actor), NewItem(rand()) ), 0.5f );
698 void ExitReplaceMode()
700 mTapDetector.Reset();
703 void EnterReplaceManyMode()
705 SetTitle("Edit: Replace Many");
707 mReplaceButton.SetVisible( true );
709 mTapDetector = TapGestureDetector::New();
711 for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i )
713 Actor child = mItemView.GetChildAt( i );
714 Actor box = child.FindChildByName( "CheckBox" );
718 mTapDetector.Attach( child );
719 box.SetVisible( true );
723 mTapDetector.DetectedSignal().Connect( this, &ItemViewExample::SelectOnTap );
726 void ExitReplaceManyMode()
728 for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i )
730 Actor child = mItemView.GetChildAt( i );
731 Actor box = child.FindChildByName( "CheckBox" );
735 box.SetVisible( false );
737 Actor tick = box.FindChildByName( "Tick" );
740 tick.SetVisible( false );
745 mTapDetector.Reset();
747 mReplaceButton.SetVisible( false );
750 bool OnReplaceButtonClicked( Toolkit::Button button )
752 ItemContainer replaceList;
754 for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i )
756 Actor child = mItemView.GetChildAt( i );
757 Actor tick = child.FindChildByName( "Tick" );
759 if( tick && tick.IsVisible() )
761 replaceList.push_back( Item( mItemView.GetItemId(child), NewItem(rand()) ) );
765 if( ! replaceList.empty() )
767 mItemView.ReplaceItems( replaceList, 0.5f );
773 void SetLayoutTitle()
775 if( MODE_NORMAL == mMode )
777 std::stringstream ss(APPLICATION_TITLE);
778 switch(mCurrentLayout)
781 ss << APPLICATION_TITLE << ": " << SPIRAL_LABEL;
784 ss << APPLICATION_TITLE << ": " << GRID_LABEL;
787 ss << APPLICATION_TITLE << ": " << DEPTH_LABEL;
796 void SetLayoutImage()
800 switch( mCurrentLayout )
804 mLayoutButton.SetBackgroundImage( ResourceImage::New( SPIRAL_LAYOUT_IMAGE ) );
810 mLayoutButton.SetBackgroundImage( ResourceImage::New( GRID_LAYOUT_IMAGE ) );
816 mLayoutButton.SetBackgroundImage( ResourceImage::New( DEPTH_LAYOUT_IMAGE ) );
826 public: // From ItemFactory
829 * Query the number of items available from the factory.
830 * The maximum available item has an ID of GetNumberOfItems() - 1.
832 virtual unsigned int GetNumberOfItems()
834 return NUM_IMAGES * 10;
838 * Create an Actor to represent a visible item.
840 * @return the created actor.
842 virtual Actor NewItem(unsigned int itemId)
844 // Create an image actor for this item
845 unsigned int imageId = itemId % NUM_IMAGES;
846 ImageActor::PixelArea pixelArea( (imageId%NUM_IMAGE_PER_ROW_IN_ATLAS)*IMAGE_WIDTH,
847 (imageId/NUM_IMAGE_PER_ROW_IN_ATLAS)*IMAGE_HEIGHT,
850 Actor actor = ImageActor::New(mImageAtlas, pixelArea);
851 actor.SetPosition( INITIAL_OFFSCREEN_POSITION );
853 // Add a border image child actor
854 ImageActor borderActor = ImageActor::New(mBorderImage);
855 borderActor.SetParentOrigin( ParentOrigin::CENTER );
856 borderActor.SetAnchorPoint( AnchorPoint::CENTER );
857 borderActor.SetPosition( 0.f, 0.f, 1.f );
858 borderActor.SetStyle( ImageActor::STYLE_NINE_PATCH );
859 borderActor.SetNinePatchBorder( Vector4( ITEM_IMAGE_BORDER_LEFT, ITEM_IMAGE_BORDER_TOP, ITEM_IMAGE_BORDER_RIGHT, ITEM_IMAGE_BORDER_BOTTOM ) );
860 borderActor.SetColorMode( USE_OWN_MULTIPLY_PARENT_COLOR ); // darken with parent image-actor
861 borderActor.SetResizePolicy( ResizePolicy::SIZE_FIXED_OFFSET_FROM_PARENT, Dimension::ALL_DIMENSIONS );
862 borderActor.SetSizeModeFactor( ITEM_BORDER_MARGIN_SIZE );
863 actor.Add(borderActor);
864 actor.SetKeyboardFocusable( true );
866 Vector3 spiralItemSize;
867 static_cast<ItemLayout&>(*mSpiralLayout).GetItemSize( 0u, Vector3( Stage::GetCurrent().GetSize() ), spiralItemSize );
869 // Add a checkbox child actor; invisible until edit-mode is enabled
871 ImageActor checkbox = ImageActor::New( mWhiteImage );
872 checkbox.SetName( "CheckBox" );
873 checkbox.SetColor( Vector4(0.0f,0.0f,0.0f,0.6f) );
874 checkbox.SetParentOrigin( ParentOrigin::TOP_RIGHT );
875 checkbox.SetAnchorPoint( AnchorPoint::TOP_RIGHT );
876 checkbox.SetSize( spiralItemSize.width * 0.2f, spiralItemSize.width * 0.2f );
877 checkbox.SetPosition( -SELECTION_BORDER_WIDTH, SELECTION_BORDER_WIDTH );
878 checkbox.SetZ( 1.0f );
879 if( MODE_REMOVE_MANY != mMode &&
880 MODE_INSERT_MANY != mMode &&
881 MODE_REPLACE_MANY != mMode )
883 checkbox.SetVisible( false );
885 actor.Add( checkbox );
887 ImageActor tick = ImageActor::New( ResourceImage::New(SELECTED_IMAGE) );
888 tick.SetColorMode( USE_OWN_COLOR );
889 tick.SetName( "Tick" );
890 tick.SetParentOrigin( ParentOrigin::TOP_RIGHT );
891 tick.SetAnchorPoint( AnchorPoint::TOP_RIGHT );
892 tick.SetSize( spiralItemSize.width * 0.2f, spiralItemSize.width * 0.2f );
894 tick.SetVisible( false );
895 checkbox.Add( tick );
897 // Connect new items for various editing modes
900 mTapDetector.Attach( actor );
909 * Create an Atlas to tile the images inside.
911 Atlas CreateImageAtlas()
913 const unsigned int atlas_width = IMAGE_WIDTH*NUM_IMAGE_PER_ROW_IN_ATLAS;
914 const unsigned int atlas_height = IMAGE_HEIGHT*ceil( static_cast<float>(NUM_IMAGES)/ static_cast<float>(NUM_IMAGE_PER_ROW_IN_ATLAS));
915 Atlas atlas = Atlas::New(atlas_width, atlas_height, Pixel::RGB888);
917 for( unsigned int i = 0; i < NUM_IMAGES; i++ )
919 atlas.Upload( IMAGE_PATHS[i], (i%NUM_IMAGE_PER_ROW_IN_ATLAS)*IMAGE_WIDTH, (i/NUM_IMAGE_PER_ROW_IN_ATLAS)*IMAGE_HEIGHT );
926 * Sets/Updates the title of the View
927 * @param[in] title The new title for the view.
929 void SetTitle(const std::string& title)
933 mTitleActor = DemoHelper::CreateToolBarLabel( "" );
934 // Add title to the tool bar.
935 mToolBar.AddControl( mTitleActor, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarTitlePercentage, Alignment::HorizontalCenter );
938 mTitleActor.SetProperty( TextLabel::Property::TEXT, title );
942 * Main key event handler
944 void OnKeyEvent(const KeyEvent& event)
946 if(event.state == KeyEvent::Down)
948 if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) )
957 Application& mApplication;
960 Toolkit::Control mView;
961 unsigned int mOrientation;
963 Toolkit::ToolBar mToolBar;
964 TextLabel mTitleActor; ///< The Toolbar's Title.
969 unsigned int mCurrentLayout;
970 float mDurationSeconds;
972 ItemLayoutPtr mSpiralLayout;
973 ItemLayoutPtr mDepthLayout;
974 ItemLayoutPtr mGridLayout;
976 TapGestureDetector mTapDetector;
977 Toolkit::PushButton mLayoutButton;
978 Toolkit::PushButton mDeleteButton;
979 Toolkit::PushButton mInsertButton;
980 Toolkit::PushButton mReplaceButton;
982 BufferImage mWhiteImage;
985 void RunTest(Application& app)
987 ItemViewExample test(app);
992 int main(int argc, char **argv)
994 Application app = Application::New(&argc, &argv);