Internal::ImagePtr LoadImage(TestApplication& application, const char* name)
{
- Internal::ImagePtr image = Internal::Image::New(name);
+ Internal::ImagePtr image = Internal::Image::New(name, Dali::ImageAttributes::DEFAULT_ATTRIBUTES );
application.SendNotification(); // Flush update messages
application.Render(); // Process resource request
Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
Internal::ImagePtr LoadImage(TestApplication& application, char* name)
{
- Internal::ImagePtr image = Internal::Image::New(name);
+ Internal::ImagePtr image = Internal::Image::New(name, Dali::ImageAttributes::DEFAULT_ATTRIBUTES );
application.SendNotification(); // Flush update messages
application.Render(); // Process resource request
Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
int UtcDaliImageNewWithPolicies02(void)
{
TestApplication application;
+ const Vector2 closestImageSize( 80, 45);
+ application.GetPlatform().SetClosestImageSize(closestImageSize);
// testing resource deletion when taken off stage
tet_infoline("UtcDaliImageNewWithPolicies02 - Load image with LoadPolicy::OnDemand, ReleasePolicy::Unused");
int UtcDaliImageNewWithPolicies03(void)
{
TestApplication application;
+ const Vector2 closestImageSize( 80, 45);
+ application.GetPlatform().SetClosestImageSize(closestImageSize);
// load immediately -> resource deletion when taken off stage -> put actor back on stage -> load resource again
tet_infoline("UtcDaliImageNewWithPolicies03 - Load image with LoadPolicy::Immediate, ReleasePolicy::Unused");
{
TestApplication application;
+ const Vector2 closestImageSize( 80, 45);
+ application.GetPlatform().SetClosestImageSize(closestImageSize);
+
// testing resource deletion when taken off stage
tet_infoline("UtcDaliImageNewDistanceFieldWithPolicies02 - Load image with LoadPolicy::OnDemand, ReleasePolicy::Unused");
int UtcDaliImageNewDistanceFieldWithPolicies03(void)
{
TestApplication application;
+ const Vector2 closestImageSize( 80, 45);
+ application.GetPlatform().SetClosestImageSize(closestImageSize);
// load immediately -> resource deletion when taken off stage -> put actor back on stage -> load resource again
tet_infoline("UtcDaliImageNewDistanceFieldWithPolicies03 - Load image with LoadPolicy::Immediate, ReleasePolicy::Unused");
{
TestApplication application;
+ const Vector2 closestImageSize( 80, 45);
+ application.GetPlatform().SetClosestImageSize(closestImageSize);
+
tet_infoline("UtcDaliImageNewDistanceFieldWithAttrandPol - Load image with LoadPolicy::OnDemand, ReleasePolicy::Unused");
Dali::ImageAttributes imageAttributes = Dali::ImageAttributes::NewDistanceField(6.0f, 12);
int UtcDaliImageDiscard02(void)
{
TestApplication application;
+ application.GetGlAbstraction().EnableTextureCallTrace( true );
tet_infoline("UtcDaliImageDiscard02 - one actor, tests TextureCache::DiscardTexture");
{
{
ImageActor actor;
{
- Image image = Image::New(gTestImageFilename);
+ ImageAttributes attrs;
+ const Vector2 requestedSize( 40, 30 );
+ attrs.SetSize( requestedSize.width, requestedSize.height );
+ Image image = Image::New(gTestImageFilename, attrs);
actor = ImageActor::New(image);
Stage::GetCurrent().Add(actor);
}
application.Render(16);
application.SendNotification();
+ DALI_TEST_CHECK( application.GetGlAbstraction().GetTextureTrace().FindMethod("BindTexture") );
} // lose image handle, actor should still keep one
application.SendNotification();
application.Render(16);
TestApplication application;
tet_infoline("UtcDaliImageDiscard03 - one actor, tests TextureCache::RemoveObserver");
+ const Vector2 closestImageSize( 1, 1);
+ application.GetPlatform().SetClosestImageSize(closestImageSize);
+
Image image = Image::New(gTestImageFilename);
ImageActor actor = ImageActor::New(image);
Stage::GetCurrent().Add(actor);
END_TEST;
}
-int UtcDaliImageActorGetCurrentImageSize01(void)
+int UtcDaliImageActorGetCurrentSize01(void)
{
TestApplication application;
- tet_infoline("Positive test for Dali::ImageActor::GetCurrentImageSize");
+ tet_infoline("Positive test for Dali::ImageActor::GetCurrentSize");
Vector2 initialImageSize(100, 50);
BitmapImage image = BitmapImage::New( initialImageSize.width, initialImageSize.height );
application.SendNotification();
application.Render();
- DALI_TEST_EQUALS( actor.GetCurrentImageSize(), initialImageSize, TEST_LOCATION );
+ DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), initialImageSize, TEST_LOCATION );
Vector2 size(200.0f, 200.0f);
actor.SetSize(size);
// flush the queue and render once
application.SendNotification();
application.Render();
- DALI_TEST_EQUALS( actor.GetCurrentImageSize(), size, TEST_LOCATION );
+ DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), size, TEST_LOCATION );
size.x = 200.0f;
size.y = 200.0f;
ImageActor::PixelArea area(0, 0, 10, 10);
actor.SetPixelArea(area);
application.Render(9);
- DALI_TEST_EQUALS( actor.GetCurrentImageSize(), Vector2( area.width, area.height ), TEST_LOCATION );
+ // natural size is not used as setsize is called
+ DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), size, TEST_LOCATION );
+
+ actor.SetToNaturalSize();
+ application.SendNotification();
+ application.Render(9);
+ DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2( area.width, area.height ), TEST_LOCATION );
+
END_TEST;
}
-int UtcDaliImageActorGetCurrentImageSize02(void)
+int UtcDaliImageActorGetCurrentSize02(void)
{
TestApplication application;
- tet_infoline("Positive test for Dali::ImageActor::GetCurrentImageSize - Test that using an image resource sets the actor size with it's natural size immediately rather than on load");
+ tet_infoline("Positive test for Dali::ImageActor::GetCurrentSize - Test that using an image resource sets the actor size with it's natural size immediately rather than on load");
Vector2 initialImageSize(100, 50);
application.SendNotification(); // Flush update messages
application.Render(); // Process resource request
- DALI_TEST_EQUALS( actor.GetCurrentImageSize(), initialImageSize, TEST_LOCATION );
+ DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), initialImageSize, TEST_LOCATION );
// Now complete the image load
Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
application.GetPlatform().ClearReadyResources(); //
- DALI_TEST_EQUALS( actor.GetCurrentImageSize(), initialImageSize, TEST_LOCATION );
+ DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), initialImageSize, TEST_LOCATION );
Vector2 size(200.0f, 200.0f);
actor.SetSize(size);
// flush the queue and render once
application.SendNotification();
application.Render();
- DALI_TEST_EQUALS( actor.GetCurrentImageSize(), size, TEST_LOCATION );
+ DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), size, TEST_LOCATION );
actor.SetToNaturalSize();
application.SendNotification();
application.Render();
- DALI_TEST_EQUALS( actor.GetCurrentImageSize(), initialImageSize, TEST_LOCATION );
+ DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), initialImageSize, TEST_LOCATION );
END_TEST;
}
-int UtcDaliImageActorGetCurrentImageSize03(void)
+int UtcDaliImageActorGetCurrentSize03(void)
{
TestApplication application;
- tet_infoline("Positive test for Dali::ImageActor::GetCurrentImageSize - Test that using an image resource with a requested size sets the actor size with it's nearest size immediately rather than on load");
-
- Vector2 closestImageSize( 80, 45);
+ tet_infoline("Positive test for Dali::ImageActor::GetCurrentSize - Test that using an image resource with a requested size sets the actor size with it's nearest size immediately rather than on load");
+ const Vector2 closestImageSize( 80, 45);
application.GetPlatform().SetClosestImageSize(closestImageSize);
ImageAttributes attrs;
- attrs.SetSize(40, 30);
+ const Vector2 requestedSize( 40, 30 );
+ attrs.SetSize( requestedSize.width, requestedSize.height );
Image image = Image::New("image.jpg", attrs);
ImageActor actor = ImageActor::New( image );
Stage::GetCurrent().Add(actor);
application.SendNotification(); // Flush update messages
application.Render(); // Process resource request
- DALI_TEST_EQUALS( actor.GetCurrentImageSize(), closestImageSize, TEST_LOCATION );
+ DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
// Now complete the image load
Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
application.GetPlatform().ClearReadyResources(); //
- DALI_TEST_EQUALS( actor.GetCurrentImageSize(), closestImageSize, TEST_LOCATION );
+ DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
// Test that setting a size on the actor can be 'undone' with SetNaturalSize()
Vector2 size(200.0f, 200.0f);
// flush the queue and render once
application.SendNotification();
application.Render();
- DALI_TEST_EQUALS( actor.GetCurrentImageSize(), size, TEST_LOCATION );
+ DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), size, TEST_LOCATION );
actor.SetToNaturalSize();
application.SendNotification();
application.Render();
- DALI_TEST_EQUALS( actor.GetCurrentImageSize(), closestImageSize, TEST_LOCATION );
+ DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
END_TEST;
}
-int UtcDaliImageActorGetCurrentImageSize04(void)
+int UtcDaliImageActorGetCurrentSize04(void)
{
TestApplication application;
- tet_infoline("Positive test for Dali::ImageActor::GetCurrentImageSize - check a new image doesn't change a set actor size");
+ tet_infoline("Positive test for Dali::ImageActor::GetCurrentSize - check a new image doesn't change a set actor size");
- Vector2 closestImageSize( 80, 45);
+ const Vector2 closestImageSize( 80, 45);
application.GetPlatform().SetClosestImageSize(closestImageSize);
+ const Vector2 requestedSize( 40, 30 );
ImageAttributes attrs;
- attrs.SetSize(40, 30); // Request a really small size we won't get.
+ attrs.SetSize( requestedSize.width, requestedSize.height );
Image image = Image::New("image.jpg", attrs);
ImageActor actor = ImageActor::New( image );
Stage::GetCurrent().Add(actor);
application.SendNotification(); // Flush update messages
application.Render(); // Process resource request
- DALI_TEST_EQUALS( actor.GetCurrentImageSize(), closestImageSize, TEST_LOCATION );
+ DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
// Now complete the image load
Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
application.GetPlatform().ClearReadyResources(); //
- DALI_TEST_EQUALS( actor.GetCurrentImageSize(), closestImageSize, TEST_LOCATION );
+ DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
Vector2 size(200.0f, 200.0f);
actor.SetSize(size);
// flush the queue and render once
application.SendNotification();
application.Render();
- DALI_TEST_EQUALS( actor.GetCurrentImageSize(), size, TEST_LOCATION );
+ DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), size, TEST_LOCATION );
// Load a different image
Vector2 image2ClosestSize = Vector2(240, 150); // The actual size image loader will return for the request below
application.GetPlatform().SetClosestImageSize(image2ClosestSize);
- attrs.SetSize(100, 100);
+ const Vector2 request2Size( 100, 100 );
+ attrs.SetSize( request2Size.width, request2Size.height );
Image image2 = Image::New("image2.jpg", attrs);
actor.SetImage(image2);
application.Render(); // Process resource request
// Ensure the actor size is kept
- DALI_TEST_EQUALS( actor.GetCurrentImageSize(), size, TEST_LOCATION );
+ DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), size, TEST_LOCATION );
// Now complete the image load
req = application.GetPlatform().GetRequest();
application.GetPlatform().ClearReadyResources(); //
// Ensure the actor size is kept
- DALI_TEST_EQUALS( actor.GetCurrentImageSize(), size, TEST_LOCATION );
+ DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), size, TEST_LOCATION );
actor.SetToNaturalSize();
application.SendNotification();
application.Render();
// Ensure the actor size gets the new image's natural size
- DALI_TEST_EQUALS( actor.GetCurrentImageSize(), image2ClosestSize, TEST_LOCATION );
+ DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), request2Size, TEST_LOCATION );
END_TEST;
}
-int UtcDaliImageActorGetCurrentImageSize05(void)
+int UtcDaliImageActorGetCurrentSize05(void)
{
TestApplication application;
- tet_infoline("Positive test for Dali::ImageActor::GetCurrentImageSize - check a new image doens't change actor size until load complete");
+ tet_infoline("Positive test for Dali::ImageActor::GetCurrentSize - check a new image doens't change actor size until load complete");
Vector2 closestImageSize( 80, 45);
application.GetPlatform().SetClosestImageSize(closestImageSize);
ImageAttributes attrs;
- attrs.SetSize(40, 30); // Request a really small size we won't get.
+ const Vector2 requestedSize( 40, 30 );
+ attrs.SetSize( requestedSize.width, requestedSize.height );
Image image = Image::New("image.jpg", attrs);
ImageActor actor = ImageActor::New( image );
Stage::GetCurrent().Add(actor);
application.SendNotification(); // Flush update messages
application.Render(); // Process resource request
- DALI_TEST_EQUALS( actor.GetCurrentImageSize(), closestImageSize, TEST_LOCATION );
+ DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
// Now complete the image load
Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
application.GetPlatform().ClearReadyResources(); //
- DALI_TEST_EQUALS( actor.GetCurrentImageSize(), closestImageSize, TEST_LOCATION );
+ DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
// Load a different image
Vector2 image2ClosestSize = Vector2(240, 150);
application.GetPlatform().SetClosestImageSize(image2ClosestSize);
- attrs.SetSize(100, 100);
+ const Vector2 requestedSize2( 100, 100 );
+ attrs.SetSize( requestedSize2.width, requestedSize2.height );
Image image2 = Image::New("image2.jpg", attrs);
actor.SetImage(image2);
application.Render(); // Process resource request
// Ensure the actor size is kept
- DALI_TEST_EQUALS( actor.GetCurrentImageSize(), closestImageSize, TEST_LOCATION );
+ DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize2, TEST_LOCATION );
// Now complete the image load
req = application.GetPlatform().GetRequest();
application.Render(); // Process LoadComplete
// Ensure the actor size gets the new image's natural size
- DALI_TEST_EQUALS( actor.GetCurrentImageSize(), image2ClosestSize, TEST_LOCATION );
+ DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize2, TEST_LOCATION );
END_TEST;
}
int UtcDaliImageActorNaturalPixelAreaSize01(void)
{
TestApplication application;
- tet_infoline("Positive test for Dali::ImageActor::GetCurrentImageSize - check a new image doens't change actor size until load complete");
+ tet_infoline("Positive test for Dali::ImageActor::GetCurrentSize - check a new image doens't change actor size until load complete");
//If an image is loaded without setting size, then the actor gets the natural size of the image
//Setting the pixel area will change the actor size to match the pixel area
application.GetPlatform().SetClosestImageSize(closestImageSize);
ImageAttributes attrs;
- attrs.SetSize(40, 30); // Request a really small size we won't get.
+ const Vector2 requestedSize( 40, 30 );
+ attrs.SetSize( requestedSize.width, requestedSize.height );
Image image = Image::New("image.jpg", attrs);
ImageActor actor = ImageActor::New( image );
Stage::GetCurrent().Add(actor);
application.SendNotification(); // Flush update messages
application.Render(); // Process resource request
- DALI_TEST_EQUALS( actor.GetCurrentImageSize(), closestImageSize, TEST_LOCATION );
- DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), closestImageSize, TEST_LOCATION );
+ DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
// Now complete the image load
Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
application.GetPlatform().ClearReadyResources(); //
- DALI_TEST_EQUALS( actor.GetCurrentImageSize(), closestImageSize, TEST_LOCATION );
- DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), closestImageSize, TEST_LOCATION );
+ DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
// Set a pixel area on a naturally sized actor - expect the actor to take the
// pixel area as size
actor.SetPixelArea(ImageActor::PixelArea(0, 0, 30, 30));
application.SendNotification(); // Process event messages
application.Render(); // Process LoadComplete
- DALI_TEST_EQUALS( actor.GetCurrentImageSize(), Vector2(30, 30), TEST_LOCATION );
DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(30, 30), TEST_LOCATION );
// Set a size. Expect the partial image to stretch to fill the new size
application.SendNotification(); // Process event messages
application.Render(); // Process LoadComplete
application.Render(); // Process LoadComplete
- DALI_TEST_EQUALS( actor.GetCurrentImageSize(), Vector2(30, 30), TEST_LOCATION );
DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(100, 100), TEST_LOCATION );
// Clear the pixel area. Expect the whole image to be shown, filling the set size.
actor.ClearPixelArea();
application.SendNotification(); // Process event messages
application.Render(); // Process LoadComplete
- DALI_TEST_EQUALS( actor.GetCurrentImageSize(), Vector2(100, 100), TEST_LOCATION );
DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(100, 100), TEST_LOCATION );
END_TEST;
}
int UtcDaliImageActorNaturalPixelAreaSize02(void)
{
TestApplication application;
- tet_infoline("Positive test for Dali::ImageActor::GetCurrentImageSize - check a new image doens't change actor size until load complete");
+ tet_infoline("Positive test for Dali::ImageActor::GetCurrentSize - check a new image doens't change actor size until load complete");
//If an image is loaded without setting size, then the actor gets the natural size of the image
//Setting the pixel area will change the actor size to match the pixel area
application.GetPlatform().SetClosestImageSize(closestImageSize);
ImageAttributes attrs;
- attrs.SetSize(40, 30); // Request a really small size we won't get.
+ const Vector2 requestedSize( 40, 30 );
+ attrs.SetSize( requestedSize.width, requestedSize.height );
Image image = Image::New("image.jpg", attrs);
ImageActor actor = ImageActor::New( image );
Stage::GetCurrent().Add(actor);
application.SendNotification(); // Flush update messages
application.Render(); // Process resource request
- DALI_TEST_EQUALS( actor.GetCurrentImageSize(), closestImageSize, TEST_LOCATION );
- DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), closestImageSize, TEST_LOCATION );
+ DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
// Now complete the image load
Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
application.GetPlatform().ClearReadyResources(); //
- DALI_TEST_EQUALS( actor.GetCurrentImageSize(), closestImageSize, TEST_LOCATION );
- DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), closestImageSize, TEST_LOCATION );
+ DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
// Set a pixel area on a naturally sized actor - expect the actor to take the
// pixel area as size
actor.SetPixelArea(ImageActor::PixelArea(0, 0, 30, 30));
application.SendNotification(); // Process event messages
application.Render(); // Process LoadComplete
- DALI_TEST_EQUALS( actor.GetCurrentImageSize(), Vector2(30, 30), TEST_LOCATION );
DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(30, 30), TEST_LOCATION );
// Clear the pixel area. Expect the whole image to be shown, changing actor size
actor.ClearPixelArea();
application.SendNotification(); // Process event messages
application.Render(); // Process LoadComplete
- DALI_TEST_EQUALS( actor.GetCurrentImageSize(), closestImageSize, TEST_LOCATION );
- DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), closestImageSize, TEST_LOCATION );
+ DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
// Set a size. Expect the partial image to stretch to fill the new size
actor.SetSize(100, 100);
application.SendNotification(); // Process event messages
application.Render(); // Process LoadComplete
- DALI_TEST_EQUALS( actor.GetCurrentImageSize(), Vector2(100, 100), TEST_LOCATION );
DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(100, 100), TEST_LOCATION );
// Set a pixel area, don't expect size to change
actor.SetPixelArea(ImageActor::PixelArea(0, 0, 40, 40));
application.SendNotification(); // Process event messages
application.Render(); // Process LoadComplete
- DALI_TEST_EQUALS( actor.GetCurrentImageSize(), Vector2(40, 40), TEST_LOCATION );
DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(100, 100), TEST_LOCATION );
// Use natural size - expect actor to change to pixel area
actor.SetToNaturalSize();
application.SendNotification(); // Process event messages
application.Render(); // Process LoadComplete
- DALI_TEST_EQUALS( actor.GetCurrentImageSize(), Vector2(40, 40), TEST_LOCATION );
DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(40, 40), TEST_LOCATION );
// Clearing pixel area should change actor size to image size
actor.ClearPixelArea();
application.SendNotification(); // Process event messages
application.Render(); // Process LoadComplete
- DALI_TEST_EQUALS( actor.GetCurrentImageSize(), closestImageSize, TEST_LOCATION );
- DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), closestImageSize, TEST_LOCATION );
+ DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
END_TEST;
}
std::vector<Property::Index> indices;
indices.push_back(ImageActor::PIXEL_AREA );
- indices.push_back(ImageActor::FADE_IN );
- indices.push_back(ImageActor::FADE_IN_DURATION);
indices.push_back(ImageActor::STYLE );
indices.push_back(ImageActor::BORDER );
indices.push_back(ImageActor::IMAGE );
END_TEST;
}
-int UtcDaliImageSetFadeIn(void)
-{
- TestApplication application;
-
- Image image = Image::New(TestImageFilename);
- ImageActor actor = ImageActor::New(image);
-
- actor.SetFadeIn(true);
-
- // flush the queue and render once
- application.SendNotification();
- application.Render();
-
- DALI_TEST_EQUALS( true, actor.GetFadeIn(), TEST_LOCATION );
-
- actor.SetFadeIn(false);
-
- // flush the queue and render once
- application.SendNotification();
- application.Render();
-
- DALI_TEST_EQUALS( false, actor.GetFadeIn(), TEST_LOCATION );
- END_TEST;
-}
-
-
-int UtcDaliImageSetFadeInDuration(void)
-{
- TestApplication application;
-
- Image image = Image::New(TestImageFilename);
- ImageActor actor = ImageActor::New(image);
-
- actor.SetFadeInDuration( 1.0f );
-
- // flush the queue and render once
- application.SendNotification();
- application.Render();
-
- DALI_TEST_EQUALS( 1.0f, actor.GetFadeInDuration(), TEST_LOCATION );
-
- actor.SetFadeInDuration( 3.0f );
-
- // flush the queue and render once
- application.SendNotification();
- application.Render();
-
- DALI_TEST_EQUALS( 3.0f, actor.GetFadeInDuration(), TEST_LOCATION );
- END_TEST;
-}
-
int UtcDaliImageActorNewNull(void)
{
TestApplication application;
namespace Internal
{
-ImageAttachmentPtr ImageAttachment::New( const SceneGraph::Node& parentNode, Image* image )
+ImageAttachmentPtr ImageAttachment::New( const SceneGraph::Node& parentNode )
{
StagePtr stage = Stage::GetCurrent();
- ImageAttachmentPtr attachment( new ImageAttachment( *stage, image ) );
+ ImageAttachmentPtr attachment( new ImageAttachment( *stage ) );
// Transfer object ownership of scene-object to message
- SceneGraph::ImageAttachment* sceneObject = CreateSceneObject( image );
+ SceneGraph::ImageAttachment* sceneObject = CreateSceneObject();
AttachToNodeMessage( stage->GetUpdateManager(), parentNode, sceneObject );
// Keep raw pointer for message passing
return attachment;
}
-ImageAttachment::ImageAttachment(Stage& stage, Image* image)
+ImageAttachment::ImageAttachment( Stage& stage )
: RenderableAttachment(stage),
mSceneObject(NULL),
mPixelArea(EMPTY_PIXEL_AREA),
mIsPixelAreaSet(false),
mBorderInPixels(false)
{
- mImageConnectable.Set( image, false );
+ mImageConnectable.Set( NULL, false );
}
ImageAttachment::~ImageAttachment()
{
}
-void ImageAttachment::SetImage(Image* image)
+void ImageAttachment::SetImage( ImagePtr& image )
{
bool onStage = OnStage();
// keep a reference to Image object
// Wait until the scene-graph attachment is connected, before providing resource ID
if ( OnStage() )
{
- unsigned int resourceId = (NULL != image) ? image->GetResourceId() : 0u;
+ unsigned int resourceId = (image) ? image->GetResourceId() : 0u;
// sceneObject is being used in a separate thread; queue a message to set
SetTextureIdMessage( mStage->GetUpdateInterface(), *mSceneObject, resourceId );
}
}
-Dali::Image ImageAttachment::GetImage()
+ImagePtr ImageAttachment::GetImage()
{
- Dali::Image image;
- Image* current = mImageConnectable.Get();
- if ( current != NULL)
- {
- image = Dali::Image( current );
- }
- else
- {
- // returning uninitialized image (empty image)
- }
- return image;
+ return mImageConnectable.Get();
}
void ImageAttachment::SetPixelArea(const PixelArea& pixelArea)
SetNinePatchBorderMessage( mStage->GetUpdateInterface(), *mSceneObject, border, inPixels );
}
-SceneGraph::ImageAttachment* ImageAttachment::CreateSceneObject( const Image* current )
+SceneGraph::ImageAttachment* ImageAttachment::CreateSceneObject()
{
- if ( current )
- {
- return SceneGraph::ImageAttachment::New( current->GetResourceId() );
- }
-
return SceneGraph::ImageAttachment::New( 0u );
}
mImageConnectable.OnStageConnect();
// Provide resource ID when scene-graph attachment is connected
- Image* image = mImageConnectable.Get();
- unsigned int resourceId = (NULL != image) ? image->GetResourceId() : 0u;
+ ImagePtr image = mImageConnectable.Get();
+ unsigned int resourceId = (image) ? image->GetResourceId() : 0u;
if ( 0u != resourceId )
{
SetTextureIdMessage( mStage->GetUpdateInterface(), *mSceneObject, resourceId );
/**
* Create a new ImageAttachment.
* @param[in] parentNode The node to attach a scene-object to.
- * @param[in] image A pointer to the image to display or NULL to not render anything.
* @return A smart-pointer to the newly allocated ImageAttachment.
*/
- static ImageAttachmentPtr New( const SceneGraph::Node& parentNode, Image* image );
+ static ImageAttachmentPtr New( const SceneGraph::Node& parentNode );
/**
* Sets image rendered by the attachment.
- * @param [in] image A pointer to the image to display or NULL to clear.
+ * @param [in] image A pointer to the image to display or NULL to clear. Reference to avoid unnecessary increment/decrement reference count.
*/
- void SetImage(Image* image);
+ void SetImage( ImagePtr& image );
/**
* Retrieve the image rendered by the attachment.
* @return The image or an uninitialized image in case the ImageActor was cleared.
*/
- Dali::Image GetImage();
+ ImagePtr GetImage();
/**
* Set a region of the image to display, in pixels.
* @param[in] stage Used to send messages to scene-graph.
* @param[in] image A pointer to the image to display or NULL to not render anything.
*/
- ImageAttachment(Stage& stage, Image* image);
+ ImageAttachment(Stage& stage);
/**
* Creates the corresponding scene-graph ImageAttachment.
* @return A newly allocated scene object.
*/
- static SceneGraph::ImageAttachment* CreateSceneObject( const Image* current );
+ static SceneGraph::ImageAttachment* CreateSceneObject();
/**
* @copydoc Dali::Internal::RenderableAttachment::OnStageConnection2()
{
const Property::Index ImageActor::PIXEL_AREA = Internal::DEFAULT_RENDERABLE_ACTOR_PROPERTY_MAX_COUNT;
-const Property::Index ImageActor::FADE_IN = Internal::DEFAULT_RENDERABLE_ACTOR_PROPERTY_MAX_COUNT + 1;
-const Property::Index ImageActor::FADE_IN_DURATION = Internal::DEFAULT_RENDERABLE_ACTOR_PROPERTY_MAX_COUNT + 2;
-const Property::Index ImageActor::STYLE = Internal::DEFAULT_RENDERABLE_ACTOR_PROPERTY_MAX_COUNT + 3;
-const Property::Index ImageActor::BORDER = Internal::DEFAULT_RENDERABLE_ACTOR_PROPERTY_MAX_COUNT + 4;
-const Property::Index ImageActor::IMAGE = Internal::DEFAULT_RENDERABLE_ACTOR_PROPERTY_MAX_COUNT + 5;
+const Property::Index ImageActor::STYLE = Internal::DEFAULT_RENDERABLE_ACTOR_PROPERTY_MAX_COUNT + 1;
+const Property::Index ImageActor::BORDER = Internal::DEFAULT_RENDERABLE_ACTOR_PROPERTY_MAX_COUNT + 2;
+const Property::Index ImageActor::IMAGE = Internal::DEFAULT_RENDERABLE_ACTOR_PROPERTY_MAX_COUNT + 3;
namespace Internal
{
const std::string DEFAULT_IMAGE_ACTOR_PROPERTY_NAMES[] =
{
"pixel-area",
- "fade-in",
- "fade-in-duration",
"style",
"border",
"image"
const Property::Type DEFAULT_IMAGE_ACTOR_PROPERTY_TYPES[DEFAULT_IMAGE_ACTOR_PROPERTY_COUNT] =
{
Property::RECTANGLE, // "pixel-area",
- Property::BOOLEAN, // "fade-in",
- Property::FLOAT, // "fade-in-duration",
Property::STRING, // "style",
Property::VECTOR4, // "border",
Property::MAP, // "image",
}
}
-ImageActorPtr ImageActor::New( Image* anImage )
+ImageActorPtr ImageActor::New()
{
- ImageActorPtr actor( new ImageActor() );
- ImagePtr theImage( anImage );
+ ImageActorPtr actor( new ImageActor );
// Second-phase construction of base class
actor->Initialize();
// Create the attachment
- actor->mImageAttachment = ImageAttachment::New( *actor->mNode, theImage.Get() );
+ actor->mImageAttachment = ImageAttachment::New( *actor->mNode );
actor->Attach( *actor->mImageAttachment );
- // don't call the external version as attachment already has the image
- actor->SetImageInternal( NULL, anImage );
-
- return actor;
-}
-
-
-ImageActorPtr ImageActor::New( Image* image, const PixelArea& pixelArea )
-{
- // re-use basic New
- ImageActorPtr actor = New( image );
- // then set the pixel area
- actor->mImageAttachment->SetPixelArea( pixelArea );
return actor;
}
}
}
-void ImageActor::SetImage( Image* image )
+void ImageActor::SetImage( ImagePtr& image )
{
- Image* currentImage = static_cast<Image*>(mImageAttachment->GetImage().GetObjectPtr());
- // early exit if it's the same image
- if ( currentImage == image || mImageNext.Get() == image )
+ ImagePtr currentImage = mImageAttachment->GetImage();
+ // early exit if it's the same image as we already have
+ if ( currentImage == image )
{
return;
}
- SetImageInternal( currentImage, image );
+ // NOTE! image might be pointing to NULL, which is fine as in that case app wants to just remove the image
+ ImagePtr newImage( image );
+ // if image is not NULL, check for 9 patch
+ if( newImage )
+ {
+ // Automatically convert nine-patch images to cropped bitmap
+ NinePatchImage* ninePatchImage = NinePatchImage::DownCast( image.Get() );
+ if( ninePatchImage )
+ {
+ newImage = ninePatchImage->CreateCroppedBitmapImage();
+ SetStyle( Dali::ImageActor::STYLE_NINE_PATCH );
+ SetNinePatchBorder( ninePatchImage->GetStretchBorders(), true );
+ }
+ }
+ // set the actual image (normal or 9 patch) and natural size based on that
+ mImageAttachment->SetImage( newImage );
+ SetNaturalSize();
}
-Dali::Image ImageActor::GetImage()
+ImagePtr ImageActor::GetImage()
{
return mImageAttachment->GetImage();
}
void ImageActor::SetToNaturalSize()
{
mUsingNaturalSize = true;
- Dali::Image image = mImageAttachment->GetImage();
- if( image )
- {
- SetNaturalSize( GetImplementation(image) );
- }
+ SetNaturalSize();
}
void ImageActor::SetPixelArea( const PixelArea& pixelArea )
{
mImageAttachment->SetPixelArea( pixelArea );
- if( mUsingNaturalSize )
- {
- mInternalSetSize = true;
- SetSize(pixelArea.width, pixelArea.height);
- mInternalSetSize = false;
- }
+ SetNaturalSize();
}
const ImageActor::PixelArea& ImageActor::GetPixelArea() const
if( mUsingNaturalSize )
{
- Dali::Image image = mImageAttachment->GetImage();
+ ImagePtr image = mImageAttachment->GetImage();
if( image )
{
mInternalSetSize = true;
- SetSize(GetImplementation(image).GetNaturalSize());
+ SetSize( image->GetNaturalSize() );
mInternalSetSize = false;
}
}
return mImageAttachment->GetNinePatchBorder();
}
-void ImageActor::SetFadeIn( bool enableFade )
-{
- mFadeIn = enableFade;
-}
-
-bool ImageActor::GetFadeIn() const
-{
- return mFadeIn;
-}
-
-void ImageActor::SetFadeInDuration( float durationSeconds )
-{
- mFadeInDuration = durationSeconds;
-}
-
-float ImageActor::GetFadeInDuration() const
-{
- return mFadeInDuration;
-}
-
ImageAttachment& ImageActor::GetImageAttachment()
{
return *mImageAttachment;
}
-Vector2 ImageActor::GetCurrentImageSize() const
-{
- Vector3 size;
- Vector3 currentSize;
-
- // get the texture size / pixel area if only a subset of it is displayed
- if( IsPixelAreaSet() )
- {
- PixelArea area(GetPixelArea());
- return Vector2(area.width, area.height );
- }
- else
- {
- return Vector2( GetCurrentSize() );
- }
-}
-
RenderableAttachment& ImageActor::GetRenderableAttachment() const
{
DALI_ASSERT_DEBUG( mImageAttachment && "ImageAttachment missing from ImageActor" );
return *mImageAttachment;
}
-void ImageActor::SignalConnected( SlotObserver*, CallbackBase* )
-{
- // nothing to do as we only ever connect to one signal, which we disconnect from in the destructor
-}
-
-void ImageActor::SignalDisconnected( SlotObserver*, CallbackBase* )
-{
- // nothing to do as we only ever connect to one signal, which we disconnect from in the destructor
- // also worth noting that we own the image whose signal we connect to so in practice this method is never called.
-}
-
ImageActor::ImageActor()
: RenderableActor(),
- mFadeInDuration( 1.0f ),
mUsingNaturalSize(true),
- mInternalSetSize(false),
- mFadeIn( false ),
- mFadeInitial( true )
+ mInternalSetSize(false)
{
}
ImageActor::~ImageActor()
{
- if( mImageAttachment )
- {
- Dali::Image image = mImageAttachment->GetImage();
- if( image )
- {
- // just call Disconnect as if not connected it is a no-op
- image.LoadingFinishedSignal().Disconnect( this, &ImageActor::ImageLoaded );
- }
- }
}
-void ImageActor::SetNaturalSize( Image& image )
+void ImageActor::SetNaturalSize()
{
if( mUsingNaturalSize )
{
+ // if no image then natural size is 0
Vector2 size;
- if( IsPixelAreaSet() )
- {
- PixelArea area(GetPixelArea());
- size.width = area.width;
- size.height = area.height;
- }
- else
+ ImagePtr image = mImageAttachment->GetImage();
+ if( image )
{
- size = image.GetNaturalSize();
+ if( IsPixelAreaSet() )
+ {
+ PixelArea area(GetPixelArea());
+ size.width = area.width;
+ size.height = area.height;
+ }
+ else
+ {
+ size = image->GetNaturalSize();
+ }
}
-
mInternalSetSize = true;
SetSize( size );
mInternalSetSize = false;
void ImageActor::OnStageConnectionInternal()
{
- FadeIn();
-
- mImageNext.OnStageConnect();
}
void ImageActor::OnStageDisconnectionInternal()
{
- mImageNext.OnStageDisconnect();
-}
-
-void ImageActor::ImageLoaded( Dali::Image image )
-{
- DALI_ASSERT_DEBUG (image && "Image handle empty!");
-
- // TODO: Handle case where image loading failed
-
- // Need to keep mUploadedConnection connected as image may change later through Reload
- // Note: Reloaded images may have changed size.
-
- // Set the attachment's image once we know the image has loaded to prevent
- // blank frames during load / reload.
- mImageAttachment->SetImage( &GetImplementation( image ) );
-
- // If size has never been set by application
- if( mUsingNaturalSize )
- {
- // If a pixel area has been set, use this size
- if( IsPixelAreaSet() )
- {
- const PixelArea& area = GetPixelArea();
- mInternalSetSize = true;
- SetSize(area.width, area.height);
- mInternalSetSize = false;
- }
- else
- {
- mInternalSetSize = true;
- SetSize( GetImplementation(image).GetNaturalSize() );
- mInternalSetSize = false;
- }
- }
-
- // fade in if required
- FadeIn();
-}
-
-void ImageActor::FadeIn()
-{
- // only fade in if enabled and newly displayed on screen
- if( mFadeIn && mFadeInitial && ( mFadeInDuration > 0.0f ) )
- {
- // need to set opacity immediately to 0 otherwise child actors might get rendered
- SetOpacity( 0.0f );
-
- Dali::Image image = mImageAttachment->GetImage();
-
- // Fade-in when on-stage & the image is loaded
- if (OnStage() &&
- image &&
- image.GetLoadingState() == Dali::ResourceLoadingSucceeded)
- {
- // fire and forget animation; will clean up after it's finished
- Dali::Animation animation = Dali::Animation::New( mFadeInDuration );
- animation.OpacityTo( Dali::Actor( this ), 1.0f, AlphaFunctions::EaseOut );
- animation.Play();
- mFadeInitial = false;
- }
- }
}
unsigned int ImageActor::GetDefaultPropertyCount() const
SetPixelArea(propertyValue.Get<Rect<int> >());
break;
}
- case Dali::ImageActor::FADE_IN:
- {
- SetFadeIn(propertyValue.Get<bool>());
- break;
- }
- case Dali::ImageActor::FADE_IN_DURATION:
- {
- SetFadeInDuration(propertyValue.Get<float>());
- break;
- }
case Dali::ImageActor::STYLE:
{
SetStyle(StyleEnum(propertyValue.Get<std::string>()));
Dali::Image img = Scripting::NewImage( propertyValue );
if(img)
{
- SetImage( &GetImplementation(img) );
+ ImagePtr image( &GetImplementation(img) );
+ SetImage( image );
}
else
{
ret = r;
break;
}
- case Dali::ImageActor::FADE_IN:
- {
- ret = GetFadeIn();
- break;
- }
- case Dali::ImageActor::FADE_IN_DURATION:
- {
- ret = GetFadeInDuration();
- break;
- }
case Dali::ImageActor::STYLE:
{
ret = StyleString(GetStyle());
case Dali::ImageActor::IMAGE:
{
Property::Map map;
- Scripting::CreatePropertyMap( mImageAttachment->GetImage(), map );
+ Scripting::CreatePropertyMap( Dali::Image( mImageAttachment->GetImage().Get() ), map );
ret = Property::Value( map );
break;
}
return ret;
}
-void ImageActor::SetImageInternal( Image* currentImage, Image* image )
-{
- if( currentImage )
- {
- // just call Disconnect as if not connected it is a no-op
- currentImage->LoadingFinishedSignal().Disconnect( this, &ImageActor::ImageLoaded );
- }
-
- ImagePtr imagePtr( image );
- // Automatically convert nine-patch images to cropped bitmap
- NinePatchImage* ninePatchImage = NinePatchImage::GetNinePatchImage( image );
- if( ninePatchImage )
- {
- imagePtr = ninePatchImage->CreateCroppedBitmapImage();
- }
- mImageNext.Set( imagePtr.Get(), OnStage() );
- if( ninePatchImage )
- {
- SetStyle( Dali::ImageActor::STYLE_NINE_PATCH );
- SetNinePatchBorder( ninePatchImage->GetStretchBorders(), true );
- }
- if( !imagePtr )
- {
- mImageAttachment->SetImage( NULL );
- }
- else
- {
- // don't disconnect currently shown image until we made sure that the new one is loaded
- if( Dali::ResourceLoading == image->GetLoadingState() && !image->GetFilename().empty() )
- {
- // observe image loading, @todo stop using signals internally!
- image->LoadingFinishedSignal().Connect( this, &ImageActor::ImageLoaded );
- }
- else
- {
- // image already loaded, generated or 9 patch
- ImageLoaded( Dali::Image( image ) );
- }
- }
-}
-
} // namespace Internal
} // namespace Dali
* mImageAttachment's member object. The first one points to the Image object that is going to
* be displayed next, the second one to the Image that is currently being displayed.
*/
-class ImageActor : public RenderableActor, public ConnectionTrackerInterface
+class ImageActor : public RenderableActor
{
public:
typedef Dali::ImageActor::PixelArea PixelArea;
/**
- * @brief Create an initialised image actor.
- * When the image is loaded the actors size will reset to the image size,
- * unless a custom size chosen via Actor:SetSize().
- * @param[in] image A pointer to the image object to display or NULL not to display anything.
+ * @brief Create an image actor instance.
* @return A smart-pointer to a newly allocated image actor.
*/
- static ImageActorPtr New( Image* image );
-
- /**
- * @brief Create an initialised image actor.
- * When the image is loaded the actors size will reset to the image size,
- * unless a custom size chosen via Actor:SetSize().
- * @param [in] image A pointer to the image object to display or NULL not to display anything.
- * @param [in] pixelArea The area of the image to display.
- * This in pixels, relative to the top-left (0,0) of the image.
- * @return A smart-pointer to a newly allocated image actor.
- */
- static ImageActorPtr New( Image* image, const PixelArea& pixelArea );
+ static ImageActorPtr New();
/**
* @copydoc Dali::Internal::Actor::OnInitialize
void OnInitialize() ;
/**
- * Set the image rendered by the actor's attachment.
- * When the image is loaded the actors size will be reset to the image size,
- * unless a custom size is chosen via Actor:SetSize().
- * The old image will continue to be displayed until the new image has loaded
- * @param [in] image A pointer to the image to display or NULL not to display anything.
+ * @see Dali::ImageActor::SetImage()
+ * @param[in] ImagePtr reference to the image object to display. Reference to avoid unnecessary increment/decrement reference.
*/
- void SetImage( Image* image );
+ void SetImage( ImagePtr& image );
/**
* Retrieve the image rendered by the actor's attachment.
- * @return The image (uninitialized Image object in case the ImageActor does not display anything).
+ * @return smart pointer to the image or an empty one if no image is assigned
*/
- Dali::Image GetImage();
+ ImagePtr GetImage();
/**
* @copydoc Dali::ImageActor::SetToNaturalSize()
void SetToNaturalSize();
/**
- * Set a region of the image to display, in pixels.
- * @param [in] pixelArea The area of the image to display.
- * This in pixels, relative to the top-left (0,0) of the image.
+ * @copydoc Dali::ImageActor::SetPixelArea()
*/
void SetPixelArea( const PixelArea& pixelArea );
/**
- * Retrieve the region of the image to display, in pixels.
- * @return The pixel area, or a default-constructed area if none was set.
+ * @copydoc Dali::ImageActor::GetPixelArea()
*/
const PixelArea& GetPixelArea() const;
/**
- * Query whether a pixel area has been set.
- * @return True if a pixel area has been set.
+ * @copydoc Dali::ImageActor::IsPixelAreaSet()
*/
bool IsPixelAreaSet() const;
/**
- * Remove any pixel areas specified with SetPixelArea; the entire image will be displayed.
+ * @copydoc Dali::ImageActor::ClearPixelArea()
*/
void ClearPixelArea();
/**
- * Set how the image is rendered; the default is STYLE_QUAD.
- * @param [in] style The new style.
+ * @copydoc Dali::ImageActor::SetStyle()
*/
void SetStyle( Style style );
/**
- * Query how the image is rendered.
- * @return The rendering style.
+ * @copydoc Dali::ImageActor::GetStyle()
*/
Style GetStyle() const;
Vector4 GetNinePatchBorder() const;
/**
- * Set whether the image should gradually fade in when first rendered.
- * @param [in] enableFade True if the image should fade in.
- */
- void SetFadeIn(bool enableFade);
-
- /**
- * Query whether the image will gradually fade in when first rendered.
- * @return True if the image will fade in.
- */
- bool GetFadeIn() const;
-
- /**
- * Set the duration of the fade-in effect; the default is 1 second.
- * @param [in] durationSeconds The duration in seconds.
- */
- void SetFadeInDuration( float durationSeconds );
-
- /**
- * Retrieve the duration of the fade-in effect.
- * @return The duration in seconds.
- */
- float GetFadeInDuration() const;
-
- /**
* Retrieve the attachment which renders the image.
* @return The attachment.
*/
ImageAttachment& GetImageAttachment();
- /**
- * @copydoc Dali::ImageActor::GetCurrentImageSize
- */
- Vector2 GetCurrentImageSize() const;
-
public: // Default property extensions from ProxyObject
/**
*/
virtual RenderableAttachment& GetRenderableAttachment() const;
-private: // From ConnectionTrackerInterface
-
- /**
- * @copydoc SignalObserver::SignalConnected
- */
- virtual void SignalConnected( SlotObserver*, CallbackBase* );
-
- /**
- * @copydoc ConnectionTrackerInterface::SignalDisconnected
- */
- virtual void SignalDisconnected(Dali::SlotObserver*, Dali::CallbackBase* );
-
protected:
/**
/**
* Helper to set the actor to the image's natural size
- * @param image that is used
*/
- void SetNaturalSize( Image& image );
+ void SetNaturalSize();
/**
* From Actor.
*/
virtual void OnStageDisconnectionInternal();
- /**
- * Helper for when the image loads.
- * @param[in] image The newly (re)loaded image.
- */
- void ImageLoaded( Dali::Image image );
-
- /**
- * Helper to start fade-in animations.
- */
- void FadeIn();
-
- /**
- * Helper to set image internally
- * @param currentImage
- * @param image to set
- */
- void SetImageInternal( Image* currentImage, Image* image );
-
private:
ImageAttachmentPtr mImageAttachment; ///< Used to display the image (holds a pointer to currently showed Image)
- ImageConnector mImageNext; ///< Manages the Image this ImageActor will show (used when changing displayed image)
-
- // For fade-in animations
- float mFadeInDuration; ///< Length of animation
- // flags, compressed to bitfield (uses only 4 bytes)
+ // flags, compressed to bitfield (uses only 1 byte)
bool mUsingNaturalSize:1; ///< True only when the actor is using
bool mInternalSetSize:1; ///< True whilst setting size internally, false at all other times
- bool mFadeIn:1; ///< True if fade in animation is enabled
- bool mFadeInitial:1; ///< True if fading in for the first time
static bool mFirstInstance ;
static DefaultPropertyLookup* mDefaultImageActorPropertyLookup; ///< Default properties
mResourceClient = &tls.GetResourceClient();
mWidth = width;
mHeight = height;
- mNaturalSizeSet = true;
const ImageTicketPtr& t = mResourceClient->AllocateBitmapImage(width, height, width, height, pixelformat);
mTicket = t.Get();
mResourceClient = &tls.GetResourceClient();
mWidth = width;
mHeight = height;
- mNaturalSizeSet = true;
Integration::Bitmap* bitmap = new BitmapExternal(pixBuf, width, height, pixelformat, stride);
const ImageTicketPtr& t = mResourceClient->AddBitmapImage(bitmap);
mTicket = t.Get();
Internal::ThreadLocalStorage::Get().GetPlatformAbstraction().GetClosestImageSize( buffer, attributes, size );
image->mWidth = (unsigned int) size.width;
image->mHeight = (unsigned int) size.height;
- image->mNaturalSizeSet = true;
ResourceClient &resourceClient = ThreadLocalStorage::Get().GetResourceClient();
ResourceTicketPtr ticket = resourceClient.DecodeResource( resourceType, buffer );
{
mWidth = width;
mHeight = height;
- mNaturalSizeSet = true;
}
{
}
-Image* ImageConnector::Get() const
+ImagePtr ImageConnector::Get() const
{
- return mImage.Get();
+ return mImage;
}
-void ImageConnector::Set( Image* image, bool onStage )
+void ImageConnector::Set( ImagePtr image, bool onStage )
{
- if ( mImage.Get() != image )
+ if ( mImage != image )
{
// Disconnect from old image
if ( mImage && onStage )
mImage->Disconnect();
}
- mImage.Reset(image);
+ mImage = image;
// Connect to new image
if ( mImage && onStage )
~ImageConnector();
/**
- * Returns a pointer to the managed Image or NULL.
- * @return a pointer to mImage or NULL if not set.
+ * Returns a smart pointer to the image
+ * @return a smart pointer to the image
*/
- Image* Get() const;
+ ImagePtr Get() const;
/**
* Assigns image, calling Connect and Disconnect methods accordingly, taking onStage into account.
- * @param [in] image pointer to new Image
+ * @param [in] image smart pointer to new Image
* @param [in] onStage whether Image is used on stage or not
*/
- void Set ( Image *image, bool onStage);
+ void Set( ImagePtr image, bool onStage );
/**
* Manages connection reference count.
const ImageConnector& operator=( const ImageConnector& ptr ); ///< copy assignment operator, not defined
ImagePtr mImage; ///< intrusive pointer to the Image. ImageConnector owns this.
+
};
} // namespace Internal
void StopLifetimeObservation();
protected:
- ~Request();
+ virtual ~Request();
private:
Request(); ///< not defined
Image::Image( LoadPolicy loadPol, ReleasePolicy releasePol )
: mWidth(0),
mHeight(0),
- mNaturalSizeSet(false),
mLoadPolicy(loadPol),
mReleasePolicy(releasePol),
mConnectionCount(0),
ImagePtr Image::New( const std::string& filename, const Dali::ImageAttributes& attributes, LoadPolicy loadPol, ReleasePolicy releasePol )
{
+ ImagePtr image;
if( IsNinePatchFileName(filename) )
{
- NinePatchImagePtr image = NinePatchImage::New( filename, attributes, loadPol, releasePol );
- return image;
+ image = NinePatchImage::New( filename, attributes, loadPol, releasePol );
}
else
{
- ImagePtr image = new Image( loadPol, releasePol );
+ image = new Image( loadPol, releasePol );
image->Initialize();
- image->mRequest = image->mImageFactory.RegisterRequest( filename, &attributes );
+ // if the attributes have a size, use that as natural size, otherwise get the size
+ const unsigned int width = attributes.GetWidth();
+ const unsigned int height = attributes.GetHeight();
+ // if one is zero, then there is some scaling calculation so we have to ask the loading logic what it will do
+ if( width > 0 && height > 0 )
+ {
+ image->mWidth = width;
+ image->mHeight = height;
+ image->mRequest = image->mImageFactory.RegisterRequest( filename, &attributes );
+ }
+ else
+ {
+ // TODO do this query only if/when its needed (if someone is calling GetSize)
+ Integration::PlatformAbstraction& platformAbstraction = Internal::ThreadLocalStorage::Get().GetPlatformAbstraction();
+ Vector2 closestSize;
+ platformAbstraction.GetClosestImageSize( filename, attributes, closestSize );
+ image->mWidth = closestSize.width;
+ image->mHeight = closestSize.height;
+ // need a new request object as we will request for the closest size
+ Dali::ImageAttributes newAttributes( attributes );
+ newAttributes.SetSize( closestSize );
+ image->mRequest = image->mImageFactory.RegisterRequest( filename, &newAttributes );
+ }
if( Dali::Image::Immediate == loadPol )
{
image->mTicket = image->mImageFactory.Load( image->mRequest.Get() );
image->mTicket->AddObserver( *image );
}
-
- // else lazily load image data later, only when it is needed to draw something:
-
- DALI_LOG_SET_OBJECT_STRING( image, filename );
-
- return image;
}
+ DALI_LOG_SET_OBJECT_STRING( image, filename );
+
+ return image;
}
ImagePtr Image::New( NativeImage& nativeImg, LoadPolicy loadPol, ReleasePolicy releasePol )
image->mWidth = nativeImg.GetWidth();
image->mHeight = nativeImg.GetHeight();
- image->mNaturalSizeSet = true;
const ResourceTicketPtr& ticket = resourceClient.AddNativeImage( nativeImg );
DALI_ASSERT_DEBUG( dynamic_cast<ImageTicket*>( ticket.Get() ) && "Resource ticket not ImageTicket subclass for image resource.\n" );
void Image::ResourceLoadingSucceeded(const ResourceTicket& ticket)
{
- // Update size with actual loaded size
- const ImageTicket* imageTicket = static_cast<const ImageTicket*>(&ticket);
- mWidth = imageTicket->GetWidth();
- mHeight = imageTicket->GetHeight();
- mNaturalSizeSet = true;
mLoadingFinishedV2.Emit( Dali::Image( this ) );
}
unsigned int Image::GetWidth() const
{
- unsigned int width = 0;
- if( mNaturalSizeSet )
- {
- // Width has already been calculated - just return that
- width = mWidth;
- }
- else if( mTicket )
- {
- const ImageAttributes& attr = mImageFactory.GetActualAttributes( mTicket->GetId() );
- width = attr.GetWidth();
- }
- else if( mRequest )
- {
- const ImageAttributes& attr = mImageFactory.GetRequestAttributes( mRequest.Get() );
- width = attr.GetWidth();
- }
-
- return width;
+ return mWidth;
}
unsigned int Image::GetHeight() const
{
- unsigned int height = 0;
- if( mNaturalSizeSet )
- {
- // Height has already been calculated - just return that
- height = mHeight;
- }
- else if( mTicket )
- {
- const ImageAttributes& attr = mImageFactory.GetActualAttributes( mTicket->GetId() );
- height = attr.GetHeight();
- }
- else if( mRequest )
- {
- const ImageAttributes& attr = mImageFactory.GetRequestAttributes( mRequest.Get() );
- height = attr.GetHeight();
- }
-
- return height;
+ return mHeight;
}
Vector2 Image::GetNaturalSize() const
{
Vector2 naturalSize(mWidth, mHeight);
- if( ! mNaturalSizeSet )
- {
- if( mTicket )
- {
- const ImageAttributes& attr = mImageFactory.GetActualAttributes( mTicket->GetId() );
- naturalSize.width = attr.GetWidth();
- naturalSize.height = attr.GetHeight();
- }
- else if( mRequest )
- {
- const ImageAttributes& attr = mImageFactory.GetRequestAttributes( mRequest.Get() );
- naturalSize.width = attr.GetWidth();
- naturalSize.height = attr.GetHeight();
- }
- }
return naturalSize;
}
* @return a pointer to a newly created object.
*/
static ImagePtr New( const std::string& filename,
- const Dali::ImageAttributes& attributes=Dali::ImageAttributes::DEFAULT_ATTRIBUTES,
+ const Dali::ImageAttributes& attributes,
LoadPolicy loadPol=ImageLoadPolicyDefault,
ReleasePolicy releasePol=ImageReleasePolicyDefault );
protected:
unsigned int mWidth;
unsigned int mHeight;
- bool mNaturalSizeSet;
ResourceTicketPtr mTicket;
ImageFactoryCache::RequestPtr mRequest; ///< contains the initially requested attributes for image. Request is reissued when memory was released.
loadedAttrs.SetSize( closestSize );
mWidth = closestSize.width;
mHeight = closestSize.height;
- mNaturalSizeSet = true;
Integration::BitmapResourceType resourceType( loadedAttrs );
}
}
-NinePatchImage* NinePatchImage::GetNinePatchImage( Image* image)
+NinePatchImage* NinePatchImage::DownCast( Image* image)
{
return dynamic_cast<NinePatchImage*>(image);
}
* @return A pointer to the 9 patch image object, or NULL
* if the conversion is not possible.
*/
- static NinePatchImage* GetNinePatchImage( Image* image);
+ static NinePatchImage* DownCast( Image* image);
protected:
ImageActor ImageActor::New()
{
- // empty image
- Internal::ImageActorPtr internal = Internal::ImageActor::New(NULL);
- return ImageActor(internal.Get());
+ Internal::ImageActorPtr internal = Internal::ImageActor::New();
+ return ImageActor( internal.Get() );
}
ImageActor ImageActor::New(Image image)
{
- Internal::ImageActorPtr internal;
- if (image)
- {
- internal = Internal::ImageActor::New(&GetImplementation(image));
- }
- else
- {
- // empty image
- internal = Internal::ImageActor::New(NULL);
- }
+ ImageActor actor = ImageActor::New();
+ actor.SetImage( image );
- return ImageActor(internal.Get());
+ return actor;
}
ImageActor ImageActor::New(Image image, PixelArea pixelArea)
{
- Internal::ImageActorPtr internal;
- if (image)
- {
- internal = Internal::ImageActor::New(&GetImplementation(image), pixelArea);
- }
- else
- {
- // empty image
- internal = Internal::ImageActor::New(NULL, pixelArea);
- }
+ ImageActor actor = ImageActor::New();
+ actor.SetImage( image );
+ actor.SetPixelArea( pixelArea );
- return ImageActor(internal.Get());
+ return actor;
}
ImageActor ImageActor::DownCast( BaseHandle handle )
void ImageActor::SetImage(Image image)
{
- if (image)
- {
- GetImplementation(*this).SetImage(&GetImplementation(image));
- }
- else
+ Internal::ImagePtr imagePtr;
+ if( image )
{
- GetImplementation(*this).SetImage(NULL);
+ imagePtr = &GetImplementation(image);
}
+ GetImplementation(*this).SetImage( imagePtr );
}
Image ImageActor::GetImage()
{
- return GetImplementation(*this).GetImage();
+ Internal::ImagePtr imagePtr( GetImplementation(*this).GetImage() );
+ return Dali::Image( imagePtr.Get() );
}
void ImageActor::SetToNaturalSize()
return GetImplementation(*this).GetNinePatchBorder();
}
-void ImageActor::SetFadeIn(bool enableFade)
-{
- GetImplementation(*this).SetFadeIn(enableFade);
-}
-
-bool ImageActor::GetFadeIn() const
-{
- return GetImplementation(*this).GetFadeIn();
-}
-
-void ImageActor::SetFadeInDuration(float durationSeconds)
-{
- GetImplementation(*this).SetFadeInDuration(durationSeconds);
-}
-
-float ImageActor::GetFadeInDuration() const
-{
- return GetImplementation(*this).GetFadeInDuration();
-}
-
-Vector2 ImageActor::GetCurrentImageSize() const
-{
- return GetImplementation(*this).GetCurrentImageSize();
-}
-
ImageActor::ImageActor(Internal::ImageActor* internal)
: RenderableActor(internal)
{
// Default Properties additional to RenderableActor
static const Property::Index PIXEL_AREA; ///< name "pixel-area", type RECTANGLE
- static const Property::Index FADE_IN; ///< name "fade-in", type BOOLEAN
- static const Property::Index FADE_IN_DURATION; ///< name "fade-in-duration", type FLOAT
static const Property::Index STYLE; ///< name "style", type STRING
static const Property::Index BORDER; ///< name "border", type VECTOR4
static const Property::Index IMAGE; ///< name "image", type MAP {"filename":"", "load-policy":...}
* @brief Create a image actor object.
*
* The actor will take the image's natural size unless a custom size
- * is chosen, e.g. via Actor:SetSize()
- * @pre image must be initialized.
+ * is chosen, e.g. via Actor:SetSize().
+ * If the handle is empty, ImageActor will display nothing
+ * @pre ImageActor must be initialized.
* @param[in] image The image to display.
* @return A handle to a newly allocated actor.
*/
/**
* @brief Create a image actor object.
*
- * When the image is loaded the actor's size will reset to the pixelArea,
- * unless a custom size was chosen, e.g. via Actor:SetSize().
- * @pre image must be initialized.
+ * The actor will take the image's natural size unless a custom size
+ * is chosen, e.g. via Actor:SetSize()
+ * If the handle is empty, ImageActor will display nothing
+ * @pre ImageActor must be initialized.
* @param [in] image The image to display.
* @param [in] pixelArea The area of the image to display.
* This in pixels, relative to the top-left (0,0) of the image.
/**
* @brief Set the image rendered by the actor.
+ * Set the image rendered by the actor.
+ * If actor was already displaying a different image, the old image is dropped and actor may
+ * temporarily display nothing. Setting an empty image (handle) causes the current image to be
+ * dropped and actor displays nothing.
+ * The actor will take the image's natural size unless a custom size
+ * is chosen, e.g. via Actor:SetSize()
*
- * When the image is loaded the actor's size will be reset to the image size,
- * unless a custom size was chosen, e.g. via Actor:SetSize() or a pixel area
- * was set.
- * @note The old image will continue to be displayed until the given image has loaded.
- * @pre image must be initialized.
+ * @pre ImageActor must be initialized.
* @param [in] image The image to display.
*/
void SetImage(Image image);
/**
- * @brief Retrieve the image rendered by the actor's attachment.
+ * @brief Retrieve the image rendered by the actor.
*
+ * If no image is assigned, an empty handle is returned
* @return The image.
*/
Image GetImage();
*/
Vector4 GetNinePatchBorder() const;
- /**
- * @brief Set whether the image should gradually fade in when first rendered.
- *
- * @pre image must be initialized.
- * @param [in] enableFade True if the image should fade in.
- */
- void SetFadeIn(bool enableFade);
-
- /**
- * @brief Query whether the image will gradually fade in when first rendered.
- *
- * @pre image must be initialized.
- * @return True if the image will fade in.
- */
- bool GetFadeIn() const;
-
- /**
- * @brief Set the duration of the fade-in effect; the default is 1 second.
- *
- * @pre image must be initialized.
- * @param [in] durationSeconds The duration in seconds.
- */
- void SetFadeInDuration(float durationSeconds);
-
- /**
- * @brief Retrieve the duration of the fade-in effect.
- *
- * @pre image must be initialized.
- * @return The duration in seconds.
- */
- float GetFadeInDuration() const;
-
- /**
- * @brief Retrieve the size of the displayed image within the image actor.
- *
- * The size of the image may be different to that of the image actor
- * size depending on the geometry scaling used.
- * @pre image must be initialized.
- * @return The actual size of the image shown.
- * @note If a pixel area is set then this returns the size of the pixel area shown.
- */
- Vector2 GetCurrentImageSize() const;
-
public: // Not intended for application developers
explicit DALI_INTERNAL ImageActor(Internal::ImageActor*);
Image Image::New(const std::string& filename)
{
- Internal::ImagePtr internal = Internal::Image::New(filename);
+ Internal::ImagePtr internal = Internal::Image::New( filename,
+ Dali::ImageAttributes::DEFAULT_ATTRIBUTES );
return Image(internal.Get());
}
Image Image::New(const std::string& filename, LoadPolicy loadPol, ReleasePolicy releasePol)
{
- Internal::ImagePtr internal = Internal::Image::New(filename,
- Dali::ImageAttributes::DEFAULT_ATTRIBUTES,
- loadPol, releasePol);
+ Internal::ImagePtr internal = Internal::Image::New( filename,
+ Dali::ImageAttributes::DEFAULT_ATTRIBUTES,
+ loadPol, releasePol );
return Image(internal.Get());
}
/**
* @brief Returns the width of the image.
*
- * Only to be used after the image has finished loading.
- * (Ticket's LoadingSucceeded callback was called)
- * The returned value will reflect the true image dimensions once the asynchronous loading has finished.
- * Connect to SignalLoadingFinished or use GetLoadingState to make sure this value is actual.
+ * Returns either the requested width or the actual loaded width if no specific size was requested.
*
* @return width of the image in pixels.
*/
/**
* @brief Returns the height of the image.
*
- * Only to be used after the image has finished loading.
- * (Ticket's LoadingSucceeded callback was called)
- * The returned value will reflect the true image dimensions once the asynchronous loading has finished.
- * Connect to SignalLoadingFinished or use GetLoadingState to make sure this value is actual.
+ * Returns either the requested height or the actual loaded height if no specific size was requested.
*
* @return height of the image in pixels.
*/