#include <dali/devel-api/scripting/scripting.h>
#include <dali-toolkit/devel-api/controls/control-devel.h>
#include <dali-toolkit/devel-api/image-loader/texture-manager.h>
+#include <dali-toolkit/devel-api/visual-factory/visual-base.h>
#include <test-native-image.h>
#include <sstream>
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;
}
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
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 )
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 )
// 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
{
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;
+ }
}
}
}
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 )
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;
+ }
}
}