scroll-view-example.cpp
25.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
//
// Copyright (c) 2014 Samsung Electronics Co., Ltd.
//
// Licensed under the Flora License, Version 1.0 (the License);
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://floralicense.org/license/
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an AS IS BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// EXTERNAL INCLUDES
#include <sstream>
// INTERNAL INCLUDES
#include "../shared/view.h"
#include <dali/dali.h>
#include <dali-toolkit/dali-toolkit.h>
using namespace std;
using namespace Dali;
using namespace Dali::Toolkit;
namespace
{
const char * const BACKGROUND_IMAGE( DALI_IMAGE_DIR "background-default.png" );
const char * const TOOLBAR_IMAGE( DALI_IMAGE_DIR "top-bar.png" );
const char * const APPLICATION_TITLE( "ScrollView" );
const char * const EFFECT_OUTER_CUBE_IMAGE( DALI_IMAGE_DIR "icon-scroll-view-outer-cube.png" );
const char * const EFFECT_DEPTH_IMAGE( DALI_IMAGE_DIR "icon-scroll-view-depth.png" );
const char * const EFFECT_INNER_CUBE_IMAGE( DALI_IMAGE_DIR "icon-scroll-view-inner-cube.png" );
const char * const EFFECT_CAROUSEL_IMAGE( DALI_IMAGE_DIR "icon-scroll-view-carousel.png" );
const char * const EFFECT_SPIRAL_IMAGE( DALI_IMAGE_DIR "icon-scroll-view-spiral.png" );
const Vector3 ICON_SIZE(100.0f, 100.0f, 0.0f);
const char* EFFECT_MODE_NAME[] = {
"OuterCube",
"Depth",
"Cube",
"InnerCube",
"Carousel",
"Spiral",
};
const char * const 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",
NULL
};
const char * const GetNextImagePath()
{
static const char * const * imagePtr = &IMAGE_PATHS[0];
if ( *(++imagePtr) == NULL )
{
imagePtr = &IMAGE_PATHS[0];
}
return *imagePtr;
}
const int PAGE_COLUMNS = 10; ///< Number of Pages going across (columns)
const int PAGE_ROWS = 1; ///< Number of Pages going down (rows)
const int IMAGE_COLUMNS = 3; ///< Number of Images going across (columns) within a Page
const int IMAGE_ROWS = 5; ///< Number of Images going down (rows) with a Page
// 3D Effect constants
const Vector3 ANGLE_CUBE_PAGE_ROTATE(Math::PI * 0.2f, Math::PI * 0.2f, 0.0f); ///< Cube page rotates as if it has ten sides with the camera positioned inside
const Vector2 ANGLE_CUSTOM_CUBE_SWING(-Math::PI * 0.45f, -Math::PI * 0.45f); ///< outer cube pages swing 90 degrees as they pan offscreen
const Vector2 ANGLE_SPIRAL_SWING_IN(Math::PI * 0.45f, Math::PI * 0.45f);
const Vector2 ANGLE_SPIRAL_SWING_OUT(Math::PI * 0.3f, Math::PI * 0.3f);
// Depth Effect constants
const Vector2 POSITION_EXTENT_DEPTH_EFFECT(0.5f, 2.5f); ///< Extent of X & Y position to alter function exponent.
const Vector2 OFFSET_EXTENT_DEPTH_EFFECT(1.0f, 1.0f); ///< Function exponent offset constant.
const float POSITION_SCALE_DEPTH_EFFECT(1.5f); ///< Position scaling.
const float SCALE_EXTENT_DEPTH_EFFECT(0.5f); ///< Maximum scale factor when Actors scrolled one page away (50% size)
// 3D Effect constants
const Vector2 ANGLE_SWING_3DEFFECT(Math::PI_2 * 0.75, Math::PI_2 * 0.75f); ///< Angle Swing in radians
const Vector2 POSITION_SWING_3DEFFECT(0.25f, 0.25f); ///< Position Swing relative to stage size.
const Vector3 ANCHOR_3DEFFECT_STYLE0(-105.0f, 30.0f, -240.0f); ///< Rotation Anchor position for 3D Effect (Style 0)
const Vector3 ANCHOR_3DEFFECT_STYLE1(65.0f, -70.0f, -300.0f); ///< Rotation Anchor position for 3D Effect (Style 1)
const unsigned int IMAGE_THUMBNAIL_WIDTH = 256; ///< Width of Thumbnail Image in texels
const unsigned int IMAGE_THUMBNAIL_HEIGHT = 256; ///< Height of Thumbnail Image in texels
const float SPIN_DURATION = 5.0f; ///< Times to spin an Image by upon touching, each spin taking a second.
const float EFFECT_SNAP_DURATION(0.66f); ///< Scroll Snap Duration for Effects
const float EFFECT_FLICK_DURATION(0.5f); ///< Scroll Flick Duration for Effects
} // unnamed namespace
/**
* This example shows how to do custom Scroll Effects
*/
class ExampleController : public ConnectionTracker
{
public:
/**
* Constructor
* @param application class, stored as reference
*/
ExampleController( Application& application )
: mApplication( application ),
mView(),
mScrolling(false),
mEffectMode(CubeEffect)
{
// Connect to the Application's Init and orientation changed signal
mApplication.InitSignal().Connect(this, &ExampleController::OnInit);
}
~ExampleController()
{
// Nothing to do here; everything gets deleted automatically
}
/**
* This method gets called once the main loop of application is up and running
*/
void OnInit(Application& app)
{
Stage::GetCurrent().KeyEventSignal().Connect(this, &ExampleController::OnKeyEvent);
// Hide the indicator bar
mApplication.GetWindow().ShowIndicator(false);
// Creates a default view with a default tool bar.
// The view is added to the stage.
mContentLayer = DemoHelper::CreateView( app,
mView,
mToolBar,
BACKGROUND_IMAGE,
TOOLBAR_IMAGE,
"" );
mEffectIcon[ OuterCubeEffect ] = Image::New( EFFECT_OUTER_CUBE_IMAGE );
mEffectIcon[ DepthEffect ] = Image::New( EFFECT_DEPTH_IMAGE );
mEffectIcon[ CubeEffect ] = Image::New( EFFECT_INNER_CUBE_IMAGE );
mEffectIcon[ InnerCubeEffect ] = Image::New( EFFECT_INNER_CUBE_IMAGE );
mEffectIcon[ CarouselEffect ] = Image::New( EFFECT_CAROUSEL_IMAGE );
mEffectIcon[ SpiralEffect ] = Image::New( EFFECT_SPIRAL_IMAGE );
// Create a effect change button. (right of toolbar)
mEffectChangeButton = Toolkit::PushButton::New();
mEffectChangeButton.ClickedSignal().Connect( this, &ExampleController::OnEffectTouched );
mToolBar.AddControl( mEffectChangeButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalRight, DemoHelper::DEFAULT_MODE_SWITCH_PADDING );
// Create the content layer.
AddContentLayer();
// Hack to force screen refresh.
Animation animation = Animation::New(1.0f);
animation.AnimateTo(Property(mContentLayer, Actor::POSITION), Vector3::ZERO );
animation.Play();
}
private:
/**
* Adds content to the ContentLayer. This is everything we see
* excluding the toolbar at the top.
*/
void AddContentLayer()
{
Stage stage = Stage::GetCurrent();
Vector2 stageSize = stage.GetSize();
mScrollView = ScrollView::New();
mScrollView.SetAnchorPoint(AnchorPoint::CENTER);
mScrollView.SetParentOrigin(ParentOrigin::CENTER);
mContentLayer.Add( mScrollView );
mScrollView.SetSize( stageSize );
mScrollView.SetAxisAutoLock( true );
mScrollView.SetAxisAutoLockGradient( 1.0f );
mScrollView.ScrollStartedSignal().Connect( this, &ExampleController::OnScrollStarted );
mScrollView.ScrollCompletedSignal().Connect( this, &ExampleController::OnScrollCompleted );
for(int row = 0;row<PAGE_ROWS;row++)
{
for(int column = 0;column<PAGE_COLUMNS;column++)
{
Actor page = CreatePage();
page.SetPosition( column * stageSize.x, row * stageSize.y );
mScrollView.Add( page );
mPages.push_back(page);
}
}
Update();
}
/**
* Updates the ScrollView and it's children based
* on the current effect.
*/
void Update()
{
std::stringstream ss(APPLICATION_TITLE);
ss << APPLICATION_TITLE << ": " << EFFECT_MODE_NAME[mEffectMode];
SetTitle(ss.str());
mEffectChangeButton.SetBackgroundImage( mEffectIcon[ mEffectMode ] );
// remove old Effect if exists.
if(mScrollViewEffect)
{
mScrollView.RemoveEffect(mScrollViewEffect);
}
// apply new Effect to ScrollView
ApplyEffectToScrollView();
for(ActorIter pageIter = mPages.begin(); pageIter != mPages.end(); ++pageIter)
{
Actor page = *pageIter;
ApplyEffectToPage( page );
unsigned int numChildren = (*pageIter).GetChildCount();
for(unsigned int i=0; i<numChildren; ++i)
{
Actor image = (*pageIter).GetChildAt(i);
// Remove old effect's manual constraints.
image.RemoveConstraints();
// Apply new effect's manual constraints.
ApplyEffectToActor( image, page );
}
}
}
/**
* Creates a page using a source of images.
*/
Actor CreatePage()
{
Actor page = Actor::New();
page.ApplyConstraint( Constraint::New<Vector3>( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ) );
page.SetParentOrigin( ParentOrigin::CENTER );
page.SetAnchorPoint( AnchorPoint::CENTER );
Stage stage = Stage::GetCurrent();
Vector2 stageSize = stage.GetSize();
const float margin = 10.0f;
const Vector3 imageSize((stageSize.x / IMAGE_COLUMNS) - margin, (stageSize.y / IMAGE_ROWS) - margin, 0.0f);
for(int row = 0;row<IMAGE_ROWS;row++)
{
for(int column = 0;column<IMAGE_COLUMNS;column++)
{
ImageActor image = CreateImage( GetNextImagePath() );
image.SetParentOrigin( ParentOrigin::CENTER );
image.SetAnchorPoint( AnchorPoint::CENTER );
Vector3 position( margin * 0.5f + (imageSize.x + margin) * column - stageSize.width * 0.5f,
margin * 0.5f + (imageSize.y + margin) * row - stageSize.height * 0.5f,
0.0f);
image.SetPosition( position + imageSize * 0.5f );
image.SetSize( imageSize );
page.Add(image);
}
}
return page;
}
/**
* [ScrollView]
* Applies effect to scrollView
*/
void ApplyEffectToScrollView()
{
bool wrap(true);
bool snap(true);
Stage stage = Stage::GetCurrent();
Vector2 stageSize = stage.GetSize();
switch(mEffectMode)
{
case OuterCubeEffect:
{
SetupOuterPageCubeEffect();
break;
}
case DepthEffect:
{
mScrollViewEffect = ScrollViewDepthEffect::New();
mScrollView.SetScrollSnapDuration(EFFECT_SNAP_DURATION);
mScrollView.SetScrollFlickDuration(EFFECT_FLICK_DURATION);
mScrollView.SetScrollSnapAlphaFunction(AlphaFunctions::EaseOut);
mScrollView.SetScrollFlickAlphaFunction(AlphaFunctions::EaseOut);
mScrollView.RemoveConstraintsFromChildren();
break;
}
case CubeEffect:
{
mScrollViewEffect = ScrollViewCubeEffect::New();
mScrollView.SetScrollSnapDuration(EFFECT_SNAP_DURATION);
mScrollView.SetScrollFlickDuration(EFFECT_FLICK_DURATION);
mScrollView.SetScrollSnapAlphaFunction(AlphaFunctions::EaseOutBack);
mScrollView.SetScrollFlickAlphaFunction(AlphaFunctions::EaseOutBack);
mScrollView.RemoveConstraintsFromChildren();
break;
}
case InnerCubeEffect:
{
SetupInnerPageCubeEffect();
break;
}
case CarouselEffect:
{
SetupCarouselPageEffect();
break;
}
case SpiralEffect:
{
SetupSpiralPageEffect();
break;
}
default:
{
break;
}
} // end switch
if(mScrollViewEffect)
{
mScrollView.ApplyEffect(mScrollViewEffect);
}
mScrollView.SetWrapMode(wrap);
RulerPtr rulerX = CreateRuler(snap ? stageSize.width : 0.0f);
RulerPtr rulerY = new DefaultRuler;
rulerX->SetDomain(RulerDomain(0.0f, stageSize.x * PAGE_COLUMNS, !wrap));
rulerY->Disable();
mScrollView.SetRulerX( rulerX );
mScrollView.SetRulerY( rulerY );
}
/**
* Creates a Ruler that snaps to a specified grid size.
* If that grid size is 0.0 then this ruler does not
* snap.
*
* @param[in] gridSize (optional) The grid size for the ruler,
* (Default = 0.0 i.e. no snapping)
* @return The ruler is returned.
*/
RulerPtr CreateRuler(float gridSize = 0.0f)
{
if(gridSize <= Math::MACHINE_EPSILON_0)
{
return new DefaultRuler();
}
return new FixedRuler(gridSize);
}
void SetupInnerPageCubeEffect()
{
ScrollViewCustomEffect customEffect;
mScrollViewEffect = customEffect = ScrollViewCustomEffect::New();
mScrollView.SetScrollSnapDuration(EFFECT_SNAP_DURATION);
mScrollView.SetScrollFlickDuration(EFFECT_FLICK_DURATION);
mScrollView.SetScrollSnapAlphaFunction(AlphaFunctions::EaseOutBack);
mScrollView.SetScrollFlickAlphaFunction(AlphaFunctions::EaseOutBack);
mScrollView.RemoveConstraintsFromChildren();
customEffect.SetPageSpacing(Vector2(30.0f, 30.0f));
customEffect.SetAngledOriginPageRotation(ANGLE_CUBE_PAGE_ROTATE);
customEffect.SetSwingAngle(ANGLE_CUBE_PAGE_ROTATE.x, Vector3(0,-1,0));
customEffect.SetOpacityThreshold(0.7f);
}
void SetupOuterPageCubeEffect()
{
ScrollViewCustomEffect customEffect;
mScrollViewEffect = customEffect = ScrollViewCustomEffect::New();
mScrollView.SetScrollSnapDuration(EFFECT_SNAP_DURATION);
mScrollView.SetScrollFlickDuration(EFFECT_FLICK_DURATION);
mScrollView.SetScrollSnapAlphaFunction(AlphaFunctions::EaseOut);
mScrollView.SetScrollFlickAlphaFunction(AlphaFunctions::EaseOut);
mScrollView.RemoveConstraintsFromChildren();
Vector2 pageSize = Stage::GetCurrent().GetSize();
customEffect.SetPageTranslation(Vector3(pageSize.x, pageSize.y, 0));
customEffect.SetSwingAngleOut(ANGLE_CUSTOM_CUBE_SWING.x, Vector3(0.0f, -1.0f, 0.0f));
customEffect.SetSwingAnchor(AnchorPoint::CENTER, AnchorPoint::CENTER_LEFT);
customEffect.SetOpacityThreshold(0.5f);
}
void SetupCarouselPageEffect()
{
ScrollViewCustomEffect customEffect;
mScrollViewEffect = customEffect = ScrollViewCustomEffect::New();
mScrollView.SetScrollSnapDuration(EFFECT_SNAP_DURATION);
mScrollView.SetScrollFlickDuration(EFFECT_FLICK_DURATION);
mScrollView.SetScrollSnapAlphaFunction(AlphaFunctions::EaseOutBack);
mScrollView.SetScrollFlickAlphaFunction(AlphaFunctions::EaseOutBack);
mScrollView.RemoveConstraintsFromChildren();
customEffect.SetPageTranslation(Vector3(0,0,0), Vector3(-30, 0, 0));
customEffect.SetPageSpacing(Vector2(60.0f, 60.0f));
customEffect.SetAngledOriginPageRotation(-ANGLE_CUBE_PAGE_ROTATE);
customEffect.SetOpacityThreshold(0.2f, 0.6f);
}
void SetupSpiralPageEffect()
{
ScrollViewCustomEffect customEffect;
mScrollViewEffect = customEffect = ScrollViewCustomEffect::New();
mScrollView.SetScrollSnapDuration(EFFECT_SNAP_DURATION);
mScrollView.SetScrollFlickDuration(EFFECT_FLICK_DURATION);
mScrollView.SetScrollSnapAlphaFunction(AlphaFunctions::EaseOutBack);
mScrollView.SetScrollFlickAlphaFunction(AlphaFunctions::EaseOutBack);
mScrollView.RemoveConstraintsFromChildren();
Vector2 pageSize = Stage::GetCurrent().GetSize();
customEffect.SetPageTranslation(Vector3(pageSize.x, pageSize.y, 0.0f));
customEffect.SetSwingAngle(-ANGLE_SPIRAL_SWING_IN.x, Vector3(0.0f, -1.0f, 0.0f), ANGLE_SPIRAL_SWING_OUT.x, Vector3(0.0f, -1.0f, 0.0f));
customEffect.SetSwingAnchor(AnchorPoint::CENTER_RIGHT);
customEffect.SetPageTranslation(Vector3(pageSize.x, pageSize.y, 0), Vector3(pageSize.x, pageSize.y, 0) * 0.5f);
customEffect.SetOpacityThreshold(0.66f);
}
/**
* [Page]
* Applies effect to the pages within scroll view.
*
* @param[in] page The page Actor to apply effect to.
*/
void ApplyEffectToPage(Actor page)
{
page.RemoveConstraints();
page.ApplyConstraint( Constraint::New<Vector3>( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ) );
if( ( mEffectMode == InnerCubeEffect ) ||
( mEffectMode == OuterCubeEffect ) ||
( mEffectMode == SpiralEffect ) ||
( mEffectMode == CarouselEffect) )
{
ApplyCustomEffectToPage(page);
}
}
void ApplyCustomEffectToPage(Actor page)
{
ScrollViewCustomEffect customEffect = ScrollViewCustomEffect::DownCast(mScrollViewEffect);
Vector2 vStageSize(Stage::GetCurrent().GetSize());
customEffect.ApplyToPage(page, Vector3(vStageSize.x, vStageSize.y, 1.0f));
}
/**
* [Actor]
* Applies effect to child which resides in page (which in turn resides in scrollview)
*
* @note Page is typically the Parent of child, although in
* some scenarios Page is simply a container which has a child as
* a descendent.
*
* @param[in] child The child actor to apply effect to
* @param[in] page The page which this child is inside
*/
void ApplyEffectToActor( Actor child, Actor page )
{
if( mEffectMode == DepthEffect )
{
ApplyDepthEffectToActor( child );
}
else if(mEffectMode == CubeEffect )
{
ApplyCubeEffectToActor( child );
}
}
/**
* Applies depth effect to the child which resides in page (which in turn resides in scrollview)
*
* @param[in] child The child actor to apply depth effect to
*/
void ApplyDepthEffectToActor( Actor child )
{
ScrollViewDepthEffect depthEffect = ScrollViewDepthEffect::DownCast(mScrollViewEffect);
depthEffect.ApplyToActor( child,
POSITION_EXTENT_DEPTH_EFFECT,
OFFSET_EXTENT_DEPTH_EFFECT,
POSITION_SCALE_DEPTH_EFFECT,
SCALE_EXTENT_DEPTH_EFFECT );
}
void ApplyCubeEffectToActor( Actor child )
{
Vector3 anchor;
if(rand()&1)
{
anchor = ANCHOR_3DEFFECT_STYLE0;
}
else
{
anchor = ANCHOR_3DEFFECT_STYLE1;
}
ScrollViewCubeEffect cubeEffect = ScrollViewCubeEffect::DownCast(mScrollViewEffect);
cubeEffect.ApplyToActor( child,
anchor,
ANGLE_SWING_3DEFFECT,
POSITION_SWING_3DEFFECT * Vector2(Stage::GetCurrent().GetSize()));
}
/**
* Creates an Image (Helper)
*
* @param[in] filename the path of the image.
* @param[in] width the width of the image in texels
* @param[in] height the height of the image in texels.
*/
ImageActor CreateImage( const std::string& filename, unsigned int width = IMAGE_THUMBNAIL_WIDTH, unsigned int height = IMAGE_THUMBNAIL_HEIGHT )
{
ImageAttributes attributes;
attributes.SetSize(width, height);
attributes.SetScalingMode(ImageAttributes::ShrinkToFit);
Image img = Image::New(filename, attributes);
ImageActor actor = ImageActor::New(img);
actor.SetName( filename );
actor.SetParentOrigin(ParentOrigin::CENTER);
actor.SetAnchorPoint(AnchorPoint::CENTER);
actor.TouchedSignal().Connect( this, &ExampleController::OnTouchImage );
return actor;
}
/**
* When scroll starts (i.e. user starts to drag scrollview),
* note this state (mScrolling = true)
* @param[in] position Current Scroll Position
*/
void OnScrollStarted( const Vector3& position )
{
mScrolling = true;
}
/**
* When scroll starts (i.e. user stops dragging scrollview, and scrollview has snapped to destination),
* note this state (mScrolling = false)
* @param[in] position Current Scroll Position
*/
void OnScrollCompleted( const Vector3& position )
{
mScrolling = false;
}
/**
* Upon Touching an image (Release), make it spin
* (provided we're not scrolling).
* @param[in] actor The actor touched
* @param[in] event The TouchEvent.
*/
bool OnTouchImage( Actor actor, const TouchEvent& event )
{
if( (event.points.size() > 0) && (!mScrolling) )
{
TouchPoint point = event.points[0];
if(point.state == TouchPoint::Up)
{
// Spin the Image a few times.
Animation animation = Animation::New(SPIN_DURATION);
animation.RotateBy( actor, Degree(360.0f * SPIN_DURATION), Vector3::XAXIS, AlphaFunctions::EaseOut);
animation.Play();
}
}
return false;
}
/**
* Signal handler, called when the 'Effect' button has been touched.
*
* @param[in] button The button that was pressed.
*/
bool OnEffectTouched(Button button)
{
mEffectMode = static_cast<EffectMode>((static_cast<int>(mEffectMode) + 1) % static_cast<int>(Total));
Update();
return true;
}
/**
* Sets/Updates the title of the View
* @param[in] title The new title for the view.
*/
void SetTitle(const std::string& title)
{
if(!mTitleActor)
{
mTitleActor = TextView::New();
// Add title to the tool bar.
mToolBar.AddControl( mTitleActor, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarTitlePercentage, Alignment::HorizontalCenter );
}
Font font = Font::New();
mTitleActor.SetText( title );
mTitleActor.SetSize( font.MeasureText( title ) );
mTitleActor.SetStyleToCurrentText(DemoHelper::GetDefaultTextStyle());
}
/**
* Main key event handler
*/
void OnKeyEvent(const KeyEvent& event)
{
if(event.state == KeyEvent::Down)
{
if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) )
{
mApplication.Quit();
}
}
}
private:
Application& mApplication; ///< Application instance
Toolkit::View mView; ///< The View instance.
Toolkit::ToolBar mToolBar; ///< The View's Toolbar.
TextView mTitleActor; ///< The Toolbar's Title.
Layer mContentLayer; ///< The content layer (contains game actors)
ScrollView mScrollView; ///< ScrollView UI Component
bool mScrolling; ///< ScrollView scrolling state (true = scrolling, false = stationary)
ScrollViewEffect mScrollViewEffect; ///< ScrollView Effect instance.
ActorContainer mPages; ///< Keeps track of all the pages for applying effects.
/**
* Enumeration of different effects this scrollview can operate under.
*/
enum EffectMode
{
OuterCubeEffect, ///< Outer Cube Effect
DepthEffect, ///< Depth Effect
CubeEffect, ///< Cube effect
InnerCubeEffect, ///< Page Cube Effect
CarouselEffect, ///< Page Carousel Effect
SpiralEffect, ///< Page Spiral Effect
Total,
};
EffectMode mEffectMode; ///< Current Effect mode
Image mEffectIcon[Total]; ///< Icons for the effect button
Toolkit::PushButton mEffectChangeButton; ///< Effect Change Button
};
int main(int argc, char **argv)
{
Application app = Application::New(&argc, &argv);
ExampleController test(app);
app.MainLoop();
return 0;
}