/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2022 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.
#include <dali/public-api/object/type-registry.h>
// INTERNAL INCLUDES
+#include <dali-toolkit/devel-api/visuals/visual-actions-devel.h>
#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>
using namespace Dali;
-ImageView::ImageView()
-: Control(ControlBehaviour(CONTROL_BEHAVIOUR_DEFAULT)),
+ImageView::ImageView(ControlBehaviour additionalBehaviour)
+: Control(ControlBehaviour(CONTROL_BEHAVIOUR_DEFAULT | additionalBehaviour)),
mImageSize(),
mImageVisualPaddingSetByTransform(false),
mImageViewPixelAreaSetByFittingMode(false)
{
}
-Toolkit::ImageView ImageView::New()
+Toolkit::ImageView ImageView::New(ControlBehaviour additionalBehaviour)
{
- ImageView* impl = new ImageView();
+ ImageView* impl = new ImageView(additionalBehaviour);
Toolkit::ImageView handle = Toolkit::ImageView(*impl);
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));
- });
-
- //Enable highightability
- Self().SetProperty(Toolkit::DevelControl::Property::ACCESSIBILITY_HIGHLIGHTABLE, true);
+ Self().SetProperty(DevelControl::Property::ACCESSIBILITY_ROLE, Dali::Accessibility::Role::IMAGE);
}
void ImageView::SetImage(const Property::Map& map)
// Signal that a Relayout may be needed
}
+void ImageView::ClearImageVisual()
+{
+ // Clear cached properties
+ mPropertyMap.Clear();
+ mUrl.clear();
+
+ // 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();
+}
+
void ImageView::EnablePreMultipliedAlpha(bool preMultipled)
{
if(mVisual)
}
}
-void ImageView::OnCreateTransitions(Dali::Animation& animation, Dali::Toolkit::Control source, AlphaFunction alphaFunction, TimePeriod timePeriod)
+void ImageView::OnCreateTransitions(std::vector<std::pair<Dali::Property::Index, Dali::Property::Map>>& sourceProperties,
+ std::vector<std::pair<Dali::Property::Index, Dali::Property::Map>>& destinationProperties,
+ Dali::Toolkit::Control source,
+ Dali::Toolkit::Control destination)
{
- 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;
- }
-
- destinationVisual.CreatePropertyMap(destinationMap);
-
- static auto findValue = [](const Property::Map& map, Property::Index index) -> Vector4 {
- Property::Value* propertyValue = map.Find(index);
- if(propertyValue)
- {
- return propertyValue->Get<Vector4>();
- }
- return Vector4{};
- };
-
- Vector4 sourceMixColor(0.0f, 0.0f, 0.0f, 0.0f);
- Vector4 sourceCornerRadius(0.0f, 0.0f, 0.0f, 0.0f);
- Vector4 destinationMixColor = findValue(destinationMap, Dali::Toolkit::Visual::Property::MIX_COLOR);
- Vector4 destinationCornerRadius = findValue(destinationMap, Toolkit::DevelVisual::Property::CORNER_RADIUS);
-
- 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)
+ // Retrieves image properties to be transitioned.
+ Dali::Property::Map imageSourcePropertyMap, imageDestinationPropertyMap;
+ MakeVisualTransition(imageSourcePropertyMap, imageDestinationPropertyMap, source, destination, Toolkit::ImageView::Property::IMAGE);
+ if(imageSourcePropertyMap.Count() > 0)
{
- sourceVisual.CreatePropertyMap(sourceMap);
- sourceMixColor = findValue(sourceMap, Dali::Toolkit::Visual::Property::MIX_COLOR);
- sourceCornerRadius = findValue(sourceMap, Toolkit::DevelVisual::Property::CORNER_RADIUS);
+ sourceProperties.push_back(std::pair<Dali::Property::Index, Dali::Property::Map>(Toolkit::ImageView::Property::IMAGE, imageSourcePropertyMap));
+ destinationProperties.push_back(std::pair<Dali::Property::Index, Dali::Property::Map>(Toolkit::ImageView::Property::IMAGE, imageDestinationPropertyMap));
}
+}
- std::vector<Dali::Property> properties;
- std::vector<std::pair<Property::Value, Property::Value>> values;
-
- if(Vector3(sourceMixColor) != Vector3(destinationMixColor))
- {
- 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)
+void ImageView::OnUpdateVisualProperties(const std::vector<std::pair<Dali::Property::Index, Dali::Property::Map>>& properties)
+{
+ Toolkit::Visual::Base visual = DevelControl::GetVisual(*this, Toolkit::ImageView::Property::IMAGE);
+ if(visual)
{
- properties.push_back(DevelControl::GetVisualProperty(destinationHandle, Toolkit::ImageView::Property::IMAGE, Toolkit::DevelVisual::Property::CORNER_RADIUS));
- values.push_back(std::make_pair(sourceCornerRadius, destinationCornerRadius));
- }
+ Dali::Toolkit::Control handle(GetOwner());
- for(uint32_t i = 0; i < properties.size(); ++i)
- {
- if(timePeriod.delaySeconds > 0.0f)
+ for(auto&& data : properties)
{
- 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));
+ if(data.first == Toolkit::ImageView::Property::IMAGE)
+ {
+ DevelControl::DoAction(handle, Toolkit::ImageView::Property::IMAGE, DevelVisual::Action::UPDATE_PROPERTY, data.second);
+ break;
+ }
}
- 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);
}
}
else
{
map = value.GetMap();
- if(map)
+ if(DALI_LIKELY(map))
{
- 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)
+ // the property map is emtpy map. Unregister visual.
+ if(DALI_UNLIKELY(map->Count() == 0u))
{
- impl.SetImage(*map);
+ impl.ClearImageVisual();
}
- // the property map contains only the custom shader
- else if((map->Count() == 1u) && (shaderValue))
+ else
{
- Property::Map* shaderMap = shaderValue->GetMap();
- if(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)
{
- impl.mShaderMap = *shaderMap;
-
- if(!impl.mUrl.empty())
- {
- impl.SetImage(impl.mUrl, impl.mImageSize);
- }
- else if(!impl.mPropertyMap.Empty())
+ impl.SetImage(*map);
+ }
+ // the property map contains only the custom shader
+ else if((map->Count() == 1u) && (shaderValue))
+ {
+ Property::Map* shaderMap = shaderValue->GetMap();
+ if(shaderMap)
{
- impl.SetImage(impl.mPropertyMap);
+ impl.mShaderMap = *shaderMap;
+
+ if(!impl.mUrl.empty())
+ {
+ impl.SetImage(impl.mUrl, impl.mImageSize);
+ }
+ else if(!impl.mPropertyMap.Empty())
+ {
+ impl.SetImage(impl.mPropertyMap);
+ }
}
}
}
}
+ else
+ {
+ // invalid property value comes. Unregister visual.
+ impl.ClearImageVisual();
+ }
}
break;
}