Cleanup for removal of ImageAttributes from public API
[platform/core/uifw/dali-demo.git] / examples / cube-transition-effect / cube-transition-effect-example.cpp
index 93e9079..0090720 100644 (file)
@@ -26,6 +26,8 @@
 
 using namespace Dali;
 
+using Dali::Toolkit::TextLabel;
+
 // LOCAL STUFF
 namespace
 {
@@ -85,6 +87,21 @@ 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
@@ -154,6 +171,7 @@ private:
   Toolkit::View                   mView;
   Toolkit::ToolBar                mToolBar;
   Layer                           mContent;
+  Toolkit::TextLabel              mTitleActor;
   Actor                           mParent;
 
   Vector2                         mViewSize;
@@ -162,7 +180,6 @@ private:
   ImageActor                      mNextImage;
   unsigned int                    mIndex;
   bool                            mIsImageLoading;
-  Constraint                      mImageConstraint;
 
   PanGestureDetector              mPanGestureDetector;
 
@@ -202,6 +219,8 @@ CubeTransitionApp::~CubeTransitionApp()
 
 void CubeTransitionApp::OnInit( Application& application )
 {
+  DemoHelper::RequestThemeChange();
+
   Stage::GetCurrent().KeyEventSignal().Connect(this, &CubeTransitionApp::OnKeyEvent);
 
   // Creates a default view with a default tool bar, the view is added to the stage.
@@ -216,6 +235,10 @@ void CubeTransitionApp::OnInit( Application& application )
   mEffectChangeButton.ClickedSignal().Connect( this, &CubeTransitionApp::OnEffectButtonClicked );
   mToolBar.AddControl( mEffectChangeButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalRight, DemoHelper::DEFAULT_MODE_SWITCH_PADDING );
 
+  // Add title to the tool bar.
+  mTitleActor = DemoHelper::CreateToolBarLabel( APPLICATION_TITLE_WAVE );
+  mToolBar.AddControl( mTitleActor, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarTitlePercentage, Toolkit::Alignment::HorizontalCenter );
+
   //Add an slideshow icon on the right of the title
   mIconSlideshowStart = ResourceImage::New( SLIDE_SHOW_START_ICON );
   mIconSlideshowStop = ResourceImage::New( SLIDE_SHOW_STOP_ICON );
@@ -259,11 +282,10 @@ void CubeTransitionApp::OnInit( Application& application )
   mViewTimer.TickSignal().Connect( this, &CubeTransitionApp::OnTimerTick );
 
   // show the first image
-  mImageConstraint = Constraint::New<Vector3>( Actor::Property::Scale, LocalSource( Actor::Property::Size ), ParentSource( Actor::Property::Size ), ScaleToFitKeepAspectRatioConstraint() );
-
-  mCurrentImage = ImageActor::New( ResourceImage::New( IMAGES[mIndex] ) );
+  mCurrentImage = ImageActor::New( LoadStageFillingImage( IMAGES[mIndex] ) );
   mCurrentImage.SetPositionInheritanceMode( USE_PARENT_POSITION );
-  mCurrentImage.ApplyConstraint( mImageConstraint );
+  mCurrentImage.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
+  mCurrentImage.SetSizeScalePolicy( SizeScalePolicy::FIT_WITH_ASPECT_RATIO );
   mParent.Add( mCurrentImage );
 
   mCurrentEffect = mCubeWaveEffect;
@@ -298,10 +320,13 @@ void CubeTransitionApp::OnPanGesture( Actor actor, const PanGesture& gesture )
 
 void CubeTransitionApp::GoToNextImage()
 {
-  ResourceImage image = ResourceImage::New( IMAGES[ mIndex ] );
+  ResourceImage image = LoadStageFillingImage( IMAGES[ mIndex ] );
   mNextImage = ImageActor::New( image );
+
   mNextImage.SetPositionInheritanceMode(USE_PARENT_POSITION);
-  mNextImage.ApplyConstraint( mImageConstraint );
+  mNextImage.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
+  mNextImage.SetSizeScalePolicy( SizeScalePolicy::FIT_WITH_ASPECT_RATIO );
+  mNextImage.SetRelayoutEnabled( false );
   mCurrentEffect.SetTargetImage(mNextImage);
   if( image.GetLoadingState() == ResourceLoadingSucceeded )
   {
@@ -329,17 +354,20 @@ bool CubeTransitionApp::OnEffectButtonClicked( Toolkit::Button button )
   if(mCurrentEffect == mCubeWaveEffect)
   {
     mCurrentEffect = mCubeCrossEffect;
+    mTitleActor.SetProperty( TextLabel::Property::TEXT, std::string(APPLICATION_TITLE_CROSS) );
     mEffectChangeButton.SetBackgroundImage(mImageCross);
 
   }
   else if(mCurrentEffect == mCubeCrossEffect)
   {
     mCurrentEffect = mCubeFoldEffect;
+    mTitleActor.SetProperty( TextLabel::Property::TEXT, std::string(APPLICATION_TITLE_FOLD) );
     mEffectChangeButton.SetBackgroundImage(mImageFold);
   }
   else
   {
     mCurrentEffect = mCubeWaveEffect;
+    mTitleActor.SetProperty( TextLabel::Property::TEXT, std::string(APPLICATION_TITLE_WAVE) );
     mEffectChangeButton.SetBackgroundImage(mImageWave);
   }
 
@@ -400,7 +428,7 @@ void CubeTransitionApp::OnKeyEvent(const KeyEvent& event)
   }
 }
 
-// Entry point for Linux & SLP applications
+// Entry point for Linux & Tizen applications
 int main( int argc, char **argv )
 {
   Application application = Application::New( &argc, &argv );