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=edff0e3402a84ea3815f3482e7b6c6a2cf93eab9;hp=720ef210802d9bddf52d50692f178aae8a396569;hb=4019119f94f02948f2dc26a8495d44d1143c684a;hpb=5daf80c30657d359f5eb95a00dc9fe7c50180cda 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 720ef21..edff0e3 100755 --- a/dali-toolkit/internal/controls/image-view/image-view-impl.cpp +++ b/dali-toolkit/internal/controls/image-view/image-view-impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. + * Copyright (c) 2019 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -64,7 +64,9 @@ DALI_TYPE_REGISTRATION_END() using namespace Dali; ImageView::ImageView() -: Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ) +: Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ), + mImageSize(), + mImageVisualPaddingSetByTransform( false ) { } @@ -109,16 +111,24 @@ void ImageView::SetImage( Image image ) mVisual = visual; } - DevelControl::RegisterVisual( *this, Toolkit::ImageView::Property::IMAGE, visual ); + if( !mShaderMap.Empty() ) + { + Internal::Visual::Base& visualImpl = Toolkit::GetImplementation( visual ); + visualImpl.SetCustomShader( mShaderMap ); + } + + DevelControl::RegisterVisual( *this, Toolkit::ImageView::Property::IMAGE, visual ); } else { - // Unregister the exsiting visual + // Unregister the existing visual DevelControl::UnregisterVisual( *this, Toolkit::ImageView::Property::IMAGE ); // Trigger a size negotiation request that may be needed when unregistering a visual. RelayoutRequest(); } + + // Signal that a Relayout may be needed } void ImageView::SetImage( const Property::Map& map ) @@ -137,6 +147,12 @@ void ImageView::SetImage( const Property::Map& map ) mVisual = visual; } + if( !mShaderMap.Empty() ) + { + Internal::Visual::Base& visualImpl = Toolkit::GetImplementation( visual ); + visualImpl.SetCustomShader( mShaderMap ); + } + DevelControl::RegisterVisual( *this, Toolkit::ImageView::Property::IMAGE, visual ); } else @@ -147,12 +163,15 @@ void ImageView::SetImage( const Property::Map& map ) // Trigger a size negotiation request that may be needed when unregistering a visual. RelayoutRequest(); } + + // Signal that a Relayout may be needed } void ImageView::SetImage( const std::string& url, ImageDimensions size ) { // Don't bother comparing if we had a visual previously, just drop old visual and create new one mUrl = url; + mImageSize = size; mImage.Reset(); mPropertyMap.Clear(); @@ -165,6 +184,12 @@ void ImageView::SetImage( const std::string& url, ImageDimensions size ) mVisual = visual; } + if( !mShaderMap.Empty() ) + { + Internal::Visual::Base& visualImpl = Toolkit::GetImplementation( visual ); + visualImpl.SetCustomShader( mShaderMap ); + } + DevelControl::RegisterVisual( *this, Toolkit::ImageView::Property::IMAGE, visual ); } else @@ -175,6 +200,8 @@ void ImageView::SetImage( const std::string& url, ImageDimensions size ) // Trigger a size negotiation request that may be needed when unregistering a visual. RelayoutRequest(); } + + // Signal that a Relayout may be needed } Image ImageView::GetImage() const @@ -265,45 +292,61 @@ void ImageView::OnRelayout( const Vector2& size, RelayoutContainer& container ) Property::Map transformMap = Property::Map(); Extents padding = Self().GetProperty( Toolkit::Control::Property::PADDING ); + const Visual::FittingMode fittingMode = Toolkit::GetImplementation(mVisual).GetFittingMode(); - Dali::LayoutDirection::Type layoutDirection = static_cast( - Self().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get() ); - - if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection ) + bool zeroPadding = ( padding == Extents() ); + if( ( !zeroPadding ) || // If padding is not zero + ( fittingMode == Visual::FittingMode::FIT_KEEP_ASPECT_RATIO ) ) { - std::swap( padding.start, padding.end ); - } + Dali::LayoutDirection::Type layoutDirection = static_cast( + Self().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get() ); + + if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection ) + { + std::swap( padding.start, padding.end ); + } - auto finalOffset = Vector2( padding.start, padding.top ); + auto finalOffset = Vector2( padding.start, padding.top ); + mImageVisualPaddingSetByTransform = true; - // remove padding from the size to know how much is left for the visual - auto finalSize = size - Vector2( padding.start + padding.end, padding.top + padding.bottom ); + // remove padding from the size to know how much is left for the visual + auto finalSize = size - Vector2( padding.start + padding.end, padding.top + padding.bottom ); - // Should provide a transform that handles aspect ratio according to image size - if( Toolkit::GetImplementation(mVisual).GetFittingMode() == Visual::FittingMode::FIT_KEEP_ASPECT_RATIO ) - { - auto availableVisualSize = finalSize; + // Should provide a transform that handles aspect ratio according to image size + if( fittingMode == Visual::FittingMode::FIT_KEEP_ASPECT_RATIO ) + { + auto availableVisualSize = finalSize; - Vector2 naturalSize; - mVisual.GetNaturalSize( naturalSize ); + Vector2 naturalSize; + mVisual.GetNaturalSize( naturalSize ); - // scale to fit the padded area - finalSize = naturalSize * std::min( ( naturalSize.width ? ( availableVisualSize.width / naturalSize.width ) : 0 ), - ( naturalSize.height ? ( availableVisualSize.height / naturalSize.height ) : 0 ) ); + // scale to fit the padded area + finalSize = naturalSize * std::min( ( naturalSize.width ? ( availableVisualSize.width / naturalSize.width ) : 0 ), + ( naturalSize.height ? ( availableVisualSize.height / naturalSize.height ) : 0 ) ); - // calculate final offset within the padded area - finalOffset += ( availableVisualSize - finalSize ) * .5f; + // calculate final offset within the padded area + finalOffset += ( availableVisualSize - finalSize ) * .5f; + } + + // populate the transform map + transformMap.Add( Toolkit::Visual::Transform::Property::OFFSET, finalOffset ) + .Add( Toolkit::Visual::Transform::Property::OFFSET_POLICY, + Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ) ) + .Add( Toolkit::Visual::Transform::Property::ORIGIN, Toolkit::Align::TOP_BEGIN ) + .Add( Toolkit::Visual::Transform::Property::ANCHOR_POINT, Toolkit::Align::TOP_BEGIN ) + .Add( Toolkit::Visual::Transform::Property::SIZE, finalSize ) + .Add( Toolkit::Visual::Transform::Property::SIZE_POLICY, + Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ) ); + } + else if ( mImageVisualPaddingSetByTransform && zeroPadding ) // Reset offset to zero only if padding applied previously + { + mImageVisualPaddingSetByTransform = false; + // Reset the transform map + transformMap.Add( Toolkit::Visual::Transform::Property::OFFSET, Vector2::ZERO ) + .Add( Toolkit::Visual::Transform::Property::OFFSET_POLICY, + Vector2( Toolkit::Visual::Transform::Policy::RELATIVE, Toolkit::Visual::Transform::Policy::RELATIVE ) ); } - // populate the transform map - transformMap.Add( Toolkit::Visual::Transform::Property::OFFSET, finalOffset ) - .Add( Toolkit::Visual::Transform::Property::OFFSET_POLICY, - Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ) ) - .Add( Toolkit::Visual::Transform::Property::ORIGIN, Toolkit::Align::TOP_BEGIN ) - .Add( Toolkit::Visual::Transform::Property::ANCHOR_POINT, Toolkit::Align::TOP_BEGIN ) - .Add( Toolkit::Visual::Transform::Property::SIZE, finalSize ) - .Add( Toolkit::Visual::Transform::Property::SIZE_POLICY, - Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ) ); mVisual.SetTransformAndSize( transformMap, size ); } @@ -313,6 +356,7 @@ void ImageView::OnResourceReady( Toolkit::Control control ) { // Visual ready so update visual attached to this ImageView, following call to RelayoutRequest will use this visual. mVisual = DevelControl::GetVisual( *this, Toolkit::ImageView::Property::IMAGE ); + // Signal that a Relayout may be needed } /////////////////////////////////////////////////////////// @@ -360,18 +404,24 @@ void ImageView::SetProperty( BaseObject* object, Property::Index index, const Pr impl.SetImage( *map ); } // the property map contains only the custom shader - else if( ( impl.mVisual )&&( map->Count() == 1u )&&( shaderValue ) ) + else if( ( 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() ) + impl.mShaderMap = *shaderMap; + + if( !impl.mUrl.empty() ) { - // force to create new core renderer to use the newly set shader - visual.SetOffStage( imageView ); - visual.SetOnStage( imageView ); + impl.SetImage( impl.mUrl, impl.mImageSize ); + } + else if( impl.mImage ) + { + impl.SetImage( impl.mImage ); + } + else if( !impl.mPropertyMap.Empty() ) + { + impl.SetImage( impl.mPropertyMap ); } } } @@ -425,9 +475,15 @@ Property::Value ImageView::GetProperty( BaseObject* object, Property::Index prop Scripting::CreatePropertyMap( impl.mImage, map ); value = map; } - else if( !impl.mPropertyMap.Empty() ) + else { - value = impl.mPropertyMap; + Property::Map map; + Toolkit::Visual::Base visual = DevelControl::GetVisual( impl, Toolkit::ImageView::Property::IMAGE ); + if( visual ) + { + visual.CreatePropertyMap( map ); + } + value = map; } break; }