Commit 01b5ab9d4d072bbebbfa38b68f5b7ec1a76888e3
Committed by
Gerrit Code Review
Merge "Changed Cube Transition example to use new CubeTransitionEffect." into devel/master
Showing
1 changed file
with
48 additions
and
52 deletions
examples/cube-transition-effect/cube-transition-effect-example.cpp
| ... | ... | @@ -167,9 +167,9 @@ private: |
| 167 | 167 | /** |
| 168 | 168 | * Callback function of cube transition completed signal |
| 169 | 169 | * @param[in] effect The cube effect used for the transition |
| 170 | - * @param[in] imageActor The target imageActor of the completed transition | |
| 170 | + * @param[in] image The target Image of the completed transition | |
| 171 | 171 | */ |
| 172 | - void OnTransitionCompleted(Toolkit::CubeTransitionEffect effect, ImageActor imageActor); | |
| 172 | + void OnTransitionCompleted(Toolkit::CubeTransitionEffect effect, Image image ); | |
| 173 | 173 | /** |
| 174 | 174 | * Callback function of timer tick |
| 175 | 175 | * The timer is used to count the image display duration in slideshow, |
| ... | ... | @@ -181,13 +181,12 @@ private: |
| 181 | 181 | Toolkit::Control mView; |
| 182 | 182 | Toolkit::ToolBar mToolBar; |
| 183 | 183 | Layer mContent; |
| 184 | - Toolkit::TextLabel mTitleActor; | |
| 185 | - Actor mParent; | |
| 184 | + Toolkit::TextLabel mTitle; | |
| 186 | 185 | |
| 187 | 186 | Vector2 mViewSize; |
| 188 | 187 | |
| 189 | - ImageActor mCurrentImage; | |
| 190 | - ImageActor mNextImage; | |
| 188 | + ResourceImage mCurrentImage; | |
| 189 | + ResourceImage mNextImage; | |
| 191 | 190 | unsigned int mIndex; |
| 192 | 191 | bool mIsImageLoading; |
| 193 | 192 | |
| ... | ... | @@ -238,8 +237,8 @@ void CubeTransitionApp::OnInit( Application& application ) |
| 238 | 237 | mToolBar.AddControl( mEffectChangeButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalRight, DemoHelper::DEFAULT_MODE_SWITCH_PADDING ); |
| 239 | 238 | |
| 240 | 239 | // Add title to the tool bar. |
| 241 | - mTitleActor = DemoHelper::CreateToolBarLabel( APPLICATION_TITLE_WAVE ); | |
| 242 | - mToolBar.AddControl( mTitleActor, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarTitlePercentage, Toolkit::Alignment::HorizontalCenter ); | |
| 240 | + mTitle = DemoHelper::CreateToolBarLabel( APPLICATION_TITLE_WAVE ); | |
| 241 | + mToolBar.AddControl( mTitle, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarTitlePercentage, Toolkit::Alignment::HorizontalCenter ); | |
| 243 | 242 | |
| 244 | 243 | //Add an slideshow icon on the right of the title |
| 245 | 244 | mSlideshowButton = Toolkit::PushButton::New(); |
| ... | ... | @@ -251,53 +250,55 @@ void CubeTransitionApp::OnInit( Application& application ) |
| 251 | 250 | // Set size to stage size to avoid seeing a black border on transition |
| 252 | 251 | mViewSize = Stage::GetCurrent().GetSize(); |
| 253 | 252 | |
| 254 | - mParent = Actor::New(); | |
| 255 | - mParent.SetSize( mViewSize ); | |
| 256 | - mParent.SetPositionInheritanceMode( USE_PARENT_POSITION ); | |
| 257 | - mContent.Add( mParent ); | |
| 258 | - | |
| 259 | - // use pan gesture to detect the cursor or finger movement | |
| 260 | - mPanGestureDetector = PanGestureDetector::New(); | |
| 261 | - mPanGestureDetector.DetectedSignal().Connect( this, &CubeTransitionApp::OnPanGesture ); | |
| 262 | - mPanGestureDetector.Attach( mParent ); | |
| 253 | + // show the first image | |
| 254 | + mCurrentImage = LoadStageFillingImage( IMAGES[mIndex] ); | |
| 263 | 255 | |
| 264 | 256 | //use small cubes |
| 265 | - mCubeWaveEffect = Toolkit::CubeTransitionWaveEffect::New(NUM_ROWS_WAVE, NUM_COLUMNS_WAVE, mViewSize); | |
| 257 | + mCubeWaveEffect = Toolkit::CubeTransitionWaveEffect::New( NUM_ROWS_WAVE, NUM_COLUMNS_WAVE ); | |
| 266 | 258 | mCubeWaveEffect.SetTransitionDuration( ANIMATION_DURATION_WAVE ); |
| 267 | 259 | mCubeWaveEffect.SetCubeDisplacement( CUBE_DISPLACEMENT_WAVE ); |
| 268 | 260 | mCubeWaveEffect.TransitionCompletedSignal().Connect(this, &CubeTransitionApp::OnTransitionCompleted); |
| 269 | - mParent.Add(mCubeWaveEffect.GetRoot()); | |
| 261 | + | |
| 262 | + mCubeWaveEffect.SetSize( mViewSize ); | |
| 263 | + mCubeWaveEffect.SetPositionInheritanceMode( USE_PARENT_POSITION ); | |
| 264 | + mCubeWaveEffect.SetCurrentImage( mCurrentImage ); | |
| 265 | + | |
| 270 | 266 | // use big cubes |
| 271 | - mCubeCrossEffect = Toolkit::CubeTransitionCrossEffect::New(NUM_ROWS_CROSS, NUM_COLUMNS_CROSS, mViewSize); | |
| 272 | - mCubeCrossEffect.SetTransitionDuration( ANIMATION_DURATION_CROSS); | |
| 267 | + mCubeCrossEffect = Toolkit::CubeTransitionCrossEffect::New(NUM_ROWS_CROSS, NUM_COLUMNS_CROSS ); | |
| 268 | + mCubeCrossEffect.SetTransitionDuration( ANIMATION_DURATION_CROSS ); | |
| 273 | 269 | mCubeCrossEffect.SetCubeDisplacement( CUBE_DISPLACEMENT_CROSS ); |
| 274 | 270 | mCubeCrossEffect.TransitionCompletedSignal().Connect(this, &CubeTransitionApp::OnTransitionCompleted); |
| 275 | - mParent.Add(mCubeCrossEffect.GetRoot()); | |
| 276 | 271 | |
| 277 | - mCubeFoldEffect = Toolkit::CubeTransitionFoldEffect::New(NUM_ROWS_FOLD, NUM_COLUMNS_FOLD, mViewSize); | |
| 278 | - mCubeFoldEffect.SetTransitionDuration( ANIMATION_DURATION_FOLD); | |
| 272 | + mCubeCrossEffect.SetSize( mViewSize ); | |
| 273 | + mCubeCrossEffect.SetPositionInheritanceMode( USE_PARENT_POSITION ); | |
| 274 | + mCubeCrossEffect.SetCurrentImage( mCurrentImage ); | |
| 275 | + | |
| 276 | + mCubeFoldEffect = Toolkit::CubeTransitionFoldEffect::New( NUM_ROWS_FOLD, NUM_COLUMNS_FOLD ); | |
| 277 | + mCubeFoldEffect.SetTransitionDuration( ANIMATION_DURATION_FOLD ); | |
| 279 | 278 | mCubeFoldEffect.TransitionCompletedSignal().Connect(this, &CubeTransitionApp::OnTransitionCompleted); |
| 280 | - mParent.Add(mCubeFoldEffect.GetRoot()); | |
| 279 | + | |
| 280 | + mCubeFoldEffect.SetSize( mViewSize ); | |
| 281 | + mCubeFoldEffect.SetPositionInheritanceMode( USE_PARENT_POSITION ); | |
| 282 | + mCubeFoldEffect.SetCurrentImage( mCurrentImage ); | |
| 281 | 283 | |
| 282 | 284 | mViewTimer = Timer::New( VIEWINGTIME ); |
| 283 | 285 | mViewTimer.TickSignal().Connect( this, &CubeTransitionApp::OnTimerTick ); |
| 284 | 286 | |
| 285 | - // show the first image | |
| 286 | - mCurrentImage = ImageActor::New( LoadStageFillingImage( IMAGES[mIndex] ) ); | |
| 287 | - mCurrentImage.SetPositionInheritanceMode( USE_PARENT_POSITION ); | |
| 288 | - mCurrentImage.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); | |
| 289 | - mCurrentImage.SetSizeScalePolicy( SizeScalePolicy::FIT_WITH_ASPECT_RATIO ); | |
| 290 | - mParent.Add( mCurrentImage ); | |
| 291 | 287 | |
| 292 | 288 | mCurrentEffect = mCubeWaveEffect; |
| 293 | - mCurrentEffect.SetCurrentImage( mCurrentImage ); | |
| 289 | + mContent.Add( mCurrentEffect ); | |
| 290 | + | |
| 291 | + // use pan gesture to detect the cursor or finger movement | |
| 292 | + mPanGestureDetector = PanGestureDetector::New(); | |
| 293 | + mPanGestureDetector.DetectedSignal().Connect( this, &CubeTransitionApp::OnPanGesture ); | |
| 294 | + mPanGestureDetector.Attach( mContent ); | |
| 294 | 295 | } |
| 295 | 296 | |
| 296 | 297 | // signal handler, called when the pan gesture is detected |
| 297 | 298 | void CubeTransitionApp::OnPanGesture( Actor actor, const PanGesture& gesture ) |
| 298 | 299 | { |
| 299 | 300 | // does not response when the transition has not finished |
| 300 | - if( mIsImageLoading || mCubeWaveEffect.IsTransiting() || mCubeCrossEffect.IsTransiting() || mCubeFoldEffect.IsTransiting() || mSlideshow ) | |
| 301 | + if( mIsImageLoading || mCubeWaveEffect.IsTransitioning() || mCubeCrossEffect.IsTransitioning() || mCubeFoldEffect.IsTransitioning() || mSlideshow ) | |
| 301 | 302 | { |
| 302 | 303 | return; |
| 303 | 304 | } |
| ... | ... | @@ -321,22 +322,17 @@ void CubeTransitionApp::OnPanGesture( Actor actor, const PanGesture& gesture ) |
| 321 | 322 | |
| 322 | 323 | void CubeTransitionApp::GoToNextImage() |
| 323 | 324 | { |
| 324 | - ResourceImage image = LoadStageFillingImage( IMAGES[ mIndex ] ); | |
| 325 | - mNextImage = ImageActor::New( image ); | |
| 326 | - | |
| 327 | - mNextImage.SetPositionInheritanceMode(USE_PARENT_POSITION); | |
| 328 | - mNextImage.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); | |
| 329 | - mNextImage.SetSizeScalePolicy( SizeScalePolicy::FIT_WITH_ASPECT_RATIO ); | |
| 330 | - mCurrentEffect.SetTargetImage(mNextImage); | |
| 331 | - if( image.GetLoadingState() == ResourceLoadingSucceeded ) | |
| 325 | + mNextImage = LoadStageFillingImage( IMAGES[ mIndex ] ); | |
| 326 | + mCurrentEffect.SetTargetImage( mNextImage ); | |
| 327 | + if( mNextImage.GetLoadingState() == ResourceLoadingSucceeded ) | |
| 332 | 328 | { |
| 333 | 329 | mIsImageLoading = false; |
| 334 | - OnImageLoaded( image ); | |
| 330 | + OnImageLoaded( mNextImage ); | |
| 335 | 331 | } |
| 336 | 332 | else |
| 337 | 333 | { |
| 338 | 334 | mIsImageLoading = true; |
| 339 | - image.LoadingFinishedSignal().Connect( this, &CubeTransitionApp::OnImageLoaded ); | |
| 335 | + mNextImage.LoadingFinishedSignal().Connect( this, &CubeTransitionApp::OnImageLoaded ); | |
| 340 | 336 | } |
| 341 | 337 | } |
| 342 | 338 | |
| ... | ... | @@ -344,17 +340,16 @@ void CubeTransitionApp::OnImageLoaded(ResourceImage image) |
| 344 | 340 | { |
| 345 | 341 | mIsImageLoading = false; |
| 346 | 342 | mCurrentEffect.StartTransition( mPanPosition, mPanDisplacement ); |
| 347 | - mParent.Remove(mCurrentImage); | |
| 348 | - mParent.Add(mNextImage); | |
| 349 | 343 | mCurrentImage = mNextImage; |
| 350 | 344 | } |
| 351 | 345 | |
| 352 | 346 | bool CubeTransitionApp::OnEffectButtonClicked( Toolkit::Button button ) |
| 353 | 347 | { |
| 348 | + mContent.Remove( mCurrentEffect ); | |
| 354 | 349 | if(mCurrentEffect == mCubeWaveEffect) |
| 355 | 350 | { |
| 356 | 351 | mCurrentEffect = mCubeCrossEffect; |
| 357 | - mTitleActor.SetProperty( TextLabel::Property::TEXT, std::string(APPLICATION_TITLE_CROSS) ); | |
| 352 | + mTitle.SetProperty( TextLabel::Property::TEXT, std::string(APPLICATION_TITLE_CROSS) ); | |
| 358 | 353 | mEffectChangeButton.SetUnselectedImage( EFFECT_CROSS_IMAGE ); |
| 359 | 354 | mEffectChangeButton.SetSelectedImage( EFFECT_CROSS_IMAGE_SELECTED ); |
| 360 | 355 | |
| ... | ... | @@ -362,21 +357,22 @@ bool CubeTransitionApp::OnEffectButtonClicked( Toolkit::Button button ) |
| 362 | 357 | else if(mCurrentEffect == mCubeCrossEffect) |
| 363 | 358 | { |
| 364 | 359 | mCurrentEffect = mCubeFoldEffect; |
| 365 | - mTitleActor.SetProperty( TextLabel::Property::TEXT, std::string(APPLICATION_TITLE_FOLD) ); | |
| 360 | + mTitle.SetProperty( TextLabel::Property::TEXT, std::string(APPLICATION_TITLE_FOLD) ); | |
| 366 | 361 | mEffectChangeButton.SetUnselectedImage( EFFECT_FOLD_IMAGE ); |
| 367 | 362 | mEffectChangeButton.SetSelectedImage( EFFECT_FOLD_IMAGE_SELECTED ); |
| 368 | 363 | } |
| 369 | 364 | else |
| 370 | 365 | { |
| 371 | 366 | mCurrentEffect = mCubeWaveEffect; |
| 372 | - mTitleActor.SetProperty( TextLabel::Property::TEXT, std::string(APPLICATION_TITLE_WAVE) ); | |
| 367 | + mTitle.SetProperty( TextLabel::Property::TEXT, std::string(APPLICATION_TITLE_WAVE) ); | |
| 373 | 368 | mEffectChangeButton.SetUnselectedImage( EFFECT_WAVE_IMAGE ); |
| 374 | 369 | mEffectChangeButton.SetSelectedImage( EFFECT_WAVE_IMAGE_SELECTED ); |
| 375 | 370 | } |
| 371 | + mContent.Add( mCurrentEffect ); | |
| 376 | 372 | |
| 377 | 373 | // Set the current image to cube transition effect |
| 378 | 374 | // only need to set at beginning or change from another effect |
| 379 | - mCurrentEffect.SetCurrentImage(mCurrentImage); | |
| 375 | + mCurrentEffect.SetCurrentImage( mCurrentImage ); | |
| 380 | 376 | return true; |
| 381 | 377 | } |
| 382 | 378 | |
| ... | ... | @@ -385,7 +381,7 @@ bool CubeTransitionApp::OnSildeshowButtonClicked( Toolkit::Button button ) |
| 385 | 381 | mSlideshow = !mSlideshow; |
| 386 | 382 | if( mSlideshow ) |
| 387 | 383 | { |
| 388 | - mPanGestureDetector.Detach( mParent ); | |
| 384 | + mPanGestureDetector.Detach( mContent ); | |
| 389 | 385 | mSlideshowButton.SetUnselectedImage( SLIDE_SHOW_STOP_ICON ); |
| 390 | 386 | mSlideshowButton.SetSelectedImage( SLIDE_SHOW_STOP_ICON_SELECTED ); |
| 391 | 387 | mPanPosition = Vector2( mViewSize.width, mViewSize.height*0.5f ); |
| ... | ... | @@ -394,7 +390,7 @@ bool CubeTransitionApp::OnSildeshowButtonClicked( Toolkit::Button button ) |
| 394 | 390 | } |
| 395 | 391 | else |
| 396 | 392 | { |
| 397 | - mPanGestureDetector.Attach( mParent ); | |
| 393 | + mPanGestureDetector.Attach( mContent ); | |
| 398 | 394 | mSlideshowButton.SetUnselectedImage( SLIDE_SHOW_START_ICON ); |
| 399 | 395 | mSlideshowButton.SetSelectedImage( SLIDE_SHOW_START_ICON_SELECTED ); |
| 400 | 396 | mViewTimer.Stop(); |
| ... | ... | @@ -402,7 +398,7 @@ bool CubeTransitionApp::OnSildeshowButtonClicked( Toolkit::Button button ) |
| 402 | 398 | return true; |
| 403 | 399 | } |
| 404 | 400 | |
| 405 | -void CubeTransitionApp::OnTransitionCompleted(Toolkit::CubeTransitionEffect effect, ImageActor imageActor) | |
| 401 | +void CubeTransitionApp::OnTransitionCompleted(Toolkit::CubeTransitionEffect effect, Image image ) | |
| 406 | 402 | { |
| 407 | 403 | if( mSlideshow ) |
| 408 | 404 | { | ... | ... |