-// Copyright (c) 2014 Samsung Electronics Co., Ltd.
+/*
+ * Copyright (c) 2021 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
// CLASS HEADER
#include "image-view-impl.h"
// EXTERNAL INCLUDES
-#include <dali/public-api/images/resource-image.h>
-#include <dali/public-api/object/type-registry.h>
-#include <dali/public-api/object/type-registry-helper.h>
#include <dali/devel-api/scripting/scripting.h>
+#include <dali/public-api/object/type-registry-helper.h>
+#include <dali/public-api/object/type-registry.h>
// INTERNAL INCLUDES
+#include <dali-toolkit/devel-api/controls/control-devel.h>
+#include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
+#include <dali-toolkit/internal/controls/control/control-data-impl.h>
+#include <dali-toolkit/internal/visuals/visual-base-data-impl.h>
+#include <dali-toolkit/internal/visuals/visual-base-impl.h>
+#include <dali-toolkit/internal/visuals/visual-string-constants.h>
#include <dali-toolkit/public-api/controls/image-view/image-view.h>
-#include <dali-toolkit/devel-api/controls/renderer-factory/renderer-factory.h>
-#include <dali-toolkit/internal/controls/renderers/renderer-string-constants.h>
-#include <dali-toolkit/internal/controls/renderers/control-renderer-impl.h>
+#include <dali-toolkit/public-api/visuals/visual-properties.h>
namespace Dali
{
-
namespace Toolkit
{
-
namespace Internal
{
-
namespace
{
+const Vector4 FULL_TEXTURE_RECT(0.f, 0.f, 1.f, 1.f);
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_TYPE_REGISTRATION_BEGIN(Toolkit::ImageView, Toolkit::Control, Create);
+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_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
using namespace Dali;
ImageView::ImageView()
-: Control( ControlBehaviour( ACTOR_BEHAVIOUR_NONE ) )
+: Control(ControlBehaviour(CONTROL_BEHAVIOUR_DEFAULT)),
+ mImageSize(),
+ mImageVisualPaddingSetByTransform(false),
+ mImageViewPixelAreaSetByFittingMode(false)
{
}
{
ImageView* impl = new ImageView();
- Toolkit::ImageView handle = Toolkit::ImageView( *impl );
+ Toolkit::ImageView handle = Toolkit::ImageView(*impl);
// Second-phase init of the implementation
// This can only be done after the CustomActor connection has been made...
/////////////////////////////////////////////////////////////
-void ImageView::SetImage( Image image )
+void ImageView::OnInitialize()
{
- 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() );
- InitializeControlRenderer( self, mRenderer, image );
- mImageSize = image ? ImageDimensions( image.GetWidth(), image.GetHeight() ) : ImageDimensions( 0, 0 );
-
- RelayoutRequest();
- }
+ // ImageView can relayout in the OnImageReady, alternative to a signal would be to have a upcall from the Control to ImageView
+ Dali::Toolkit::Control handle(GetOwner());
+ handle.ResourceReadySignal().Connect(this, &ImageView::OnResourceReady);
+
+ DevelControl::SetAccessibilityConstructor(Self(), [](Dali::Actor actor) {
+ return std::unique_ptr<Dali::Accessibility::Accessible>(
+ new DevelControl::AccessibleImpl(actor, Dali::Accessibility::Role::IMAGE));
+ });
}
-void ImageView::SetImage( Property::Map map )
+void ImageView::SetImage(const Property::Map& map)
{
- mUrl.clear();
- mImage.Reset();
+ // Comparing a property map is too expensive so just creating a new visual
mPropertyMap = map;
+ mUrl.clear();
- Actor self( Self() );
- InitializeControlRenderer( self, mRenderer, mPropertyMap );
-
- Property::Value* widthValue = mPropertyMap.Find( "width" );
- if( widthValue )
+ Toolkit::Visual::Base visual = Toolkit::VisualFactory::Get().CreateVisual(mPropertyMap);
+ if(visual)
{
- int width;
- if( widthValue->Get( width ) )
+ // Don't set mVisual until it is ready and shown. Getters will still use current visual.
+ if(!mVisual)
{
- mImageSize = ImageDimensions( width, mImageSize.GetHeight() );
+ mVisual = visual;
}
- }
- Property::Value* heightValue = mPropertyMap.Find( "height" );
- if( heightValue )
- {
- int height;
- if( heightValue->Get( height ) )
+ if(!mShaderMap.Empty())
{
- mImageSize = ImageDimensions( mImageSize.GetWidth(), height );
+ Internal::Visual::Base& visualImpl = Toolkit::GetImplementation(visual);
+ visualImpl.SetCustomShader(mShaderMap);
}
+
+ DevelControl::RegisterVisual(*this, Toolkit::ImageView::Property::IMAGE, visual);
}
+ else
+ {
+ // Unregister the exsiting visual
+ DevelControl::UnregisterVisual(*this, Toolkit::ImageView::Property::IMAGE);
- RelayoutRequest();
+ // 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 )
+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
+ // Don't bother comparing if we had a visual previously, just drop old visual and create new one
+ mUrl = url;
+ mImageSize = size;
+ mPropertyMap.Clear();
+
+ // Don't set mVisual until it is ready and shown. Getters will still use current visual.
+ Toolkit::Visual::Base visual = Toolkit::VisualFactory::Get().CreateVisual(url, size);
+ if(visual)
{
- mImage.Reset();
- mPropertyMap.Clear();
-
- mUrl = url;
-
- if( size.GetWidth() != 0u && size.GetHeight() != 0u )
+ if(!mVisual)
{
- mImageSize = size;
+ mVisual = visual;
}
- Actor self( Self() );
- InitializeControlRenderer( self, mRenderer, url, size );
+ if(!mShaderMap.Empty())
+ {
+ Internal::Visual::Base& visualImpl = Toolkit::GetImplementation(visual);
+ visualImpl.SetCustomShader(mShaderMap);
+ }
- mRenderer.SetSize( mSizeSet );
+ DevelControl::RegisterVisual(*this, Toolkit::ImageView::Property::IMAGE, visual);
+ }
+ else
+ {
+ // Unregister the exsiting visual
+ DevelControl::UnregisterVisual(*this, Toolkit::ImageView::Property::IMAGE);
+ // Trigger a size negotiation request that may be needed when unregistering a visual.
RelayoutRequest();
}
-}
-Image ImageView::GetImage() const
-{
- return mImage;
+ // Signal that a Relayout may be needed
}
-void ImageView::EnablePreMultipliedAlpha( bool preMultipled )
+void ImageView::EnablePreMultipliedAlpha(bool preMultipled)
{
- if( mRenderer )
+ if(mVisual)
{
- GetImplementation( mRenderer ).EnablePreMultipliedAlpha( preMultipled );
+ Toolkit::GetImplementation(mVisual).EnablePreMultipliedAlpha(preMultipled);
}
}
bool ImageView::IsPreMultipliedAlphaEnabled() const
{
- if( mRenderer )
+ if(mVisual)
{
- return GetImplementation( mRenderer ).IsPreMultipliedAlphaEnabled();
+ return Toolkit::GetImplementation(mVisual).IsPreMultipliedAlphaEnabled();
}
return false;
}
-void ImageView::SetDepthIndex( int depthIndex )
+void ImageView::SetDepthIndex(int depthIndex)
{
- if( mRenderer )
+ if(mVisual)
{
- mRenderer.SetDepthIndex( depthIndex );
+ mVisual.SetDepthIndex(depthIndex);
}
}
Vector3 ImageView::GetNaturalSize()
{
- if( mRenderer )
+ if(mVisual)
{
Vector2 rendererNaturalSize;
- mRenderer.GetNaturalSize( rendererNaturalSize );
- return Vector3( rendererNaturalSize );
+ mVisual.GetNaturalSize(rendererNaturalSize);
+
+ Extents padding;
+ padding = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
+
+ rendererNaturalSize.width += (padding.start + padding.end);
+ rendererNaturalSize.height += (padding.top + padding.bottom);
+ return Vector3(rendererNaturalSize);
}
- Vector3 size;
- size.x = mImageSize.GetWidth();
- size.y = mImageSize.GetHeight();
+ // if no visual then use Control's natural size
+ return Control::GetNaturalSize();
+}
- if( size.x > 0 && size.y > 0 )
+float ImageView::GetHeightForWidth(float width)
+{
+ Extents padding;
+ padding = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
+
+ if(mVisual)
{
- size.z = std::min(size.x, size.y);
- return size;
+ return mVisual.GetHeightForWidth(width) + padding.top + padding.bottom;
}
else
{
- // if no image then use Control's natural size
- return Control::GetNaturalSize();
+ return Control::GetHeightForWidth(width) + padding.top + padding.bottom;
}
}
-float ImageView::GetHeightForWidth( float width )
+float ImageView::GetWidthForHeight(float height)
{
- if( mImageSize.GetWidth() > 0 && mImageSize.GetHeight() > 0 )
+ Extents padding;
+ padding = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
+
+ if(mVisual)
{
- return GetHeightForWidthBase( width );
+ return mVisual.GetWidthForHeight(height) + padding.start + padding.end;
}
else
{
- return Control::GetHeightForWidth( width );
+ return Control::GetWidthForHeight(height) + padding.start + padding.end;
}
}
-float ImageView::GetWidthForHeight( float height )
+void ImageView::OnRelayout(const Vector2& size, RelayoutContainer& container)
{
- if( mImageSize.GetWidth() > 0 && mImageSize.GetHeight() > 0 )
+ Control::OnRelayout(size, container);
+ if(mVisual)
{
- return GetWidthForHeightBase( height );
+ Property::Map transformMap = Property::Map();
+
+ Extents padding = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
+
+ bool zeroPadding = (padding == Extents());
+
+ Vector2 naturalSize;
+ mVisual.GetNaturalSize(naturalSize);
+
+ Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>(
+ Self().GetProperty(Dali::Actor::Property::LAYOUT_DIRECTION).Get<int>());
+ if(Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection)
+ {
+ std::swap(padding.start, padding.end);
+ }
+
+ // remove padding from the size to know how much is left for the visual
+ Vector2 finalSize = size - Vector2(padding.start + padding.end, padding.top + padding.bottom);
+ Vector2 finalOffset = Vector2(padding.start, padding.top);
+
+ ApplyFittingMode(finalSize, naturalSize, finalOffset, zeroPadding, transformMap);
+
+ mVisual.SetTransformAndSize(transformMap, size);
+
+ // mVisual is not updated util the resource is ready in the case of visual replacement.
+ // in this case, the Property Map must be initialized so that the previous value is not reused.
+ // after mVisual is updated, the correct value will be reset.
+ Toolkit::Visual::Base visual = DevelControl::GetVisual(*this, Toolkit::ImageView::Property::IMAGE);
+ if(visual && visual != mVisual)
+ {
+ visual.SetTransformAndSize(Property::Map(), size);
+ }
}
- else
+}
+
+void ImageView::OnCreateTransitions(Dali::Animation& animation, Dali::Toolkit::Control source, AlphaFunction alphaFunction, TimePeriod timePeriod)
+{
+ Dali::Toolkit::ImageView destinationHandle = Toolkit::ImageView(GetOwner());
+ Toolkit::Visual::Base destinationVisual = DevelControl::GetVisual(GetImplementation(destinationHandle), Toolkit::ImageView::Property::IMAGE);
+ Property::Map destinationMap;
+
+ if(!destinationVisual)
{
- return Control::GetWidthForHeight( height );
+ return;
}
-}
+ destinationVisual.CreatePropertyMap(destinationMap);
-///////////////////////////////////////////////////////////
-//
-// Private methods
-//
+ static auto findValueVector4 = [](const Property::Map& map, Property::Index index, const Vector4& defaultValue = Vector4()) -> Vector4 {
+ Property::Value* propertyValue = map.Find(index);
+ if(propertyValue)
+ {
+ return propertyValue->Get<Vector4>();
+ }
+ return defaultValue;
+ };
-void ImageView::OnStageConnection( int depth )
-{
- Control::OnStageConnection( depth );
+ static auto findValueFloat = [](const Property::Map& map, Property::Index index, const float& defaultValue = 0.0f) -> float {
+ Property::Value* propertyValue = map.Find(index);
+ if(propertyValue)
+ {
+ return propertyValue->Get<float>();
+ }
+ return defaultValue;
+ };
+
+ Vector4 sourceMixColor(0.0f, 0.0f, 0.0f, 0.0f);
+ Vector4 sourceCornerRadius(0.0f, 0.0f, 0.0f, 0.0f);
+ float sourceBorderlineWidth(0.0f);
+ Vector4 sourceBorderlineColor(0.0f, 0.0f, 0.0f, 1.0f);
+ float sourceBorderlineOffset(0.0f);
+ Vector4 destinationMixColor = findValueVector4(destinationMap, Dali::Toolkit::Visual::Property::MIX_COLOR, sourceMixColor);
+ Vector4 destinationCornerRadius = findValueVector4(destinationMap, Toolkit::DevelVisual::Property::CORNER_RADIUS, sourceCornerRadius);
+ float destinationBorderlineWidth = findValueFloat(destinationMap, Toolkit::DevelVisual::Property::BORDERLINE_WIDTH, sourceBorderlineWidth);
+ Vector4 destinationBorderlineColor = findValueVector4(destinationMap, Toolkit::DevelVisual::Property::BORDERLINE_COLOR, sourceBorderlineColor);
+ float destinationBorderlineOffset = findValueFloat(destinationMap, Toolkit::DevelVisual::Property::BORDERLINE_OFFSET, sourceBorderlineOffset);
+
+ Dali::Toolkit::ImageView sourceHandle = Dali::Toolkit::ImageView::DownCast(source);
+ Toolkit::Visual::Base sourceVisual;
+ Property::Map sourceMap;
+
+ if(sourceHandle)
+ {
+ sourceVisual = DevelControl::GetVisual(GetImplementation(sourceHandle), Toolkit::ImageView::Property::IMAGE);
+ }
+
+ if(sourceVisual)
+ {
+ sourceVisual.CreatePropertyMap(sourceMap);
+ sourceMixColor = findValueVector4(sourceMap, Dali::Toolkit::Visual::Property::MIX_COLOR, sourceMixColor);
+ sourceCornerRadius = findValueVector4(sourceMap, Toolkit::DevelVisual::Property::CORNER_RADIUS, sourceCornerRadius);
+ sourceBorderlineWidth = findValueFloat(sourceMap, Toolkit::DevelVisual::Property::BORDERLINE_WIDTH, sourceBorderlineWidth);
+ sourceBorderlineColor = findValueVector4(sourceMap, Toolkit::DevelVisual::Property::BORDERLINE_COLOR, sourceBorderlineColor);
+ sourceBorderlineOffset = findValueFloat(sourceMap, Toolkit::DevelVisual::Property::BORDERLINE_OFFSET, sourceBorderlineOffset);
+ }
+
+ std::vector<Dali::Property> properties;
+ std::vector<std::pair<Property::Value, Property::Value>> values;
- if( mRenderer )
+ if(Vector3(sourceMixColor) != Vector3(destinationMixColor))
{
- CustomActor self = Self();
- mRenderer.SetOnStage( self );
+ properties.push_back(DevelControl::GetVisualProperty(destinationHandle, Toolkit::ImageView::Property::IMAGE, Toolkit::Visual::Property::MIX_COLOR));
+ values.push_back(std::make_pair(Vector3(sourceMixColor), Vector3(destinationMixColor)));
}
+ if(std::abs(sourceMixColor.a - destinationMixColor.a) > Math::MACHINE_EPSILON_1)
+ {
+ properties.push_back(DevelControl::GetVisualProperty(destinationHandle, Toolkit::ImageView::Property::IMAGE, Toolkit::Visual::Property::OPACITY));
+ values.push_back(std::make_pair(sourceMixColor.a, destinationMixColor.a));
+ }
+ if(sourceCornerRadius != destinationCornerRadius)
+ {
+ properties.push_back(DevelControl::GetVisualProperty(destinationHandle, Toolkit::ImageView::Property::IMAGE, Toolkit::DevelVisual::Property::CORNER_RADIUS));
+ values.push_back(std::make_pair(sourceCornerRadius, destinationCornerRadius));
+ }
+ if(sourceBorderlineWidth != destinationBorderlineWidth)
+ {
+ properties.push_back(DevelControl::GetVisualProperty(destinationHandle, Toolkit::ImageView::Property::IMAGE, Toolkit::DevelVisual::Property::BORDERLINE_WIDTH));
+ values.push_back(std::make_pair(sourceBorderlineWidth, destinationBorderlineWidth));
+ }
+ if(sourceBorderlineColor != destinationBorderlineColor)
+ {
+ properties.push_back(DevelControl::GetVisualProperty(destinationHandle, Toolkit::ImageView::Property::IMAGE, Toolkit::DevelVisual::Property::BORDERLINE_COLOR));
+ values.push_back(std::make_pair(sourceBorderlineColor, destinationBorderlineColor));
+ }
+ if(sourceBorderlineOffset != destinationBorderlineOffset)
+ {
+ properties.push_back(DevelControl::GetVisualProperty(destinationHandle, Toolkit::ImageView::Property::IMAGE, Toolkit::DevelVisual::Property::BORDERLINE_OFFSET));
+ values.push_back(std::make_pair(sourceBorderlineOffset, destinationBorderlineOffset));
+ }
+
+ for(uint32_t i = 0; i < properties.size(); ++i)
+ {
+ if(timePeriod.delaySeconds > 0.0f)
+ {
+ Dali::KeyFrames initialKeyframes = Dali::KeyFrames::New();
+ initialKeyframes.Add(0.0f, values[i].first);
+ initialKeyframes.Add(1.0f, values[i].first);
+ animation.AnimateBetween(properties[i], initialKeyframes, TimePeriod(timePeriod.delaySeconds));
+ }
+ Dali::KeyFrames keyframes = Dali::KeyFrames::New();
+ keyframes.Add(0.0f, values[i].first);
+ keyframes.Add(1.0f, values[i].second);
+ animation.AnimateBetween(properties[i], keyframes, alphaFunction, timePeriod);
+ }
+}
+
+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
}
-void ImageView::OnStageDisconnection()
+void ImageView::SetTransformMapForFittingMode(Vector2 finalSize, Vector2 naturalSize, Vector2 finalOffset, Visual::FittingMode fittingMode, Property::Map& transformMap)
{
- if( mRenderer )
+ switch(fittingMode)
{
- CustomActor self = Self();
- mRenderer.SetOffStage( self );
- }
+ case Visual::FittingMode::FIT_KEEP_ASPECT_RATIO:
+ {
+ auto availableVisualSize = finalSize;
+
+ // 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;
+
+ // populate the transform map
+ transformMap.Add(Toolkit::Visual::Transform::Property::OFFSET, finalOffset)
+ .Add(Toolkit::Visual::Transform::Property::SIZE, finalSize);
+ break;
+ }
+ case Visual::FittingMode::OVER_FIT_KEEP_ASPECT_RATIO:
+ {
+ mImageViewPixelAreaSetByFittingMode = true;
+ auto availableVisualSize = finalSize;
+ finalSize = naturalSize * std::max((naturalSize.width ? (availableVisualSize.width / naturalSize.width) : 0),
+ (naturalSize.height ? (availableVisualSize.height / naturalSize.height) : 0));
+
+ auto originalOffset = finalOffset;
+ finalOffset += (availableVisualSize - finalSize) * .5f;
+
+ float x = abs((availableVisualSize.width - finalSize.width) / finalSize.width) * .5f;
+ float y = abs((availableVisualSize.height - finalSize.height) / finalSize.height) * .5f;
+ float widthRatio = 1.f - abs((availableVisualSize.width - finalSize.width) / finalSize.width);
+ float heightRatio = 1.f - abs((availableVisualSize.height - finalSize.height) / finalSize.height);
+ Vector4 pixelArea = Vector4(x, y, widthRatio, heightRatio);
+ Self().SetProperty(Toolkit::ImageView::Property::PIXEL_AREA, pixelArea);
+
+ // populate the transform map
+ transformMap.Add(Toolkit::Visual::Transform::Property::OFFSET, originalOffset)
+ .Add(Toolkit::Visual::Transform::Property::SIZE, availableVisualSize);
+ break;
+ }
+ case Visual::FittingMode::CENTER:
+ {
+ auto availableVisualSize = finalSize;
+ if(availableVisualSize.width > naturalSize.width && availableVisualSize.height > naturalSize.height)
+ {
+ finalSize = naturalSize;
+ }
+ else
+ {
+ finalSize = naturalSize * std::min((naturalSize.width ? (availableVisualSize.width / naturalSize.width) : 0),
+ (naturalSize.height ? (availableVisualSize.height / naturalSize.height) : 0));
+ }
+
+ finalOffset += (availableVisualSize - finalSize) * .5f;
- Control::OnStageDisconnection();
+ // populate the transform map
+ transformMap.Add(Toolkit::Visual::Transform::Property::OFFSET, finalOffset)
+ .Add(Toolkit::Visual::Transform::Property::SIZE, finalSize);
+ break;
+ }
+ case Visual::FittingMode::FILL:
+ {
+ transformMap.Add(Toolkit::Visual::Transform::Property::OFFSET, finalOffset)
+ .Add(Toolkit::Visual::Transform::Property::SIZE, finalSize);
+ break;
+ }
+ case Visual::FittingMode::FIT_WIDTH:
+ case Visual::FittingMode::FIT_HEIGHT:
+ {
+ // This FittingMode already converted
+ break;
+ }
+ }
}
-void ImageView::OnSizeSet( const Vector3& targetSize )
+void ImageView::ApplyFittingMode(Vector2 finalSize, Vector2 naturalSize, Vector2 finalOffset, bool zeroPadding, Property::Map& transformMap)
{
- Control::OnSizeSet( targetSize );
- mSizeSet = targetSize;
+ Visual::FittingMode fittingMode = Toolkit::GetImplementation(mVisual).GetFittingMode();
+
+ // Reset PIXEL_AREA after using OVER_FIT_KEEP_ASPECT_RATIO
+ if(mImageViewPixelAreaSetByFittingMode)
+ {
+ Self().SetProperty(Toolkit::ImageView::Property::PIXEL_AREA, FULL_TEXTURE_RECT);
+ mImageViewPixelAreaSetByFittingMode = false;
+ }
+
+ if((!zeroPadding) || // If padding is not zero
+ (fittingMode != Visual::FittingMode::FILL))
+ {
+ mImageVisualPaddingSetByTransform = true;
+
+ // If FittingMode use FIT_WIDTH or FIT_HEIGTH, it need to change proper fittingMode
+ if(fittingMode == Visual::FittingMode::FIT_WIDTH)
+ {
+ fittingMode = (finalSize.height / naturalSize.height) < (finalSize.width / naturalSize.width) ? Visual::FittingMode::OVER_FIT_KEEP_ASPECT_RATIO : Visual::FittingMode::FIT_KEEP_ASPECT_RATIO;
+ }
+ else if(fittingMode == Visual::FittingMode::FIT_HEIGHT)
+ {
+ fittingMode = (finalSize.height / naturalSize.height) < (finalSize.width / naturalSize.width) ? Visual::FittingMode::FIT_KEEP_ASPECT_RATIO : Visual::FittingMode::OVER_FIT_KEEP_ASPECT_RATIO;
+ }
- if( mRenderer )
+ SetTransformMapForFittingMode(finalSize, naturalSize, finalOffset, fittingMode, transformMap);
+
+ // Set extra value for applying transformMap
+ transformMap.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_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
{
- Vector2 size( targetSize );
- mRenderer.SetSize( size );
+ 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))
+ .Add(Toolkit::Visual::Transform::Property::SIZE, Vector2::ONE)
+ .Add(Toolkit::Visual::Transform::Property::SIZE_POLICY,
+ Vector2(Toolkit::Visual::Transform::Policy::RELATIVE, Toolkit::Visual::Transform::Policy::RELATIVE));
}
}
// Properties
//
-void ImageView::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
+void ImageView::SetProperty(BaseObject* object, Property::Index index, const Property::Value& value)
{
- Toolkit::ImageView imageView = Toolkit::ImageView::DownCast( Dali::BaseHandle( object ) );
+ Toolkit::ImageView imageView = Toolkit::ImageView::DownCast(Dali::BaseHandle(object));
- if ( imageView )
+ if(imageView)
{
- ImageView& impl = GetImpl( imageView );
- switch ( index )
+ ImageView& impl = GetImpl(imageView);
+ switch(index)
{
- case Toolkit::ImageView::Property::RESOURCE_URL:
- {
- std::string imageUrl;
- if( value.Get( imageUrl ) )
- {
- impl.SetImage( imageUrl, ImageDimensions() );
- }
- break;
- }
-
case Toolkit::ImageView::Property::IMAGE:
{
- std::string imageUrl;
- Property::Map map;
- if( value.Get( imageUrl ) )
+ std::string imageUrl;
+ const Property::Map* map;
+ if(value.Get(imageUrl))
{
- impl.SetImage( imageUrl, ImageDimensions() );
+ impl.SetImage(imageUrl, ImageDimensions());
}
// if its not a string then get a Property::Map from the property if possible.
- else if( value.Get( map ) )
+ else
{
- Property::Value* shaderValue = map.Find( "shader" );
- // set image only if property map contains image information other than custom shader
- if( map.Count() > 1u || !shaderValue )
+ map = value.GetMap();
+ if(map)
{
- impl.SetImage( map );
- }
- // the property map contains only the custom shader
- else if( impl.mRenderer && map.Count() == 1u && shaderValue )
- {
- Property::Map shaderMap;
- if( shaderValue->Get( shaderMap ) )
+ Property::Value* shaderValue = map->Find(Toolkit::Visual::Property::SHADER, CUSTOM_SHADER);
+ // set image only if property map contains image information other than custom shader
+ if(map->Count() > 1u || !shaderValue)
{
- Internal::ControlRenderer& renderer = GetImplementation( impl.mRenderer );
- renderer.SetCustomShader( shaderMap );
- if( imageView.OnStage() )
+ impl.SetImage(*map);
+ }
+ // the property map contains only the custom shader
+ else if((map->Count() == 1u) && (shaderValue))
+ {
+ Property::Map* shaderMap = shaderValue->GetMap();
+ if(shaderMap)
{
- // force to create new core renderer to use the newly set shader
- renderer.SetOffStage( imageView );
- renderer.SetOnStage( imageView );
+ impl.mShaderMap = *shaderMap;
+
+ if(!impl.mUrl.empty())
+ {
+ impl.SetImage(impl.mUrl, impl.mImageSize);
+ }
+ else if(!impl.mPropertyMap.Empty())
+ {
+ impl.SetImage(impl.mPropertyMap);
+ }
}
}
}
case Toolkit::ImageView::Property::PRE_MULTIPLIED_ALPHA:
{
bool isPre;
- if( value.Get( isPre ) )
+ if(value.Get(isPre))
{
- impl.EnablePreMultipliedAlpha( isPre );
+ impl.EnablePreMultipliedAlpha(isPre);
}
break;
}
}
}
-Property::Value ImageView::GetProperty( BaseObject* object, Property::Index propertyIndex )
+Property::Value ImageView::GetProperty(BaseObject* object, Property::Index propertyIndex)
{
Property::Value value;
- Toolkit::ImageView imageview = Toolkit::ImageView::DownCast( Dali::BaseHandle( object ) );
+ Toolkit::ImageView imageview = Toolkit::ImageView::DownCast(Dali::BaseHandle(object));
- if ( imageview )
+ if(imageview)
{
- ImageView& impl = GetImpl( imageview );
- switch ( propertyIndex )
+ 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:
{
- if ( !impl.mUrl.empty() )
+ if(!impl.mUrl.empty())
{
value = impl.mUrl;
}
- else if( impl.mImage )
+ else
{
- Property::Map map;
- Scripting::CreatePropertyMap( impl.mImage, map );
+ Property::Map map;
+ Toolkit::Visual::Base visual = DevelControl::GetVisual(impl, Toolkit::ImageView::Property::IMAGE);
+ if(visual)
+ {
+ visual.CreatePropertyMap(map);
+ }
value = map;
}
- else if( !impl.mPropertyMap.Empty() )
- {
- value = impl.mPropertyMap;
- }
break;
}