X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fcontrols%2Fimage-view%2Fimage-view-impl.cpp;h=80f1ee472d562a851a80743484d778d427ea6a9a;hb=abc25cd0d8c1551e54f6ac0e2c612300f650d2a5;hp=e98f539edff9b82e36f4f30c2fd45d87174de186;hpb=a5fd3c7972dade609f0a66a3c4fca27d33ee7454;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git diff --git a/dali-toolkit/internal/controls/image-view/image-view-impl.cpp b/dali-toolkit/internal/controls/image-view/image-view-impl.cpp index e98f539..80f1ee4 100644 --- a/dali-toolkit/internal/controls/image-view/image-view-impl.cpp +++ b/dali-toolkit/internal/controls/image-view/image-view-impl.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014 Samsung Electronics Co., Ltd. +// Copyright (c) 2016 Samsung Electronics Co., Ltd. // CLASS HEADER #include "image-view-impl.h" @@ -6,13 +6,16 @@ // EXTERNAL INCLUDES #include #include -#include +#include #include // INTERNAL INCLUDES #include -#include -#include +#include +#include +#include +#include +#include namespace Dali { @@ -35,6 +38,9 @@ BaseHandle Create() DALI_TYPE_REGISTRATION_BEGIN( Toolkit::ImageView, Toolkit::Control, Create ); DALI_PROPERTY_REGISTRATION( Toolkit, ImageView, "resourceUrl", STRING, RESOURCE_URL ) DALI_PROPERTY_REGISTRATION( Toolkit, ImageView, "image", MAP, IMAGE ) +DALI_PROPERTY_REGISTRATION( Toolkit, ImageView, "preMultipliedAlpha", BOOLEAN, PRE_MULTIPLIED_ALPHA ) + +DALI_ANIMATABLE_PROPERTY_REGISTRATION_WITH_DEFAULT( Toolkit, ImageView, "pixelArea", Vector4(0.f, 0.f, 1.f, 1.f), PIXEL_AREA ) DALI_TYPE_REGISTRATION_END() } // anonymous namespace @@ -42,7 +48,7 @@ DALI_TYPE_REGISTRATION_END() using namespace Dali; ImageView::ImageView() -: Control( ControlBehaviour( ACTOR_BEHAVIOUR_NONE ) ) +: Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ) { } @@ -67,111 +73,91 @@ Toolkit::ImageView ImageView::New() void ImageView::SetImage( Image image ) { - if( ( mImage != image ) || - ! mUrl.empty() || // If we're changing from a URL type to an Image type - ! mPropertyMap.Empty() ) // If we're changing from a property map type to an Image type - { - mUrl.clear(); - mPropertyMap.Clear(); - - mImage = image; + // Don't bother comparing if we had a visual previously, just drop old visual and create new one + mImage = image; + mUrl.clear(); + mPropertyMap.Clear(); - Actor self = Self(); - Toolkit::RendererFactory::Get().ResetRenderer( mRenderer, self, image ); - mImageSize = image ? ImageDimensions( image.GetWidth(), image.GetHeight() ) : ImageDimensions( 0, 0 ); + mVisual = Toolkit::VisualFactory::Get().CreateVisual( image ); + RegisterVisual( Toolkit::ImageView::Property::IMAGE, mVisual ); - RelayoutRequest(); - } + RelayoutRequest(); } -void ImageView::SetImage( Property::Map map ) +void ImageView::SetImage( const Property::Map& map ) { + // Comparing a property map is too expensive so just creating a new visual + mPropertyMap = map; mUrl.clear(); mImage.Reset(); - mPropertyMap = map; - Actor self = Self(); - Toolkit::RendererFactory::Get().ResetRenderer( mRenderer, self, mPropertyMap ); - - Property::Value* widthValue = mPropertyMap.Find( "width" ); - if( widthValue ) - { - int width; - if( widthValue->Get( width ) ) - { - mImageSize = ImageDimensions( width, mImageSize.GetHeight() ); - } - } - - Property::Value* heightValue = mPropertyMap.Find( "height" ); - if( heightValue ) - { - int height; - if( heightValue->Get( height ) ) - { - mImageSize = ImageDimensions( mImageSize.GetWidth(), height ); - } - } + mVisual = Toolkit::VisualFactory::Get().CreateVisual( mPropertyMap ); + RegisterVisual( Toolkit::ImageView::Property::IMAGE, mVisual ); RelayoutRequest(); } void ImageView::SetImage( const std::string& url, ImageDimensions size ) { - if( ( mUrl != url ) || - mImage || // If we're changing from an Image type to a URL type - ! mPropertyMap.Empty() ) // If we're changing from a property map type to a URL type - { - mImage.Reset(); - mPropertyMap.Clear(); + // Don't bother comparing if we had a visual previously, just drop old visual and create new one + mUrl = url; + mImage.Reset(); + mPropertyMap.Clear(); - mUrl = url; + mVisual = Toolkit::VisualFactory::Get().CreateVisual( url, size ); + RegisterVisual( Toolkit::ImageView::Property::IMAGE, mVisual ); - if( size.GetWidth() == 0u && size.GetHeight() == 0u ) - { - mImageSize = ResourceImage::GetImageSize( mUrl ); - } - else - { - mImageSize = size; - } + RelayoutRequest(); +} - Actor self = Self(); - Toolkit::RendererFactory::Get().ResetRenderer( mRenderer, self, mUrl, mImageSize ); +Image ImageView::GetImage() const +{ + return mImage; +} - RelayoutRequest(); +void ImageView::EnablePreMultipliedAlpha( bool preMultipled ) +{ + if( mVisual ) + { + Toolkit::GetImplementation( mVisual ).EnablePreMultipliedAlpha( preMultipled ); } } -void ImageView::SetDepthIndex( int depthIndex ) +bool ImageView::IsPreMultipliedAlphaEnabled() const { - mRenderer.SetDepthIndex( depthIndex ); + if( mVisual ) + { + return Toolkit::GetImplementation( mVisual ).IsPreMultipliedAlphaEnabled(); + } + return false; } -Vector3 ImageView::GetNaturalSize() +void ImageView::SetDepthIndex( int depthIndex ) { - Vector3 size; - - size.x = mImageSize.GetWidth(); - size.y = mImageSize.GetHeight(); - size.z = std::min(size.x, size.y); - - if( size.x > 0 && size.y > 0 ) + if( mVisual ) { - return size; + mVisual.SetDepthIndex( depthIndex ); } - else +} + +Vector3 ImageView::GetNaturalSize() +{ + if( mVisual ) { - // if no image then use Control's natural size - return Control::GetNaturalSize(); + Vector2 rendererNaturalSize; + mVisual.GetNaturalSize( rendererNaturalSize ); + return Vector3( rendererNaturalSize ); } + + // if no visual then use Control's natural size + return Control::GetNaturalSize(); } float ImageView::GetHeightForWidth( float width ) { - if( mImageSize.GetWidth() > 0 && mImageSize.GetHeight() > 0 ) + if( mVisual ) { - return GetHeightForWidthBase( width ); + return mVisual.GetHeightForWidth( width ); } else { @@ -181,9 +167,9 @@ float ImageView::GetHeightForWidth( float width ) float ImageView::GetWidthForHeight( float height ) { - if( mImageSize.GetWidth() > 0 && mImageSize.GetHeight() > 0 ) + if( mVisual ) { - return GetWidthForHeightBase( height ); + return mVisual.GetWidthForHeight( height ); } else { @@ -191,34 +177,18 @@ float ImageView::GetWidthForHeight( float height ) } } -/////////////////////////////////////////////////////////// -// -// Private methods -// - -void ImageView::OnStageConnection( int depth ) +void ImageView::OnRelayout( const Vector2& size, RelayoutContainer& container ) { - Control::OnStageConnection( depth ); - - if( mRenderer ) - { - CustomActor self = Self(); - mRenderer.SetOnStage( self ); - } -} + Control::OnRelayout( size, container ); -void ImageView::OnStageDisconnection() -{ - if( mRenderer ) + if( mVisual ) { - CustomActor self = Self(); - mRenderer.SetOffStage( self ); + // Pass in an empty map which uses default transform values meaning our visual fills the control + // Should provide a transform that handles aspect ratio according to image size + mVisual.SetTransformAndSize( Property::Map(), size ); } - - Control::OnStageDisconnection(); } - /////////////////////////////////////////////////////////// // // Properties @@ -230,6 +200,7 @@ void ImageView::SetProperty( BaseObject* object, Property::Index index, const Pr if ( imageView ) { + ImageView& impl = GetImpl( imageView ); switch ( index ) { case Toolkit::ImageView::Property::RESOURCE_URL: @@ -237,7 +208,7 @@ void ImageView::SetProperty( BaseObject* object, Property::Index index, const Pr std::string imageUrl; if( value.Get( imageUrl ) ) { - GetImpl( imageView ).SetImage( imageUrl, ImageDimensions() ); + impl.SetImage( imageUrl, ImageDimensions() ); } break; } @@ -245,20 +216,51 @@ void ImageView::SetProperty( BaseObject* object, Property::Index index, const Pr case Toolkit::ImageView::Property::IMAGE: { std::string imageUrl; + Property::Map* map; if( value.Get( imageUrl ) ) { - ImageView& impl = GetImpl( imageView ); impl.SetImage( imageUrl, ImageDimensions() ); } - // if its not a string then get a Property::Map from the property if possible. - Property::Map map; - if( value.Get( map ) ) + else { - ImageView& impl = GetImpl( imageView ); - impl.SetImage( map ); + map = value.GetMap(); + if( map ) + { + Property::Value* shaderValue = map->Find( Toolkit::DevelVisual::Property::SHADER, CUSTOM_SHADER ); + // set image only if property map contains image information other than custom shader + if( map->Count() > 1u || !shaderValue ) + { + impl.SetImage( *map ); + } + // the property map contains only the custom shader + else if( ( impl.mVisual )&&( map->Count() == 1u )&&( shaderValue ) ) + { + Property::Map* shaderMap = shaderValue->GetMap(); + if( shaderMap ) + { + Internal::Visual::Base& visual = Toolkit::GetImplementation( impl.mVisual ); + visual.SetCustomShader( *shaderMap ); + if( imageView.OnStage() ) + { + // force to create new core renderer to use the newly set shader + visual.SetOffStage( imageView ); + visual.SetOnStage( imageView ); + } + } + } + } } + break; + } + case Toolkit::ImageView::Property::PRE_MULTIPLIED_ALPHA: + { + bool isPre; + if( value.Get( isPre ) ) + { + impl.EnablePreMultipliedAlpha( isPre ); + } break; } } @@ -273,11 +275,11 @@ Property::Value ImageView::GetProperty( BaseObject* object, Property::Index prop if ( imageview ) { + ImageView& impl = GetImpl( imageview ); switch ( propertyIndex ) { case Toolkit::ImageView::Property::RESOURCE_URL: { - ImageView& impl = GetImpl( imageview ); if ( !impl.mUrl.empty() ) { value = impl.mUrl; @@ -287,7 +289,6 @@ Property::Value ImageView::GetProperty( BaseObject* object, Property::Index prop case Toolkit::ImageView::Property::IMAGE: { - ImageView& impl = GetImpl( imageview ); if ( !impl.mUrl.empty() ) { value = impl.mUrl; @@ -304,6 +305,12 @@ Property::Value ImageView::GetProperty( BaseObject* object, Property::Index prop } break; } + + case Toolkit::ImageView::Property::PRE_MULTIPLIED_ALPHA: + { + value = impl.IsPreMultipliedAlphaEnabled(); + break; + } } }