Commit dd1469baad23937c868bf10a787b7dd66e5e3920
1 parent
1353cb13
Modified scroll-view-example to use path based scroll view effects
Change-Id: Iebf13abe6ef65c880afa22c1010d5350a40c1067
Showing
1 changed file
with
100 additions
and
46 deletions
examples/scroll-view/scroll-view-example.cpp
| 1 | /* | 1 | /* |
| 2 | - * Copyright (c) 2014 Samsung Electronics Co., Ltd. | 2 | + * Copyright (c) 2015 Samsung Electronics Co., Ltd. |
| 3 | * | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. | 5 | * you may not use this file except in compliance with the License. |
| @@ -42,7 +42,8 @@ const char* EFFECT_MODE_NAME[] = { | @@ -42,7 +42,8 @@ const char* EFFECT_MODE_NAME[] = { | ||
| 42 | "Cube", | 42 | "Cube", |
| 43 | "PageCarousel", | 43 | "PageCarousel", |
| 44 | "PageCube", | 44 | "PageCube", |
| 45 | - "PageSpiral" | 45 | + "PageSpiral", |
| 46 | + "PageWave" | ||
| 46 | }; | 47 | }; |
| 47 | 48 | ||
| 48 | const char * const IMAGE_PATHS[] = { | 49 | const char * const IMAGE_PATHS[] = { |
| @@ -201,6 +202,7 @@ public: | @@ -201,6 +202,7 @@ public: | ||
| 201 | mEffectIcon[ PageCarouselEffect ] = ResourceImage::New( EFFECT_CAROUSEL_IMAGE ); | 202 | mEffectIcon[ PageCarouselEffect ] = ResourceImage::New( EFFECT_CAROUSEL_IMAGE ); |
| 202 | mEffectIcon[ PageCubeEffect ] = ResourceImage::New( EFFECT_CAROUSEL_IMAGE ); | 203 | mEffectIcon[ PageCubeEffect ] = ResourceImage::New( EFFECT_CAROUSEL_IMAGE ); |
| 203 | mEffectIcon[ PageSpiralEffect ] = ResourceImage::New( EFFECT_CAROUSEL_IMAGE ); | 204 | mEffectIcon[ PageSpiralEffect ] = ResourceImage::New( EFFECT_CAROUSEL_IMAGE ); |
| 205 | + mEffectIcon[ PageWaveEffect ] = ResourceImage::New( EFFECT_CAROUSEL_IMAGE ); | ||
| 204 | 206 | ||
| 205 | // Create a effect change button. (right of toolbar) | 207 | // Create a effect change button. (right of toolbar) |
| 206 | mEffectChangeButton = Toolkit::PushButton::New(); | 208 | mEffectChangeButton = Toolkit::PushButton::New(); |
| @@ -274,11 +276,11 @@ private: | @@ -274,11 +276,11 @@ private: | ||
| 274 | 276 | ||
| 275 | // apply new Effect to ScrollView | 277 | // apply new Effect to ScrollView |
| 276 | ApplyEffectToScrollView(); | 278 | ApplyEffectToScrollView(); |
| 277 | - | 279 | + unsigned int pageCount(0); |
| 278 | for( std::vector< Actor >::iterator pageIter = mPages.begin(); pageIter != mPages.end(); ++pageIter) | 280 | for( std::vector< Actor >::iterator pageIter = mPages.begin(); pageIter != mPages.end(); ++pageIter) |
| 279 | { | 281 | { |
| 280 | Actor page = *pageIter; | 282 | Actor page = *pageIter; |
| 281 | - ApplyEffectToPage( page ); | 283 | + ApplyEffectToPage( page, pageCount++ ); |
| 282 | 284 | ||
| 283 | unsigned int numChildren = (*pageIter).GetChildCount(); | 285 | unsigned int numChildren = (*pageIter).GetChildCount(); |
| 284 | for(unsigned int i=0; i<numChildren; ++i) | 286 | for(unsigned int i=0; i<numChildren; ++i) |
| @@ -346,6 +348,11 @@ private: | @@ -346,6 +348,11 @@ private: | ||
| 346 | Stage stage = Stage::GetCurrent(); | 348 | Stage stage = Stage::GetCurrent(); |
| 347 | Vector2 stageSize = stage.GetSize(); | 349 | Vector2 stageSize = stage.GetSize(); |
| 348 | 350 | ||
| 351 | + RulerPtr rulerX = CreateRuler(snap ? stageSize.width : 0.0f); | ||
| 352 | + RulerPtr rulerY = new DefaultRuler; | ||
| 353 | + rulerX->SetDomain(RulerDomain(0.0f, stageSize.x * PAGE_COLUMNS, !wrap)); | ||
| 354 | + rulerY->Disable(); | ||
| 355 | + | ||
| 349 | switch( mEffectMode ) | 356 | switch( mEffectMode ) |
| 350 | { | 357 | { |
| 351 | case DepthEffect: | 358 | case DepthEffect: |
| @@ -371,35 +378,95 @@ private: | @@ -371,35 +378,95 @@ private: | ||
| 371 | } | 378 | } |
| 372 | 379 | ||
| 373 | case PageCarouselEffect: | 380 | case PageCarouselEffect: |
| 374 | - { | ||
| 375 | - mScrollViewEffect = ScrollViewPageCarouselEffect::New(); | ||
| 376 | - mScrollView.SetScrollSnapDuration(EFFECT_SNAP_DURATION); | ||
| 377 | - mScrollView.SetScrollFlickDuration(EFFECT_FLICK_DURATION); | ||
| 378 | - mScrollView.SetScrollSnapAlphaFunction(AlphaFunction::EASE_OUT); | ||
| 379 | - mScrollView.SetScrollFlickAlphaFunction(AlphaFunction::EASE_OUT); | ||
| 380 | - mScrollView.RemoveConstraintsFromChildren(); | ||
| 381 | - break; | ||
| 382 | - } | ||
| 383 | - | ||
| 384 | case PageCubeEffect: | 381 | case PageCubeEffect: |
| 385 | - { | ||
| 386 | - mScrollViewEffect = ScrollViewPageCubeEffect::New(); | ||
| 387 | - mScrollView.SetScrollSnapDuration(EFFECT_SNAP_DURATION); | ||
| 388 | - mScrollView.SetScrollFlickDuration(EFFECT_FLICK_DURATION); | ||
| 389 | - mScrollView.SetScrollSnapAlphaFunction(AlphaFunction::EASE_OUT); | ||
| 390 | - mScrollView.SetScrollFlickAlphaFunction(AlphaFunction::EASE_OUT); | ||
| 391 | - mScrollView.RemoveConstraintsFromChildren(); | ||
| 392 | - break; | ||
| 393 | - } | ||
| 394 | - | ||
| 395 | case PageSpiralEffect: | 382 | case PageSpiralEffect: |
| 383 | + case PageWaveEffect: | ||
| 396 | { | 384 | { |
| 397 | - mScrollViewEffect = ScrollViewPageSpiralEffect::New(); | 385 | + Dali::Path path = Dali::Path::New(); |
| 386 | + Dali::Property::Array points; | ||
| 387 | + points.resize(3); | ||
| 388 | + Dali::Property::Array controlPoints; | ||
| 389 | + controlPoints.resize(4); | ||
| 390 | + Vector3 forward; | ||
| 391 | + if( mEffectMode == PageCarouselEffect) | ||
| 392 | + { | ||
| 393 | + | ||
| 394 | + points[0] = Vector3( stageSize.x*0.75, 0.0f, -stageSize.x*0.75f); | ||
| 395 | + points[1] = Vector3( 0.0f, 0.0f, 0.0f ); | ||
| 396 | + points[2] = Vector3( -stageSize.x*0.75f, 0.0f, -stageSize.x*0.75f); | ||
| 397 | + path.SetProperty( Path::Property::POINTS, points ); | ||
| 398 | + | ||
| 399 | + controlPoints[0] = Vector3( stageSize.x*0.5f, 0.0f, 0.0f ); | ||
| 400 | + controlPoints[1] = Vector3( stageSize.x*0.5f, 0.0f, 0.0f ); | ||
| 401 | + controlPoints[2] = Vector3(-stageSize.x*0.5f, 0.0f, 0.0f ); | ||
| 402 | + controlPoints[3] = Vector3(-stageSize.x*0.5f, 0.0f, 0.0f ); | ||
| 403 | + path.SetProperty( Path::Property::CONTROL_POINTS, controlPoints ); | ||
| 404 | + | ||
| 405 | + forward = Vector3::ZERO; | ||
| 406 | + } | ||
| 407 | + else if( mEffectMode == PageCubeEffect) | ||
| 408 | + { | ||
| 409 | + points[0] = Vector3( stageSize.x*0.5, 0.0f, stageSize.x*0.5f); | ||
| 410 | + points[1] = Vector3( 0.0f, 0.0f, 0.0f ); | ||
| 411 | + points[2] = Vector3( -stageSize.x*0.5f, 0.0f, stageSize.x*0.5f); | ||
| 412 | + path.SetProperty( Path::Property::POINTS, points ); | ||
| 413 | + | ||
| 414 | + controlPoints[0] = Vector3( stageSize.x*0.5f, 0.0f, stageSize.x*0.3f ); | ||
| 415 | + controlPoints[1] = Vector3( stageSize.x*0.3f, 0.0f, 0.0f ); | ||
| 416 | + controlPoints[2] = Vector3(-stageSize.x*0.3f, 0.0f, 0.0f ); | ||
| 417 | + controlPoints[3] = Vector3(-stageSize.x*0.5f, 0.0f, stageSize.x*0.3f ); | ||
| 418 | + path.SetProperty( Path::Property::CONTROL_POINTS, controlPoints ); | ||
| 419 | + | ||
| 420 | + forward = Vector3(-1.0f,0.0f,0.0f); | ||
| 421 | + } | ||
| 422 | + else if( mEffectMode == PageSpiralEffect) | ||
| 423 | + { | ||
| 424 | + points[0] = Vector3( stageSize.x*0.5, 0.0f, -stageSize.x*0.5f); | ||
| 425 | + points[1] = Vector3( 0.0f, 0.0f, 0.0f ); | ||
| 426 | + points[2] = Vector3( -stageSize.x*0.5f, 0.0f, -stageSize.x*0.5f); | ||
| 427 | + path.SetProperty( Path::Property::POINTS, points ); | ||
| 428 | + | ||
| 429 | + controlPoints[0] = Vector3( stageSize.x*0.5f, 0.0f, 0.0f ); | ||
| 430 | + controlPoints[1] = Vector3( stageSize.x*0.5f, 0.0f, 0.0f ); | ||
| 431 | + controlPoints[2] = Vector3(-stageSize.x*0.5f, 0.0f, 0.0f ); | ||
| 432 | + controlPoints[3] = Vector3(-stageSize.x*0.5f, 0.0f, 0.0f ); | ||
| 433 | + path.SetProperty( Path::Property::CONTROL_POINTS, controlPoints ); | ||
| 434 | + | ||
| 435 | + forward = Vector3(-1.0f,0.0f,0.0f); | ||
| 436 | + } | ||
| 437 | + else if( mEffectMode == PageWaveEffect) | ||
| 438 | + { | ||
| 439 | + points[0] = Vector3( stageSize.x, 0.0f, -stageSize.x); | ||
| 440 | + points[1] = Vector3( 0.0f, 0.0f, 0.0f ); | ||
| 441 | + points[2] = Vector3( -stageSize.x, 0.0f, -stageSize.x); | ||
| 442 | + path.SetProperty( Path::Property::POINTS, points ); | ||
| 443 | + | ||
| 444 | + controlPoints[0] = Vector3( 0.0f, 0.0f, -stageSize.x ); | ||
| 445 | + controlPoints[1] = Vector3( stageSize.x*0.5f, 0.0f, 0.0f ); | ||
| 446 | + controlPoints[2] = Vector3( -stageSize.x*0.5f, 0.0f, 0.0f); | ||
| 447 | + controlPoints[3] = Vector3(0.0f, 0.0f,-stageSize.x ); | ||
| 448 | + path.SetProperty( Path::Property::CONTROL_POINTS, controlPoints ); | ||
| 449 | + | ||
| 450 | + forward = Vector3(-1.0f,0.0f,0.0f); | ||
| 451 | + } | ||
| 452 | + | ||
| 453 | + mScrollViewEffect = ScrollViewPagePathEffect::New(path, forward,Toolkit::ScrollView::Property::SCROLL_FINAL_X, Vector3(stageSize.x,stageSize.y,0.0f),PAGE_COLUMNS); | ||
| 398 | mScrollView.SetScrollSnapDuration(EFFECT_SNAP_DURATION); | 454 | mScrollView.SetScrollSnapDuration(EFFECT_SNAP_DURATION); |
| 399 | mScrollView.SetScrollFlickDuration(EFFECT_FLICK_DURATION); | 455 | mScrollView.SetScrollFlickDuration(EFFECT_FLICK_DURATION); |
| 400 | mScrollView.SetScrollSnapAlphaFunction(AlphaFunction::EASE_OUT); | 456 | mScrollView.SetScrollSnapAlphaFunction(AlphaFunction::EASE_OUT); |
| 401 | mScrollView.SetScrollFlickAlphaFunction(AlphaFunction::EASE_OUT); | 457 | mScrollView.SetScrollFlickAlphaFunction(AlphaFunction::EASE_OUT); |
| 402 | mScrollView.RemoveConstraintsFromChildren(); | 458 | mScrollView.RemoveConstraintsFromChildren(); |
| 459 | + | ||
| 460 | + rulerX = CreateRuler(snap ? stageSize.width * 0.5f : 0.0f); | ||
| 461 | + if( wrap ) | ||
| 462 | + { | ||
| 463 | + rulerX->SetDomain(RulerDomain(0.0f, stageSize.x * 0.5f * PAGE_COLUMNS, !wrap)); | ||
| 464 | + } | ||
| 465 | + else | ||
| 466 | + { | ||
| 467 | + rulerX->SetDomain(RulerDomain(0.0f, stageSize.x*0.5f* (PAGE_COLUMNS+1), !wrap)); | ||
| 468 | + } | ||
| 469 | + | ||
| 403 | break; | 470 | break; |
| 404 | } | 471 | } |
| 405 | 472 | ||
| @@ -409,20 +476,17 @@ private: | @@ -409,20 +476,17 @@ private: | ||
| 409 | } | 476 | } |
| 410 | } | 477 | } |
| 411 | 478 | ||
| 479 | + unsigned int currentPage = mScrollView.GetCurrentPage(); | ||
| 412 | if( mScrollViewEffect ) | 480 | if( mScrollViewEffect ) |
| 413 | { | 481 | { |
| 414 | mScrollView.ApplyEffect(mScrollViewEffect); | 482 | mScrollView.ApplyEffect(mScrollViewEffect); |
| 415 | } | 483 | } |
| 416 | 484 | ||
| 417 | mScrollView.SetWrapMode(wrap); | 485 | mScrollView.SetWrapMode(wrap); |
| 418 | - | ||
| 419 | - RulerPtr rulerX = CreateRuler(snap ? stageSize.width : 0.0f); | ||
| 420 | - RulerPtr rulerY = new DefaultRuler; | ||
| 421 | - rulerX->SetDomain(RulerDomain(0.0f, stageSize.x * PAGE_COLUMNS, !wrap)); | ||
| 422 | - rulerY->Disable(); | ||
| 423 | - | ||
| 424 | mScrollView.SetRulerX( rulerX ); | 486 | mScrollView.SetRulerX( rulerX ); |
| 425 | mScrollView.SetRulerY( rulerY ); | 487 | mScrollView.SetRulerY( rulerY ); |
| 488 | + | ||
| 489 | + mScrollView.ScrollTo( currentPage, 0.0f ); | ||
| 426 | } | 490 | } |
| 427 | 491 | ||
| 428 | /** | 492 | /** |
| @@ -449,7 +513,7 @@ private: | @@ -449,7 +513,7 @@ private: | ||
| 449 | * | 513 | * |
| 450 | * @param[in] page The page Actor to apply effect to. | 514 | * @param[in] page The page Actor to apply effect to. |
| 451 | */ | 515 | */ |
| 452 | - void ApplyEffectToPage(Actor page) | 516 | + void ApplyEffectToPage(Actor page, unsigned int pageOrder ) |
| 453 | { | 517 | { |
| 454 | page.RemoveConstraints(); | 518 | page.RemoveConstraints(); |
| 455 | page.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); | 519 | page.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); |
| @@ -457,23 +521,12 @@ private: | @@ -457,23 +521,12 @@ private: | ||
| 457 | switch( mEffectMode ) | 521 | switch( mEffectMode ) |
| 458 | { | 522 | { |
| 459 | case PageCarouselEffect: | 523 | case PageCarouselEffect: |
| 460 | - { | ||
| 461 | - ScrollViewPageCarouselEffect effect = ScrollViewPageCarouselEffect::DownCast( mScrollViewEffect ); | ||
| 462 | - effect.ApplyToPage( page ); | ||
| 463 | - break; | ||
| 464 | - } | ||
| 465 | - | ||
| 466 | case PageCubeEffect: | 524 | case PageCubeEffect: |
| 467 | - { | ||
| 468 | - ScrollViewPageCubeEffect effect = ScrollViewPageCubeEffect::DownCast( mScrollViewEffect ); | ||
| 469 | - effect.ApplyToPage( page, ANGLE_SWING_3DEFFECT ); | ||
| 470 | - break; | ||
| 471 | - } | ||
| 472 | - | ||
| 473 | case PageSpiralEffect: | 525 | case PageSpiralEffect: |
| 526 | + case PageWaveEffect: | ||
| 474 | { | 527 | { |
| 475 | - ScrollViewPageSpiralEffect effect = ScrollViewPageSpiralEffect::DownCast( mScrollViewEffect ); | ||
| 476 | - effect.ApplyToPage( page, ANGLE_SWING_3DEFFECT ); | 528 | + ScrollViewPagePathEffect effect = ScrollViewPagePathEffect::DownCast( mScrollViewEffect ); |
| 529 | + effect.ApplyToPage( page, pageOrder ); | ||
| 477 | break; | 530 | break; |
| 478 | } | 531 | } |
| 479 | 532 | ||
| @@ -678,6 +731,7 @@ private: | @@ -678,6 +731,7 @@ private: | ||
| 678 | PageCarouselEffect, ///< Page carousel effect | 731 | PageCarouselEffect, ///< Page carousel effect |
| 679 | PageCubeEffect, ///< Page cube effect | 732 | PageCubeEffect, ///< Page cube effect |
| 680 | PageSpiralEffect, ///< Page spiral effect | 733 | PageSpiralEffect, ///< Page spiral effect |
| 734 | + PageWaveEffect, ///< Page wave effect | ||
| 681 | 735 | ||
| 682 | Total | 736 | Total |
| 683 | }; | 737 | }; |