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 Stage stage = Dali::Stage::GetCurrent();
207 stage.KeyEventSignal().Connect(this, &ItemViewExample::OnKeyEvent);
209 Vector2 stageSize = Stage::GetCurrent().GetSize();
211 // Create a border image shared by all the item actors
212 mBorderImage = ResourceImage::New(ITEM_BORDER_IMAGE_PATH);
214 // Creates a default view with a default tool bar.
215 // The view is added to the stage.
216 Layer contents = DemoHelper::CreateView( mApplication,
223 //app.GetWindow().GetOrientation().ChangedSignal().Connect( this, &ItemViewExample::OnOrientationChanged );
225 // Create an edit mode button. (left of toolbar)
226 Toolkit::PushButton editButton = Toolkit::PushButton::New();
227 editButton.SetBackgroundImage( ResourceImage::New( EDIT_IMAGE ) );
228 editButton.ClickedSignal().Connect( this, &ItemViewExample::OnModeButtonClicked);
229 editButton.SetLeaveRequired( true );
230 mToolBar.AddControl( editButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalLeft, DemoHelper::DEFAULT_MODE_SWITCH_PADDING );
232 // Create a layout toggle button. (right of toolbar)
233 mLayoutButton = Toolkit::PushButton::New();
234 mLayoutButton.SetBackgroundImage( ResourceImage::New( SPIRAL_LAYOUT_IMAGE ) );
235 mLayoutButton.ClickedSignal().Connect( this, &ItemViewExample::OnLayoutButtonClicked);
236 mLayoutButton.SetLeaveRequired( true );
237 mToolBar.AddControl( mLayoutButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalRight, DemoHelper::DEFAULT_MODE_SWITCH_PADDING );
239 // Create a delete button (bottom right of screen)
240 mDeleteButton = Toolkit::PushButton::New();
241 mDeleteButton.SetParentOrigin(ParentOrigin::BOTTOM_RIGHT);
242 mDeleteButton.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
243 mDeleteButton.SetPosition( BUTTON_BORDER, BUTTON_BORDER );
244 mDeleteButton.SetDrawMode( DrawMode::OVERLAY );
245 mDeleteButton.SetButtonImage( ResourceImage::New( DELETE_IMAGE ) );
246 mDeleteButton.SetBackgroundImage( ResourceImage::New( TOOLBAR_IMAGE ) );
247 mDeleteButton.SetSize( Vector2( stageSize.width * 0.15f, stageSize.width * 0.15f ) );
248 mDeleteButton.ClickedSignal().Connect( this, &ItemViewExample::OnDeleteButtonClicked);
249 mDeleteButton.SetLeaveRequired( true );
250 mDeleteButton.SetVisible( false );
251 stage.Add( mDeleteButton );
253 // Create an insert button (bottom right of screen)
254 mInsertButton = Toolkit::PushButton::New();
255 mInsertButton.SetParentOrigin(ParentOrigin::BOTTOM_RIGHT);
256 mInsertButton.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
257 mInsertButton.SetPosition( BUTTON_BORDER, BUTTON_BORDER );
258 mInsertButton.SetDrawMode( DrawMode::OVERLAY );
259 mInsertButton.SetButtonImage( ResourceImage::New( INSERT_IMAGE ) );
260 mInsertButton.SetBackgroundImage( ResourceImage::New( TOOLBAR_IMAGE ) );
261 mInsertButton.SetSize( stageSize.width * 0.15f, stageSize.width * 0.15f );
262 mInsertButton.ClickedSignal().Connect( this, &ItemViewExample::OnInsertButtonClicked);
263 mInsertButton.SetLeaveRequired( true );
264 mInsertButton.SetVisible( false );
265 stage.Add( mInsertButton );
267 // Create an replace button (bottom right of screen)
268 mReplaceButton = Toolkit::PushButton::New();
269 mReplaceButton.SetParentOrigin(ParentOrigin::BOTTOM_RIGHT);
270 mReplaceButton.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
271 mReplaceButton.SetPosition( BUTTON_BORDER, BUTTON_BORDER );
272 mReplaceButton.SetDrawMode( DrawMode::OVERLAY );
273 mReplaceButton.SetButtonImage( ResourceImage::New( REPLACE_IMAGE ) );
274 mReplaceButton.SetBackgroundImage( ResourceImage::New( TOOLBAR_IMAGE ) );
275 mReplaceButton.SetSize( stageSize.width * 0.15f, stageSize.width * 0.15f );
276 mReplaceButton.ClickedSignal().Connect( this, &ItemViewExample::OnReplaceButtonClicked);
277 mReplaceButton.SetLeaveRequired( true );
278 mReplaceButton.SetVisible( false );
279 stage.Add( mReplaceButton );
281 // Create the item view actor
282 mImageAtlas = CreateImageAtlas();
283 mItemView = ItemView::New(*this);
284 mItemView.SetParentOrigin(ParentOrigin::CENTER);
285 mItemView.SetAnchorPoint(AnchorPoint::CENTER);
287 // Display item view on the stage
288 stage.Add( mItemView );
290 // Create the layouts
291 mSpiralLayout = DefaultItemLayout::New( DefaultItemLayout::SPIRAL );
292 mDepthLayout = DefaultItemLayout::New( DefaultItemLayout::DEPTH );
293 mGridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
295 // Add the layouts to item view
296 mItemView.AddLayout(*mSpiralLayout);
297 mItemView.AddLayout(*mDepthLayout);
298 mItemView.AddLayout(*mGridLayout);
300 mItemView.SetMinimumSwipeDistance(MIN_SWIPE_DISTANCE);
301 mItemView.SetMinimumSwipeSpeed(MIN_SWIPE_SPEED);
303 // Activate the spiral layout
304 SetLayout( mCurrentLayout );
305 mItemView.SetKeyboardFocusable( true );
306 KeyboardFocusManager::Get().PreFocusChangeSignal().Connect( this, &ItemViewExample::OnKeyboardPreFocusChange );
308 // Set the title and icon to the current layout
312 // Store one 1x1 white image for multiple items to share for backgrounds:
313 mWhiteImage = BufferImage::WHITE();
316 Actor OnKeyboardPreFocusChange( Actor current, Actor proposed, Control::KeyboardFocus::Direction direction )
318 if ( !current && !proposed )
327 * Animate to a different layout
331 Animation animation = Animation::New( mDurationSeconds );
332 animation.FinishedSignal().Connect( this, &ItemViewExample::AnimationFinished );
333 animation.AnimateTo( Property( mItemView, Actor::Property::COLOR_ALPHA ), 0.0f );
337 void AnimationFinished( Animation& )
339 SetLayout( mCurrentLayout );
341 Animation animation = Animation::New( mDurationSeconds );
342 animation.AnimateTo( Property( mItemView, Actor::Property::COLOR_ALPHA ), 1.0f );
347 * Switch to a different item view layout
349 void SetLayout( int layoutId )
351 // Set the new orientation to the layout
352 mItemView.GetLayout(layoutId)->SetOrientation(static_cast<ControlOrientation::Type>(mOrientation / 90));
354 Vector2 stageSize = Stage::GetCurrent().GetSize();
356 if(layoutId == DEPTH_LAYOUT)
358 // Set up the depth layout according to the new orientation
359 if(Toolkit::IsVertical(mDepthLayout->GetOrientation()))
361 mDepthLayout->SetItemSize( DepthLayoutItemSizeFunctionPortrait( stageSize.width ) );
365 mDepthLayout->SetItemSize( DepthLayoutItemSizeFunctionLandscape( stageSize.height ) );
369 // Enable anchoring for depth layout only
370 mItemView.SetAnchoring(layoutId == DEPTH_LAYOUT);
372 // Activate the layout
373 mItemView.ActivateLayout( layoutId, Vector3(stageSize.x, stageSize.y, stageSize.x), 0.0f );
377 * Orientation changed signal callback
380 void OnOrientationChanged( Orientation orientation )
382 const unsigned int angle = orientation.GetDegrees();
384 // If orientation really changed
385 if( mOrientation != angle )
387 // Remember orientation
388 mOrientation = angle;
390 SetLayout( mCurrentLayout );
394 bool OnLayoutButtonClicked( Toolkit::Button button )
396 // Switch to the next layout
397 mCurrentLayout = (mCurrentLayout + 1) % mItemView.GetLayoutCount();
407 bool OnModeButtonClicked( Toolkit::Button button )
414 void SwitchToNextMode()
421 mMode = MODE_REMOVE_MANY;
422 EnterRemoveManyMode();
426 case MODE_REMOVE_MANY:
428 ExitRemoveManyMode();
437 mMode = MODE_INSERT_MANY;
438 EnterInsertManyMode();
442 case MODE_INSERT_MANY:
444 ExitInsertManyMode();
445 mMode = MODE_REPLACE;
453 mMode = MODE_REPLACE_MANY;
454 EnterReplaceManyMode();
458 case MODE_REPLACE_MANY:
460 ExitReplaceManyMode();
476 void EnterRemoveMode()
478 SetTitle("Edit: Remove");
480 mTapDetector = TapGestureDetector::New();
482 for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i )
484 mTapDetector.Attach(mItemView.GetChildAt(i));
487 mTapDetector.DetectedSignal().Connect( this, &ItemViewExample::RemoveOnTap );
490 void ExitRemoveMode()
492 mTapDetector.Reset();
495 void RemoveOnTap( Actor actor, const TapGesture& tap )
497 mItemView.RemoveItem( mItemView.GetItemId(actor), 0.5f );
500 void EnterRemoveManyMode()
502 SetTitle("Edit: Remove Many");
504 mDeleteButton.SetVisible( true );
506 mTapDetector = TapGestureDetector::New();
508 for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i )
510 Actor child = mItemView.GetChildAt( i );
511 Actor box = child.FindChildByName( "CheckBox" );
515 mTapDetector.Attach( child );
516 box.SetVisible( true );
520 mTapDetector.DetectedSignal().Connect( this, &ItemViewExample::SelectOnTap );
523 void ExitRemoveManyMode()
525 for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i )
527 Actor child = mItemView.GetChildAt( i );
528 Actor box = child.FindChildByName( "CheckBox" );
532 box.SetVisible( false );
534 Actor tick = box.FindChildByName( "Tick" );
537 tick.SetVisible( false );
542 mTapDetector.Reset();
544 mDeleteButton.SetVisible( false );
547 void SelectOnTap( Actor actor, const TapGesture& tap )
549 Actor tick = actor.FindChildByName( "Tick" );
552 tick.SetVisible( !tick.IsVisible() );
556 bool OnDeleteButtonClicked( Toolkit::Button button )
558 ItemIdContainer removeList;
560 for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i )
562 Actor child = mItemView.GetChildAt( i );
563 Actor tick = child.FindChildByName( "Tick" );
565 if( tick && tick.IsVisible() )
567 removeList.push_back( mItemView.GetItemId(child) );
571 if( ! removeList.empty() )
573 mItemView.RemoveItems( removeList, 0.5f );
579 void EnterInsertMode()
581 SetTitle("Edit: Insert");
583 mTapDetector = TapGestureDetector::New();
585 for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i )
587 mTapDetector.Attach( mItemView.GetChildAt(i) );
590 mTapDetector.DetectedSignal().Connect( this, &ItemViewExample::InsertOnTap );
593 void ExitInsertMode()
595 mTapDetector.Reset();
598 void InsertOnTap( Actor actor, const TapGesture& tap )
600 ItemId id = mItemView.GetItemId( actor );
602 Actor newActor = NewItem( rand() );
604 mItemView.InsertItem( Item(id,newActor), 0.5f );
607 void EnterInsertManyMode()
609 SetTitle("Edit: Insert Many");
611 mInsertButton.SetVisible( true );
613 mTapDetector = TapGestureDetector::New();
615 for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i )
617 Actor child = mItemView.GetChildAt( i );
618 Actor box = child.FindChildByName( "CheckBox" );
622 mTapDetector.Attach( child );
623 box.SetVisible( true );
627 mTapDetector.DetectedSignal().Connect( this, &ItemViewExample::SelectOnTap );
630 void ExitInsertManyMode()
632 for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i )
634 Actor child = mItemView.GetChildAt( i );
635 Actor box = child.FindChildByName( "CheckBox" );
639 box.SetVisible( false );
641 Actor tick = box.FindChildByName( "Tick" );
644 tick.SetVisible( false );
649 mTapDetector.Reset();
651 mInsertButton.SetVisible( false );
654 bool OnInsertButtonClicked( Toolkit::Button button )
656 ItemContainer insertList;
658 for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i )
660 Actor child = mItemView.GetChildAt( i );
661 Actor tick = child.FindChildByName( "Tick" );
663 if( tick && tick.IsVisible() )
665 insertList.push_back( Item( mItemView.GetItemId(child), NewItem(rand()) ) );
669 if( ! insertList.empty() )
671 mItemView.InsertItems( insertList, 0.5f );
677 void EnterReplaceMode()
679 SetTitle("Edit: Replace");
681 mTapDetector = TapGestureDetector::New();
683 for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i )
685 mTapDetector.Attach(mItemView.GetChildAt(i));
688 mTapDetector.DetectedSignal().Connect( this, &ItemViewExample::ReplaceOnTap );
691 void ReplaceOnTap( Actor actor, const TapGesture& tap )
693 mItemView.ReplaceItem( Item( mItemView.GetItemId(actor), NewItem(rand()) ), 0.5f );
696 void ExitReplaceMode()
698 mTapDetector.Reset();
701 void EnterReplaceManyMode()
703 SetTitle("Edit: Replace Many");
705 mReplaceButton.SetVisible( true );
707 mTapDetector = TapGestureDetector::New();
709 for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i )
711 Actor child = mItemView.GetChildAt( i );
712 Actor box = child.FindChildByName( "CheckBox" );
716 mTapDetector.Attach( child );
717 box.SetVisible( true );
721 mTapDetector.DetectedSignal().Connect( this, &ItemViewExample::SelectOnTap );
724 void ExitReplaceManyMode()
726 for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i )
728 Actor child = mItemView.GetChildAt( i );
729 Actor box = child.FindChildByName( "CheckBox" );
733 box.SetVisible( false );
735 Actor tick = box.FindChildByName( "Tick" );
738 tick.SetVisible( false );
743 mTapDetector.Reset();
745 mReplaceButton.SetVisible( false );
748 bool OnReplaceButtonClicked( Toolkit::Button button )
750 ItemContainer replaceList;
752 for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i )
754 Actor child = mItemView.GetChildAt( i );
755 Actor tick = child.FindChildByName( "Tick" );
757 if( tick && tick.IsVisible() )
759 replaceList.push_back( Item( mItemView.GetItemId(child), NewItem(rand()) ) );
763 if( ! replaceList.empty() )
765 mItemView.ReplaceItems( replaceList, 0.5f );
771 void SetLayoutTitle()
773 if( MODE_NORMAL == mMode )
775 std::stringstream ss(APPLICATION_TITLE);
776 switch(mCurrentLayout)
779 ss << APPLICATION_TITLE << ": " << SPIRAL_LABEL;
782 ss << APPLICATION_TITLE << ": " << GRID_LABEL;
785 ss << APPLICATION_TITLE << ": " << DEPTH_LABEL;
794 void SetLayoutImage()
798 switch( mCurrentLayout )
802 mLayoutButton.SetBackgroundImage( ResourceImage::New( SPIRAL_LAYOUT_IMAGE ) );
808 mLayoutButton.SetBackgroundImage( ResourceImage::New( GRID_LAYOUT_IMAGE ) );
814 mLayoutButton.SetBackgroundImage( ResourceImage::New( DEPTH_LAYOUT_IMAGE ) );
824 public: // From ItemFactory
827 * Query the number of items available from the factory.
828 * The maximum available item has an ID of GetNumberOfItems() - 1.
830 virtual unsigned int GetNumberOfItems()
832 return NUM_IMAGES * 10;
836 * Create an Actor to represent a visible item.
838 * @return the created actor.
840 virtual Actor NewItem(unsigned int itemId)
842 // Create an image actor for this item
843 unsigned int imageId = itemId % NUM_IMAGES;
844 ImageActor::PixelArea pixelArea( (imageId%NUM_IMAGE_PER_ROW_IN_ATLAS)*IMAGE_WIDTH,
845 (imageId/NUM_IMAGE_PER_ROW_IN_ATLAS)*IMAGE_HEIGHT,
848 Actor actor = ImageActor::New(mImageAtlas, pixelArea);
849 actor.SetPosition( INITIAL_OFFSCREEN_POSITION );
851 // Add a border image child actor
852 ImageActor borderActor = ImageActor::New(mBorderImage);
853 borderActor.SetParentOrigin( ParentOrigin::CENTER );
854 borderActor.SetAnchorPoint( AnchorPoint::CENTER );
855 borderActor.SetPosition( 0.f, 0.f, 1.f );
856 borderActor.SetStyle( ImageActor::STYLE_NINE_PATCH );
857 borderActor.SetNinePatchBorder( Vector4( ITEM_IMAGE_BORDER_LEFT, ITEM_IMAGE_BORDER_TOP, ITEM_IMAGE_BORDER_RIGHT, ITEM_IMAGE_BORDER_BOTTOM ) );
858 borderActor.SetColorMode( USE_OWN_MULTIPLY_PARENT_COLOR ); // darken with parent image-actor
859 borderActor.SetResizePolicy( ResizePolicy::SIZE_FIXED_OFFSET_FROM_PARENT, Dimension::ALL_DIMENSIONS );
860 borderActor.SetSizeModeFactor( ITEM_BORDER_MARGIN_SIZE );
861 actor.Add(borderActor);
862 actor.SetKeyboardFocusable( true );
864 Vector3 spiralItemSize;
865 static_cast<ItemLayout&>(*mSpiralLayout).GetItemSize( 0u, Vector3( Stage::GetCurrent().GetSize() ), spiralItemSize );
867 // Add a checkbox child actor; invisible until edit-mode is enabled
869 ImageActor checkbox = ImageActor::New( mWhiteImage );
870 checkbox.SetName( "CheckBox" );
871 checkbox.SetColor( Vector4(0.0f,0.0f,0.0f,0.6f) );
872 checkbox.SetParentOrigin( ParentOrigin::TOP_RIGHT );
873 checkbox.SetAnchorPoint( AnchorPoint::TOP_RIGHT );
874 checkbox.SetSize( spiralItemSize.width * 0.2f, spiralItemSize.width * 0.2f );
875 checkbox.SetPosition( -SELECTION_BORDER_WIDTH, SELECTION_BORDER_WIDTH );
876 checkbox.SetZ( 1.0f );
877 if( MODE_REMOVE_MANY != mMode &&
878 MODE_INSERT_MANY != mMode &&
879 MODE_REPLACE_MANY != mMode )
881 checkbox.SetVisible( false );
883 actor.Add( checkbox );
885 ImageActor tick = ImageActor::New( ResourceImage::New(SELECTED_IMAGE) );
886 tick.SetColorMode( USE_OWN_COLOR );
887 tick.SetName( "Tick" );
888 tick.SetParentOrigin( ParentOrigin::TOP_RIGHT );
889 tick.SetAnchorPoint( AnchorPoint::TOP_RIGHT );
890 tick.SetSize( spiralItemSize.width * 0.2f, spiralItemSize.width * 0.2f );
892 tick.SetVisible( false );
893 checkbox.Add( tick );
895 // Connect new items for various editing modes
898 mTapDetector.Attach( actor );
907 * Create an Atlas to tile the images inside.
909 Atlas CreateImageAtlas()
911 const unsigned int atlas_width = IMAGE_WIDTH*NUM_IMAGE_PER_ROW_IN_ATLAS;
912 const unsigned int atlas_height = IMAGE_HEIGHT*ceil( static_cast<float>(NUM_IMAGES)/ static_cast<float>(NUM_IMAGE_PER_ROW_IN_ATLAS));
913 Atlas atlas = Atlas::New(atlas_width, atlas_height, Pixel::RGB888);
915 for( unsigned int i = 0; i < NUM_IMAGES; i++ )
917 atlas.Upload( IMAGE_PATHS[i], (i%NUM_IMAGE_PER_ROW_IN_ATLAS)*IMAGE_WIDTH, (i/NUM_IMAGE_PER_ROW_IN_ATLAS)*IMAGE_HEIGHT );
924 * Sets/Updates the title of the View
925 * @param[in] title The new title for the view.
927 void SetTitle(const std::string& title)
931 mTitleActor = DemoHelper::CreateToolBarLabel( "" );
932 // Add title to the tool bar.
933 mToolBar.AddControl( mTitleActor, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarTitlePercentage, Alignment::HorizontalCenter );
936 mTitleActor.SetProperty( TextLabel::Property::TEXT, title );
940 * Main key event handler
942 void OnKeyEvent(const KeyEvent& event)
944 if(event.state == KeyEvent::Down)
946 if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) )
955 Application& mApplication;
958 Toolkit::Control mView;
959 unsigned int mOrientation;
961 Toolkit::ToolBar mToolBar;
962 TextLabel mTitleActor; ///< The Toolbar's Title.
967 unsigned int mCurrentLayout;
968 float mDurationSeconds;
970 ItemLayoutPtr mSpiralLayout;
971 ItemLayoutPtr mDepthLayout;
972 ItemLayoutPtr mGridLayout;
974 TapGestureDetector mTapDetector;
975 Toolkit::PushButton mLayoutButton;
976 Toolkit::PushButton mDeleteButton;
977 Toolkit::PushButton mInsertButton;
978 Toolkit::PushButton mReplaceButton;
980 BufferImage mWhiteImage;
983 void RunTest(Application& app)
985 ItemViewExample test(app);
990 int main(int argc, char **argv)
992 Application app = Application::New(&argc, &argv, DALI_DEMO_THEME_PATH);