/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 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.
// INTERNAL INCLUDES
#include "shared/view.h"
+#include "shared/utility.h"
#include <dali/dali.h>
#include <dali-toolkit/dali-toolkit.h>
+#include <dali-toolkit/devel-api/controls/buttons/toggle-button.h>
#include <dali-toolkit/devel-api/transition-effects/cube-transition-effect.h>
#include <dali-toolkit/devel-api/transition-effects/cube-transition-cross-effect.h>
#include <dali-toolkit/devel-api/transition-effects/cube-transition-fold-effect.h>
// 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
*/
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);
/**
* 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 window and creates a textue out of it
+ * @param[in] filepath Path to the image file
+ * @return New texture object
+ */
+ Texture LoadWindowFillingTexture( const char* filepath );
+
private:
Application& mApplication;
Toolkit::Control mView;
Vector2 mViewSize;
- ResourceImage mCurrentImage;
- ResourceImage mNextImage;
+ Texture mCurrentTexture;
+ Texture mNextTexture;
unsigned int mIndex;
bool mIsImageLoading;
Vector2 mPanPosition;
Vector2 mPanDisplacement;
-
- Toolkit::PushButton mEffectChangeButton;
};
CubeTransitionApp::CubeTransitionApp( Application& application )
void CubeTransitionApp::OnInit( Application& application )
{
- Stage::GetCurrent().KeyEventSignal().Connect(this, &CubeTransitionApp::OnKeyEvent);
+ application.GetWindow().KeyEventSignal().Connect(this, &CubeTransitionApp::OnKeyEvent);
- // Creates a default view with a default tool bar, the view is added to the stage.
+ // Creates a default view with a default tool bar, the view is added to the window.
mContent = DemoHelper::CreateView( application, mView, mToolBar, "", TOOLBAR_IMAGE, "" );
- mContent.SetBehavior( Layer::LAYER_3D );
+ mContent.SetProperty( Layer::Property::BEHAVIOR, Layer::LAYER_3D );
+
+
+ // 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 }
+ );
- // 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 );
+ 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 );
//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::Button::Property::UNSELECTED_BACKGROUND_VISUAL, SLIDE_SHOW_START_ICON );
+ mSlideshowButton.SetProperty( Toolkit::Button::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 );
- // Set size to stage size to avoid seeing a black border on transition
- mViewSize = Stage::GetCurrent().GetSize();
+ // Set size to window size to avoid seeing a black border on transition
+ mViewSize = application.GetWindow().GetSize();
// show the first image
- mCurrentImage = LoadStageFillingImage( IMAGES[mIndex] );
+ mCurrentTexture = LoadWindowFillingTexture( IMAGES[mIndex] );
//use small cubes
mCubeWaveEffect = Toolkit::CubeTransitionWaveEffect::New( NUM_ROWS_WAVE, NUM_COLUMNS_WAVE );
mCubeWaveEffect.SetCubeDisplacement( CUBE_DISPLACEMENT_WAVE );
mCubeWaveEffect.TransitionCompletedSignal().Connect(this, &CubeTransitionApp::OnTransitionCompleted);
- mCubeWaveEffect.SetSize( mViewSize );
- mCubeWaveEffect.SetPositionInheritanceMode( USE_PARENT_POSITION );
- mCubeWaveEffect.SetCurrentImage( mCurrentImage );
+ mCubeWaveEffect.SetProperty( Actor::Property::SIZE, mViewSize );
+ mCubeWaveEffect.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
+ mCubeWaveEffect.SetCurrentTexture( mCurrentTexture );
// use big cubes
mCubeCrossEffect = Toolkit::CubeTransitionCrossEffect::New(NUM_ROWS_CROSS, NUM_COLUMNS_CROSS );
mCubeCrossEffect.SetCubeDisplacement( CUBE_DISPLACEMENT_CROSS );
mCubeCrossEffect.TransitionCompletedSignal().Connect(this, &CubeTransitionApp::OnTransitionCompleted);
- mCubeCrossEffect.SetSize( mViewSize );
- mCubeCrossEffect.SetPositionInheritanceMode( USE_PARENT_POSITION );
- mCubeCrossEffect.SetCurrentImage( mCurrentImage );
+ mCubeCrossEffect.SetProperty( Actor::Property::SIZE, mViewSize );
+ mCubeCrossEffect.SetProperty( Actor::Property::PARENT_ORIGIN, 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.SetProperty( Actor::Property::SIZE, mViewSize );
+ mCubeFoldEffect.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
+ mCubeFoldEffect.SetCurrentTexture( mCurrentTexture );
mViewTimer = Timer::New( VIEWINGTIME );
mViewTimer.TickSignal().Connect( this, &CubeTransitionApp::OnTimerTick );
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 = LoadWindowFillingTexture( IMAGES[ mIndex ] );
+ mCurrentEffect.SetTargetTexture( mNextTexture );
+ mIsImageLoading = false;
+ mCurrentEffect.StartTransition( mPanPosition, mPanDisplacement );
+ mCurrentTexture = mNextTexture;
}
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;
}
if( mSlideshow )
{
mPanGestureDetector.Detach( mContent );
- mSlideshowButton.SetUnselectedImage( SLIDE_SHOW_STOP_ICON );
- mSlideshowButton.SetSelectedImage( SLIDE_SHOW_STOP_ICON_SELECTED );
+ mSlideshowButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, SLIDE_SHOW_STOP_ICON );
+ mSlideshowButton.SetProperty( Toolkit::Button::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();
else
{
mPanGestureDetector.Attach( mContent );
- mSlideshowButton.SetUnselectedImage( SLIDE_SHOW_START_ICON );
- mSlideshowButton.SetSelectedImage( SLIDE_SHOW_START_ICON_SELECTED );
+ mSlideshowButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, SLIDE_SHOW_START_ICON );
+ mSlideshowButton.SetProperty( Toolkit::Button::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 )
{
return false;
}
+Texture CubeTransitionApp::LoadWindowFillingTexture( const char* filepath )
+{
+ ImageDimensions dimensions( mApplication.GetWindow().GetSize() );
+ 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)
+ if(event.GetState() == KeyEvent::Down)
{
if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) )
{
}
}
-// 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, DEMO_THEME_PATH );
CubeTransitionApp test( application );