From d297df11a47467613a6d3a38af6bd04fe8ffd360 Mon Sep 17 00:00:00 2001 From: Kimmo Hoikka Date: Tue, 2 Sep 2014 13:33:57 +0100 Subject: [PATCH] Removing unused "fade-in" and "replace image" features, stop using raw pointers and external handles for images and clean up the code Reason for removing features: When for example UI control changes style, it does not want to display the old image in new images size Fade is and replace image can be both implemented outside dali-core by connecting to the image loaded signal. [Problem] messy code, duplication of logic, unnecessary handle creation, using signals internally etc [Cause] mixing handles, intrusive pointers and raw pointers [Solution] clean up Change-Id: I79600cc53ce306f272ca6874846b5e2be0af1000 --- .../dali-internal/utc-Dali-Internal-Material.cpp | 2 +- .../utc-Dali-Internal-ResourceClient.cpp | 2 +- automated-tests/src/dali/utc-Dali-Image.cpp | 22 +- automated-tests/src/dali/utc-Dali-ImageActor.cpp | 177 +++++-------- .../actor-attachments/image-attachment-impl.cpp | 39 +-- .../actor-attachments/image-attachment-impl.h | 13 +- dali/internal/event/actors/image-actor-impl.cpp | 293 ++++----------------- dali/internal/event/actors/image-actor-impl.h | 121 ++------- dali/internal/event/images/bitmap-image-impl.cpp | 2 - .../event/images/encoded-buffer-image-impl.cpp | 1 - .../event/images/frame-buffer-image-impl.cpp | 1 - dali/internal/event/images/image-connector.cpp | 10 +- dali/internal/event/images/image-connector.h | 11 +- dali/internal/event/images/image-factory-cache.h | 2 +- dali/internal/event/images/image-impl.cpp | 99 +++---- dali/internal/event/images/image-impl.h | 3 +- .../event/images/nine-patch-image-impl.cpp | 3 +- dali/internal/event/images/nine-patch-image-impl.h | 2 +- dali/public-api/actors/image-actor.cpp | 72 ++--- dali/public-api/actors/image-actor.h | 72 ++--- dali/public-api/images/image.cpp | 9 +- dali/public-api/images/image.h | 10 +- 22 files changed, 253 insertions(+), 713 deletions(-) diff --git a/automated-tests/src/dali-internal/utc-Dali-Internal-Material.cpp b/automated-tests/src/dali-internal/utc-Dali-Internal-Material.cpp index e5643c8..f3679cc 100644 --- a/automated-tests/src/dali-internal/utc-Dali-Internal-Material.cpp +++ b/automated-tests/src/dali-internal/utc-Dali-Internal-Material.cpp @@ -198,7 +198,7 @@ Internal::ResourceTicketPtr CheckLoadBitmap(TestApplication& application, const 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(); diff --git a/automated-tests/src/dali-internal/utc-Dali-Internal-ResourceClient.cpp b/automated-tests/src/dali-internal/utc-Dali-Internal-ResourceClient.cpp index 484bb95..c93981c 100644 --- a/automated-tests/src/dali-internal/utc-Dali-Internal-ResourceClient.cpp +++ b/automated-tests/src/dali-internal/utc-Dali-Internal-ResourceClient.cpp @@ -117,7 +117,7 @@ static TestTicketLifetimeObserver testTicketLifetimeObserver; 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(); diff --git a/automated-tests/src/dali/utc-Dali-Image.cpp b/automated-tests/src/dali/utc-Dali-Image.cpp index 3e7f150..f070c16 100644 --- a/automated-tests/src/dali/utc-Dali-Image.cpp +++ b/automated-tests/src/dali/utc-Dali-Image.cpp @@ -158,6 +158,8 @@ int UtcDaliImageNewWithPolicies01(void) 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"); @@ -214,6 +216,8 @@ int UtcDaliImageNewWithPolicies02(void) 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"); @@ -422,6 +426,9 @@ int UtcDaliImageNewDistanceFieldWithPolicies02(void) { 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"); @@ -477,6 +484,8 @@ int UtcDaliImageNewDistanceFieldWithPolicies02(void) 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"); @@ -630,6 +639,9 @@ int UtcDaliImageNewDistanceFieldWithAttrandPol(void) { 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); @@ -998,13 +1010,17 @@ int UtcDaliImageDiscard01(void) 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); @@ -1025,6 +1041,7 @@ int UtcDaliImageDiscard02(void) } 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); @@ -1054,6 +1071,9 @@ int UtcDaliImageDiscard03(void) 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); diff --git a/automated-tests/src/dali/utc-Dali-ImageActor.cpp b/automated-tests/src/dali/utc-Dali-ImageActor.cpp index ad43e2e..51a428c 100644 --- a/automated-tests/src/dali/utc-Dali-ImageActor.cpp +++ b/automated-tests/src/dali/utc-Dali-ImageActor.cpp @@ -174,10 +174,10 @@ int UtcDaliImageActorPixelArea(void) 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 ); @@ -187,7 +187,7 @@ int UtcDaliImageActorGetCurrentImageSize01(void) 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); @@ -195,7 +195,7 @@ int UtcDaliImageActorGetCurrentImageSize01(void) // 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; @@ -206,15 +206,22 @@ int UtcDaliImageActorGetCurrentImageSize01(void) 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); @@ -229,7 +236,7 @@ int UtcDaliImageActorGetCurrentImageSize02(void) 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(); @@ -243,7 +250,7 @@ int UtcDaliImageActorGetCurrentImageSize02(void) 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); @@ -251,27 +258,27 @@ int UtcDaliImageActorGetCurrentImageSize02(void) // 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); @@ -281,7 +288,7 @@ int UtcDaliImageActorGetCurrentImageSize03(void) 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(); @@ -295,7 +302,7 @@ int UtcDaliImageActorGetCurrentImageSize03(void) 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); @@ -304,26 +311,27 @@ int UtcDaliImageActorGetCurrentImageSize03(void) // 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); @@ -331,7 +339,7 @@ int UtcDaliImageActorGetCurrentImageSize04(void) 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(); @@ -345,7 +353,7 @@ int UtcDaliImageActorGetCurrentImageSize04(void) 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); @@ -353,14 +361,15 @@ int UtcDaliImageActorGetCurrentImageSize04(void) // 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); @@ -370,7 +379,7 @@ int UtcDaliImageActorGetCurrentImageSize04(void) 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(); @@ -385,27 +394,28 @@ int UtcDaliImageActorGetCurrentImageSize04(void) 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); @@ -413,7 +423,7 @@ int UtcDaliImageActorGetCurrentImageSize05(void) 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(); @@ -427,14 +437,15 @@ int UtcDaliImageActorGetCurrentImageSize05(void) 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); @@ -444,7 +455,7 @@ int UtcDaliImageActorGetCurrentImageSize05(void) 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(); @@ -462,14 +473,14 @@ int UtcDaliImageActorGetCurrentImageSize05(void) 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 @@ -482,7 +493,8 @@ int UtcDaliImageActorNaturalPixelAreaSize01(void) 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); @@ -490,8 +502,7 @@ int UtcDaliImageActorNaturalPixelAreaSize01(void) 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(); @@ -505,15 +516,13 @@ int UtcDaliImageActorNaturalPixelAreaSize01(void) 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 @@ -521,14 +530,12 @@ int UtcDaliImageActorNaturalPixelAreaSize01(void) 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; } @@ -536,7 +543,7 @@ int UtcDaliImageActorNaturalPixelAreaSize01(void) 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 @@ -549,7 +556,8 @@ int UtcDaliImageActorNaturalPixelAreaSize02(void) 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); @@ -557,8 +565,7 @@ int UtcDaliImageActorNaturalPixelAreaSize02(void) 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(); @@ -572,51 +579,44 @@ int UtcDaliImageActorNaturalPixelAreaSize02(void) 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; } @@ -632,8 +632,6 @@ int UtcDaliImageActorDefaultProperties(void) std::vector 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 ); @@ -840,57 +838,6 @@ int UtcDaliImageSetNinePatchBorder(void) 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; diff --git a/dali/internal/event/actor-attachments/image-attachment-impl.cpp b/dali/internal/event/actor-attachments/image-attachment-impl.cpp index 2019bd0..8bde322 100644 --- a/dali/internal/event/actor-attachments/image-attachment-impl.cpp +++ b/dali/internal/event/actor-attachments/image-attachment-impl.cpp @@ -36,14 +36,14 @@ namespace Dali 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 @@ -52,7 +52,7 @@ ImageAttachmentPtr ImageAttachment::New( const SceneGraph::Node& parentNode, Ima return attachment; } -ImageAttachment::ImageAttachment(Stage& stage, Image* image) +ImageAttachment::ImageAttachment( Stage& stage ) : RenderableAttachment(stage), mSceneObject(NULL), mPixelArea(EMPTY_PIXEL_AREA), @@ -61,14 +61,14 @@ ImageAttachment::ImageAttachment(Stage& stage, Image* image) 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 @@ -77,26 +77,16 @@ void ImageAttachment::SetImage(Image* image) // 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) @@ -141,13 +131,8 @@ void ImageAttachment::SetNinePatchBorder(const Vector4& border, bool inPixels) 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 ); } @@ -156,8 +141,8 @@ void ImageAttachment::OnStageConnection2() 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 ); diff --git a/dali/internal/event/actor-attachments/image-attachment-impl.h b/dali/internal/event/actor-attachments/image-attachment-impl.h index d873036..5e216cd 100644 --- a/dali/internal/event/actor-attachments/image-attachment-impl.h +++ b/dali/internal/event/actor-attachments/image-attachment-impl.h @@ -51,22 +51,21 @@ public: /** * 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. @@ -138,13 +137,13 @@ private: * @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() diff --git a/dali/internal/event/actors/image-actor-impl.cpp b/dali/internal/event/actors/image-actor-impl.cpp index 03b892e..7a981f2 100644 --- a/dali/internal/event/actors/image-actor-impl.cpp +++ b/dali/internal/event/actors/image-actor-impl.cpp @@ -29,11 +29,9 @@ namespace Dali { 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 { @@ -53,8 +51,6 @@ TypeRegistration mType( typeid(Dali::ImageActor), typeid(Dali::RenderableActor), const std::string DEFAULT_IMAGE_ACTOR_PROPERTY_NAMES[] = { "pixel-area", - "fade-in", - "fade-in-duration", "style", "border", "image" @@ -64,8 +60,6 @@ const int DEFAULT_IMAGE_ACTOR_PROPERTY_COUNT = sizeof( DEFAULT_IMAGE_ACTOR_PROPE 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", @@ -96,31 +90,17 @@ std::string StyleString(const ImageActor::Style style) } } -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; } @@ -138,19 +118,35 @@ void ImageActor::OnInitialize() } } -void ImageActor::SetImage( Image* image ) +void ImageActor::SetImage( ImagePtr& image ) { - Image* currentImage = static_cast(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(); } @@ -158,24 +154,15 @@ Dali::Image ImageActor::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 @@ -194,11 +181,11 @@ void ImageActor::ClearPixelArea() if( mUsingNaturalSize ) { - Dali::Image image = mImageAttachment->GetImage(); + ImagePtr image = mImageAttachment->GetImage(); if( image ) { mInternalSetSize = true; - SetSize(GetImplementation(image).GetNaturalSize()); + SetSize( image->GetNaturalSize() ); mInternalSetSize = false; } } @@ -224,104 +211,48 @@ Vector4 ImageActor::GetNinePatchBorder() const 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; @@ -343,74 +274,10 @@ void ImageActor::OnSizeAnimation(Animation& animation, const Vector3& targetSize 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 @@ -545,16 +412,6 @@ void ImageActor::SetDefaultProperty( Property::Index index, const Property::Valu SetPixelArea(propertyValue.Get >()); break; } - case Dali::ImageActor::FADE_IN: - { - SetFadeIn(propertyValue.Get()); - break; - } - case Dali::ImageActor::FADE_IN_DURATION: - { - SetFadeInDuration(propertyValue.Get()); - break; - } case Dali::ImageActor::STYLE: { SetStyle(StyleEnum(propertyValue.Get())); @@ -570,7 +427,8 @@ void ImageActor::SetDefaultProperty( Property::Index index, const Property::Valu Dali::Image img = Scripting::NewImage( propertyValue ); if(img) { - SetImage( &GetImplementation(img) ); + ImagePtr image( &GetImplementation(img) ); + SetImage( image ); } else { @@ -605,16 +463,6 @@ Property::Value ImageActor::GetDefaultProperty( Property::Index index ) const 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()); @@ -628,7 +476,7 @@ Property::Value ImageActor::GetDefaultProperty( Property::Index index ) const 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; } @@ -643,47 +491,6 @@ Property::Value ImageActor::GetDefaultProperty( Property::Index index ) const 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 diff --git a/dali/internal/event/actors/image-actor-impl.h b/dali/internal/event/actors/image-actor-impl.h index beac18d..fb6aaca 100644 --- a/dali/internal/event/actors/image-actor-impl.h +++ b/dali/internal/event/actors/image-actor-impl.h @@ -48,7 +48,7 @@ class Image; * 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: @@ -56,24 +56,10 @@ 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 @@ -81,19 +67,16 @@ public: 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() @@ -101,38 +84,32 @@ public: 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; @@ -147,40 +124,11 @@ public: 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 /** @@ -240,18 +188,6 @@ private: // From RenderableActor */ 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: /** @@ -268,9 +204,8 @@ private: /** * Helper to set the actor to the image's natural size - * @param image that is used */ - void SetNaturalSize( Image& image ); + void SetNaturalSize(); /** * From Actor. @@ -293,37 +228,13 @@ private: */ 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 diff --git a/dali/internal/event/images/bitmap-image-impl.cpp b/dali/internal/event/images/bitmap-image-impl.cpp index 96e1eff..20773b7 100644 --- a/dali/internal/event/images/bitmap-image-impl.cpp +++ b/dali/internal/event/images/bitmap-image-impl.cpp @@ -59,7 +59,6 @@ BitmapImage::BitmapImage(unsigned int width, unsigned int height, Pixel::Format mResourceClient = &tls.GetResourceClient(); mWidth = width; mHeight = height; - mNaturalSizeSet = true; const ImageTicketPtr& t = mResourceClient->AllocateBitmapImage(width, height, width, height, pixelformat); mTicket = t.Get(); @@ -75,7 +74,6 @@ BitmapImage::BitmapImage(PixelBuffer* pixBuf, unsigned int width, unsigned int h 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(); diff --git a/dali/internal/event/images/encoded-buffer-image-impl.cpp b/dali/internal/event/images/encoded-buffer-image-impl.cpp index 015165c..0d3faf8 100644 --- a/dali/internal/event/images/encoded-buffer-image-impl.cpp +++ b/dali/internal/event/images/encoded-buffer-image-impl.cpp @@ -63,7 +63,6 @@ EncodedBufferImagePtr EncodedBufferImage::New( const uint8_t * const encodedImag 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 ); diff --git a/dali/internal/event/images/frame-buffer-image-impl.cpp b/dali/internal/event/images/frame-buffer-image-impl.cpp index 08ecf50..8735abb 100644 --- a/dali/internal/event/images/frame-buffer-image-impl.cpp +++ b/dali/internal/event/images/frame-buffer-image-impl.cpp @@ -65,7 +65,6 @@ FrameBufferImage::FrameBufferImage(unsigned int width, unsigned int height, Pixe { mWidth = width; mHeight = height; - mNaturalSizeSet = true; } diff --git a/dali/internal/event/images/image-connector.cpp b/dali/internal/event/images/image-connector.cpp index f043543..20ffdef 100644 --- a/dali/internal/event/images/image-connector.cpp +++ b/dali/internal/event/images/image-connector.cpp @@ -35,14 +35,14 @@ ImageConnector::~ImageConnector() { } -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 ) @@ -50,7 +50,7 @@ void ImageConnector::Set( Image* image, bool onStage ) mImage->Disconnect(); } - mImage.Reset(image); + mImage = image; // Connect to new image if ( mImage && onStage ) diff --git a/dali/internal/event/images/image-connector.h b/dali/internal/event/images/image-connector.h index 328f67b..a778ed8 100644 --- a/dali/internal/event/images/image-connector.h +++ b/dali/internal/event/images/image-connector.h @@ -48,17 +48,17 @@ public: ~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. @@ -78,6 +78,7 @@ private: const ImageConnector& operator=( const ImageConnector& ptr ); ///< copy assignment operator, not defined ImagePtr mImage; ///< intrusive pointer to the Image. ImageConnector owns this. + }; } // namespace Internal diff --git a/dali/internal/event/images/image-factory-cache.h b/dali/internal/event/images/image-factory-cache.h index 47e673d..f719d81 100644 --- a/dali/internal/event/images/image-factory-cache.h +++ b/dali/internal/event/images/image-factory-cache.h @@ -99,7 +99,7 @@ public: void StopLifetimeObservation(); protected: - ~Request(); + virtual ~Request(); private: Request(); ///< not defined diff --git a/dali/internal/event/images/image-impl.cpp b/dali/internal/event/images/image-impl.cpp index e52ead8..2db8661 100644 --- a/dali/internal/event/images/image-impl.cpp +++ b/dali/internal/event/images/image-impl.cpp @@ -57,7 +57,6 @@ Dali::SignalConnectorType signalConnector2(mType, Dali::Image::SIGNAL_IMAGE_UPLO Image::Image( LoadPolicy loadPol, ReleasePolicy releasePol ) : mWidth(0), mHeight(0), - mNaturalSizeSet(false), mLoadPolicy(loadPol), mReleasePolicy(releasePol), mConnectionCount(0), @@ -74,17 +73,39 @@ ImagePtr Image::New() 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 ) { @@ -93,13 +114,10 @@ ImagePtr Image::New( const std::string& filename, const Dali::ImageAttributes& a 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 ) @@ -111,7 +129,6 @@ ImagePtr Image::New( NativeImage& nativeImg, LoadPolicy loadPol, ReleasePolicy r image->mWidth = nativeImg.GetWidth(); image->mHeight = nativeImg.GetHeight(); - image->mNaturalSizeSet = true; const ResourceTicketPtr& ticket = resourceClient.AddNativeImage( nativeImg ); DALI_ASSERT_DEBUG( dynamic_cast( ticket.Get() ) && "Resource ticket not ImageTicket subclass for image resource.\n" ); @@ -201,11 +218,6 @@ void Image::ResourceLoadingFailed(const ResourceTicket& ticket) void Image::ResourceLoadingSucceeded(const ResourceTicket& ticket) { - // Update size with actual loaded size - const ImageTicket* imageTicket = static_cast(&ticket); - mWidth = imageTicket->GetWidth(); - mHeight = imageTicket->GetHeight(); - mNaturalSizeSet = true; mLoadingFinishedV2.Emit( Dali::Image( this ) ); } @@ -226,66 +238,17 @@ void Image::ResourceSavingFailed( const ResourceTicket& ticket ) 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; } diff --git a/dali/internal/event/images/image-impl.h b/dali/internal/event/images/image-impl.h index d05918e..45e72ea 100644 --- a/dali/internal/event/images/image-impl.h +++ b/dali/internal/event/images/image-impl.h @@ -86,7 +86,7 @@ public: * @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 ); @@ -257,7 +257,6 @@ private: 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. diff --git a/dali/internal/event/images/nine-patch-image-impl.cpp b/dali/internal/event/images/nine-patch-image-impl.cpp index a1762b1..b2876a5 100644 --- a/dali/internal/event/images/nine-patch-image-impl.cpp +++ b/dali/internal/event/images/nine-patch-image-impl.cpp @@ -157,7 +157,6 @@ NinePatchImage::NinePatchImage( const std::string& filename, const Dali::ImageAt loadedAttrs.SetSize( closestSize ); mWidth = closestSize.width; mHeight = closestSize.height; - mNaturalSizeSet = true; Integration::BitmapResourceType resourceType( loadedAttrs ); @@ -173,7 +172,7 @@ NinePatchImage::NinePatchImage( const std::string& filename, const Dali::ImageAt } } -NinePatchImage* NinePatchImage::GetNinePatchImage( Image* image) +NinePatchImage* NinePatchImage::DownCast( Image* image) { return dynamic_cast(image); } diff --git a/dali/internal/event/images/nine-patch-image-impl.h b/dali/internal/event/images/nine-patch-image-impl.h index ef12156..74febe3 100644 --- a/dali/internal/event/images/nine-patch-image-impl.h +++ b/dali/internal/event/images/nine-patch-image-impl.h @@ -82,7 +82,7 @@ public: * @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: diff --git a/dali/public-api/actors/image-actor.cpp b/dali/public-api/actors/image-actor.cpp index aeaa2bb..b3984cc 100644 --- a/dali/public-api/actors/image-actor.cpp +++ b/dali/public-api/actors/image-actor.cpp @@ -32,41 +32,25 @@ ImageActor::ImageActor() 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 ) @@ -98,19 +82,18 @@ ImageActor& ImageActor::operator=(BaseHandle::NullType* rhs) 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() @@ -158,31 +141,6 @@ Vector4 ImageActor::GetNinePatchBorder() const 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) { diff --git a/dali/public-api/actors/image-actor.h b/dali/public-api/actors/image-actor.h index 918535d..463513e 100644 --- a/dali/public-api/actors/image-actor.h +++ b/dali/public-api/actors/image-actor.h @@ -64,8 +64,6 @@ public: // 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":...} @@ -158,8 +156,9 @@ public: * @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. */ @@ -168,9 +167,10 @@ public: /** * @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. @@ -223,19 +223,22 @@ public: /** * @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(); @@ -322,49 +325,6 @@ public: */ 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*); diff --git a/dali/public-api/images/image.cpp b/dali/public-api/images/image.cpp index e087293..41079ca 100644 --- a/dali/public-api/images/image.cpp +++ b/dali/public-api/images/image.cpp @@ -70,15 +70,16 @@ Image& Image::operator=(BaseHandle::NullType* rhs) 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()); } diff --git a/dali/public-api/images/image.h b/dali/public-api/images/image.h index b941759..fb4f68b 100644 --- a/dali/public-api/images/image.h +++ b/dali/public-api/images/image.h @@ -331,10 +331,7 @@ public: /** * @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. */ @@ -343,10 +340,7 @@ public: /** * @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. */ -- 2.7.4