2 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include "visual-base-impl.h"
22 #include <dali-toolkit/public-api/dali-toolkit-common.h>
23 #include <dali/devel-api/rendering/renderer-devel.h>
24 #include <dali/devel-api/scripting/enum-helper.h>
25 #include <dali/integration-api/debug.h>
28 #include <dali-toolkit/devel-api/visuals/visual-actions-devel.h>
29 #include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
30 #include <dali-toolkit/internal/helpers/property-helper.h>
31 #include <dali-toolkit/internal/visuals/visual-base-data-impl.h>
32 #include <dali-toolkit/internal/visuals/visual-string-constants.h>
33 #include <dali-toolkit/public-api/visuals/color-visual-properties.h>
34 #include <dali-toolkit/public-api/visuals/primitive-visual-properties.h>
35 #include <dali-toolkit/public-api/visuals/visual-properties.h>
39 #if defined(DEBUG_ENABLED)
40 Debug::Filter* gVisualBaseLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_VISUAL_BASE");
43 const char* const PRE_MULTIPLIED_ALPHA_PROPERTY("preMultipliedAlpha");
55 DALI_ENUM_TO_STRING_TABLE_BEGIN(VISUAL_FITTING_MODE)
56 DALI_ENUM_TO_STRING_WITH_SCOPE(Visual::FittingMode, FIT_KEEP_ASPECT_RATIO)
57 DALI_ENUM_TO_STRING_WITH_SCOPE(Visual::FittingMode, FILL)
58 DALI_ENUM_TO_STRING_WITH_SCOPE(Visual::FittingMode, OVER_FIT_KEEP_ASPECT_RATIO)
59 DALI_ENUM_TO_STRING_WITH_SCOPE(Visual::FittingMode, CENTER)
60 DALI_ENUM_TO_STRING_WITH_SCOPE(Visual::FittingMode, FIT_WIDTH)
61 DALI_ENUM_TO_STRING_WITH_SCOPE(Visual::FittingMode, FIT_HEIGHT)
62 DALI_ENUM_TO_STRING_TABLE_END(VISUAL_FITTING_MODE)
65 * @brief Check whether this visual type can use corner radius feature or not.
66 * @param type VisualType that want to checkup
67 * @return true if type can use corner radius feature.
69 static bool IsTypeAvailableForCornerRadius(Toolkit::Visual::Type type)
71 switch(static_cast<Toolkit::DevelVisual::Type>(type))
73 case Toolkit::Visual::Type::COLOR:
74 case Toolkit::Visual::Type::GRADIENT:
75 case Toolkit::Visual::Type::IMAGE:
76 case Toolkit::Visual::Type::SVG:
77 case Toolkit::Visual::Type::ANIMATED_IMAGE:
78 case Toolkit::DevelVisual::Type::ANIMATED_VECTOR_IMAGE:
90 * @brief Check whether this visual type can use borderline feature or not.
91 * @param type VisualType that want to checkup
92 * @return true if type can use borderline feature.
94 static bool IsTypeAvailableForBorderline(Toolkit::Visual::Type type)
96 switch(static_cast<Toolkit::DevelVisual::Type>(type))
98 case Toolkit::Visual::Type::COLOR:
99 case Toolkit::Visual::Type::GRADIENT:
100 case Toolkit::Visual::Type::IMAGE:
101 case Toolkit::Visual::Type::SVG:
102 case Toolkit::Visual::Type::ANIMATED_IMAGE:
103 case Toolkit::DevelVisual::Type::ANIMATED_VECTOR_IMAGE:
116 Visual::Base::Base(VisualFactoryCache& factoryCache, FittingMode fittingMode, Toolkit::Visual::Type type)
117 : mImpl(new Impl(fittingMode, type)),
118 mFactoryCache(factoryCache)
122 Visual::Base::~Base()
127 void Visual::Base::Initialize()
129 // The Renderer should be created inside derived class here.
136 if(IsRoundedCornerRequired())
138 mImpl->mCornerRadiusIndex = mImpl->mRenderer.RegisterProperty(DevelVisual::Property::CORNER_RADIUS, CORNER_RADIUS, mImpl->mCornerRadius);
139 mImpl->mRenderer.RegisterProperty(CORNER_RADIUS_POLICY, mImpl->mCornerRadiusPolicy);
141 mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON);
143 if(IsBorderlineRequired())
145 mImpl->mBorderlineWidthIndex = mImpl->mRenderer.RegisterProperty(DevelVisual::Property::BORDERLINE_WIDTH, BORDERLINE_WIDTH, mImpl->mBorderlineWidth);
146 mImpl->mBorderlineColorIndex = mImpl->mRenderer.RegisterProperty(DevelVisual::Property::BORDERLINE_COLOR, BORDERLINE_COLOR, mImpl->mBorderlineColor);
147 mImpl->mBorderlineOffsetIndex = mImpl->mRenderer.RegisterProperty(DevelVisual::Property::BORDERLINE_OFFSET, BORDERLINE_OFFSET, mImpl->mBorderlineOffset);
149 mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON_WITHOUT_CULL);
154 void Visual::Base::SetCustomShader(const Property::Map& shaderMap)
156 if(mImpl->mCustomShader)
158 mImpl->mCustomShader->SetPropertyMap(shaderMap);
162 mImpl->mCustomShader = new Impl::CustomShader(shaderMap);
165 // Let derived class know
169 void Visual::Base::SetProperties(const Property::Map& propertyMap)
171 for(size_t i = 0; i < propertyMap.Count(); ++i)
173 const KeyValuePair& pair = propertyMap.GetKeyValue(i);
174 const Property::Key& key = pair.first;
175 const Property::Value& value = pair.second;
177 Property::Key matchKey = key;
178 if(matchKey.type == Property::Key::STRING)
180 if(matchKey == CUSTOM_SHADER)
182 matchKey = Property::Key(Toolkit::Visual::Property::SHADER);
184 else if(matchKey == TRANSFORM)
186 matchKey = Property::Key(Toolkit::Visual::Property::TRANSFORM);
188 else if(matchKey == PREMULTIPLIED_ALPHA)
190 matchKey = Property::Key(Toolkit::Visual::Property::PREMULTIPLIED_ALPHA);
192 else if(matchKey == MIX_COLOR)
194 matchKey = Property::Key(Toolkit::Visual::Property::MIX_COLOR);
196 else if(matchKey == OPACITY)
198 matchKey = Property::Key(Toolkit::Visual::Property::OPACITY);
200 else if(matchKey == VISUAL_FITTING_MODE)
202 matchKey = Property::Key(Toolkit::DevelVisual::Property::VISUAL_FITTING_MODE);
204 else if(matchKey == BORDERLINE_WIDTH)
206 matchKey = Property::Key(Toolkit::DevelVisual::Property::BORDERLINE_WIDTH);
208 else if(matchKey == BORDERLINE_COLOR)
210 matchKey = Property::Key(Toolkit::DevelVisual::Property::BORDERLINE_COLOR);
212 else if(matchKey == BORDERLINE_OFFSET)
214 matchKey = Property::Key(Toolkit::DevelVisual::Property::BORDERLINE_OFFSET);
216 else if(matchKey == CORNER_RADIUS)
218 matchKey = Property::Key(Toolkit::DevelVisual::Property::CORNER_RADIUS);
220 else if(matchKey == CORNER_RADIUS_POLICY)
222 matchKey = Property::Key(Toolkit::DevelVisual::Property::CORNER_RADIUS_POLICY);
226 switch(matchKey.indexKey)
228 case Toolkit::Visual::Property::SHADER:
230 Property::Map shaderMap;
231 if(value.Get(shaderMap))
233 SetCustomShader(shaderMap);
238 case Toolkit::Visual::Property::TRANSFORM:
243 mImpl->mTransform.SetPropertyMap(map);
248 case Toolkit::Visual::Property::PREMULTIPLIED_ALPHA:
250 bool premultipliedAlpha = false;
251 if(value.Get(premultipliedAlpha))
253 EnablePreMultipliedAlpha(premultipliedAlpha);
258 case Toolkit::Visual::Property::MIX_COLOR:
261 if(value.Get(mixColor))
263 if(value.GetType() == Property::VECTOR4)
265 SetMixColor(mixColor);
269 Vector3 mixColor3(mixColor);
270 SetMixColor(mixColor3);
275 case Toolkit::Visual::Property::OPACITY:
278 if(value.Get(opacity))
280 mImpl->mMixColor.a = opacity;
281 SetMixColor(mImpl->mMixColor);
285 case Toolkit::DevelVisual::Property::VISUAL_FITTING_MODE:
287 Scripting::GetEnumerationProperty<Visual::FittingMode>(
288 value, VISUAL_FITTING_MODE_TABLE, VISUAL_FITTING_MODE_TABLE_COUNT, mImpl->mFittingMode);
291 case Toolkit::DevelVisual::Property::BORDERLINE_WIDTH:
296 mImpl->mBorderlineWidth = width;
299 if(mImpl->mBorderlineWidthIndex != Property::INVALID_INDEX)
301 mImpl->mRenderer.SetProperty(mImpl->mBorderlineWidthIndex, mImpl->mBorderlineWidth);
305 case Toolkit::DevelVisual::Property::BORDERLINE_COLOR:
310 mImpl->mBorderlineColor = color;
313 if(mImpl->mBorderlineColorIndex != Property::INVALID_INDEX)
315 mImpl->mRenderer.SetProperty(mImpl->mBorderlineColorIndex, mImpl->mBorderlineColor);
319 case Toolkit::DevelVisual::Property::BORDERLINE_OFFSET:
322 if(value.Get(offset))
324 mImpl->mBorderlineOffset = offset;
327 if(mImpl->mBorderlineOffsetIndex != Property::INVALID_INDEX)
329 mImpl->mRenderer.SetProperty(mImpl->mBorderlineOffsetIndex, mImpl->mBorderlineOffset);
333 case Toolkit::DevelVisual::Property::CORNER_RADIUS:
335 if(value.GetType() == Property::VECTOR4)
337 // If CORNER_RADIUS Property is Vector4,
338 // Each values mean the radius of
339 // (top-left, top-right, bottom-right, bottom-left)
341 if(value.Get(radius))
343 mImpl->mCornerRadius = radius;
348 // If CORNER_RADIUS Property is float,
349 // Every corner radius have same value
351 if(value.Get(radius))
353 mImpl->mCornerRadius = Vector4(radius, radius, radius, radius);
357 if(mImpl->mCornerRadiusIndex != Property::INVALID_INDEX)
359 mImpl->mRenderer.SetProperty(mImpl->mCornerRadiusIndex, mImpl->mCornerRadius);
363 case Toolkit::DevelVisual::Property::CORNER_RADIUS_POLICY:
366 if(value.Get(policy))
370 case Toolkit::Visual::Transform::Policy::RELATIVE:
371 case Toolkit::Visual::Transform::Policy::ABSOLUTE:
373 mImpl->mCornerRadiusPolicy = policy;
378 DALI_LOG_ERROR("Unsupported policy: %d\n", policy);
388 DoSetProperties(propertyMap);
391 void Visual::Base::SetTransformAndSize(const Property::Map& transform, Size controlSize)
393 mImpl->mControlSize = controlSize;
394 mImpl->mTransform.UpdatePropertyMap(transform);
396 #if defined(DEBUG_ENABLED)
397 std::ostringstream oss;
399 DALI_LOG_INFO(gVisualBaseLogFilter, Debug::General, "Visual::Base::SetTransformAndSize(%s) - [\e[1;32mtransform: %s controlSize: (%3.1f, %3.1f)]\e[0m\n", GetName().c_str(), oss.str().c_str(), controlSize.x, controlSize.y);
405 void Visual::Base::SetName(const std::string& name)
410 const std::string& Visual::Base::GetName() const
415 float Visual::Base::GetHeightForWidth(float width)
417 float aspectCorrectedHeight = 0.f;
419 GetNaturalSize(naturalSize);
420 if(naturalSize.width)
422 aspectCorrectedHeight = naturalSize.height * width / naturalSize.width;
424 return aspectCorrectedHeight;
427 float Visual::Base::GetWidthForHeight(float height)
429 float aspectCorrectedWidth = 0.f;
431 GetNaturalSize(naturalSize);
432 if(naturalSize.height > 0.0f)
434 aspectCorrectedWidth = naturalSize.width * height / naturalSize.height;
436 return aspectCorrectedWidth;
439 void Visual::Base::GetNaturalSize(Vector2& naturalSize)
441 naturalSize = Vector2::ZERO;
444 void Visual::Base::DoAction(const Property::Index actionId, const Property::Value attributes)
446 OnDoAction(actionId, attributes);
448 // Check if action is valid for this visual type and perform action if possible
451 case DevelVisual::Action::UPDATE_PROPERTY:
453 const Property::Map* map = attributes.GetMap();
463 void Visual::Base::SetDepthIndex(int index)
465 mImpl->mDepthIndex = index;
468 mImpl->mRenderer.SetProperty(Renderer::Property::DEPTH_INDEX, mImpl->mDepthIndex);
472 int Visual::Base::GetDepthIndex() const
474 return mImpl->mDepthIndex;
477 void Visual::Base::SetOnScene(Actor& actor)
481 // To display the actor correctly, renderer should not be added to actor until all required resources are ready.
482 // Thus the calling of actor.AddRenderer() should happen inside derived class as base class does not know the exact timing.
487 mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, IsPreMultipliedAlphaEnabled());
488 mImpl->mRenderer.SetProperty(Renderer::Property::DEPTH_INDEX, mImpl->mDepthIndex);
491 mImpl->mFlags |= Impl::IS_ON_SCENE;
495 void Visual::Base::SetOffScene(Actor& actor)
499 DoSetOffScene(actor);
500 mImpl->mFlags &= ~Impl::IS_ON_SCENE;
504 void Visual::Base::CreatePropertyMap(Property::Map& map) const
508 // Update values from Renderer
509 mImpl->mMixColor = mImpl->mRenderer.GetProperty<Vector3>(mImpl->mMixColorIndex);
510 mImpl->mMixColor.a = mImpl->mRenderer.GetProperty<float>(DevelRenderer::Property::OPACITY);
511 if(mImpl->mTransform.mOffsetIndex != Property::INVALID_INDEX)
513 mImpl->mTransform.mOffset = mImpl->mRenderer.GetProperty<Vector2>(mImpl->mTransform.mOffsetIndex);
515 if(mImpl->mTransform.mSizeIndex != Property::INVALID_INDEX)
517 mImpl->mTransform.mSize = mImpl->mRenderer.GetProperty<Vector2>(mImpl->mTransform.mSizeIndex);
519 if(mImpl->mCornerRadiusIndex != Property::INVALID_INDEX)
521 mImpl->mCornerRadius = mImpl->mRenderer.GetProperty<Vector4>(mImpl->mCornerRadiusIndex);
523 if(mImpl->mBorderlineWidthIndex != Property::INVALID_INDEX)
525 mImpl->mBorderlineWidth = mImpl->mRenderer.GetProperty<float>(mImpl->mBorderlineWidthIndex);
527 if(mImpl->mBorderlineColorIndex != Property::INVALID_INDEX)
529 mImpl->mBorderlineColor = mImpl->mRenderer.GetProperty<Vector4>(mImpl->mBorderlineColorIndex);
531 if(mImpl->mBorderlineOffsetIndex != Property::INVALID_INDEX)
533 mImpl->mBorderlineOffset = mImpl->mRenderer.GetProperty<float>(mImpl->mBorderlineOffsetIndex);
537 DoCreatePropertyMap(map);
539 if(mImpl->mCustomShader)
541 mImpl->mCustomShader->CreatePropertyMap(map);
544 Property::Map transform;
545 mImpl->mTransform.GetPropertyMap(transform);
546 map.Insert(Toolkit::Visual::Property::TRANSFORM, transform);
548 bool premultipliedAlpha(IsPreMultipliedAlphaEnabled());
549 map.Insert(Toolkit::Visual::Property::PREMULTIPLIED_ALPHA, premultipliedAlpha);
551 // Note, Color and Primitive will also insert their own mix color into the map
552 // which is ok, because they have a different key value range.
553 map.Insert(Toolkit::Visual::Property::MIX_COLOR, mImpl->mMixColor); // vec4
554 map.Insert(Toolkit::Visual::Property::OPACITY, mImpl->mMixColor.a);
556 auto fittingModeString = Scripting::GetLinearEnumerationName<FittingMode>(
557 mImpl->mFittingMode, VISUAL_FITTING_MODE_TABLE, VISUAL_FITTING_MODE_TABLE_COUNT);
558 map.Insert(Toolkit::DevelVisual::Property::VISUAL_FITTING_MODE, fittingModeString);
560 map.Insert(Toolkit::DevelVisual::Property::BORDERLINE_WIDTH, mImpl->mBorderlineWidth);
561 map.Insert(Toolkit::DevelVisual::Property::BORDERLINE_COLOR, mImpl->mBorderlineColor);
562 map.Insert(Toolkit::DevelVisual::Property::BORDERLINE_OFFSET, mImpl->mBorderlineOffset);
564 map.Insert(Toolkit::DevelVisual::Property::CORNER_RADIUS, mImpl->mCornerRadius);
565 map.Insert(Toolkit::DevelVisual::Property::CORNER_RADIUS_POLICY, static_cast<int>(mImpl->mCornerRadiusPolicy));
568 void Visual::Base::CreateInstancePropertyMap(Property::Map& map) const
570 DoCreateInstancePropertyMap(map);
572 if(mImpl->mCustomShader)
574 mImpl->mCustomShader->CreatePropertyMap(map);
578 void Visual::Base::EnablePreMultipliedAlpha(bool preMultiplied)
582 mImpl->mFlags |= Impl::IS_PREMULTIPLIED_ALPHA;
586 mImpl->mFlags &= ~Impl::IS_PREMULTIPLIED_ALPHA;
591 mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, preMultiplied);
592 mImpl->mRenderer.RegisterProperty(PRE_MULTIPLIED_ALPHA_PROPERTY, static_cast<float>(preMultiplied));
596 bool Visual::Base::IsPreMultipliedAlphaEnabled() const
598 return mImpl->mFlags & Impl::IS_PREMULTIPLIED_ALPHA;
601 void Visual::Base::DoSetOffScene(Actor& actor)
603 actor.RemoveRenderer(mImpl->mRenderer);
606 bool Visual::Base::IsOnScene() const
608 return mImpl->mFlags & Impl::IS_ON_SCENE;
611 bool Visual::Base::IsRoundedCornerRequired() const
613 // If VisualType doesn't support rounded corner, always return false.
614 if(IsTypeAvailableForCornerRadius(mImpl->mType))
616 if(mImpl->mRenderer && mImpl->mCornerRadiusIndex != Property::INVALID_INDEX)
618 // Update values from Renderer
619 mImpl->mCornerRadius = mImpl->mRenderer.GetProperty<Vector4>(mImpl->mCornerRadiusIndex);
621 return !(mImpl->mCornerRadius == Vector4::ZERO) || mImpl->mAlwaysUsingCornerRadius;
626 bool Visual::Base::IsBorderlineRequired() const
628 // If VisualType doesn't support borderline, always return false.
629 if(IsTypeAvailableForBorderline(mImpl->mType))
631 if(mImpl->mRenderer && mImpl->mBorderlineWidthIndex != Property::INVALID_INDEX)
633 // Update values from Renderer
634 mImpl->mBorderlineWidth = mImpl->mRenderer.GetProperty<float>(mImpl->mBorderlineWidthIndex);
636 return !EqualsZero(mImpl->mBorderlineWidth) || mImpl->mAlwaysUsingBorderline;
641 void Visual::Base::OnDoAction(const Property::Index actionId, const Property::Value& attributes)
643 // May be overriden by derived class
646 void Visual::Base::RegisterMixColor()
648 // Only register if not already registered.
649 // (Color and Primitive visuals will register their own and save to this index)
650 if(mImpl->mMixColorIndex == Property::INVALID_INDEX)
652 mImpl->mMixColorIndex = mImpl->mRenderer.RegisterProperty(
653 Toolkit::Visual::Property::MIX_COLOR,
655 Vector3(mImpl->mMixColor));
658 mImpl->mRenderer.SetProperty(DevelRenderer::Property::OPACITY, mImpl->mMixColor.a);
660 float preMultipliedAlpha = 0.0f;
661 if(IsPreMultipliedAlphaEnabled())
663 preMultipliedAlpha = 1.0f;
665 mImpl->mRenderer.RegisterProperty(PRE_MULTIPLIED_ALPHA_PROPERTY, preMultipliedAlpha);
668 void Visual::Base::SetMixColor(const Vector4& color)
670 mImpl->mMixColor = color;
674 mImpl->mRenderer.SetProperty(mImpl->mMixColorIndex, Vector3(color));
675 mImpl->mRenderer.SetProperty(DevelRenderer::Property::OPACITY, color.a);
679 void Visual::Base::SetMixColor(const Vector3& color)
681 mImpl->mMixColor.r = color.r;
682 mImpl->mMixColor.g = color.g;
683 mImpl->mMixColor.b = color.b;
687 mImpl->mRenderer.SetProperty(mImpl->mMixColorIndex, color);
691 void Visual::Base::AddEventObserver(Visual::EventObserver& observer)
693 mImpl->mEventObserver = &observer;
696 void Visual::Base::RemoveEventObserver(Visual::EventObserver& observer)
698 mImpl->mEventObserver = NULL;
701 void Visual::Base::ResourceReady(Toolkit::Visual::ResourceStatus resourceStatus)
703 if(mImpl->mResourceStatus != resourceStatus)
705 mImpl->mResourceStatus = resourceStatus;
707 if(mImpl->mEventObserver)
709 // observer is currently a control impl
710 mImpl->mEventObserver->ResourceReady(*this);
715 bool Visual::Base::IsResourceReady() const
717 return (mImpl->mResourceStatus == Toolkit::Visual::ResourceStatus::READY);
720 bool Visual::Base::IsSynchronousLoadingRequired() const
722 return (mImpl->mFlags & Impl::IS_SYNCHRONOUS_RESOURCE_LOADING);
725 Toolkit::Visual::Type Visual::Base::GetType() const
730 Toolkit::Visual::ResourceStatus Visual::Base::GetResourceStatus() const
732 return mImpl->mResourceStatus;
735 Visual::FittingMode Visual::Base::GetFittingMode() const
737 return mImpl->mFittingMode;
740 Visual::Base& Visual::Base::GetVisualObject()
745 Renderer Visual::Base::GetRenderer()
747 return mImpl->mRenderer;
750 Property::Index Visual::Base::GetPropertyIndex(Property::Key key)
752 Property::Index index = mImpl->mRenderer.GetPropertyIndex(key);
754 if(index == Property::INVALID_INDEX)
756 // Is it a shader property?
757 Shader shader = mImpl->mRenderer.GetShader();
758 index = shader.GetPropertyIndex(key);
759 if(index != Property::INVALID_INDEX)
761 // Yes - we should register it in the Renderer so it can be set / animated
762 // independently, as shaders are shared across multiple renderers.
764 Property::Index keyIndex(Property::INVALID_KEY);
765 if(key.type == Property::Key::INDEX)
767 keyName = shader.GetPropertyName(index);
768 keyIndex = key.indexKey;
772 keyName = key.stringKey;
773 // Leave keyIndex as INVALID_KEY - it can still be registered against the string key.
775 Property::Value value = shader.GetProperty(index);
776 index = mImpl->mRenderer.RegisterProperty(keyIndex, keyName, value);
782 void Visual::Base::SetupTransition(
783 Dali::Animation& transition,
784 Internal::TransitionData::Animator& animator,
785 Property::Index index,
786 Property::Value& initialValue,
787 Property::Value& targetValue)
789 if(index != Property::INVALID_INDEX)
793 if(animator.animate == false)
795 mImpl->mRenderer.SetProperty(index, targetValue);
799 if(animator.initialValue.GetType() != Property::NONE)
801 mImpl->mRenderer.SetProperty(index, initialValue);
806 transition = Dali::Animation::New(0.1f);
809 transition.AnimateTo(Property(mImpl->mRenderer, index),
811 animator.alphaFunction,
812 TimePeriod(animator.timePeriodDelay,
813 animator.timePeriodDuration));
819 void Visual::Base::AnimateProperty(
820 Dali::Animation& transition,
821 Internal::TransitionData::Animator& animator)
823 #if defined(DEBUG_ENABLED)
825 std::ostringstream oss;
826 oss << "Visual::Base::AnimateProperty(Visual:" << mImpl->mName << " Property:" << animator.propertyKey << " Target: " << animator.targetValue << std::endl;
827 DALI_LOG_INFO(gVisualBaseLogFilter, Debug::General, oss.str().c_str());
831 if(animator.propertyKey == Toolkit::Visual::Property::MIX_COLOR ||
832 animator.propertyKey == MIX_COLOR ||
833 (mImpl->mType == Toolkit::Visual::COLOR &&
834 animator.propertyKey == ColorVisual::Property::MIX_COLOR) ||
835 (mImpl->mType == Toolkit::Visual::PRIMITIVE &&
836 animator.propertyKey == PrimitiveVisual::Property::MIX_COLOR))
838 AnimateMixColorProperty(transition, animator);
840 else if(animator.propertyKey == Toolkit::Visual::Property::OPACITY ||
841 animator.propertyKey == OPACITY)
843 AnimateOpacityProperty(transition, animator);
845 else if(mImpl->mRenderer)
847 AnimateRendererProperty(transition, animator);
851 void Visual::Base::AnimateOpacityProperty(
852 Dali::Animation& transition,
853 Internal::TransitionData::Animator& animator)
856 if(animator.targetValue.Get(targetOpacity))
858 mImpl->mMixColor.a = targetOpacity;
861 SetupTransition(transition, animator, DevelRenderer::Property::OPACITY, animator.initialValue, animator.targetValue);
864 void Visual::Base::AnimateRendererProperty(
865 Dali::Animation& transition,
866 Internal::TransitionData::Animator& animator)
868 Property::Index index = GetPropertyIndex(animator.propertyKey);
869 if(index != Property::INVALID_INDEX)
871 if(animator.targetValue.GetType() != Property::NONE)
873 // Try writing target value into transform property map
874 // if it's not a valid key, then it won't alter mTransform
876 if(animator.propertyKey.type == Property::Key::INDEX)
878 map.Add(animator.propertyKey.indexKey, animator.targetValue);
882 map.Add(animator.propertyKey.stringKey, animator.targetValue);
885 mImpl->mTransform.UpdatePropertyMap(map);
888 SetupTransition(transition, animator, index, animator.initialValue, animator.targetValue);
892 void Visual::Base::AnimateMixColorProperty(
893 Dali::Animation& transition,
894 Internal::TransitionData::Animator& animator)
896 Property::Index index = mImpl->mMixColorIndex;
897 bool animateOpacity = false;
899 Property::Value initialOpacity;
900 Property::Value targetOpacity;
901 Property::Value initialMixColor;
902 Property::Value targetMixColor;
904 if(index != Property::INVALID_INDEX)
906 Vector4 initialColor;
907 if(animator.initialValue.Get(initialColor))
909 if(animator.initialValue.GetType() == Property::VECTOR4)
911 // if there is an initial color specifying alpha, test it
912 initialOpacity = initialColor.a;
914 initialMixColor = Vector3(initialColor);
917 // Set target value into data store
918 if(animator.targetValue.GetType() != Property::NONE)
921 animator.targetValue.Get(mixColor);
922 if(animator.targetValue.GetType() == Property::VECTOR4)
924 mImpl->mMixColor.a = mixColor.a;
925 targetOpacity = mixColor.a;
926 animateOpacity = true;
929 mImpl->mMixColor.r = mixColor.r;
930 mImpl->mMixColor.g = mixColor.g;
931 mImpl->mMixColor.b = mixColor.b;
932 targetMixColor = Vector3(mixColor);
935 SetupTransition(transition, animator, index, initialMixColor, targetMixColor);
938 SetupTransition(transition, animator, DevelRenderer::Property::OPACITY, initialOpacity, targetOpacity);
943 Dali::Property Visual::Base::GetPropertyObject(Dali::Property::Key key)
945 if(!mImpl->mRenderer)
948 return Dali::Property(handle, Property::INVALID_INDEX);
951 // Mix color or opacity cases
952 if(key.type == Property::Key::INDEX)
954 if(key.indexKey == Toolkit::Visual::Property::MIX_COLOR || (mImpl->mType == Toolkit::Visual::COLOR && key.indexKey == ColorVisual::Property::MIX_COLOR) || (mImpl->mType == Toolkit::Visual::PRIMITIVE && key.indexKey == PrimitiveVisual::Property::MIX_COLOR))
956 return Dali::Property(mImpl->mRenderer, mImpl->mMixColorIndex);
958 else if(key.indexKey == Toolkit::Visual::Property::OPACITY)
960 return Dali::Property(mImpl->mRenderer, DevelRenderer::Property::OPACITY);
962 else if(key.indexKey == Toolkit::Visual::Transform::Property::OFFSET)
964 return Dali::Property(mImpl->mRenderer, OFFSET);
966 else if(key.indexKey == Toolkit::Visual::Transform::Property::SIZE)
968 return Dali::Property(mImpl->mRenderer, SIZE);
973 if(key.stringKey == MIX_COLOR)
975 return Dali::Property(mImpl->mRenderer, mImpl->mMixColorIndex);
977 else if(key.stringKey == OPACITY)
979 return Dali::Property(mImpl->mRenderer, DevelRenderer::Property::OPACITY);
981 else if(key.stringKey == OFFSET)
983 return Dali::Property(mImpl->mRenderer, OFFSET);
985 else if(key.stringKey == SIZE)
987 return Dali::Property(mImpl->mRenderer, SIZE);
992 Property::Index index = GetPropertyIndex(key);
993 if(index == Property::INVALID_INDEX)
995 if(IsTypeAvailableForBorderline(mImpl->mType) &&
996 ((key.type == Property::Key::INDEX && key.indexKey == DevelVisual::Property::BORDERLINE_WIDTH) || (key.type == Property::Key::STRING && key.stringKey == BORDERLINE_WIDTH) ||
997 (key.type == Property::Key::INDEX && key.indexKey == DevelVisual::Property::BORDERLINE_COLOR) || (key.type == Property::Key::STRING && key.stringKey == BORDERLINE_COLOR) ||
998 (key.type == Property::Key::INDEX && key.indexKey == DevelVisual::Property::BORDERLINE_OFFSET) || (key.type == Property::Key::STRING && key.stringKey == BORDERLINE_OFFSET)))
1000 mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON_WITHOUT_CULL);
1002 // Register borderline properties
1003 mImpl->mBorderlineWidthIndex = mImpl->mRenderer.RegisterProperty(DevelVisual::Property::BORDERLINE_WIDTH, BORDERLINE_WIDTH, mImpl->mBorderlineWidth);
1004 mImpl->mBorderlineColorIndex = mImpl->mRenderer.RegisterProperty(DevelVisual::Property::BORDERLINE_COLOR, BORDERLINE_COLOR, mImpl->mBorderlineColor);
1005 mImpl->mBorderlineOffsetIndex = mImpl->mRenderer.RegisterProperty(DevelVisual::Property::BORDERLINE_OFFSET, BORDERLINE_OFFSET, mImpl->mBorderlineOffset);
1007 // Borderline is animated now. we always have to use borderline feature.
1008 mImpl->mAlwaysUsingBorderline = true;
1010 index = mImpl->mRenderer.GetPropertyIndex(key);
1015 else if(IsTypeAvailableForCornerRadius(mImpl->mType) && ((key.type == Property::Key::INDEX && key.indexKey == DevelVisual::Property::CORNER_RADIUS) || (key.type == Property::Key::STRING && key.stringKey == CORNER_RADIUS)))
1017 // Register CORNER_RADIUS property
1018 mImpl->mCornerRadiusIndex = mImpl->mRenderer.RegisterProperty(DevelVisual::Property::CORNER_RADIUS, CORNER_RADIUS, mImpl->mCornerRadius);
1019 mImpl->mRenderer.RegisterProperty(CORNER_RADIUS_POLICY, mImpl->mCornerRadiusPolicy);
1021 // ConerRadius is animated now. we always have to use corner radius feature.
1022 mImpl->mAlwaysUsingCornerRadius = true;
1024 if(!IsBorderlineRequired())
1026 // If IsBorderlineRequired is true, BLEND_MODE is already BlendMode::ON_WITHOUT_CULL. So we don't overwrite it.
1027 mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON);
1030 index = mImpl->mCornerRadiusIndex;
1037 // We can't find the property in the base class.
1038 // Request to child class
1039 return OnGetPropertyObject(key);
1043 return Dali::Property(mImpl->mRenderer, index);
1046 } // namespace Internal
1048 } // namespace Toolkit