X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=examples%2Fcube-transition-effect%2Fcube-transition-effect-example.cpp;h=300b92a13e36e74e56198e7aa1ce5601e81ba5ae;hb=refs%2Ftags%2Faccepted%2Ftizen%2Funified%2F20190514.080104;hp=29fbdaf06e461c6dc35fced621a0a2b5078b7998;hpb=db440ac3ebf329c18796617518b1fbe5f9b24c5b;p=platform%2Fcore%2Fuifw%2Fdali-demo.git diff --git a/examples/cube-transition-effect/cube-transition-effect-example.cpp b/examples/cube-transition-effect/cube-transition-effect-example.cpp index 29fbdaf..300b92a 100644 --- a/examples/cube-transition-effect/cube-transition-effect-example.cpp +++ b/examples/cube-transition-effect/cube-transition-effect-example.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Copyright (c) 2019 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,9 +20,12 @@ // INTERNAL INCLUDES #include "shared/view.h" +#include "shared/utility.h" #include #include +#include +#include #include #include #include @@ -37,44 +40,44 @@ using Dali::Toolkit::TextLabel; namespace { -const char * const TOOLBAR_IMAGE( DALI_IMAGE_DIR "top-bar.png" ); +const char * const TOOLBAR_IMAGE( DEMO_IMAGE_DIR "top-bar.png" ); const char * const APPLICATION_TITLE_WAVE( "Cube Transition: Wave" ); const char * const APPLICATION_TITLE_CROSS( "Cube Transition: Cross" ); const char * const APPLICATION_TITLE_FOLD( "Cube Transition: Fold" ); -const char * const EFFECT_WAVE_IMAGE( DALI_IMAGE_DIR "icon-effect-wave.png" ); -const char * const EFFECT_WAVE_IMAGE_SELECTED( DALI_IMAGE_DIR "icon-effect-wave-selected.png" ); -const char * const EFFECT_CROSS_IMAGE( DALI_IMAGE_DIR "icon-effect-cross.png" ); -const char * const EFFECT_CROSS_IMAGE_SELECTED( DALI_IMAGE_DIR "icon-effect-cross-selected.png" ); -const char * const EFFECT_FOLD_IMAGE( DALI_IMAGE_DIR "icon-effect-fold.png" ); -const char * const EFFECT_FOLD_IMAGE_SELECTED( DALI_IMAGE_DIR "icon-effect-fold-selected.png" ); -const char * const SLIDE_SHOW_START_ICON( DALI_IMAGE_DIR "icon-play.png" ); -const char * const SLIDE_SHOW_START_ICON_SELECTED( DALI_IMAGE_DIR "icon-play-selected.png" ); -const char * const SLIDE_SHOW_STOP_ICON( DALI_IMAGE_DIR "icon-stop.png" ); -const char * const SLIDE_SHOW_STOP_ICON_SELECTED( DALI_IMAGE_DIR "icon-stop-selected.png" ); +const char * const EFFECT_WAVE_IMAGE( DEMO_IMAGE_DIR "icon-effect-wave.png" ); +const char * const EFFECT_WAVE_IMAGE_SELECTED( DEMO_IMAGE_DIR "icon-effect-wave-selected.png" ); +const char * const EFFECT_CROSS_IMAGE( DEMO_IMAGE_DIR "icon-effect-cross.png" ); +const char * const EFFECT_CROSS_IMAGE_SELECTED( DEMO_IMAGE_DIR "icon-effect-cross-selected.png" ); +const char * const EFFECT_FOLD_IMAGE( DEMO_IMAGE_DIR "icon-effect-fold.png" ); +const char * const EFFECT_FOLD_IMAGE_SELECTED( DEMO_IMAGE_DIR "icon-effect-fold-selected.png" ); +const char * const SLIDE_SHOW_START_ICON( DEMO_IMAGE_DIR "icon-play.png" ); +const char * const SLIDE_SHOW_START_ICON_SELECTED( DEMO_IMAGE_DIR "icon-play-selected.png" ); +const char * const SLIDE_SHOW_STOP_ICON( DEMO_IMAGE_DIR "icon-stop.png" ); +const char * const SLIDE_SHOW_STOP_ICON_SELECTED( DEMO_IMAGE_DIR "icon-stop-selected.png" ); const char* IMAGES[] = { - DALI_IMAGE_DIR "gallery-large-1.jpg", - DALI_IMAGE_DIR "gallery-large-2.jpg", - DALI_IMAGE_DIR "gallery-large-3.jpg", - DALI_IMAGE_DIR "gallery-large-4.jpg", - DALI_IMAGE_DIR "gallery-large-5.jpg", - DALI_IMAGE_DIR "gallery-large-6.jpg", - DALI_IMAGE_DIR "gallery-large-7.jpg", - DALI_IMAGE_DIR "gallery-large-8.jpg", - DALI_IMAGE_DIR "gallery-large-9.jpg", - DALI_IMAGE_DIR "gallery-large-10.jpg", - DALI_IMAGE_DIR "gallery-large-11.jpg", - DALI_IMAGE_DIR "gallery-large-12.jpg", - DALI_IMAGE_DIR "gallery-large-13.jpg", - DALI_IMAGE_DIR "gallery-large-14.jpg", - DALI_IMAGE_DIR "gallery-large-15.jpg", - DALI_IMAGE_DIR "gallery-large-16.jpg", - DALI_IMAGE_DIR "gallery-large-17.jpg", - DALI_IMAGE_DIR "gallery-large-18.jpg", - DALI_IMAGE_DIR "gallery-large-19.jpg", - DALI_IMAGE_DIR "gallery-large-20.jpg", - DALI_IMAGE_DIR "gallery-large-21.jpg", + DEMO_IMAGE_DIR "gallery-large-1.jpg", + DEMO_IMAGE_DIR "gallery-large-2.jpg", + DEMO_IMAGE_DIR "gallery-large-3.jpg", + DEMO_IMAGE_DIR "gallery-large-4.jpg", + DEMO_IMAGE_DIR "gallery-large-5.jpg", + DEMO_IMAGE_DIR "gallery-large-6.jpg", + DEMO_IMAGE_DIR "gallery-large-7.jpg", + DEMO_IMAGE_DIR "gallery-large-8.jpg", + DEMO_IMAGE_DIR "gallery-large-9.jpg", + DEMO_IMAGE_DIR "gallery-large-10.jpg", + DEMO_IMAGE_DIR "gallery-large-11.jpg", + DEMO_IMAGE_DIR "gallery-large-12.jpg", + DEMO_IMAGE_DIR "gallery-large-13.jpg", + DEMO_IMAGE_DIR "gallery-large-14.jpg", + DEMO_IMAGE_DIR "gallery-large-15.jpg", + DEMO_IMAGE_DIR "gallery-large-16.jpg", + DEMO_IMAGE_DIR "gallery-large-17.jpg", + DEMO_IMAGE_DIR "gallery-large-18.jpg", + DEMO_IMAGE_DIR "gallery-large-19.jpg", + DEMO_IMAGE_DIR "gallery-large-20.jpg", + DEMO_IMAGE_DIR "gallery-large-21.jpg", }; const int NUM_IMAGES( sizeof(IMAGES) / sizeof(IMAGES[0]) ); @@ -98,20 +101,6 @@ const float CUBE_DISPLACEMENT_CROSS(30.f); // The duration of the current image staying on screen when slideshow is on const int VIEWINGTIME = 2000; // 2 seconds -/** - * @brief Load an image, scaled-down to no more than the stage dimensions. - * - * Uses image scaling mode SCALE_TO_FILL to resize the image at - * load time to cover the entire stage with pixels with no borders, - * and filter mode BOX_THEN_LINEAR to sample the image with - * maximum quality. - */ -ResourceImage LoadStageFillingImage( const char * const imagePath ) -{ - Size stageSize = Stage::GetCurrent().GetSize(); - return ResourceImage::New( imagePath, ImageDimensions( stageSize.x, stageSize.y ), Dali::FittingMode::SCALE_TO_FILL, Dali::SamplingMode::BOX_THEN_LINEAR ); -} - } // namespace class CubeTransitionApp : public ConnectionTracker @@ -143,12 +132,6 @@ private: */ void GoToNextImage(); /** - * Callback function of image resource loading succeed - * Start the transition - * @param[in] image The image content of the imageActor for transition - */ - void OnImageLoaded(ResourceImage image); - /** * Main key event handler */ void OnKeyEvent(const KeyEvent& event); @@ -167,15 +150,22 @@ private: /** * Callback function of cube transition completed signal * @param[in] effect The cube effect used for the transition - * @param[in] image The target Image of the completed transition + * @param[in] texture The target Texture of the completed transition */ - void OnTransitionCompleted(Toolkit::CubeTransitionEffect effect, Image image ); + void OnTransitionCompleted(Toolkit::CubeTransitionEffect effect, Texture image ); /** * Callback function of timer tick * The timer is used to count the image display duration in slideshow, */ bool OnTimerTick(); + /** + * Loads image, resizes it to the size of stage and creates a textue out of it + * @param[in] filepath Path to the image file + * @return New texture object + */ + Texture LoadStageFillingTexture( const char* filepath ); + private: Application& mApplication; Toolkit::Control mView; @@ -185,8 +175,8 @@ private: Vector2 mViewSize; - ResourceImage mCurrentImage; - ResourceImage mNextImage; + Texture mCurrentTexture; + Texture mNextTexture; unsigned int mIndex; bool mIsImageLoading; @@ -203,8 +193,6 @@ private: Vector2 mPanPosition; Vector2 mPanDisplacement; - - Toolkit::PushButton mEffectChangeButton; }; CubeTransitionApp::CubeTransitionApp( Application& application ) @@ -229,12 +217,18 @@ void CubeTransitionApp::OnInit( Application& application ) mContent = DemoHelper::CreateView( application, mView, mToolBar, "", TOOLBAR_IMAGE, "" ); mContent.SetBehavior( Layer::LAYER_3D ); - // Add an effect-changing button on the right of the tool bar. - mEffectChangeButton = Toolkit::PushButton::New(); - mEffectChangeButton.SetUnselectedImage( EFFECT_WAVE_IMAGE ); - mEffectChangeButton.SetSelectedImage( EFFECT_WAVE_IMAGE_SELECTED ); - mEffectChangeButton.ClickedSignal().Connect( this, &CubeTransitionApp::OnEffectButtonClicked ); - mToolBar.AddControl( mEffectChangeButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalRight, DemoHelper::DEFAULT_MODE_SWITCH_PADDING ); + + // Add an effect changing toggle button + Toolkit::ToggleButton effectChangeToggleButton = Toolkit::ToggleButton::ToggleButton::New(); + + effectChangeToggleButton.SetProperty( Toolkit::ToggleButton::Property::STATE_VISUALS, + Property::Array{ EFFECT_WAVE_IMAGE, + EFFECT_CROSS_IMAGE, + EFFECT_FOLD_IMAGE } + ); + + effectChangeToggleButton.ClickedSignal().Connect( this, &CubeTransitionApp::OnEffectButtonClicked ); + mToolBar.AddControl( effectChangeToggleButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalRight, DemoHelper::DEFAULT_MODE_SWITCH_PADDING ); // Add title to the tool bar. mTitle = DemoHelper::CreateToolBarLabel( APPLICATION_TITLE_WAVE ); @@ -242,8 +236,8 @@ void CubeTransitionApp::OnInit( Application& application ) //Add an slideshow icon on the right of the title mSlideshowButton = Toolkit::PushButton::New(); - mSlideshowButton.SetUnselectedImage( SLIDE_SHOW_START_ICON ); - mSlideshowButton.SetSelectedImage( SLIDE_SHOW_START_ICON_SELECTED ); + mSlideshowButton.SetProperty( Toolkit::DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL, SLIDE_SHOW_START_ICON ); + mSlideshowButton.SetProperty( Toolkit::DevelButton::Property::SELECTED_BACKGROUND_VISUAL, SLIDE_SHOW_START_ICON_SELECTED ); mSlideshowButton.ClickedSignal().Connect( this, &CubeTransitionApp::OnSildeshowButtonClicked ); mToolBar.AddControl( mSlideshowButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalCenter, DemoHelper::DEFAULT_PLAY_PADDING ); @@ -251,7 +245,7 @@ void CubeTransitionApp::OnInit( Application& application ) mViewSize = Stage::GetCurrent().GetSize(); // show the first image - mCurrentImage = LoadStageFillingImage( IMAGES[mIndex] ); + mCurrentTexture = LoadStageFillingTexture( IMAGES[mIndex] ); //use small cubes mCubeWaveEffect = Toolkit::CubeTransitionWaveEffect::New( NUM_ROWS_WAVE, NUM_COLUMNS_WAVE ); @@ -260,8 +254,8 @@ void CubeTransitionApp::OnInit( Application& application ) mCubeWaveEffect.TransitionCompletedSignal().Connect(this, &CubeTransitionApp::OnTransitionCompleted); mCubeWaveEffect.SetSize( mViewSize ); - mCubeWaveEffect.SetPositionInheritanceMode( USE_PARENT_POSITION ); - mCubeWaveEffect.SetCurrentImage( mCurrentImage ); + mCubeWaveEffect.SetParentOrigin( ParentOrigin::CENTER ); + mCubeWaveEffect.SetCurrentTexture( mCurrentTexture ); // use big cubes mCubeCrossEffect = Toolkit::CubeTransitionCrossEffect::New(NUM_ROWS_CROSS, NUM_COLUMNS_CROSS ); @@ -270,16 +264,16 @@ void CubeTransitionApp::OnInit( Application& application ) mCubeCrossEffect.TransitionCompletedSignal().Connect(this, &CubeTransitionApp::OnTransitionCompleted); mCubeCrossEffect.SetSize( mViewSize ); - mCubeCrossEffect.SetPositionInheritanceMode( USE_PARENT_POSITION ); - mCubeCrossEffect.SetCurrentImage( mCurrentImage ); + mCubeCrossEffect.SetParentOrigin( ParentOrigin::CENTER ); + mCubeCrossEffect.SetCurrentTexture( mCurrentTexture ); mCubeFoldEffect = Toolkit::CubeTransitionFoldEffect::New( NUM_ROWS_FOLD, NUM_COLUMNS_FOLD ); mCubeFoldEffect.SetTransitionDuration( ANIMATION_DURATION_FOLD ); mCubeFoldEffect.TransitionCompletedSignal().Connect(this, &CubeTransitionApp::OnTransitionCompleted); mCubeFoldEffect.SetSize( mViewSize ); - mCubeFoldEffect.SetPositionInheritanceMode( USE_PARENT_POSITION ); - mCubeFoldEffect.SetCurrentImage( mCurrentImage ); + mCubeFoldEffect.SetParentOrigin( ParentOrigin::CENTER ); + mCubeFoldEffect.SetCurrentTexture( mCurrentTexture ); mViewTimer = Timer::New( VIEWINGTIME ); mViewTimer.TickSignal().Connect( this, &CubeTransitionApp::OnTimerTick ); @@ -322,25 +316,11 @@ void CubeTransitionApp::OnPanGesture( Actor actor, const PanGesture& gesture ) void CubeTransitionApp::GoToNextImage() { - mNextImage = LoadStageFillingImage( IMAGES[ mIndex ] ); - mCurrentEffect.SetTargetImage( mNextImage ); - if( mNextImage.GetLoadingState() == ResourceLoadingSucceeded ) - { - mIsImageLoading = false; - OnImageLoaded( mNextImage ); - } - else - { - mIsImageLoading = true; - mNextImage.LoadingFinishedSignal().Connect( this, &CubeTransitionApp::OnImageLoaded ); - } -} - -void CubeTransitionApp::OnImageLoaded(ResourceImage image) -{ - mIsImageLoading = false; - mCurrentEffect.StartTransition( mPanPosition, mPanDisplacement ); - mCurrentImage = mNextImage; + mNextTexture = LoadStageFillingTexture( IMAGES[ mIndex ] ); + mCurrentEffect.SetTargetTexture( mNextTexture ); + mIsImageLoading = false; + mCurrentEffect.StartTransition( mPanPosition, mPanDisplacement ); + mCurrentTexture = mNextTexture; } bool CubeTransitionApp::OnEffectButtonClicked( Toolkit::Button button ) @@ -350,29 +330,22 @@ bool CubeTransitionApp::OnEffectButtonClicked( Toolkit::Button button ) { mCurrentEffect = mCubeCrossEffect; mTitle.SetProperty( TextLabel::Property::TEXT, std::string(APPLICATION_TITLE_CROSS) ); - mEffectChangeButton.SetUnselectedImage( EFFECT_CROSS_IMAGE ); - mEffectChangeButton.SetSelectedImage( EFFECT_CROSS_IMAGE_SELECTED ); - } else if(mCurrentEffect == mCubeCrossEffect) { mCurrentEffect = mCubeFoldEffect; mTitle.SetProperty( TextLabel::Property::TEXT, std::string(APPLICATION_TITLE_FOLD) ); - mEffectChangeButton.SetUnselectedImage( EFFECT_FOLD_IMAGE ); - mEffectChangeButton.SetSelectedImage( EFFECT_FOLD_IMAGE_SELECTED ); } else { mCurrentEffect = mCubeWaveEffect; mTitle.SetProperty( TextLabel::Property::TEXT, std::string(APPLICATION_TITLE_WAVE) ); - mEffectChangeButton.SetUnselectedImage( EFFECT_WAVE_IMAGE ); - mEffectChangeButton.SetSelectedImage( EFFECT_WAVE_IMAGE_SELECTED ); } mContent.Add( mCurrentEffect ); // Set the current image to cube transition effect // only need to set at beginning or change from another effect - mCurrentEffect.SetCurrentImage( mCurrentImage ); + mCurrentEffect.SetCurrentTexture( mCurrentTexture ); return true; } @@ -382,8 +355,8 @@ bool CubeTransitionApp::OnSildeshowButtonClicked( Toolkit::Button button ) if( mSlideshow ) { mPanGestureDetector.Detach( mContent ); - mSlideshowButton.SetUnselectedImage( SLIDE_SHOW_STOP_ICON ); - mSlideshowButton.SetSelectedImage( SLIDE_SHOW_STOP_ICON_SELECTED ); + mSlideshowButton.SetProperty( Toolkit::DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL, SLIDE_SHOW_STOP_ICON ); + mSlideshowButton.SetProperty( Toolkit::DevelButton::Property::SELECTED_BACKGROUND_VISUAL, SLIDE_SHOW_STOP_ICON_SELECTED ); mPanPosition = Vector2( mViewSize.width, mViewSize.height*0.5f ); mPanDisplacement = Vector2( -10.f, 0.f ); mViewTimer.Start(); @@ -391,14 +364,14 @@ bool CubeTransitionApp::OnSildeshowButtonClicked( Toolkit::Button button ) else { mPanGestureDetector.Attach( mContent ); - mSlideshowButton.SetUnselectedImage( SLIDE_SHOW_START_ICON ); - mSlideshowButton.SetSelectedImage( SLIDE_SHOW_START_ICON_SELECTED ); + mSlideshowButton.SetProperty( Toolkit::DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL, SLIDE_SHOW_START_ICON ); + mSlideshowButton.SetProperty( Toolkit::DevelButton::Property::SELECTED_BACKGROUND_VISUAL, SLIDE_SHOW_START_ICON_SELECTED ); mViewTimer.Stop(); } return true; } -void CubeTransitionApp::OnTransitionCompleted(Toolkit::CubeTransitionEffect effect, Image image ) +void CubeTransitionApp::OnTransitionCompleted(Toolkit::CubeTransitionEffect effect, Texture texture ) { if( mSlideshow ) { @@ -418,6 +391,17 @@ bool CubeTransitionApp::OnTimerTick() return false; } +Texture CubeTransitionApp::LoadStageFillingTexture( const char* filepath ) +{ + ImageDimensions dimensions( Stage::GetCurrent().GetSize().x, Stage::GetCurrent().GetSize().y ); + Devel::PixelBuffer pixelBuffer = LoadImageFromFile( filepath, dimensions, FittingMode::SCALE_TO_FILL ); + PixelData pixelData = Devel::PixelBuffer::Convert(pixelBuffer); + + Texture texture = Texture::New( TextureType::TEXTURE_2D, pixelData.GetPixelFormat(), pixelData.GetWidth(), pixelData.GetHeight() ); + texture.Upload( pixelData ); + return texture; +} + void CubeTransitionApp::OnKeyEvent(const KeyEvent& event) { if(event.state == KeyEvent::Down) @@ -429,10 +413,9 @@ void CubeTransitionApp::OnKeyEvent(const KeyEvent& event) } } -// Entry point for Linux & Tizen applications -int main( int argc, char **argv ) +int DALI_EXPORT_API main( int argc, char **argv ) { - Application application = Application::New( &argc, &argv, DALI_DEMO_THEME_PATH ); + Application application = Application::New( &argc, &argv, DEMO_THEME_PATH ); CubeTransitionApp test( application ); application.MainLoop();