X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fcontrols%2Fimage-view%2Fimage-view-impl.cpp;h=29442fd53e01d062661cab8daf61b76760ef12a4;hp=c7f1d8c289175b054fe285dada0afdea2535c514;hb=dee3ce49e3e1e46c82f024283b51d85734cbb3ff;hpb=6da8438e9ac7350d9cc6f69b35cbcc4ab3987da1 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 c7f1d8c..29442fd 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 { @@ -33,15 +36,32 @@ BaseHandle Create() // Setup properties, signals and actions using the type-registry. 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() + +void SetDefaultTransformMap( Property::Map& transformMap ) +{ + transformMap.Clear(); + transformMap + .Add( Toolkit::Visual::DevelProperty::Transform::Property::OFFSET, Vector2(0.0f, 0.0f) ) + .Add( Toolkit::Visual::DevelProperty::Transform::Property::SIZE, Vector2(1.0f, 1.0f) ) + .Add( Toolkit::Visual::DevelProperty::Transform::Property::ORIGIN, Toolkit::Align::CENTER ) + .Add( Toolkit::Visual::DevelProperty::Transform::Property::ANCHOR_POINT, Toolkit::Align::CENTER ) + .Add( Toolkit::Visual::DevelProperty::Transform::Property::OFFSET_SIZE_MODE, Vector4::ZERO ); + +} + } // anonymous namespace using namespace Dali; ImageView::ImageView() -: Control( ControlBehaviour( ACTOR_BEHAVIOUR_NONE ) ) +: Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ) { } @@ -66,69 +86,130 @@ Toolkit::ImageView ImageView::New() void ImageView::SetImage( Image image ) { - if( mImage != 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; - Actor self = Self(); - Toolkit::RendererFactory::Get().ResetRenderer( mRenderer, self, image ); + mVisual = Toolkit::VisualFactory::Get().CreateVisual( image ); + RegisterVisual( Toolkit::ImageView::Property::IMAGE, mVisual ); mImageSize = image ? ImageDimensions( image.GetWidth(), image.GetHeight() ) : ImageDimensions( 0, 0 ); + + RelayoutRequest(); } } void ImageView::SetImage( Property::Map map ) { + mUrl.clear(); + mImage.Reset(); mPropertyMap = map; - Actor self = Self(); - Toolkit::RendererFactory::Get().ResetRenderer( mRenderer, self, mPropertyMap ); + mVisual = Toolkit::VisualFactory::Get().CreateVisual( mPropertyMap ); + RegisterVisual( Toolkit::ImageView::Property::IMAGE, mVisual ); - int width = 0; Property::Value* widthValue = mPropertyMap.Find( "width" ); if( widthValue ) { - widthValue->Get( width ); + int width; + if( widthValue->Get( width ) ) + { + mImageSize = ImageDimensions( width, mImageSize.GetHeight() ); + } } - int height = 0; Property::Value* heightValue = mPropertyMap.Find( "height" ); if( heightValue ) { - heightValue->Get( height ); + int height; + if( heightValue->Get( height ) ) + { + mImageSize = ImageDimensions( mImageSize.GetWidth(), height ); + } } - mImageSize = ImageDimensions( width, height ); + RelayoutRequest(); } -void ImageView::SetImage( const std::string& url ) +void ImageView::SetImage( const std::string& url, ImageDimensions size ) { - if( mUrl != url ) + 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(); mUrl = url; - Actor self = Self(); - Toolkit::RendererFactory::Get().ResetRenderer( mRenderer, self, mUrl ); + if( size.GetWidth() != 0u && size.GetHeight() != 0u ) + { + mImageSize = size; + } + + mVisual = Toolkit::VisualFactory::Get().CreateVisual( url, size ); + RegisterVisual( Toolkit::ImageView::Property::IMAGE, mVisual ); - mImageSize = ResourceImage::GetImageSize( mUrl ); + // This transform fills the control + // Should provide a transform that handles aspect ratio according to image size + Property::Map transformMap; + SetDefaultTransformMap( transformMap ); + mVisual.SetTransformAndSize( transformMap, mSizeSet ); + + RelayoutRequest(); + } +} + +Image ImageView::GetImage() const +{ + return mImage; +} + +void ImageView::EnablePreMultipliedAlpha( bool preMultipled ) +{ + if( mVisual ) + { + Toolkit::GetImplementation( mVisual ).EnablePreMultipliedAlpha( preMultipled ); + } +} + +bool ImageView::IsPreMultipliedAlphaEnabled() const +{ + if( mVisual ) + { + return Toolkit::GetImplementation( mVisual ).IsPreMultipliedAlphaEnabled(); + } + return false; +} + +void ImageView::SetDepthIndex( int depthIndex ) +{ + if( mVisual ) + { + mVisual.SetDepthIndex( depthIndex ); } } Vector3 ImageView::GetNaturalSize() { - Vector3 size; + if( mVisual ) + { + Vector2 rendererNaturalSize; + mVisual.GetNaturalSize( rendererNaturalSize ); + return Vector3( rendererNaturalSize ); + } + 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 ) { + size.z = std::min(size.x, size.y); return size; } else @@ -162,34 +243,29 @@ float ImageView::GetWidthForHeight( float height ) } } + /////////////////////////////////////////////////////////// // // Private methods // -void ImageView::OnStageConnection( int depth ) +void ImageView::OnSizeSet( const Vector3& targetSize ) { - Control::OnStageConnection( depth ); + Control::OnSizeSet( targetSize ); + mSizeSet = targetSize; - if( mRenderer ) + if( mVisual ) { - CustomActor self = Self(); - mRenderer.SetOnStage( self ); - } -} + Vector2 size( targetSize ); -void ImageView::OnStageDisconnection() -{ - if( mRenderer ) - { - CustomActor self = Self(); - mRenderer.SetOffStage( self ); + // This transform fills the control + // Should provide a transform that handles aspect ratio according to image size + Property::Map transformMap; + SetDefaultTransformMap( transformMap ); + mVisual.SetTransformAndSize( transformMap, size ); } - - Control::OnStageDisconnection(); } - /////////////////////////////////////////////////////////// // // Properties @@ -201,25 +277,67 @@ void ImageView::SetProperty( BaseObject* object, Property::Index index, const Pr if ( imageView ) { + ImageView& impl = GetImpl( imageView ); switch ( index ) { - case Toolkit::ImageView::Property::IMAGE: + case Toolkit::ImageView::Property::RESOURCE_URL: { std::string imageUrl; if( value.Get( imageUrl ) ) { - ImageView& impl = GetImpl( imageView ); - impl.SetImage( imageUrl ); + impl.SetImage( imageUrl, ImageDimensions() ); } + break; + } + case Toolkit::ImageView::Property::IMAGE: + { + std::string imageUrl; + Property::Map* map; + if( value.Get( imageUrl ) ) + { + 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::VisualProperty::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; } } @@ -234,11 +352,20 @@ Property::Value ImageView::GetProperty( BaseObject* object, Property::Index prop if ( imageview ) { + ImageView& impl = GetImpl( imageview ); switch ( propertyIndex ) { + case Toolkit::ImageView::Property::RESOURCE_URL: + { + if ( !impl.mUrl.empty() ) + { + value = impl.mUrl; + } + break; + } + case Toolkit::ImageView::Property::IMAGE: { - ImageView& impl = GetImpl( imageview ); if ( !impl.mUrl.empty() ) { value = impl.mUrl; @@ -255,6 +382,12 @@ Property::Value ImageView::GetProperty( BaseObject* object, Property::Index prop } break; } + + case Toolkit::ImageView::Property::PRE_MULTIPLIED_ALPHA: + { + value = impl.IsPreMultipliedAlphaEnabled(); + break; + } } }