From 0d42f61a0f1ea695328c831b03874d9db914e068 Mon Sep 17 00:00:00 2001 From: Heeyong Song Date: Tue, 24 Oct 2017 15:24:31 +0900 Subject: [PATCH] [4.0] Support to reset the image in ImageView Change-Id: Ifdd57a09c6ecf3639558ee3ce80af666aa6108e8 --- .../src/dali-toolkit/utc-Dali-ImageView.cpp | 77 +++++++++++++++ .../controls/control/control-data-impl.cpp | 29 ++++-- .../controls/image-view/image-view-impl.cpp | 53 ++++++++-- .../internal/visuals/visual-factory-impl.cpp | 107 +++++++++++---------- 4 files changed, 197 insertions(+), 69 deletions(-) diff --git a/automated-tests/src/dali-toolkit/utc-Dali-ImageView.cpp b/automated-tests/src/dali-toolkit/utc-Dali-ImageView.cpp index 51df879..c8cf88f 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-ImageView.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-ImageView.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -956,43 +957,119 @@ int UtcDaliImageViewSetImageTypeChangesP(void) ToolkitTestApplication application; ImageView imageView = ImageView::New(); + Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( imageView ); + Stage::GetCurrent().Add( imageView ); std::string url; Property::Map map; + Toolkit::Visual::Base visual; Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) ); + visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE ); + + application.SendNotification(); + application.Render( 16 ); + DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty + DALI_TEST_CHECK( ! visual ); // Visual should be invalid // Set a URL imageView.SetImage( "TEST_URL" ); + + application.SendNotification(); + application.Render( 16 ); + value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) ); + visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE ); DALI_TEST_CHECK( value.Get( url ) ); // Value should NOT be empty DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty + DALI_TEST_CHECK( visual ); // Visual should be valid // Set an empty Image imageView.SetImage( Image() ); + + application.SendNotification(); + application.Render( 16 ); + value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) ); + visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE ); DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty + DALI_TEST_CHECK( ! visual ); // Visual should be invalid // Set an Image ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME ); imageView.SetImage( image1 ); + + application.SendNotification(); + application.Render( 16 ); + value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) ); + visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE ); DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty DALI_TEST_CHECK( value.Get( map ) ); // Value should NOT be empty + DALI_TEST_CHECK( visual ); // Visual should be valid // Set an empty URL imageView.SetImage( "" ); + + application.SendNotification(); + application.Render( 16 ); + value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) ); + visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE ); DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty + DALI_TEST_CHECK( ! visual ); // Visual should be invalid + + // Set a URL in property map + Property::Map propertyMap; + propertyMap[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME; + imageView.SetProperty( ImageView::Property::IMAGE, propertyMap ); + + application.SendNotification(); + application.Render( 16 ); + + value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) ); + visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE ); + + DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty + DALI_TEST_CHECK( value.Get( map ) ); // Value should NOT be empty + DALI_TEST_CHECK( visual ); // Visual should be valid + + // Set a URL in property map again + propertyMap[ImageVisual::Property::URL] = gImage_34_RGBA; + imageView.SetProperty( ImageView::Property::IMAGE, propertyMap ); + + application.SendNotification(); + application.Render( 16 ); + + value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) ); + visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE ); + + DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty + DALI_TEST_CHECK( value.Get( map ) ); // Value should NOT be empty + DALI_TEST_CHECK( visual ); // Visual should be valid + + // Set an empty URL in property map + propertyMap[ImageVisual::Property::URL] = std::string(); + imageView.SetProperty( ImageView::Property::IMAGE, propertyMap ); + + application.SendNotification(); + application.Render( 16 ); + + value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) ); + visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE ); + + DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty + DALI_TEST_CHECK( value.Get( map ) ); // Value should NOT be empty + DALI_TEST_CHECK( ! visual ); // Visual should be invalid END_TEST; } diff --git a/dali-toolkit/internal/controls/control/control-data-impl.cpp b/dali-toolkit/internal/controls/control/control-data-impl.cpp index 57cb46d..4f26d11 100644 --- a/dali-toolkit/internal/controls/control/control-data-impl.cpp +++ b/dali-toolkit/internal/controls/control/control-data-impl.cpp @@ -538,17 +538,26 @@ void Control::Impl::RegisterVisual( Property::Index index, Toolkit::Visual::Base void Control::Impl::UnregisterVisual( Property::Index index ) { - RegisteredVisualContainer::Iterator iter; - if ( FindVisual( index, mVisuals, iter ) ) - { - // stop observing visual - StopObservingVisual( (*iter)->visual ); + RegisteredVisualContainer::Iterator iter; + if ( FindVisual( index, mVisuals, iter ) ) + { + // stop observing visual + StopObservingVisual( (*iter)->visual ); - Actor self( mControlImpl.Self() ); - Toolkit::GetImplementation((*iter)->visual).SetOffStage( self ); - (*iter)->visual.Reset(); - mVisuals.Erase( iter ); - } + Actor self( mControlImpl.Self() ); + Toolkit::GetImplementation((*iter)->visual).SetOffStage( self ); + (*iter)->visual.Reset(); + mVisuals.Erase( iter ); + } + + if( FindVisual( index, mRemoveVisuals, iter ) ) + { + Actor self( mControlImpl.Self() ); + Toolkit::GetImplementation( (*iter)->visual ).SetOffStage( self ); + (*iter)->pending = false; + (*iter)->visual.Reset(); + mRemoveVisuals.Erase( iter ); + } } Toolkit::Visual::Base Control::Impl::GetVisual( Property::Index index ) const diff --git a/dali-toolkit/internal/controls/image-view/image-view-impl.cpp b/dali-toolkit/internal/controls/image-view/image-view-impl.cpp index ff5d046..7ac831a 100644 --- a/dali-toolkit/internal/controls/image-view/image-view-impl.cpp +++ b/dali-toolkit/internal/controls/image-view/image-view-impl.cpp @@ -102,12 +102,23 @@ void ImageView::SetImage( Image image ) mPropertyMap.Clear(); Toolkit::Visual::Base visual = Toolkit::VisualFactory::Get().CreateVisual( image ); - if (!mVisual) + if( visual ) { - mVisual = visual; + if( !mVisual ) + { + mVisual = visual; + } + + DevelControl::RegisterVisual( *this, Toolkit::ImageView::Property::IMAGE, visual ); } + else + { + // Unregister the exsiting visual + DevelControl::UnregisterVisual( *this, Toolkit::ImageView::Property::IMAGE ); - DevelControl::RegisterVisual( *this, Toolkit::ImageView::Property::IMAGE, visual ); + // Trigger a size negotiation request that may be needed when unregistering a visual. + RelayoutRequest(); + } } void ImageView::SetImage( const Property::Map& map ) @@ -118,13 +129,24 @@ void ImageView::SetImage( const Property::Map& map ) mImage.Reset(); Toolkit::Visual::Base visual = Toolkit::VisualFactory::Get().CreateVisual( mPropertyMap ); - // Don't set mVisual until it is ready and shown. Getters will still use current visual. - if (!mVisual) + if( visual ) { - mVisual = visual; + // Don't set mVisual until it is ready and shown. Getters will still use current visual. + if( !mVisual ) + { + mVisual = visual; + } + + DevelControl::RegisterVisual( *this, Toolkit::ImageView::Property::IMAGE, visual ); } + else + { + // Unregister the exsiting visual + DevelControl::UnregisterVisual( *this, Toolkit::ImageView::Property::IMAGE ); - DevelControl::RegisterVisual( *this, Toolkit::ImageView::Property::IMAGE, visual ); + // Trigger a size negotiation request that may be needed when unregistering a visual. + RelayoutRequest(); + } } void ImageView::SetImage( const std::string& url, ImageDimensions size ) @@ -136,12 +158,23 @@ void ImageView::SetImage( const std::string& url, ImageDimensions size ) // Don't set mVisual until it is ready and shown. Getters will still use current visual. Toolkit::Visual::Base visual = Toolkit::VisualFactory::Get().CreateVisual( url, size ); - if (!mVisual) + if( visual ) { - mVisual = visual; + if( !mVisual ) + { + mVisual = visual; + } + + DevelControl::RegisterVisual( *this, Toolkit::ImageView::Property::IMAGE, visual ); } + else + { + // Unregister the exsiting visual + DevelControl::UnregisterVisual( *this, Toolkit::ImageView::Property::IMAGE ); - DevelControl::RegisterVisual( *this, Toolkit::ImageView::Property::IMAGE, visual ); + // Trigger a size negotiation request that may be needed when unregistering a visual. + RelayoutRequest(); + } } Image ImageView::GetImage() const diff --git a/dali-toolkit/internal/visuals/visual-factory-impl.cpp b/dali-toolkit/internal/visuals/visual-factory-impl.cpp index 365c614..826de69 100644 --- a/dali-toolkit/internal/visuals/visual-factory-impl.cpp +++ b/dali-toolkit/internal/visuals/visual-factory-impl.cpp @@ -122,29 +122,32 @@ Toolkit::Visual::Base VisualFactory::CreateVisual( const Property::Map& property { if( imageURLValue->Get( imageUrl ) ) { - VisualUrl visualUrl( imageUrl ); - - switch( visualUrl.GetType() ) + if( !imageUrl.empty() ) { - case VisualUrl::N_PATCH: - { - visualPtr = NPatchVisual::New( *( mFactoryCache.Get() ), visualUrl, propertyMap ); - break; - } - case VisualUrl::SVG: - { - visualPtr = SvgVisual::New( *( mFactoryCache.Get() ), visualUrl, propertyMap ); - break; - } - case VisualUrl::GIF: - { - visualPtr = AnimatedImageVisual::New( *( mFactoryCache.Get() ), visualUrl, propertyMap ); - break; - } - case VisualUrl::REGULAR_IMAGE: + VisualUrl visualUrl( imageUrl ); + + switch( visualUrl.GetType() ) { - visualPtr = ImageVisual::New( *( mFactoryCache.Get() ), visualUrl, propertyMap ); - break; + case VisualUrl::N_PATCH: + { + visualPtr = NPatchVisual::New( *( mFactoryCache.Get() ), visualUrl, propertyMap ); + break; + } + case VisualUrl::SVG: + { + visualPtr = SvgVisual::New( *( mFactoryCache.Get() ), visualUrl, propertyMap ); + break; + } + case VisualUrl::GIF: + { + visualPtr = AnimatedImageVisual::New( *( mFactoryCache.Get() ), visualUrl, propertyMap ); + break; + } + case VisualUrl::REGULAR_IMAGE: + { + visualPtr = ImageVisual::New( *( mFactoryCache.Get() ), visualUrl, propertyMap ); + break; + } } } } @@ -252,14 +255,17 @@ Toolkit::Visual::Base VisualFactory::CreateVisual( const Image& image ) Visual::BasePtr visualPtr; - NinePatchImage npatchImage = NinePatchImage::DownCast( image ); - if( npatchImage ) + if( image ) { - visualPtr = NPatchVisual::New( *( mFactoryCache.Get() ), npatchImage ); - } - else - { - visualPtr = ImageVisual::New( *( mFactoryCache.Get() ), image ); + NinePatchImage npatchImage = NinePatchImage::DownCast( image ); + if( npatchImage ) + { + visualPtr = NPatchVisual::New( *( mFactoryCache.Get() ), npatchImage ); + } + else + { + visualPtr = ImageVisual::New( *( mFactoryCache.Get() ), image ); + } } if( mDebugEnabled ) @@ -280,29 +286,32 @@ Toolkit::Visual::Base VisualFactory::CreateVisual( const std::string& url, Image Visual::BasePtr visualPtr; - // first resolve url type to know which visual to create - VisualUrl visualUrl( url ); - switch( visualUrl.GetType() ) + if( !url.empty() ) { - case VisualUrl::N_PATCH: - { - visualPtr = NPatchVisual::New( *( mFactoryCache.Get() ), visualUrl ); - break; - } - case VisualUrl::SVG: - { - visualPtr = SvgVisual::New( *( mFactoryCache.Get() ), visualUrl ); - break; - } - case VisualUrl::GIF: + // first resolve url type to know which visual to create + VisualUrl visualUrl( url ); + switch( visualUrl.GetType() ) { - visualPtr = AnimatedImageVisual::New( *( mFactoryCache.Get() ), visualUrl ); - break; - } - case VisualUrl::REGULAR_IMAGE: - { - visualPtr = ImageVisual::New( *( mFactoryCache.Get() ), visualUrl, size ); - break; + case VisualUrl::N_PATCH: + { + visualPtr = NPatchVisual::New( *( mFactoryCache.Get() ), visualUrl ); + break; + } + case VisualUrl::SVG: + { + visualPtr = SvgVisual::New( *( mFactoryCache.Get() ), visualUrl ); + break; + } + case VisualUrl::GIF: + { + visualPtr = AnimatedImageVisual::New( *( mFactoryCache.Get() ), visualUrl ); + break; + } + case VisualUrl::REGULAR_IMAGE: + { + visualPtr = ImageVisual::New( *( mFactoryCache.Get() ), visualUrl, size ); + break; + } } } -- 2.7.4