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;
300 case Toolkit::DevelVisual::Property::BORDERLINE_COLOR:
305 mImpl->mBorderlineColor = color;
309 case Toolkit::DevelVisual::Property::BORDERLINE_OFFSET:
312 if(value.Get(offset))
314 mImpl->mBorderlineOffset = offset;
318 case Toolkit::DevelVisual::Property::CORNER_RADIUS:
320 if(value.GetType() == Property::VECTOR4)
322 // If CORNER_RADIUS Property is Vector4,
323 // Each values mean the radius of
324 // (top-left, top-right, bottom-right, bottom-left)
326 if(value.Get(radius))
328 mImpl->mCornerRadius = radius;
333 // If CORNER_RADIUS Property is float,
334 // Every corner radius have same value
336 if(value.Get(radius))
338 mImpl->mCornerRadius = Vector4(radius, radius, radius, radius);
343 case Toolkit::DevelVisual::Property::CORNER_RADIUS_POLICY:
346 if(value.Get(policy))
350 case Toolkit::Visual::Transform::Policy::RELATIVE:
351 case Toolkit::Visual::Transform::Policy::ABSOLUTE:
353 mImpl->mCornerRadiusPolicy = policy;
358 DALI_LOG_ERROR("Unsupported policy: %d\n", policy);
368 DoSetProperties(propertyMap);
371 void Visual::Base::SetTransformAndSize(const Property::Map& transform, Size controlSize)
373 mImpl->mControlSize = controlSize;
374 mImpl->mTransform.UpdatePropertyMap(transform);
376 #if defined(DEBUG_ENABLED)
377 std::ostringstream oss;
379 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);
385 void Visual::Base::SetName(const std::string& name)
390 const std::string& Visual::Base::GetName() const
395 float Visual::Base::GetHeightForWidth(float width)
397 float aspectCorrectedHeight = 0.f;
399 GetNaturalSize(naturalSize);
400 if(naturalSize.width)
402 aspectCorrectedHeight = naturalSize.height * width / naturalSize.width;
404 return aspectCorrectedHeight;
407 float Visual::Base::GetWidthForHeight(float height)
409 float aspectCorrectedWidth = 0.f;
411 GetNaturalSize(naturalSize);
412 if(naturalSize.height > 0.0f)
414 aspectCorrectedWidth = naturalSize.width * height / naturalSize.height;
416 return aspectCorrectedWidth;
419 void Visual::Base::GetNaturalSize(Vector2& naturalSize)
421 naturalSize = Vector2::ZERO;
424 void Visual::Base::DoAction(const Property::Index actionId, const Property::Value attributes)
426 OnDoAction(actionId, attributes);
428 // Check if action is valid for this visual type and perform action if possible
431 case DevelVisual::Action::UPDATE_PROPERTY:
433 const Property::Map* map = attributes.GetMap();
443 void Visual::Base::SetDepthIndex(int index)
445 mImpl->mDepthIndex = index;
448 mImpl->mRenderer.SetProperty(Renderer::Property::DEPTH_INDEX, mImpl->mDepthIndex);
452 int Visual::Base::GetDepthIndex() const
454 return mImpl->mDepthIndex;
457 void Visual::Base::SetOnScene(Actor& actor)
461 // To display the actor correctly, renderer should not be added to actor until all required resources are ready.
462 // Thus the calling of actor.AddRenderer() should happen inside derived class as base class does not know the exact timing.
467 mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, IsPreMultipliedAlphaEnabled());
468 mImpl->mRenderer.SetProperty(Renderer::Property::DEPTH_INDEX, mImpl->mDepthIndex);
471 mImpl->mFlags |= Impl::IS_ON_SCENE;
475 void Visual::Base::SetOffScene(Actor& actor)
479 DoSetOffScene(actor);
480 mImpl->mFlags &= ~Impl::IS_ON_SCENE;
484 void Visual::Base::CreatePropertyMap(Property::Map& map) const
488 // Update values from Renderer
489 mImpl->mMixColor = mImpl->mRenderer.GetProperty<Vector3>(mImpl->mMixColorIndex);
490 mImpl->mMixColor.a = mImpl->mRenderer.GetProperty<float>(DevelRenderer::Property::OPACITY);
491 if(mImpl->mTransform.mOffsetIndex != Property::INVALID_INDEX)
493 mImpl->mTransform.mOffset = mImpl->mRenderer.GetProperty<Vector2>(mImpl->mTransform.mOffsetIndex);
495 if(mImpl->mTransform.mSizeIndex != Property::INVALID_INDEX)
497 mImpl->mTransform.mSize = mImpl->mRenderer.GetProperty<Vector2>(mImpl->mTransform.mSizeIndex);
499 if(mImpl->mCornerRadiusIndex != Property::INVALID_INDEX)
501 mImpl->mCornerRadius = mImpl->mRenderer.GetProperty<Vector4>(mImpl->mCornerRadiusIndex);
503 if(mImpl->mBorderlineWidthIndex != Property::INVALID_INDEX)
505 mImpl->mBorderlineWidth = mImpl->mRenderer.GetProperty<float>(mImpl->mBorderlineWidthIndex);
507 if(mImpl->mBorderlineColorIndex != Property::INVALID_INDEX)
509 mImpl->mBorderlineColor = mImpl->mRenderer.GetProperty<Vector4>(mImpl->mBorderlineColorIndex);
511 if(mImpl->mBorderlineOffsetIndex != Property::INVALID_INDEX)
513 mImpl->mBorderlineOffset = mImpl->mRenderer.GetProperty<float>(mImpl->mBorderlineOffsetIndex);
517 DoCreatePropertyMap(map);
519 if(mImpl->mCustomShader)
521 mImpl->mCustomShader->CreatePropertyMap(map);
524 Property::Map transform;
525 mImpl->mTransform.GetPropertyMap(transform);
526 map.Insert(Toolkit::Visual::Property::TRANSFORM, transform);
528 bool premultipliedAlpha(IsPreMultipliedAlphaEnabled());
529 map.Insert(Toolkit::Visual::Property::PREMULTIPLIED_ALPHA, premultipliedAlpha);
531 // Note, Color and Primitive will also insert their own mix color into the map
532 // which is ok, because they have a different key value range.
533 map.Insert(Toolkit::Visual::Property::MIX_COLOR, mImpl->mMixColor); // vec4
534 map.Insert(Toolkit::Visual::Property::OPACITY, mImpl->mMixColor.a);
536 auto fittingModeString = Scripting::GetLinearEnumerationName<FittingMode>(
537 mImpl->mFittingMode, VISUAL_FITTING_MODE_TABLE, VISUAL_FITTING_MODE_TABLE_COUNT);
538 map.Insert(Toolkit::DevelVisual::Property::VISUAL_FITTING_MODE, fittingModeString);
540 map.Insert(Toolkit::DevelVisual::Property::BORDERLINE_WIDTH, mImpl->mBorderlineWidth);
541 map.Insert(Toolkit::DevelVisual::Property::BORDERLINE_COLOR, mImpl->mBorderlineColor);
542 map.Insert(Toolkit::DevelVisual::Property::BORDERLINE_OFFSET, mImpl->mBorderlineOffset);
544 map.Insert(Toolkit::DevelVisual::Property::CORNER_RADIUS, mImpl->mCornerRadius);
545 map.Insert(Toolkit::DevelVisual::Property::CORNER_RADIUS_POLICY, static_cast<int>(mImpl->mCornerRadiusPolicy));
548 void Visual::Base::CreateInstancePropertyMap(Property::Map& map) const
550 DoCreateInstancePropertyMap(map);
552 if(mImpl->mCustomShader)
554 mImpl->mCustomShader->CreatePropertyMap(map);
558 void Visual::Base::EnablePreMultipliedAlpha(bool preMultiplied)
562 mImpl->mFlags |= Impl::IS_PREMULTIPLIED_ALPHA;
566 mImpl->mFlags &= ~Impl::IS_PREMULTIPLIED_ALPHA;
571 mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, preMultiplied);
572 mImpl->mRenderer.RegisterProperty(PRE_MULTIPLIED_ALPHA_PROPERTY, static_cast<float>(preMultiplied));
576 bool Visual::Base::IsPreMultipliedAlphaEnabled() const
578 return mImpl->mFlags & Impl::IS_PREMULTIPLIED_ALPHA;
581 void Visual::Base::DoSetOffScene(Actor& actor)
583 actor.RemoveRenderer(mImpl->mRenderer);
586 bool Visual::Base::IsOnScene() const
588 return mImpl->mFlags & Impl::IS_ON_SCENE;
591 bool Visual::Base::IsRoundedCornerRequired() const
593 // If VisualType doesn't support rounded corner, always return false.
594 if(IsTypeAvailableForCornerRadius(mImpl->mType))
596 if(mImpl->mRenderer && mImpl->mCornerRadiusIndex != Property::INVALID_INDEX)
598 // Update values from Renderer
599 mImpl->mCornerRadius = mImpl->mRenderer.GetProperty<Vector4>(mImpl->mCornerRadiusIndex);
601 return !(mImpl->mCornerRadius == Vector4::ZERO) || mImpl->mAlwaysUsingCornerRadius;
606 bool Visual::Base::IsBorderlineRequired() const
608 // If VisualType doesn't support borderline, always return false.
609 if(IsTypeAvailableForBorderline(mImpl->mType))
611 if(mImpl->mRenderer && mImpl->mBorderlineWidthIndex != Property::INVALID_INDEX)
613 // Update values from Renderer
614 mImpl->mBorderlineWidth = mImpl->mRenderer.GetProperty<float>(mImpl->mBorderlineWidthIndex);
616 return !EqualsZero(mImpl->mBorderlineWidth) || mImpl->mAlwaysUsingBorderline;
621 void Visual::Base::OnDoAction(const Property::Index actionId, const Property::Value& attributes)
623 // May be overriden by derived class
626 void Visual::Base::RegisterMixColor()
628 // Only register if not already registered.
629 // (Color and Primitive visuals will register their own and save to this index)
630 if(mImpl->mMixColorIndex == Property::INVALID_INDEX)
632 mImpl->mMixColorIndex = mImpl->mRenderer.RegisterProperty(
633 Toolkit::Visual::Property::MIX_COLOR,
635 Vector3(mImpl->mMixColor));
638 mImpl->mRenderer.SetProperty(DevelRenderer::Property::OPACITY, mImpl->mMixColor.a);
640 float preMultipliedAlpha = 0.0f;
641 if(IsPreMultipliedAlphaEnabled())
643 preMultipliedAlpha = 1.0f;
645 mImpl->mRenderer.RegisterProperty(PRE_MULTIPLIED_ALPHA_PROPERTY, preMultipliedAlpha);
648 void Visual::Base::SetMixColor(const Vector4& color)
650 mImpl->mMixColor = color;
654 mImpl->mRenderer.SetProperty(mImpl->mMixColorIndex, Vector3(color));
655 mImpl->mRenderer.SetProperty(DevelRenderer::Property::OPACITY, color.a);
659 void Visual::Base::SetMixColor(const Vector3& color)
661 mImpl->mMixColor.r = color.r;
662 mImpl->mMixColor.g = color.g;
663 mImpl->mMixColor.b = color.b;
667 mImpl->mRenderer.SetProperty(mImpl->mMixColorIndex, color);
671 void Visual::Base::AddEventObserver(Visual::EventObserver& observer)
673 mImpl->mEventObserver = &observer;
676 void Visual::Base::RemoveEventObserver(Visual::EventObserver& observer)
678 mImpl->mEventObserver = NULL;
681 void Visual::Base::ResourceReady(Toolkit::Visual::ResourceStatus resourceStatus)
683 if(mImpl->mResourceStatus != resourceStatus)
685 mImpl->mResourceStatus = resourceStatus;
687 if(mImpl->mEventObserver)
689 // observer is currently a control impl
690 mImpl->mEventObserver->ResourceReady(*this);
695 bool Visual::Base::IsResourceReady() const
697 return (mImpl->mResourceStatus == Toolkit::Visual::ResourceStatus::READY);
700 bool Visual::Base::IsSynchronousLoadingRequired() const
702 return (mImpl->mFlags & Impl::IS_SYNCHRONOUS_RESOURCE_LOADING);
705 Toolkit::Visual::Type Visual::Base::GetType() const
710 Toolkit::Visual::ResourceStatus Visual::Base::GetResourceStatus() const
712 return mImpl->mResourceStatus;
715 Visual::FittingMode Visual::Base::GetFittingMode() const
717 return mImpl->mFittingMode;
720 Visual::Base& Visual::Base::GetVisualObject()
725 Renderer Visual::Base::GetRenderer()
727 return mImpl->mRenderer;
730 Property::Index Visual::Base::GetPropertyIndex(Property::Key key)
732 Property::Index index = mImpl->mRenderer.GetPropertyIndex(key);
734 if(index == Property::INVALID_INDEX)
736 // Is it a shader property?
737 Shader shader = mImpl->mRenderer.GetShader();
738 index = shader.GetPropertyIndex(key);
739 if(index != Property::INVALID_INDEX)
741 // Yes - we should register it in the Renderer so it can be set / animated
742 // independently, as shaders are shared across multiple renderers.
744 Property::Index keyIndex(Property::INVALID_KEY);
745 if(key.type == Property::Key::INDEX)
747 keyName = shader.GetPropertyName(index);
748 keyIndex = key.indexKey;
752 keyName = key.stringKey;
753 // Leave keyIndex as INVALID_KEY - it can still be registered against the string key.
755 Property::Value value = shader.GetProperty(index);
756 index = mImpl->mRenderer.RegisterProperty(keyIndex, keyName, value);
762 void Visual::Base::SetupTransition(
763 Dali::Animation& transition,
764 Internal::TransitionData::Animator& animator,
765 Property::Index index,
766 Property::Value& initialValue,
767 Property::Value& targetValue)
769 if(index != Property::INVALID_INDEX)
773 if(animator.animate == false)
775 mImpl->mRenderer.SetProperty(index, targetValue);
779 if(animator.initialValue.GetType() != Property::NONE)
781 mImpl->mRenderer.SetProperty(index, initialValue);
786 transition = Dali::Animation::New(0.1f);
789 transition.AnimateTo(Property(mImpl->mRenderer, index),
791 animator.alphaFunction,
792 TimePeriod(animator.timePeriodDelay,
793 animator.timePeriodDuration));
799 void Visual::Base::AnimateProperty(
800 Dali::Animation& transition,
801 Internal::TransitionData::Animator& animator)
803 #if defined(DEBUG_ENABLED)
805 std::ostringstream oss;
806 oss << "Visual::Base::AnimateProperty(Visual:" << mImpl->mName << " Property:" << animator.propertyKey << " Target: " << animator.targetValue << std::endl;
807 DALI_LOG_INFO(gVisualBaseLogFilter, Debug::General, oss.str().c_str());
811 if(animator.propertyKey == Toolkit::Visual::Property::MIX_COLOR ||
812 animator.propertyKey == MIX_COLOR ||
813 (mImpl->mType == Toolkit::Visual::COLOR &&
814 animator.propertyKey == ColorVisual::Property::MIX_COLOR) ||
815 (mImpl->mType == Toolkit::Visual::PRIMITIVE &&
816 animator.propertyKey == PrimitiveVisual::Property::MIX_COLOR))
818 AnimateMixColorProperty(transition, animator);
820 else if(animator.propertyKey == Toolkit::Visual::Property::OPACITY ||
821 animator.propertyKey == OPACITY)
823 AnimateOpacityProperty(transition, animator);
825 else if(mImpl->mRenderer)
827 AnimateRendererProperty(transition, animator);
831 void Visual::Base::AnimateOpacityProperty(
832 Dali::Animation& transition,
833 Internal::TransitionData::Animator& animator)
836 if(animator.targetValue.Get(targetOpacity))
838 mImpl->mMixColor.a = targetOpacity;
841 SetupTransition(transition, animator, DevelRenderer::Property::OPACITY, animator.initialValue, animator.targetValue);
844 void Visual::Base::AnimateRendererProperty(
845 Dali::Animation& transition,
846 Internal::TransitionData::Animator& animator)
848 Property::Index index = GetPropertyIndex(animator.propertyKey);
849 if(index != Property::INVALID_INDEX)
851 if(animator.targetValue.GetType() != Property::NONE)
853 // Try writing target value into transform property map
854 // if it's not a valid key, then it won't alter mTransform
856 if(animator.propertyKey.type == Property::Key::INDEX)
858 map.Add(animator.propertyKey.indexKey, animator.targetValue);
862 map.Add(animator.propertyKey.stringKey, animator.targetValue);
865 mImpl->mTransform.UpdatePropertyMap(map);
868 SetupTransition(transition, animator, index, animator.initialValue, animator.targetValue);
872 void Visual::Base::AnimateMixColorProperty(
873 Dali::Animation& transition,
874 Internal::TransitionData::Animator& animator)
876 Property::Index index = mImpl->mMixColorIndex;
877 bool animateOpacity = false;
879 Property::Value initialOpacity;
880 Property::Value targetOpacity;
881 Property::Value initialMixColor;
882 Property::Value targetMixColor;
884 if(index != Property::INVALID_INDEX)
886 Vector4 initialColor;
887 if(animator.initialValue.Get(initialColor))
889 if(animator.initialValue.GetType() == Property::VECTOR4)
891 // if there is an initial color specifying alpha, test it
892 initialOpacity = initialColor.a;
894 initialMixColor = Vector3(initialColor);
897 // Set target value into data store
898 if(animator.targetValue.GetType() != Property::NONE)
901 animator.targetValue.Get(mixColor);
902 if(animator.targetValue.GetType() == Property::VECTOR4)
904 mImpl->mMixColor.a = mixColor.a;
905 targetOpacity = mixColor.a;
906 animateOpacity = true;
909 mImpl->mMixColor.r = mixColor.r;
910 mImpl->mMixColor.g = mixColor.g;
911 mImpl->mMixColor.b = mixColor.b;
912 targetMixColor = Vector3(mixColor);
915 SetupTransition(transition, animator, index, initialMixColor, targetMixColor);
918 SetupTransition(transition, animator, DevelRenderer::Property::OPACITY, initialOpacity, targetOpacity);
923 Dali::Property Visual::Base::GetPropertyObject(Dali::Property::Key key)
925 if(!mImpl->mRenderer)
928 return Dali::Property(handle, Property::INVALID_INDEX);
931 // Mix color or opacity cases
932 if(key.type == Property::Key::INDEX)
934 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))
936 return Dali::Property(mImpl->mRenderer, mImpl->mMixColorIndex);
938 else if(key.indexKey == Toolkit::Visual::Property::OPACITY)
940 return Dali::Property(mImpl->mRenderer, DevelRenderer::Property::OPACITY);
942 else if(key.indexKey == Toolkit::Visual::Transform::Property::OFFSET)
944 return Dali::Property(mImpl->mRenderer, OFFSET);
946 else if(key.indexKey == Toolkit::Visual::Transform::Property::SIZE)
948 return Dali::Property(mImpl->mRenderer, SIZE);
953 if(key.stringKey == MIX_COLOR)
955 return Dali::Property(mImpl->mRenderer, mImpl->mMixColorIndex);
957 else if(key.stringKey == OPACITY)
959 return Dali::Property(mImpl->mRenderer, DevelRenderer::Property::OPACITY);
961 else if(key.stringKey == OFFSET)
963 return Dali::Property(mImpl->mRenderer, OFFSET);
965 else if(key.stringKey == SIZE)
967 return Dali::Property(mImpl->mRenderer, SIZE);
972 Property::Index index = GetPropertyIndex(key);
973 if(index == Property::INVALID_INDEX)
975 if(IsTypeAvailableForBorderline(mImpl->mType) &&
976 ((key.type == Property::Key::INDEX && key.indexKey == DevelVisual::Property::BORDERLINE_WIDTH) || (key.type == Property::Key::STRING && key.stringKey == BORDERLINE_WIDTH) ||
977 (key.type == Property::Key::INDEX && key.indexKey == DevelVisual::Property::BORDERLINE_COLOR) || (key.type == Property::Key::STRING && key.stringKey == BORDERLINE_COLOR) ||
978 (key.type == Property::Key::INDEX && key.indexKey == DevelVisual::Property::BORDERLINE_OFFSET) || (key.type == Property::Key::STRING && key.stringKey == BORDERLINE_OFFSET)))
980 mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON_WITHOUT_CULL);
982 // Register borderline properties
983 mImpl->mBorderlineWidthIndex = mImpl->mRenderer.RegisterProperty(DevelVisual::Property::BORDERLINE_WIDTH, BORDERLINE_WIDTH, mImpl->mBorderlineWidth);
984 mImpl->mBorderlineColorIndex = mImpl->mRenderer.RegisterProperty(DevelVisual::Property::BORDERLINE_COLOR, BORDERLINE_COLOR, mImpl->mBorderlineColor);
985 mImpl->mBorderlineOffsetIndex = mImpl->mRenderer.RegisterProperty(DevelVisual::Property::BORDERLINE_OFFSET, BORDERLINE_OFFSET, mImpl->mBorderlineOffset);
987 // Borderline is animated now. we always have to use borderline feature.
988 mImpl->mAlwaysUsingBorderline = true;
990 index = mImpl->mRenderer.GetPropertyIndex(key);
995 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)))
997 // Register CORNER_RADIUS property
998 mImpl->mCornerRadiusIndex = mImpl->mRenderer.RegisterProperty(DevelVisual::Property::CORNER_RADIUS, CORNER_RADIUS, mImpl->mCornerRadius);
999 mImpl->mRenderer.RegisterProperty(CORNER_RADIUS_POLICY, mImpl->mCornerRadiusPolicy);
1001 // ConerRadius is animated now. we always have to use corner radius feature.
1002 mImpl->mAlwaysUsingCornerRadius = true;
1004 if(!IsBorderlineRequired())
1006 // If IsBorderlineRequired is true, BLEND_MODE is already BlendMode::ON_WITHOUT_CULL. So we don't overwrite it.
1007 mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON);
1010 index = mImpl->mCornerRadiusIndex;
1017 // We can't find the property in the base class.
1018 // Request to child class
1019 return OnGetPropertyObject(key);
1023 return Dali::Property(mImpl->mRenderer, index);
1026 } // namespace Internal
1028 } // namespace Toolkit