From ff961cccdcbf1c30b0f53b0da027df855cde2b63 Mon Sep 17 00:00:00 2001 From: Xiangyin Ma Date: Wed, 22 Jun 2016 18:36:42 +0100 Subject: [PATCH] Remove ResourceImage usage from demos --- demo/dali-table-view.cpp | 5 ++--- examples/blocks/blocks-example.cpp | 21 +++++++++++++++------ examples/bubble-effect/bubble-effect-example.cpp | 23 +++++------------------ examples/buttons/buttons-example.cpp | 23 ++++++++--------------- examples/cube-transition-effect/cube-transition-effect-example.cpp | 49 ++++++++----------------------------------------- examples/dissolve-effect/dissolve-effect-example.cpp | 77 ++++++++++++++++++++++++++++++++++++----------------------------------------- examples/image-scaling-and-filtering/image-scaling-and-filtering-example.cpp | 5 ++--- examples/image-view-alpha-blending/image-view-alpha-blending-example.cpp | 10 +++++++--- examples/mesh-sorting/mesh-sorting-example.cpp | 5 +++-- examples/metaball-explosion/metaball-explosion-example.cpp | 3 ++- examples/metaball-refrac/metaball-refrac-example.cpp | 3 ++- examples/model3d-view/model3d-view-example.cpp | 3 +-- examples/motion-blur/motion-blur-example.cpp | 28 +++++++++++++++++----------- examples/motion-stretch/motion-stretch-example.cpp | 12 ++++++------ examples/new-window/new-window-example.cpp | 27 ++++++++++++--------------- examples/page-turn-view/page-turn-view-example.cpp | 46 +++++++++++++++++++++++++++------------------- examples/perf-scroll/perf-scroll.cpp | 6 ++++-- examples/point-mesh/point-mesh-example.cpp | 9 +++++---- examples/popup/popup-example.cpp | 5 ----- examples/radial-menu/radial-menu-example.cpp | 6 ++---- examples/refraction-effect/refraction-effect-example.cpp | 22 +++++----------------- examples/scroll-view/scroll-view-example.cpp | 13 ++++++++++--- examples/super-blur-bloom/super-blur-bloom-example.cpp | 18 +++--------------- examples/text-field/text-field-example.cpp | 4 ++-- examples/text-label/text-label-example.cpp | 3 +-- examples/textured-mesh/textured-mesh-example.cpp | 10 +++++----- shared/utility.h | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ shared/view.h | 16 ++++++++++++---- 28 files changed, 293 insertions(+), 250 deletions(-) create mode 100644 shared/utility.h diff --git a/demo/dali-table-view.cpp b/demo/dali-table-view.cpp index 04cfaa3..daebe61 100644 --- a/demo/dali-table-view.cpp +++ b/demo/dali-table-view.cpp @@ -485,7 +485,6 @@ Actor DaliTableView::CreateTile( const std::string& name, const std::string& tit Toolkit::ImageView DaliTableView::NewStencilImage() { Toolkit::ImageView stencil = ImageView::New( TILE_BACKGROUND_ALPHA ); - stencil.SetParentOrigin( ParentOrigin::CENTER ); stencil.SetAnchorPoint( AnchorPoint::CENTER ); stencil.SetDrawMode( DrawMode::STENCIL ); @@ -717,6 +716,7 @@ void DaliTableView::AddBackgroundActors( Actor layer, int count, BufferImage dis Dali::Property::Map effect = Toolkit::CreateDistanceFieldEffect(); dfActor.SetProperty( Toolkit::ImageView::Property::IMAGE, effect ); dfActor.SetColor( BUBBLE_COLOR[ i%NUMBER_OF_BUBBLE_COLOR ] ); + layer.Add( dfActor ); } @@ -790,8 +790,7 @@ void DaliTableView::GenerateCircle( const Size& size, std::vector< unsigned char ImageView DaliTableView::CreateLogo( std::string imagePath ) { - Image image = ResourceImage::New( imagePath ); - ImageView logo = ImageView::New( image ); + ImageView logo = ImageView::New( imagePath ); logo.SetAnchorPoint( AnchorPoint::CENTER ); logo.SetParentOrigin( ParentOrigin::CENTER ); diff --git a/examples/blocks/blocks-example.cpp b/examples/blocks/blocks-example.cpp index a308be3..28eb286 100644 --- a/examples/blocks/blocks-example.cpp +++ b/examples/blocks/blocks-example.cpp @@ -362,6 +362,17 @@ private: mBrickCount = 0; + if( mBrickImageMap.Empty() ) + { + Vector2 stageSize(Stage::GetCurrent().GetSize()); + const Vector2 brickSize(BRICK_SIZE * Vector2(stageSize.x, stageSize.x)); + + mBrickImageMap["desiredWidth"] = static_cast( brickSize.width ); + mBrickImageMap["desiredHeight"] = static_cast( brickSize.height ); + mBrickImageMap["fittingMode"] = "SCALE_TO_FILL"; + mBrickImageMap["samplingMode"] = "BOX_THEN_LINEAR"; + } + switch(level%TOTAL_LEVELS) { case 0: @@ -519,14 +530,11 @@ private: */ Actor CreateBrick( const Vector2& position, int type ) { - Vector2 stageSize(Stage::GetCurrent().GetSize()); - const Vector2 brickSize(BRICK_SIZE * Vector2(stageSize.x, stageSize.x)); - - Image img = ResourceImage::New( BRICK_IMAGE_PATH[type], Dali::ImageDimensions( 128, 64 ), Dali::FittingMode::SCALE_TO_FILL, Dali::SamplingMode::BOX_THEN_LINEAR ); - ImageView brick = ImageView::New(img); + mBrickImageMap["url"] = BRICK_IMAGE_PATH[type]; + ImageView brick = ImageView::New(); + brick.SetProperty( ImageView::Property::IMAGE, mBrickImageMap ); brick.SetParentOrigin(ParentOrigin::TOP_LEFT); brick.SetAnchorPoint(AnchorPoint::CENTER); - brick.SetSize( brickSize ); brick.SetPosition( Vector3( position ) ); // Add a constraint on the brick between it and the ball generating a collision-property @@ -815,6 +823,7 @@ private: Animation mWobbleAnimation; ///< Paddle's animation when hit (wobbles) Property::Index mWobbleProperty; ///< The wobble property (generated from animation) Actor mLevelContainer; ///< The level container (contains bricks) + Property::Map mBrickImageMap; ///< The property map used to load the brick // actor - dragging functionality diff --git a/examples/bubble-effect/bubble-effect-example.cpp b/examples/bubble-effect/bubble-effect-example.cpp index fbd83db..6e16fd5 100644 --- a/examples/bubble-effect/bubble-effect-example.cpp +++ b/examples/bubble-effect/bubble-effect-example.cpp @@ -19,6 +19,7 @@ #include #include #include "shared/view.h" +#include "shared/utility.h" using namespace Dali; @@ -53,20 +54,6 @@ const unsigned int NUM_BUBBLE_SHAPE_IMAGES( sizeof( BUBBLE_SHAPE_IMAGES ) / size const Vector2 DEFAULT_BUBBLE_SIZE( 10.f, 30.f ); const unsigned int DEFAULT_NUMBER_OF_BUBBLES( 1000 ); -/** - * @brief Load an image, scaled-down to no more than the stage dimensions. - * - * Uses image scaling mode FittingMode::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, Dali::ImageDimensions( stageSize.x, stageSize.y ), Dali::FittingMode::SCALE_TO_FILL, Dali::SamplingMode::BOX_THEN_LINEAR ); -} - }// end LOCAL_STUFF // This example shows the usage of BubbleEmitter which displays lots of moving bubbles on the stage. @@ -130,10 +117,10 @@ private: // Create and initialize the BubbleEmitter object mBubbleEmitter = Toolkit::BubbleEmitter::New( stageSize, - ResourceImage::New( BUBBLE_SHAPE_IMAGES[mCurrentBubbleShapeImageId] ), + DemoHelper::LoadImage( BUBBLE_SHAPE_IMAGES[mCurrentBubbleShapeImageId] ), DEFAULT_NUMBER_OF_BUBBLES, DEFAULT_BUBBLE_SIZE); - mBackgroundImage = LoadStageFillingImage( BACKGROUND_IMAGES[mCurrentBackgroundImageId] ); + mBackgroundImage = DemoHelper::LoadStageFillingImage( BACKGROUND_IMAGES[mCurrentBackgroundImageId] ); mBubbleEmitter.SetBackground( mBackgroundImage, mHSVDelta ); // Get the root actor of all bubbles, and add it to stage. @@ -253,7 +240,7 @@ private: { if(button == mChangeBackgroundButton) { - mBackgroundImage = LoadStageFillingImage( BACKGROUND_IMAGES[ ++mCurrentBackgroundImageId % NUM_BACKGROUND_IMAGES ] ); + mBackgroundImage = DemoHelper::LoadStageFillingImage( BACKGROUND_IMAGES[ ++mCurrentBackgroundImageId % NUM_BACKGROUND_IMAGES ] ); mBubbleEmitter.SetBackground( mBackgroundImage, mHSVDelta ); @@ -261,7 +248,7 @@ private: } else if( button == mChangeBubbleShapeButton ) { - mBubbleEmitter.SetShapeImage( ResourceImage::New( BUBBLE_SHAPE_IMAGES[ ++mCurrentBubbleShapeImageId % NUM_BUBBLE_SHAPE_IMAGES ] ) ); + mBubbleEmitter.SetShapeImage( DemoHelper::LoadImage( BUBBLE_SHAPE_IMAGES[ ++mCurrentBubbleShapeImageId % NUM_BUBBLE_SHAPE_IMAGES ] ) ); } return true; } diff --git a/examples/buttons/buttons-example.cpp b/examples/buttons/buttons-example.cpp index 14d532c..bd10f40 100644 --- a/examples/buttons/buttons-example.cpp +++ b/examples/buttons/buttons-example.cpp @@ -157,7 +157,7 @@ class ButtonsController: public ConnectionTracker // Radio 1 { - Toolkit::ImageView image = Toolkit::ImageView::New( ResourceImage::New( SMALL_IMAGE_1 ) ); + Toolkit::ImageView image = Toolkit::ImageView::New( SMALL_IMAGE_1 ); image.SetSize( DP(RADIO_LABEL_THUMBNAIL_SIZE), DP(RADIO_LABEL_THUMBNAIL_SIZE) ); mRadioButtonImage1 = Dali::Toolkit::RadioButton::New( "1" ); @@ -174,7 +174,7 @@ class ButtonsController: public ConnectionTracker { radioY += RADIO_LABEL_THUMBNAIL_SIZE + RADIO_IMAGE_SPACING; - Toolkit::ImageView image = Toolkit::ImageView::New( ResourceImage::New( SMALL_IMAGE_2 ) ); + Toolkit::ImageView image = Toolkit::ImageView::New( SMALL_IMAGE_2 ); image.SetSize( DP(RADIO_LABEL_THUMBNAIL_SIZE), DP(RADIO_LABEL_THUMBNAIL_SIZE) ); mRadioButtonImage2 = Dali::Toolkit::RadioButton::New( "2" ); @@ -190,7 +190,7 @@ class ButtonsController: public ConnectionTracker { radioY += RADIO_LABEL_THUMBNAIL_SIZE + RADIO_IMAGE_SPACING; - Toolkit::ImageView image = Toolkit::ImageView::New( ResourceImage::New( SMALL_IMAGE_3 ) ); + Toolkit::ImageView image = Toolkit::ImageView::New( SMALL_IMAGE_3 ); image.SetSize( DP(RADIO_LABEL_THUMBNAIL_SIZE), DP(RADIO_LABEL_THUMBNAIL_SIZE) ); mRadioButtonImage3 = Dali::Toolkit::RadioButton::New( "3" ); @@ -213,11 +213,7 @@ class ButtonsController: public ConnectionTracker radioGroup2Background.AddChild( mUpdateButton, Toolkit::TableView::CellPosition( 1, 0 ) ); // ImageView to display selected image - mBigImage1 = ResourceImage::New( BIG_IMAGE_1 ); - mBigImage2 = ResourceImage::New( BIG_IMAGE_2 ); - mBigImage3 = ResourceImage::New( BIG_IMAGE_3 ); - - mImage = Toolkit::ImageView::New( mBigImage1 ); + mImage = Toolkit::ImageView::New( BIG_IMAGE_1 ); mImage.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); mImage.SetSizeScalePolicy( SizeScalePolicy::FIT_WITH_ASPECT_RATIO ); radioGroup2Background.AddChild( mImage, Toolkit::TableView::CellPosition( 0, 1, 2, 1 ) ); @@ -257,7 +253,7 @@ class ButtonsController: public ConnectionTracker textLabel.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT ); textLabel.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" ); - Toolkit::ImageView image = Toolkit::ImageView::New( ResourceImage::New( ENABLED_IMAGE ) ); + Toolkit::ImageView image = Toolkit::ImageView::New( ENABLED_IMAGE ); image.SetSize( DP(RADIO_LABEL_THUMBNAIL_SIZE), DP(RADIO_LABEL_THUMBNAIL_SIZE) ); image.SetPadding( Padding( DP(20.0f), 0.0f, 0.0f, 0.0f ) ); tableView.AddChild( image, Toolkit::TableView::CellPosition( 0, 1 ) ); @@ -425,15 +421,15 @@ class ButtonsController: public ConnectionTracker { if( mRadioButtonImage1.IsSelected() ) { - mImage.SetImage( mBigImage1 ); + mImage.SetImage( BIG_IMAGE_1 ); } else if( mRadioButtonImage2.IsSelected() ) { - mImage.SetImage( mBigImage2 ); + mImage.SetImage( BIG_IMAGE_2 ); } else if( mRadioButtonImage3.IsSelected() ) { - mImage.SetImage( mBigImage3 ); + mImage.SetImage( BIG_IMAGE_3 ); } return true; } @@ -500,9 +496,6 @@ private: Animation mAnimation; float mLastPoint; - Image mBigImage1; - Image mBigImage2; - Image mBigImage3; Toolkit::ImageView mImage; }; diff --git a/examples/cube-transition-effect/cube-transition-effect-example.cpp b/examples/cube-transition-effect/cube-transition-effect-example.cpp index 46d7fcd..7f50537 100644 --- a/examples/cube-transition-effect/cube-transition-effect-example.cpp +++ b/examples/cube-transition-effect/cube-transition-effect-example.cpp @@ -20,6 +20,7 @@ // INTERNAL INCLUDES #include "shared/view.h" +#include "shared/utility.h" #include #include @@ -98,20 +99,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 +130,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); @@ -185,8 +166,8 @@ private: Vector2 mViewSize; - ResourceImage mCurrentImage; - ResourceImage mNextImage; + Image mCurrentImage; + Image mNextImage; unsigned int mIndex; bool mIsImageLoading; @@ -251,7 +232,7 @@ void CubeTransitionApp::OnInit( Application& application ) mViewSize = Stage::GetCurrent().GetSize(); // show the first image - mCurrentImage = LoadStageFillingImage( IMAGES[mIndex] ); + mCurrentImage = DemoHelper::LoadStageFillingImage( IMAGES[mIndex] ); //use small cubes mCubeWaveEffect = Toolkit::CubeTransitionWaveEffect::New( NUM_ROWS_WAVE, NUM_COLUMNS_WAVE ); @@ -322,25 +303,11 @@ void CubeTransitionApp::OnPanGesture( Actor actor, const PanGesture& gesture ) void CubeTransitionApp::GoToNextImage() { - mNextImage = LoadStageFillingImage( IMAGES[ mIndex ] ); + mNextImage = DemoHelper::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; + mIsImageLoading = false; + mCurrentEffect.StartTransition( mPanPosition, mPanDisplacement ); + mCurrentImage = mNextImage; } bool CubeTransitionApp::OnEffectButtonClicked( Toolkit::Button button ) diff --git a/examples/dissolve-effect/dissolve-effect-example.cpp b/examples/dissolve-effect/dissolve-effect-example.cpp index cd927ae..4d49c58 100644 --- a/examples/dissolve-effect/dissolve-effect-example.cpp +++ b/examples/dissolve-effect/dissolve-effect-example.cpp @@ -80,17 +80,27 @@ const float TRANSITION_DURATION = 2.5f; //2.5 second const float INITIAL_DEPTH = 10.0f; /** - * @brief Load an image, scaled-down to no more than the stage dimensions. + * @brief Create an image view with an image which would be 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. + * and filter mode BOX_THEN_LINEAR to sample the image with maximum quality. */ -ResourceImage LoadStageFillingImage( const char * const imagePath ) +Toolkit::ImageView CreateStageFillingImageView( 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 ); + Toolkit::ImageView imageView = Toolkit::ImageView::New(); + Property::Map map; + map["rendererType"] = "image"; + map["url"] = imagePath; + map["desiredWidth"] = stageSize.x; + map["desiredHeight"] = stageSize.y; + map["fittingMode"] = "SCALE_TO_FILL"; + map["samplingMode"] = "BOX_THEN_LINEAR"; + map["synchronousLoading"] = true; + imageView.SetProperty( Toolkit::ImageView::Property::IMAGE, map ); + + return imageView; } } // namespace @@ -181,16 +191,7 @@ private: bool mTimerReady; unsigned int mCentralLineIndex; - Image mIconPlay; - Image mIconPlaySelected; - Image mIconStop; - Image mIconStopSelected; Toolkit::PushButton mPlayStopButton; - - Image mIconHighP; - Image mIconHighPSelected; - Image mIconMediumP; - Image mIconMediumPSelected; Toolkit::PushButton mEffectChangeButton; }; @@ -219,13 +220,9 @@ void DissolveEffectApp::OnInit( Application& application ) mContent = DemoHelper::CreateView( application, mView,mToolBar, "", TOOLBAR_IMAGE, "" ); // Add an effect-changing button on the right of the tool bar. - mIconHighP = ResourceImage::New( EFFECT_HIGHP_IMAGE ); - mIconHighPSelected = ResourceImage::New( EFFECT_HIGHP_IMAGE_SELECTED ); - mIconMediumP = ResourceImage::New( EFFECT_MEDIUMP_IMAGE ); - mIconMediumPSelected = ResourceImage::New( EFFECT_MEDIUMP_IMAGE_SELECTED ); mEffectChangeButton = Toolkit::PushButton::New(); - mEffectChangeButton.SetButtonImage( mIconHighP ); - mEffectChangeButton.SetSelectedImage( mIconHighPSelected ); + mEffectChangeButton.SetProperty( Toolkit::Button::Property::UNSELECTED_STATE_IMAGE, EFFECT_HIGHP_IMAGE ); + mEffectChangeButton.SetProperty( Toolkit::Button::Property::SELECTED_STATE_IMAGE, EFFECT_HIGHP_IMAGE_SELECTED ); mEffectChangeButton.ClickedSignal().Connect( this, &DissolveEffectApp::OnEffectButtonClicked ); mToolBar.AddControl( mEffectChangeButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalRight, DemoHelper::DEFAULT_MODE_SWITCH_PADDING ); @@ -234,13 +231,9 @@ void DissolveEffectApp::OnInit( Application& application ) mToolBar.AddControl( mTitleActor, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarTitlePercentage, Toolkit::Alignment::HorizontalCenter ); // Add an slide-show button on the right of the title - mIconPlay = ResourceImage::New( PLAY_ICON ); - mIconPlaySelected = ResourceImage::New( PLAY_ICON_SELECTED ); - mIconStop = ResourceImage::New( STOP_ICON ); - mIconStopSelected = ResourceImage::New( STOP_ICON_SELECTED ); mPlayStopButton = Toolkit::PushButton::New(); - mPlayStopButton.SetButtonImage( mIconPlay ); - mPlayStopButton.SetSelectedImage( mIconPlaySelected ); + mPlayStopButton.SetProperty( Toolkit::Button::Property::UNSELECTED_STATE_IMAGE, PLAY_ICON ); + mPlayStopButton.SetProperty( Toolkit::Button::Property::SELECTED_STATE_IMAGE, PLAY_ICON_SELECTED ); mPlayStopButton.ClickedSignal().Connect( this, &DissolveEffectApp::OnSildeshowButtonClicked ); mToolBar.AddControl( mPlayStopButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalCenter, DemoHelper::DEFAULT_PLAY_PADDING ); @@ -259,7 +252,7 @@ void DissolveEffectApp::OnInit( Application& application ) mContent.Add( mParent ); // show the first image - mCurrentImage = Toolkit::ImageView::New( LoadStageFillingImage( IMAGES[mIndex] ) ); + mCurrentImage = CreateStageFillingImageView( IMAGES[mIndex] ); mCurrentImage.SetParentOrigin( ParentOrigin::CENTER ); mCurrentImage.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); mCurrentImage.SetSizeScalePolicy( SizeScalePolicy::FIT_WITH_ASPECT_RATIO ); @@ -268,7 +261,8 @@ void DissolveEffectApp::OnInit( Application& application ) mPanGestureDetector.Attach( mCurrentImage ); mDissolveEffect = Dali::Toolkit::CreateDissolveEffect( mUseHighPrecision ); - mEmptyEffect.Insert( "shader", Property::Value() ); + Property::Map emptyShaderMap; + mEmptyEffect.Insert( "shader", emptyShaderMap ); } // signal handler, called when the pan gesture is detected @@ -291,8 +285,7 @@ void DissolveEffectApp::OnPanGesture( Actor actor, const PanGesture& gesture ) mIndex = (mIndex + NUM_IMAGES -1)%NUM_IMAGES; } - Image image = LoadStageFillingImage( IMAGES[ mIndex ] ); - mNextImage = Toolkit::ImageView::New( image ); + mNextImage = CreateStageFillingImageView( IMAGES[ mIndex ] ); mNextImage.SetParentOrigin( ParentOrigin::CENTER ); mNextImage.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); mNextImage.SetSizeScalePolicy( SizeScalePolicy::FIT_WITH_ASPECT_RATIO ); @@ -348,14 +341,14 @@ bool DissolveEffectApp::OnEffectButtonClicked( Toolkit::Button button ) if(mUseHighPrecision) { mTitleActor.SetProperty( TextLabel::Property::TEXT, std::string(APPLICATION_TITLE_HIGHP) ); - mEffectChangeButton.SetButtonImage( mIconHighP ); - mEffectChangeButton.SetSelectedImage( mIconHighPSelected ); + mEffectChangeButton.SetProperty( Toolkit::Button::Property::UNSELECTED_STATE_IMAGE, EFFECT_HIGHP_IMAGE ); + mEffectChangeButton.SetProperty( Toolkit::Button::Property::SELECTED_STATE_IMAGE, EFFECT_HIGHP_IMAGE_SELECTED ); } else { mTitleActor.SetProperty( TextLabel::Property::TEXT, std::string(APPLICATION_TITLE_MEDIUMP) ); - mEffectChangeButton.SetButtonImage( mIconMediumP ); - mEffectChangeButton.SetSelectedImage( mIconMediumPSelected ); + mEffectChangeButton.SetProperty( Toolkit::Button::Property::UNSELECTED_STATE_IMAGE, EFFECT_MEDIUMP_IMAGE ); + mEffectChangeButton.SetProperty( Toolkit::Button::Property::SELECTED_STATE_IMAGE, EFFECT_MEDIUMP_IMAGE_SELECTED ); } return true; @@ -366,16 +359,16 @@ bool DissolveEffectApp::OnSildeshowButtonClicked( Toolkit::Button button ) mSlideshow = !mSlideshow; if( mSlideshow ) { - mPlayStopButton.SetButtonImage( mIconStop ); - mPlayStopButton.SetSelectedImage( mIconStopSelected ); + mPlayStopButton.SetProperty( Toolkit::Button::Property::UNSELECTED_STATE_IMAGE, STOP_ICON ); + mPlayStopButton.SetProperty( Toolkit::Button::Property::SELECTED_STATE_IMAGE, STOP_ICON_SELECTED ); mPanGestureDetector.Detach( mParent ); mViewTimer.Start(); mTimerReady = false; } else { - mPlayStopButton.SetButtonImage( mIconPlay ); - mPlayStopButton.SetSelectedImage( mIconPlaySelected ); + mPlayStopButton.SetProperty( Toolkit::Button::Property::UNSELECTED_STATE_IMAGE, PLAY_ICON ); + mPlayStopButton.SetProperty( Toolkit::Button::Property::SELECTED_STATE_IMAGE, PLAY_ICON_SELECTED ); mTimerReady = true; mPanGestureDetector.Attach( mParent ); } @@ -384,7 +377,10 @@ bool DissolveEffectApp::OnSildeshowButtonClicked( Toolkit::Button button ) void DissolveEffectApp::OnTransitionCompleted( Animation& source ) { - mNextImage.SetProperty( Toolkit::ImageView::Property::IMAGE, mEmptyEffect ); + if(mUseHighPrecision) + { + mNextImage.SetProperty( Toolkit::ImageView::Property::IMAGE, mEmptyEffect ); + } mParent.Remove( mCurrentImage ); mPanGestureDetector.Detach( mCurrentImage ); mCurrentImage = mNextImage; @@ -404,8 +400,7 @@ bool DissolveEffectApp::OnTimerTick() if(mSlideshow) { mIndex = (mIndex + 1)%NUM_IMAGES; - Image image = LoadStageFillingImage( IMAGES[ mIndex ] ); - mNextImage = Toolkit::ImageView::New( image ); + mNextImage = CreateStageFillingImageView( IMAGES[ mIndex ] ); mNextImage.SetParentOrigin( ParentOrigin::CENTER ); mNextImage.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); mNextImage.SetSizeScalePolicy( SizeScalePolicy::FIT_WITH_ASPECT_RATIO ); diff --git a/examples/image-scaling-and-filtering/image-scaling-and-filtering-example.cpp b/examples/image-scaling-and-filtering/image-scaling-and-filtering-example.cpp index 042ce7a..b6fff18 100644 --- a/examples/image-scaling-and-filtering/image-scaling-and-filtering-example.cpp +++ b/examples/image-scaling-and-filtering/image-scaling-and-filtering-example.cpp @@ -284,8 +284,7 @@ public: // Back and next image buttons in corners of stage: unsigned int playWidth = std::min( stage.GetSize().x * (1 / 5.0f), 58.0f ); - Image playImage = ResourceImage::New( DALI_ICON_PLAY, ImageDimensions( playWidth, playWidth ), FittingMode::SHRINK_TO_FIT, SamplingMode::BOX_THEN_LINEAR ); - Toolkit::ImageView imagePrevious = Toolkit::ImageView::New( playImage ); + Toolkit::ImageView imagePrevious = Toolkit::ImageView::New( DALI_ICON_PLAY, ImageDimensions( playWidth, playWidth ) ); // Last image button: imagePrevious.SetAnchorPoint( AnchorPoint::TOP_LEFT ); @@ -298,7 +297,7 @@ public: imagePrevious.TouchSignal().Connect( this, &ImageScalingAndFilteringController::OnControlTouched ); // Next image button: - Toolkit::ImageView imageNext = Toolkit::ImageView::New( playImage ); + Toolkit::ImageView imageNext = Toolkit::ImageView::New( DALI_ICON_PLAY, ImageDimensions( playWidth, playWidth ) ); imageNext.SetAnchorPoint( AnchorPoint::TOP_RIGHT ); imageNext.SetY( playWidth * 0.5f ); imageNext.SetX( stage.GetSize().x - playWidth * 0.5f ); diff --git a/examples/image-view-alpha-blending/image-view-alpha-blending-example.cpp b/examples/image-view-alpha-blending/image-view-alpha-blending-example.cpp index db6adfa..3a4ce7f 100644 --- a/examples/image-view-alpha-blending/image-view-alpha-blending-example.cpp +++ b/examples/image-view-alpha-blending/image-view-alpha-blending-example.cpp @@ -19,6 +19,11 @@ using namespace Dali; +namespace +{ +const char* const IMAGE_PATH ( DEMO_IMAGE_DIR "gallery-large-20.jpg" ); +} + class ImageViewAlphaBlendApp : public ConnectionTracker { public: @@ -47,10 +52,9 @@ private: Vector4 green1 = Vector4( 0.f, 0.25f, 0.f, 0.25f ); BufferImage redGreen0 = CreateBufferImage( Color::RED, green0 ); BufferImage redGreen1 = CreateBufferImage( Color::RED, green1 ); - ResourceImage testImage = ResourceImage::New( DEMO_IMAGE_DIR "gallery-large-20.jpg" ); float imageSize = 512.f; - Toolkit::ImageView imageView0 = Toolkit::ImageView::New( testImage ); + Toolkit::ImageView imageView0 = Toolkit::ImageView::New( IMAGE_PATH ); imageView0.SetSize(imageSize, imageSize); imageView0.SetParentOrigin( ParentOrigin::CENTER ); imageView0.SetY( -imageSize*0.5f ); @@ -60,7 +64,7 @@ private: imageView1.SetSize(imageSize, imageSize); imageView0.Add(imageView1); - Toolkit::ImageView imageView2 = Toolkit::ImageView::New( testImage); + Toolkit::ImageView imageView2 = Toolkit::ImageView::New( IMAGE_PATH ); imageView2.SetSize(imageSize, imageSize); imageView2.SetParentOrigin( ParentOrigin::CENTER ); imageView2.SetY( imageSize*0.5f ); diff --git a/examples/mesh-sorting/mesh-sorting-example.cpp b/examples/mesh-sorting/mesh-sorting-example.cpp index b521708..a11e2e5 100644 --- a/examples/mesh-sorting/mesh-sorting-example.cpp +++ b/examples/mesh-sorting/mesh-sorting-example.cpp @@ -24,6 +24,7 @@ // INTERNAL INCLUDES #include "shared/view.h" +#include "shared/utility.h" using namespace Dali; @@ -164,9 +165,9 @@ public: for( unsigned i=0; i #include "shared/view.h" +#include "shared/utility.h" using namespace Dali; using namespace Dali::Toolkit; @@ -328,7 +329,7 @@ void MetaballExplosionController::Create( Application& app ) stage.SetBackgroundColor(Color::BLACK); //Set background image for the view - mBackImage = ResourceImage::New( BACKGROUND_IMAGE ); + mBackImage = DemoHelper::LoadImage( BACKGROUND_IMAGE ); srand((unsigned)time(0)); diff --git a/examples/metaball-refrac/metaball-refrac-example.cpp b/examples/metaball-refrac/metaball-refrac-example.cpp index b55515a..ce43545 100644 --- a/examples/metaball-refrac/metaball-refrac-example.cpp +++ b/examples/metaball-refrac/metaball-refrac-example.cpp @@ -21,6 +21,7 @@ #include #include +#include "shared/utility.h" using namespace Dali; using namespace Dali::Toolkit; @@ -270,7 +271,7 @@ void MetaballRefracController::Create( Application& app ) stage.SetBackgroundColor(Color::BLACK); //Set background image for the view - mBackImage = ResourceImage::New( BACKGROUND_IMAGE ); + mBackImage = DemoHelper::LoadImage( BACKGROUND_IMAGE ); mGravity = Vector2(GRAVITY_X,GRAVITY_Y); mGravityVar = Vector2(0,0); diff --git a/examples/model3d-view/model3d-view-example.cpp b/examples/model3d-view/model3d-view-example.cpp index d9b5ec2..b2b4b57 100644 --- a/examples/model3d-view/model3d-view-example.cpp +++ b/examples/model3d-view/model3d-view-example.cpp @@ -76,8 +76,7 @@ public: Vector2 screenSize = stage.GetSize(); //Add background - Image imageBackground = ResourceImage::New( BACKGROUND_IMAGE ); - Toolkit::ImageView backView = Toolkit::ImageView::New(imageBackground); + Toolkit::ImageView backView = Toolkit::ImageView::New(BACKGROUND_IMAGE); backView.SetAnchorPoint( AnchorPoint::TOP_LEFT ); stage.Add(backView); diff --git a/examples/motion-blur/motion-blur-example.cpp b/examples/motion-blur/motion-blur-example.cpp index 37b0626..a638249 100644 --- a/examples/motion-blur/motion-blur-example.cpp +++ b/examples/motion-blur/motion-blur-example.cpp @@ -95,16 +95,24 @@ const float BUTTON_TITLE_LABEL_Y_OFFSET = 0.05f; const float ORIENTATION_DURATION = 0.5f; ///< Time to rotate to new orientation. /** - * @brief Load an image, scaled-down to no more than the dimensions passed in. + * @brief Set an image to image view, scaled-down to no more than the dimensions passed in. * * Uses SHRINK_TO_FIT which ensures the resulting image is - * smaller than or equal to the specified dimensions while preserving its - * original aspect ratio. + * smaller than or equal to the specified dimensions while preserving its original aspect ratio. */ -ResourceImage LoadImageFittedInBox( const char * const imagePath, uint32_t maxWidth, uint32_t maxHeight ) +void SetImageFittedInBox( ImageView& imageView, Property::Map& shaderEffect, const char * const imagePath, int maxWidth, int maxHeight ) { + Property::Map map; + map["rendererType"] = "image"; + map["url"] = imagePath; // Load the image nicely scaled-down to fit within the specified max width and height: - return ResourceImage::New( imagePath, ImageDimensions( maxWidth, maxHeight ), FittingMode::SHRINK_TO_FIT, Dali::SamplingMode::BOX_THEN_LINEAR ); + map["desiredWidth"] = maxWidth; + map["desiredHeight"] = maxHeight; + map["fittingMode"] = "SHRINK_TO_FIT"; + map["samplingMode"] = "BOX_THEN_LINEAR"; + map.Merge( shaderEffect ); + + imageView.SetProperty( ImageView::Property::IMAGE, map ); } } // unnamed namespace @@ -207,8 +215,9 @@ public: mMotionBlurActorSize = Size( std::min( stageSize.x * 0.3f, MOTION_BLUR_ACTOR_WIDTH ), std::min( stageSize.y * 0.3f, MOTION_BLUR_ACTOR_HEIGHT ) ); mMotionBlurActorSize = Size( std::min( mMotionBlurActorSize.x, mMotionBlurActorSize.y ), std::min( mMotionBlurActorSize.x, mMotionBlurActorSize.y ) ); - Image image = LoadImageFittedInBox( MOTION_BLUR_ACTOR_IMAGE1, mMotionBlurActorSize.x, mMotionBlurActorSize.y ); - mMotionBlurImageView = ImageView::New(image); + mMotionBlurEffect = CreateMotionBlurEffect(); + mMotionBlurImageView = ImageView::New(); + SetImageFittedInBox( mMotionBlurImageView, mMotionBlurEffect, MOTION_BLUR_ACTOR_IMAGE1, mMotionBlurActorSize.x, mMotionBlurActorSize.y ); mMotionBlurImageView.SetParentOrigin( ParentOrigin::CENTER ); mMotionBlurImageView.SetSize(mMotionBlurActorSize.x, mMotionBlurActorSize.y); @@ -219,7 +228,6 @@ public: // set actor shader to the blur one Toolkit::SetMotionBlurProperties( mMotionBlurImageView, MOTION_BLUR_NUM_SAMPLES ); - mMotionBlurImageView.SetProperty( Toolkit::ImageView::Property::IMAGE, mMotionBlurEffect ); #ifdef MULTIPLE_MOTION_BLURRED_ACTORS @@ -483,10 +491,8 @@ public: { mCurrentImage = 0; } + SetImageFittedInBox( mMotionBlurImageView, mMotionBlurEffect, MOTION_BLUR_ACTOR_IMAGES[mCurrentImage], mMotionBlurActorSize.x, mMotionBlurActorSize.y ); - Image blurImage = LoadImageFittedInBox( MOTION_BLUR_ACTOR_IMAGES[mCurrentImage], mMotionBlurActorSize.x, mMotionBlurActorSize.y ); - - mMotionBlurImageView.SetImage(blurImage); #ifdef MULTIPLE_MOTION_BLURRED_ACTORS mMotionBlurImageView2.SetImage(blurImage); mMotionBlurImageView3.SetImage(blurImage); diff --git a/examples/motion-stretch/motion-stretch-example.cpp b/examples/motion-stretch/motion-stretch-example.cpp index b055b4f..cdb631f 100644 --- a/examples/motion-stretch/motion-stretch-example.cpp +++ b/examples/motion-stretch/motion-stretch-example.cpp @@ -175,8 +175,10 @@ public: // // Motion stretched actor // - - mMotionStretchImageView = ImageView::New( MOTION_STRETCH_ACTOR_IMAGE1 ); + mMotionStretchEffect = Toolkit::CreateMotionStretchEffect(); + mMotionStretchEffect["url"] = MOTION_STRETCH_ACTOR_IMAGE1; + mMotionStretchImageView = ImageView::New(); + mMotionStretchImageView.SetProperty( Toolkit::ImageView::Property::IMAGE, mMotionStretchEffect ); mMotionStretchImageView.SetParentOrigin( ParentOrigin::CENTER ); mMotionStretchImageView.SetAnchorPoint( AnchorPoint::CENTER ); mMotionStretchImageView.SetSize( MOTION_STRETCH_ACTOR_WIDTH, MOTION_STRETCH_ACTOR_HEIGHT ); @@ -184,9 +186,7 @@ public: mContentLayer.Add( mMotionStretchImageView ); // Create shader used for doing motion stretch - mMotionStretchEffect = Toolkit::CreateMotionStretchEffect(); Toolkit::SetMotionStretchProperties( mMotionStretchImageView ); - mMotionStretchImageView.SetProperty( Toolkit::ImageView::Property::IMAGE, mMotionStretchEffect ); } ////////////////////////////////////////////////////////////// @@ -390,8 +390,8 @@ public: mCurrentImage = 0; } - Image stretchImage = ResourceImage::New( MOTION_STRETCH_ACTOR_IMAGES[mCurrentImage] ); - mMotionStretchImageView.SetImage(stretchImage); + mMotionStretchEffect["url"] = MOTION_STRETCH_ACTOR_IMAGES[mCurrentImage]; + mMotionStretchImageView.SetProperty( Toolkit::ImageView::Property::IMAGE, mMotionStretchEffect ); } diff --git a/examples/new-window/new-window-example.cpp b/examples/new-window/new-window-example.cpp index 022c15a..a72e1de 100644 --- a/examples/new-window/new-window-example.cpp +++ b/examples/new-window/new-window-example.cpp @@ -24,6 +24,7 @@ // INTERNAL INCLUDES #include "shared/view.h" +#include "shared/utility.h" using namespace Dali; using namespace Dali::Toolkit; @@ -187,8 +188,7 @@ void NewWindowController::Create( Application& app ) "Context recovery" ); Size stageSize = stage.GetSize(); - Image backgroundImage = ResourceImage::New( BACKGROUND_IMAGE, Dali::ImageDimensions( stageSize.x, stageSize.y ), Dali::FittingMode::SCALE_TO_FILL, Dali::SamplingMode::BOX_THEN_LINEAR ); - ImageView backgroundActor = ImageView::New( backgroundImage ); + ImageView backgroundActor = ImageView::New( BACKGROUND_IMAGE, Dali::ImageDimensions( stageSize.x, stageSize.y ) ); backgroundActor.SetParentOrigin( ParentOrigin::CENTER ); mContentLayer.Add(backgroundActor); @@ -212,16 +212,15 @@ void NewWindowController::Create( Application& app ) logoLayoutActor.SetScale(0.5f); backgroundActor.Add(logoLayoutActor); - Image image = ResourceImage::New(LOGO_IMAGE); - ImageView imageView = ImageView::New(image); + ImageView imageView = ImageView::New( LOGO_IMAGE ); imageView.SetName("daliLogo"); imageView.SetParentOrigin(ParentOrigin::CENTER); imageView.SetAnchorPoint(AnchorPoint::BOTTOM_CENTER); logoLayoutActor.Add(imageView); ImageView mirrorImageView = CreateBlurredMirrorImage(LOGO_IMAGE); - mirrorImageView.SetParentOrigin(ParentOrigin::CENTER); - mirrorImageView.SetAnchorPoint(AnchorPoint::TOP_CENTER); + mirrorImageView.SetParentOrigin(ParentOrigin::TOP_CENTER); + mirrorImageView.SetAnchorPoint(AnchorPoint::BOTTOM_CENTER); logoLayoutActor.Add(mirrorImageView); AddBubbles( backgroundActor, stage.GetSize()); @@ -241,10 +240,10 @@ void NewWindowController::Destroy( Application& app ) void NewWindowController::AddBubbles( Actor& parentActor, const Vector2& stageSize) { mEmitter = Toolkit::BubbleEmitter::New( stageSize, - ResourceImage::New( DEMO_IMAGE_DIR "bubble-ball.png" ), + DemoHelper::LoadImage( DEMO_IMAGE_DIR "bubble-ball.png" ), 200, Vector2( 5.0f, 5.0f ) ); - Image background = ResourceImage::New(BACKGROUND_IMAGE); + Image background = DemoHelper::LoadImage(BACKGROUND_IMAGE); mEmitter.SetBackground( background, Vector3(0.5f, 0.f,0.5f) ); mEmitter.SetBubbleDensity( 9.f ); Actor bubbleRoot = mEmitter.GetRootActor(); @@ -275,10 +274,10 @@ void NewWindowController::AddMeshActor( Actor& parentActor ) colorMeshActor.SetName("ColorMeshActor"); // Create a textured mesh - Image effectImage = ResourceImage::New(EFFECT_IMAGE); + Texture effectTexture = DemoHelper::LoadTexture(EFFECT_IMAGE); Shader shaderTextureMesh = Shader::New( VERTEX_TEXTURE_MESH, FRAGMENT_TEXTURE_MESH ); TextureSet textureSet = TextureSet::New(); - textureSet.SetImage( 0u, effectImage ); + textureSet.SetTexture( 0u, effectTexture ); Renderer textureMeshRenderer = Renderer::New( meshGeometry, shaderTextureMesh ); textureMeshRenderer.SetTextures( textureSet ); @@ -320,8 +319,7 @@ void NewWindowController::AddBlendingImageActor( Actor& parentActor ) Property::Map map; map[ "shader" ] = customShader; - Image baseImage = ResourceImage::New(BASE_IMAGE); - ImageView blendActor = ImageView::New( baseImage ); + ImageView blendActor = ImageView::New( BASE_IMAGE ); blendActor.SetProperty( ImageView::Property::IMAGE, map ); blendActor.RegisterProperty( "alpha", 0.5f ); @@ -345,10 +343,9 @@ void NewWindowController::AddTextLabel( Actor& parentActor ) ImageView NewWindowController::CreateBlurredMirrorImage(const char* imageName) { - Image image = ResourceImage::New(imageName); + Image image = DemoHelper::LoadImage(imageName); - Uint16Pair intFboSize = ResourceImage::GetImageSize(imageName); - Vector2 FBOSize = Vector2( intFboSize.GetWidth(), intFboSize.GetHeight() ); + Vector2 FBOSize = Vector2( image.GetWidth(), image.GetHeight() ); FrameBufferImage fbo = FrameBufferImage::New( FBOSize.width, FBOSize.height, Pixel::RGBA8888); GaussianBlurView gbv = GaussianBlurView::New(5, 2.0f, Pixel::RGBA8888, 0.5f, 0.5f, true); diff --git a/examples/page-turn-view/page-turn-view-example.cpp b/examples/page-turn-view/page-turn-view-example.cpp index 16a1b44..b1b71ab 100644 --- a/examples/page-turn-view/page-turn-view-example.cpp +++ b/examples/page-turn-view/page-turn-view-example.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -25,6 +26,7 @@ #include #include "shared/view.h" +#include "shared/utility.h" using namespace Dali; using namespace Dali::Toolkit; @@ -39,9 +41,9 @@ const char* const CHANGE_IMAGE_ICON_SELECTED( DEMO_IMAGE_DIR "icon-change-select // set a ratio to modify the current page number when the rotation is changed const float PAGE_NUMBER_CORRESPONDING_RATIO(1.25f); -const char* BOOK_COVER_PORTRAIT = ( DEMO_IMAGE_DIR "book-portrait-cover.jpg" ); -const char* BOOK_COVER_LANDSCAPE = ( DEMO_IMAGE_DIR "book-landscape-cover.jpg" ); -const char* BOOK_COVER_BACK_LANDSCAPE = ( DEMO_IMAGE_DIR "book-landscape-cover-back.jpg" ); +const char* BOOK_COVER_PORTRAIT( DEMO_IMAGE_DIR "book-portrait-cover.jpg" ); +const char* BOOK_COVER_LANDSCAPE( DEMO_IMAGE_DIR "book-landscape-cover.jpg" ); +const char* BOOK_COVER_BACK_LANDSCAPE( DEMO_IMAGE_DIR "book-landscape-cover-back.jpg" ); const char* PAGE_IMAGES_PORTRAIT[] = { @@ -66,6 +68,21 @@ const char* PAGE_IMAGES_LANDSCAPE[] = }; const unsigned int NUMBER_OF_LANDSCAPE_IMAGE( sizeof(PAGE_IMAGES_LANDSCAPE) / sizeof(PAGE_IMAGES_LANDSCAPE[0]) ); +Atlas LoadImages( const char*imagePath1, const char* imagePath2 ) +{ + PixelData pixelData1 = DemoHelper::LoadPixelData( imagePath1, ImageDimensions(), FittingMode::DEFAULT, SamplingMode::DEFAULT ); + PixelData pixelData2 = DemoHelper::LoadPixelData( imagePath2, ImageDimensions(), FittingMode::DEFAULT, SamplingMode::DEFAULT ); + + unsigned int width = pixelData1.GetWidth()+pixelData2.GetWidth(); + unsigned int height = pixelData1.GetHeight() > pixelData2.GetHeight() ? pixelData1.GetHeight() : pixelData2.GetHeight(); + + Atlas image = Atlas::New( width, height ); + image.Upload( pixelData1, 0u, 0u ); + image.Upload( pixelData2, pixelData1.GetWidth(), 0u ); + + return image; +} + }// end LOCAL STUFF class PortraitPageFactory : public PageFactory @@ -85,15 +102,15 @@ class PortraitPageFactory : public PageFactory */ virtual Image NewPage( unsigned int pageId ) { - Image page; + Atlas page; if( pageId == 0 ) { - page = ResourceImage::New( BOOK_COVER_PORTRAIT ); + page = DemoHelper::LoadImage( BOOK_COVER_PORTRAIT ); } else { - page = ResourceImage::New( PAGE_IMAGES_PORTRAIT[ (pageId-1) % NUMBER_OF_PORTRAIT_IMAGE ] ); + page = DemoHelper::LoadImage( PAGE_IMAGES_PORTRAIT[ (pageId-1) % NUMBER_OF_PORTRAIT_IMAGE ] ); } return page; @@ -118,29 +135,20 @@ class LandscapePageFactory : public PageFactory */ virtual Image NewPage( unsigned int pageId ) { - if( mImageSize.GetWidth() == 0u || mImageSize.GetHeight() == 0u ) - { - mImageSize = ResourceImage::GetImageSize(BOOK_COVER_LANDSCAPE); - } - ImageAtlas atlas = ImageAtlas::New( mImageSize.GetWidth()*2u, mImageSize.GetHeight(), Pixel::RGB888 ); - Vector4 textureRect; + Atlas page; if( pageId == 0 ) { - atlas.Upload( textureRect, BOOK_COVER_LANDSCAPE, mImageSize ); - atlas.Upload( textureRect, BOOK_COVER_BACK_LANDSCAPE, mImageSize ); + page = LoadImages( BOOK_COVER_LANDSCAPE, BOOK_COVER_BACK_LANDSCAPE ); } else { unsigned int imageId = (pageId-1)*2; - atlas.Upload( textureRect, PAGE_IMAGES_LANDSCAPE[ imageId % NUMBER_OF_LANDSCAPE_IMAGE ], mImageSize ); - atlas.Upload( textureRect, PAGE_IMAGES_LANDSCAPE[ (imageId+1) % NUMBER_OF_LANDSCAPE_IMAGE ], mImageSize ); + page = LoadImages( PAGE_IMAGES_LANDSCAPE[ imageId % NUMBER_OF_LANDSCAPE_IMAGE ], PAGE_IMAGES_LANDSCAPE[ (imageId+1) % NUMBER_OF_LANDSCAPE_IMAGE ] ); } - return atlas.GetAtlas(); + return page; } - - ImageDimensions mImageSize; }; /** diff --git a/examples/perf-scroll/perf-scroll.cpp b/examples/perf-scroll/perf-scroll.cpp index bdf2195..f77d01f 100644 --- a/examples/perf-scroll/perf-scroll.cpp +++ b/examples/perf-scroll/perf-scroll.cpp @@ -23,6 +23,8 @@ #include #include +#include "shared/utility.h" + using namespace Dali; using namespace Dali::Toolkit; @@ -225,10 +227,10 @@ Renderer CreateRenderer( unsigned int index ) Shader shader = Shader::New( VERTEX_SHADER_TEXTURE, FRAGMENT_SHADER_TEXTURE ); const char* imagePath = !gNinePatch ? IMAGE_PATH[index] : NINEPATCH_IMAGE_PATH[index]; - Image image = ResourceImage::New( imagePath ); + Texture texture = DemoHelper::LoadTexture( imagePath ); TextureSet textureSet = TextureSet::New(); - textureSet.SetImage( 0u, image ); + textureSet.SetTexture( 0u, texture ); renderers[index] = Renderer::New( QuadMesh(), shader ); renderers[index].SetTextures( textureSet ); renderers[index].SetProperty( Renderer::Property::BLEND_MODE, BlendMode::OFF ); diff --git a/examples/point-mesh/point-mesh-example.cpp b/examples/point-mesh/point-mesh-example.cpp index 22d557d..9ab923b 100644 --- a/examples/point-mesh/point-mesh-example.cpp +++ b/examples/point-mesh/point-mesh-example.cpp @@ -21,6 +21,7 @@ // INTERNAL INCLUDES #include "shared/view.h" +#include "shared/utility.h" using namespace Dali; @@ -152,14 +153,14 @@ public: // Hide the indicator bar application.GetWindow().ShowIndicator( Dali::Window::INVISIBLE ); - Image image0 = ResourceImage::New( MATERIAL_SAMPLE ); - Image image1 = ResourceImage::New( MATERIAL_SAMPLE2 ); + Texture texture0 = DemoHelper::LoadTexture( MATERIAL_SAMPLE ); + Texture texture1 = DemoHelper::LoadTexture( MATERIAL_SAMPLE2 ); Shader shader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER ); TextureSet textureSet = TextureSet::New(); - textureSet.SetImage( 0u, image0 ); - textureSet.SetImage( 1u, image1 ); + textureSet.SetTexture( 0u, texture0 ); + textureSet.SetTexture( 1u, texture1 ); Geometry geometry = CreateGeometry(); diff --git a/examples/popup/popup-example.cpp b/examples/popup/popup-example.cpp index b88982f..b79bccc 100644 --- a/examples/popup/popup-example.cpp +++ b/examples/popup/popup-example.cpp @@ -712,11 +712,6 @@ private: bool mContextual; ///< True if currently using the contextual popup mode. bool mAnimationFade; ///< True if currently using the fade animation. - ResourceImage mContextButtonDisabledImage; ///< The disabled context button icon. - ResourceImage mContextButtonEnabledImage; ///< The enabled context button icon. - ResourceImage mAnimationButtonZoomImage; ///< The zoom animation button icon. - ResourceImage mAnimationButtonFadeImage; ///< The fade animation button icon. - Toolkit::Popup mPopup; ///< The current example popup. Toolkit::ItemView mItemView; ///< ItemView to hold test images diff --git a/examples/radial-menu/radial-menu-example.cpp b/examples/radial-menu/radial-menu-example.cpp index 4086fbc..13be24a 100644 --- a/examples/radial-menu/radial-menu-example.cpp +++ b/examples/radial-menu/radial-menu-example.cpp @@ -172,8 +172,7 @@ void RadialMenuExample::OnInit(Application& app) mRadialSweepView3.SetInitialActorAngle(Degree(-110)); mRadialSweepView3.SetFinalActorAngle(Degree(0)); - Image dial = ResourceImage::New( TEST_DIAL_FILENAME ); - mDialView = ImageView::New( dial ); + mDialView = ImageView::New( TEST_DIAL_FILENAME ); mDialView.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); mDialView.SetParentOrigin( ParentOrigin::CENTER ); mDialView.SetScale(scale); @@ -254,8 +253,7 @@ RadialSweepView RadialMenuExample::CreateSweepView( std::string imageName, Degree finalAngle) { // Create the image - Image image = ResourceImage::New(imageName); - mImageView = ImageView::New(image); + mImageView = ImageView::New(imageName); mImageView.SetParentOrigin(ParentOrigin::CENTER); mImageView.SetAnchorPoint(AnchorPoint::CENTER); mImageView.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); diff --git a/examples/refraction-effect/refraction-effect-example.cpp b/examples/refraction-effect/refraction-effect-example.cpp index 189a7c7..d4e0213 100644 --- a/examples/refraction-effect/refraction-effect-example.cpp +++ b/examples/refraction-effect/refraction-effect-example.cpp @@ -26,6 +26,7 @@ // INTERNAL INCLUDES #include "shared/view.h" +#include "shared/utility.h" using namespace Dali; @@ -74,19 +75,6 @@ struct LightOffsetConstraint }; /** - * @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 ); -} - -/** * structure of the vertex in the mesh */ struct Vertex @@ -280,9 +268,9 @@ private: mShaderFlat = Shader::New( VERTEX_SHADER_FLAT, FRAGMENT_SHADER_FLAT ); mGeometry = CreateGeometry( MESH_FILES[mCurrentMeshId] ); - Image texture = LoadStageFillingImage( TEXTURE_IMAGES[mCurrentTextureId] ); + Texture texture = DemoHelper::LoadStageFillingTexture( TEXTURE_IMAGES[mCurrentTextureId] ); mTextureSet = TextureSet::New(); - mTextureSet.SetImage( 0u, texture ); + mTextureSet.SetTexture( 0u, texture ); mRenderer = Renderer::New( mGeometry, mShaderFlat ); mRenderer.SetTextures( mTextureSet ); @@ -343,8 +331,8 @@ private: bool OnChangeTexture( Toolkit::Button button ) { mCurrentTextureId = ( mCurrentTextureId + 1 ) % NUM_TEXTURE_IMAGES; - Image texture = LoadStageFillingImage( TEXTURE_IMAGES[mCurrentTextureId] ); - mTextureSet.SetImage( 0u, texture ); + Texture texture = DemoHelper::LoadStageFillingTexture( TEXTURE_IMAGES[mCurrentTextureId] ); + mTextureSet.SetTexture( 0u, texture ); return true; } diff --git a/examples/scroll-view/scroll-view-example.cpp b/examples/scroll-view/scroll-view-example.cpp index 1a8d12a..8929d68 100644 --- a/examples/scroll-view/scroll-view-example.cpp +++ b/examples/scroll-view/scroll-view-example.cpp @@ -450,11 +450,18 @@ private: * @param[in] width the width of the image in texels * @param[in] height the height of the image in texels. */ - ImageView CreateImage( const std::string& filename, unsigned int width = IMAGE_THUMBNAIL_WIDTH, unsigned int height = IMAGE_THUMBNAIL_HEIGHT ) + ImageView CreateImage( const std::string& filename, int width = IMAGE_THUMBNAIL_WIDTH, int height = IMAGE_THUMBNAIL_HEIGHT ) { - Image img = ResourceImage::New(filename, ImageDimensions( width, height ), Dali::FittingMode::SCALE_TO_FILL, Dali::SamplingMode::BOX_THEN_LINEAR ); + ImageView actor = ImageView::New(); + Property::Map map; + map["rendererType"] = "image"; + map["url"] = filename; + map["desiredWidth"] = width; + map["desiredHeight"] = height; + map["fittingMode"] = "SCALE_TO_FILL"; + map["samplingMode"] = "BOX_THEN_LINEAR"; + actor.SetProperty( ImageView::Property::IMAGE, map ); - ImageView actor = ImageView::New(img); actor.SetName( filename ); actor.SetParentOrigin(ParentOrigin::CENTER); actor.SetAnchorPoint(AnchorPoint::CENTER); diff --git a/examples/super-blur-bloom/super-blur-bloom-example.cpp b/examples/super-blur-bloom/super-blur-bloom-example.cpp index 3196a3b..088692a 100644 --- a/examples/super-blur-bloom/super-blur-bloom-example.cpp +++ b/examples/super-blur-bloom/super-blur-bloom-example.cpp @@ -19,6 +19,7 @@ #include #include #include "shared/view.h" +#include "shared/utility.h" using namespace Dali; @@ -42,20 +43,7 @@ const char* BACKGROUND_IMAGES[]= DEMO_IMAGE_DIR "background-magnifier.jpg", }; const unsigned int NUM_BACKGROUND_IMAGES( sizeof( BACKGROUND_IMAGES ) / sizeof( BACKGROUND_IMAGES[0] ) ); -} -/** - * @brief Load an image, scaled-down to no more than the stage dimensions. - * - * Uses image scaling mode FittingMode::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, Dali::ImageDimensions( stageSize.x, stageSize.y ), Dali::FittingMode::SCALE_TO_FILL, Dali::SamplingMode::BOX_THEN_LINEAR ); } class BlurExample : public ConnectionTracker @@ -116,7 +104,7 @@ private: mSuperBlurView.SetParentOrigin( ParentOrigin::CENTER ); mSuperBlurView.SetAnchorPoint( AnchorPoint::CENTER ); mSuperBlurView.BlurFinishedSignal().Connect(this, &BlurExample::OnBlurFinished); - mCurrentImage = LoadStageFillingImage( BACKGROUND_IMAGES[mImageIndex] ); + mCurrentImage = DemoHelper::LoadStageFillingImage( BACKGROUND_IMAGES[mImageIndex] ); mSuperBlurView.SetImage( mCurrentImage ); mBackground.Add( mSuperBlurView ); mIsBlurring = true; @@ -215,7 +203,7 @@ private: } mImageIndex = (mImageIndex+1u)%NUM_BACKGROUND_IMAGES; - mCurrentImage = LoadStageFillingImage( BACKGROUND_IMAGES[mImageIndex] ); + mCurrentImage = DemoHelper::LoadStageFillingImage( BACKGROUND_IMAGES[mImageIndex] ); if( mSuperBlurView.OnStage() ) { diff --git a/examples/text-field/text-field-example.cpp b/examples/text-field/text-field-example.cpp index 2a60569..6d357eb 100644 --- a/examples/text-field/text-field-example.cpp +++ b/examples/text-field/text-field-example.cpp @@ -87,8 +87,8 @@ public: button.SetSelectedImage( FOLDER_OPEN_ICON_IMAGE ); button.SetAnchorPoint( AnchorPoint::TOP_LEFT ); button.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS ); - ResourceImage imageClosed = ResourceImage::New( FOLDER_ICON_IMAGE ); - button.SetSize( imageClosed.GetWidth(), imageClosed.GetHeight() ); + ImageDimensions imageSize = ResourceImage::GetImageSize( FOLDER_ICON_IMAGE ); + button.SetSize( imageSize.GetWidth(), imageSize.GetHeight() ); return button; } diff --git a/examples/text-label/text-label-example.cpp b/examples/text-label/text-label-example.cpp index 8c5ddfc..b2ad9a5 100644 --- a/examples/text-label/text-label-example.cpp +++ b/examples/text-label/text-label-example.cpp @@ -111,11 +111,10 @@ public: stage.Add( mContainer ); // Resize the center layout when the corner is grabbed - mGrabCorner = Control::New(); + mGrabCorner = ImageView::New( BACKGROUND_IMAGE ); mGrabCorner.SetName( "GrabCorner" ); mGrabCorner.SetAnchorPoint( AnchorPoint::TOP_CENTER ); mGrabCorner.SetParentOrigin( ParentOrigin::BOTTOM_RIGHT ); - mGrabCorner.SetBackgroundImage( ResourceImage::New( BACKGROUND_IMAGE ) ); mGrabCorner.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); mContainer.Add( mGrabCorner ); diff --git a/examples/textured-mesh/textured-mesh-example.cpp b/examples/textured-mesh/textured-mesh-example.cpp index 1de4316..6285ae3 100644 --- a/examples/textured-mesh/textured-mesh-example.cpp +++ b/examples/textured-mesh/textured-mesh-example.cpp @@ -21,6 +21,7 @@ // INTERNAL INCLUDES #include "shared/view.h" +#include "shared/utility.h" using namespace Dali; @@ -140,15 +141,15 @@ public: // Hide the indicator bar application.GetWindow().ShowIndicator( Dali::Window::INVISIBLE ); - mImage = ResourceImage::New( MATERIAL_SAMPLE ); - Image image = ResourceImage::New( MATERIAL_SAMPLE2 ); + Texture texture1 = DemoHelper::LoadTexture( MATERIAL_SAMPLE ); + Texture texture2 = DemoHelper::LoadTexture( MATERIAL_SAMPLE2 ); mShader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER ); mTextureSet1 = TextureSet::New(); - mTextureSet1.SetImage( 0u, mImage ); + mTextureSet1.SetTexture( 0u, texture1 ); mTextureSet2 = TextureSet::New(); - mTextureSet2.SetImage( 0u, image ); + mTextureSet2.SetTexture( 0u, texture2 ); mGeometry = CreateGeometry(); @@ -258,7 +259,6 @@ private: Application& mApplication; ///< Application instance Vector3 mStageSize; ///< The size of the stage - Image mImage; Shader mShader; TextureSet mTextureSet1; TextureSet mTextureSet2; diff --git a/shared/utility.h b/shared/utility.h new file mode 100644 index 0000000..3285b98 --- /dev/null +++ b/shared/utility.h @@ -0,0 +1,91 @@ +#ifndef __DALI_DEMO_UTILITY_H__ +#define __DALI_DEMO_UTILITY_H__ + +/* + * Copyright (c) 2014 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include +#include +#include + +namespace DemoHelper +{ + +Dali::PixelData LoadPixelData( const char* imagePath, + Dali::ImageDimensions size, + Dali::FittingMode::Type fittingMode, + Dali::SamplingMode::Type samplingMode ) +{ + Dali::BitmapLoader loader = Dali::BitmapLoader::New( imagePath, size, fittingMode, samplingMode ); + loader.Load(); + return loader.GetPixelData(); +} + + +Dali::Atlas LoadImage( const char* imagePath, + Dali::ImageDimensions size = Dali::ImageDimensions(), + Dali::FittingMode::Type fittingMode = Dali::FittingMode::DEFAULT, + Dali::SamplingMode::Type samplingMode = Dali::SamplingMode::DEFAULT ) +{ + Dali::PixelData pixelData = LoadPixelData(imagePath, size, fittingMode, samplingMode); + Dali::Atlas image =Dali:: Atlas::New( pixelData.GetWidth(), pixelData.GetHeight(), pixelData.GetPixelFormat() ); + image.Upload( pixelData, 0u, 0u ); + + return image; +} + +Dali::Texture LoadTexture( const char* imagePath, + Dali::ImageDimensions size = Dali::ImageDimensions(), + Dali::FittingMode::Type fittingMode = Dali::FittingMode::DEFAULT, + Dali::SamplingMode::Type samplingMode = Dali::SamplingMode::DEFAULT ) +{ + Dali::PixelData pixelData = LoadPixelData(imagePath, size, fittingMode, samplingMode); + Dali::Texture texture = Dali::Texture::New( Dali::TextureType::TEXTURE_2D, + pixelData.GetPixelFormat(), + pixelData.GetWidth(), + pixelData.GetHeight() ); + texture.Upload( pixelData ); + + return texture; +} + +/** + * @brief Load an bitmap resource. + * + * If it is required to scaled-down to no more than the stage dimensions, + * uses image scaling mode FittingMode::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. + */ + +Dali::Atlas LoadStageFillingImage( const char* imagePath ) +{ + Dali::Vector2 stageSize = Dali::Stage::GetCurrent().GetSize(); + return LoadImage( imagePath, Dali::ImageDimensions( stageSize.x, stageSize.y ), Dali::FittingMode::SCALE_TO_FILL, Dali::SamplingMode::BOX_THEN_LINEAR ); +} + +Dali::Texture LoadStageFillingTexture( const char* imagePath ) +{ + Dali::Vector2 stageSize = Dali::Stage::GetCurrent().GetSize(); + return LoadTexture( imagePath, Dali::ImageDimensions( stageSize.x, stageSize.y ), Dali::FittingMode::SCALE_TO_FILL, Dali::SamplingMode::BOX_THEN_LINEAR ); +} + +} // DemoHelper + +#endif // __DALI_DEMO_HELPER_VIEW_H__ diff --git a/shared/view.h b/shared/view.h index 5d7f8be..a0b528f 100644 --- a/shared/view.h +++ b/shared/view.h @@ -77,10 +77,11 @@ Dali::Layer CreateToolbar( Dali::Toolkit::ToolBar& toolBar, toolBarLayer.RaiseToTop(); // Tool bar - Dali::Image image = Dali::ResourceImage::New( toolbarImagePath ); toolBar = Dali::Toolkit::ToolBar::New(); toolBar.SetName( "TOOLBAR" ); - toolBar.SetBackgroundImage( image ); + Dali::Property::Map background; + background["url"] = toolbarImagePath; + toolBar.SetProperty( Dali::Toolkit::Control::Property::BACKGROUND, background ); toolBar.SetParentOrigin( Dali::ParentOrigin::TOP_CENTER ); toolBar.SetAnchorPoint( Dali::AnchorPoint::TOP_CENTER ); toolBar.SetResizePolicy( Dali::ResizePolicy::FILL_TO_PARENT, Dali::Dimension::ALL_DIMENSIONS ); @@ -129,8 +130,15 @@ Dali::Layer CreateView( Dali::Application& application, // Set background image, loading it at screen resolution: if ( !backgroundImagePath.empty() ) { - Dali::Image backgroundImage = Dali::ResourceImage::New( backgroundImagePath, Dali::ImageDimensions( stage.GetSize().x, stage.GetSize().y ), Dali::FittingMode::SCALE_TO_FILL, Dali::SamplingMode::BOX_THEN_LINEAR ); - view.SetBackgroundImage( backgroundImage ); + Dali::Property::Map map; + map["rendererType"] = "image"; + map["url"] = backgroundImagePath; + map["desiredWidth"] = stage.GetSize().x; + map["desiredHeight"] = stage.GetSize().y; + map["fittingMode"] = "SCALE_TO_FILL"; + map["samplingMode"] = "BOX_THEN_LINEAR"; + map["synchronousLoading"] = true; + view.SetProperty( Dali::Toolkit::Control::Property::BACKGROUND, map ); } // FIXME -- libgit2 0.21.4