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-properties-devel.h>
29 #include <dali-toolkit/internal/helpers/property-helper.h>
30 #include <dali-toolkit/internal/visuals/visual-base-data-impl.h>
31 #include <dali-toolkit/internal/visuals/visual-string-constants.h>
32 #include <dali-toolkit/public-api/visuals/color-visual-properties.h>
33 #include <dali-toolkit/public-api/visuals/primitive-visual-properties.h>
34 #include <dali-toolkit/public-api/visuals/visual-properties.h>
38 #if defined(DEBUG_ENABLED)
39 Debug::Filter* gVisualBaseLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_VISUAL_BASE");
42 const char* const PRE_MULTIPLIED_ALPHA_PROPERTY("preMultipliedAlpha");
54 DALI_ENUM_TO_STRING_TABLE_BEGIN(VISUAL_FITTING_MODE)
55 DALI_ENUM_TO_STRING_WITH_SCOPE(Visual::FittingMode, FIT_KEEP_ASPECT_RATIO)
56 DALI_ENUM_TO_STRING_WITH_SCOPE(Visual::FittingMode, FILL)
57 DALI_ENUM_TO_STRING_WITH_SCOPE(Visual::FittingMode, OVER_FIT_KEEP_ASPECT_RATIO)
58 DALI_ENUM_TO_STRING_WITH_SCOPE(Visual::FittingMode, CENTER)
59 DALI_ENUM_TO_STRING_WITH_SCOPE(Visual::FittingMode, FIT_WIDTH)
60 DALI_ENUM_TO_STRING_WITH_SCOPE(Visual::FittingMode, FIT_HEIGHT)
61 DALI_ENUM_TO_STRING_TABLE_END(VISUAL_FITTING_MODE)
64 * @brief Check whether this visual type can use corner radius feature or not.
65 * @param type VisualType that want to checkup
66 * @return true if type can use corner radius feature.
68 static bool IsTypeAvailableForCornerRadius(Toolkit::Visual::Type type)
70 switch(static_cast<Toolkit::DevelVisual::Type>(type))
72 case Toolkit::Visual::Type::COLOR:
73 case Toolkit::Visual::Type::GRADIENT:
74 case Toolkit::Visual::Type::IMAGE:
75 case Toolkit::Visual::Type::SVG:
76 case Toolkit::Visual::Type::ANIMATED_IMAGE:
77 case Toolkit::DevelVisual::Type::ANIMATED_VECTOR_IMAGE:
89 * @brief Check whether this visual type can use borderline feature or not.
90 * @param type VisualType that want to checkup
91 * @return true if type can use borderline feature.
93 static bool IsTypeAvailableForBorderline(Toolkit::Visual::Type type)
95 switch(static_cast<Toolkit::DevelVisual::Type>(type))
97 case Toolkit::Visual::Type::COLOR:
98 case Toolkit::Visual::Type::GRADIENT:
99 case Toolkit::Visual::Type::IMAGE:
100 case Toolkit::Visual::Type::SVG:
101 case Toolkit::Visual::Type::ANIMATED_IMAGE:
102 case Toolkit::DevelVisual::Type::ANIMATED_VECTOR_IMAGE:
115 Visual::Base::Base(VisualFactoryCache& factoryCache, FittingMode fittingMode, Toolkit::Visual::Type type)
116 : mImpl(new Impl(fittingMode, type)),
117 mFactoryCache(factoryCache)
121 Visual::Base::~Base()
126 void Visual::Base::Initialize()
128 // The Renderer should be created inside derived class here.
135 if(IsRoundedCornerRequired())
137 mImpl->mCornerRadiusIndex = mImpl->mRenderer.RegisterProperty(DevelVisual::Property::CORNER_RADIUS, CORNER_RADIUS, mImpl->mCornerRadius);
138 mImpl->mRenderer.RegisterProperty(CORNER_RADIUS_POLICY, mImpl->mCornerRadiusPolicy);
140 mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON);
142 if(IsBorderlineRequired())
144 mImpl->mBorderlineWidthIndex = mImpl->mRenderer.RegisterProperty(DevelVisual::Property::BORDERLINE_WIDTH, BORDERLINE_WIDTH, mImpl->mBorderlineWidth);
145 mImpl->mBorderlineColorIndex = mImpl->mRenderer.RegisterProperty(DevelVisual::Property::BORDERLINE_COLOR, BORDERLINE_COLOR, mImpl->mBorderlineColor);
146 mImpl->mBorderlineOffsetIndex = mImpl->mRenderer.RegisterProperty(DevelVisual::Property::BORDERLINE_OFFSET, BORDERLINE_OFFSET, mImpl->mBorderlineOffset);
148 mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON_WITHOUT_CULL);
153 void Visual::Base::SetCustomShader(const Property::Map& shaderMap)
155 if(mImpl->mCustomShader)
157 mImpl->mCustomShader->SetPropertyMap(shaderMap);
161 mImpl->mCustomShader = new Impl::CustomShader(shaderMap);
164 // Let derived class know
168 void Visual::Base::SetProperties(const Property::Map& propertyMap)
170 for(size_t i = 0; i < propertyMap.Count(); ++i)
172 const KeyValuePair& pair = propertyMap.GetKeyValue(i);
173 const Property::Key& key = pair.first;
174 const Property::Value& value = pair.second;
176 Property::Key matchKey = key;
177 if(matchKey.type == Property::Key::STRING)
179 if(matchKey == CUSTOM_SHADER)
181 matchKey = Property::Key(Toolkit::Visual::Property::SHADER);
183 else if(matchKey == TRANSFORM)
185 matchKey = Property::Key(Toolkit::Visual::Property::TRANSFORM);
187 else if(matchKey == PREMULTIPLIED_ALPHA)
189 matchKey = Property::Key(Toolkit::Visual::Property::PREMULTIPLIED_ALPHA);
191 else if(matchKey == MIX_COLOR)
193 matchKey = Property::Key(Toolkit::Visual::Property::MIX_COLOR);
195 else if(matchKey == OPACITY)
197 matchKey = Property::Key(Toolkit::Visual::Property::OPACITY);
199 else if(matchKey == VISUAL_FITTING_MODE)
201 matchKey = Property::Key(Toolkit::DevelVisual::Property::VISUAL_FITTING_MODE);
203 else if(matchKey == BORDERLINE_WIDTH)
205 matchKey = Property::Key(Toolkit::DevelVisual::Property::BORDERLINE_WIDTH);
207 else if(matchKey == BORDERLINE_COLOR)
209 matchKey = Property::Key(Toolkit::DevelVisual::Property::BORDERLINE_COLOR);
211 else if(matchKey == BORDERLINE_OFFSET)
213 matchKey = Property::Key(Toolkit::DevelVisual::Property::BORDERLINE_OFFSET);
215 else if(matchKey == CORNER_RADIUS)
217 matchKey = Property::Key(Toolkit::DevelVisual::Property::CORNER_RADIUS);
219 else if(matchKey == CORNER_RADIUS_POLICY)
221 matchKey = Property::Key(Toolkit::DevelVisual::Property::CORNER_RADIUS_POLICY);
225 switch(matchKey.indexKey)
227 case Toolkit::Visual::Property::SHADER:
229 Property::Map shaderMap;
230 if(value.Get(shaderMap))
232 SetCustomShader(shaderMap);
237 case Toolkit::Visual::Property::TRANSFORM:
242 mImpl->mTransform.SetPropertyMap(map);
247 case Toolkit::Visual::Property::PREMULTIPLIED_ALPHA:
249 bool premultipliedAlpha = false;
250 if(value.Get(premultipliedAlpha))
252 EnablePreMultipliedAlpha(premultipliedAlpha);
257 case Toolkit::Visual::Property::MIX_COLOR:
260 if(value.Get(mixColor))
262 if(value.GetType() == Property::VECTOR4)
264 SetMixColor(mixColor);
268 Vector3 mixColor3(mixColor);
269 SetMixColor(mixColor3);
274 case Toolkit::Visual::Property::OPACITY:
277 if(value.Get(opacity))
279 mImpl->mMixColor.a = opacity;
280 SetMixColor(mImpl->mMixColor);
284 case Toolkit::DevelVisual::Property::VISUAL_FITTING_MODE:
286 Scripting::GetEnumerationProperty<Visual::FittingMode>(
287 value, VISUAL_FITTING_MODE_TABLE, VISUAL_FITTING_MODE_TABLE_COUNT, mImpl->mFittingMode);
290 case Toolkit::DevelVisual::Property::BORDERLINE_WIDTH:
295 mImpl->mBorderlineWidth = width;
299 case Toolkit::DevelVisual::Property::BORDERLINE_COLOR:
304 mImpl->mBorderlineColor = color;
308 case Toolkit::DevelVisual::Property::BORDERLINE_OFFSET:
311 if(value.Get(offset))
313 mImpl->mBorderlineOffset = offset;
317 case Toolkit::DevelVisual::Property::CORNER_RADIUS:
319 if(value.GetType() == Property::VECTOR4)
321 // If CORNER_RADIUS Property is Vector4,
322 // Each values mean the radius of
323 // (top-left, top-right, bottom-right, bottom-left)
325 if(value.Get(radius))
327 mImpl->mCornerRadius = radius;
332 // If CORNER_RADIUS Property is float,
333 // Every corner radius have same value
335 if(value.Get(radius))
337 mImpl->mCornerRadius = Vector4(radius, radius, radius, radius);
342 case Toolkit::DevelVisual::Property::CORNER_RADIUS_POLICY:
345 if(value.Get(policy))
349 case Toolkit::Visual::Transform::Policy::RELATIVE:
350 case Toolkit::Visual::Transform::Policy::ABSOLUTE:
352 mImpl->mCornerRadiusPolicy = policy;
357 DALI_LOG_ERROR("Unsupported policy: %d\n", policy);
367 DoSetProperties(propertyMap);
370 void Visual::Base::SetTransformAndSize(const Property::Map& transform, Size controlSize)
372 mImpl->mControlSize = controlSize;
373 mImpl->mTransform.UpdatePropertyMap(transform);
375 #if defined(DEBUG_ENABLED)
376 std::ostringstream oss;
378 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);
384 void Visual::Base::SetName(const std::string& name)
389 const std::string& Visual::Base::GetName() const
394 float Visual::Base::GetHeightForWidth(float width)
396 float aspectCorrectedHeight = 0.f;
398 GetNaturalSize(naturalSize);
399 if(naturalSize.width)
401 aspectCorrectedHeight = naturalSize.height * width / naturalSize.width;
403 return aspectCorrectedHeight;
406 float Visual::Base::GetWidthForHeight(float height)
408 float aspectCorrectedWidth = 0.f;
410 GetNaturalSize(naturalSize);
411 if(naturalSize.height > 0.0f)
413 aspectCorrectedWidth = naturalSize.width * height / naturalSize.height;
415 return aspectCorrectedWidth;
418 void Visual::Base::GetNaturalSize(Vector2& naturalSize)
420 naturalSize = Vector2::ZERO;
423 void Visual::Base::DoAction(const Property::Index actionId, const Property::Value attributes)
425 OnDoAction(actionId, attributes);
428 void Visual::Base::SetDepthIndex(int index)
430 mImpl->mDepthIndex = index;
433 mImpl->mRenderer.SetProperty(Renderer::Property::DEPTH_INDEX, mImpl->mDepthIndex);
437 int Visual::Base::GetDepthIndex() const
439 return mImpl->mDepthIndex;
442 void Visual::Base::SetOnScene(Actor& actor)
446 // To display the actor correctly, renderer should not be added to actor until all required resources are ready.
447 // Thus the calling of actor.AddRenderer() should happen inside derived class as base class does not know the exact timing.
452 mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, IsPreMultipliedAlphaEnabled());
453 mImpl->mRenderer.SetProperty(Renderer::Property::DEPTH_INDEX, mImpl->mDepthIndex);
456 mImpl->mFlags |= Impl::IS_ON_SCENE;
460 void Visual::Base::SetOffScene(Actor& actor)
464 DoSetOffScene(actor);
465 mImpl->mFlags &= ~Impl::IS_ON_SCENE;
469 void Visual::Base::CreatePropertyMap(Property::Map& map) const
473 // Update values from Renderer
474 mImpl->mMixColor = mImpl->mRenderer.GetProperty<Vector3>(mImpl->mMixColorIndex);
475 mImpl->mMixColor.a = mImpl->mRenderer.GetProperty<float>(DevelRenderer::Property::OPACITY);
476 if(mImpl->mTransform.mOffsetIndex != Property::INVALID_INDEX)
478 mImpl->mTransform.mOffset = mImpl->mRenderer.GetProperty<Vector2>(mImpl->mTransform.mOffsetIndex);
480 if(mImpl->mTransform.mSizeIndex != Property::INVALID_INDEX)
482 mImpl->mTransform.mSize = mImpl->mRenderer.GetProperty<Vector2>(mImpl->mTransform.mSizeIndex);
484 if(mImpl->mCornerRadiusIndex != Property::INVALID_INDEX)
486 mImpl->mCornerRadius = mImpl->mRenderer.GetProperty<Vector4>(mImpl->mCornerRadiusIndex);
488 if(mImpl->mBorderlineWidthIndex != Property::INVALID_INDEX)
490 mImpl->mBorderlineWidth = mImpl->mRenderer.GetProperty<float>(mImpl->mBorderlineWidthIndex);
492 if(mImpl->mBorderlineColorIndex != Property::INVALID_INDEX)
494 mImpl->mBorderlineColor = mImpl->mRenderer.GetProperty<Vector4>(mImpl->mBorderlineColorIndex);
496 if(mImpl->mBorderlineOffsetIndex != Property::INVALID_INDEX)
498 mImpl->mBorderlineOffset = mImpl->mRenderer.GetProperty<float>(mImpl->mBorderlineOffsetIndex);
502 DoCreatePropertyMap(map);
504 if(mImpl->mCustomShader)
506 mImpl->mCustomShader->CreatePropertyMap(map);
509 Property::Map transform;
510 mImpl->mTransform.GetPropertyMap(transform);
511 map.Insert(Toolkit::Visual::Property::TRANSFORM, transform);
513 bool premultipliedAlpha(IsPreMultipliedAlphaEnabled());
514 map.Insert(Toolkit::Visual::Property::PREMULTIPLIED_ALPHA, premultipliedAlpha);
516 // Note, Color and Primitive will also insert their own mix color into the map
517 // which is ok, because they have a different key value range.
518 map.Insert(Toolkit::Visual::Property::MIX_COLOR, mImpl->mMixColor); // vec4
519 map.Insert(Toolkit::Visual::Property::OPACITY, mImpl->mMixColor.a);
521 auto fittingModeString = Scripting::GetLinearEnumerationName<FittingMode>(
522 mImpl->mFittingMode, VISUAL_FITTING_MODE_TABLE, VISUAL_FITTING_MODE_TABLE_COUNT);
523 map.Insert(Toolkit::DevelVisual::Property::VISUAL_FITTING_MODE, fittingModeString);
525 map.Insert(Toolkit::DevelVisual::Property::BORDERLINE_WIDTH, mImpl->mBorderlineWidth);
526 map.Insert(Toolkit::DevelVisual::Property::BORDERLINE_COLOR, mImpl->mBorderlineColor);
527 map.Insert(Toolkit::DevelVisual::Property::BORDERLINE_OFFSET, mImpl->mBorderlineOffset);
529 map.Insert(Toolkit::DevelVisual::Property::CORNER_RADIUS, mImpl->mCornerRadius);
530 map.Insert(Toolkit::DevelVisual::Property::CORNER_RADIUS_POLICY, static_cast<int>(mImpl->mCornerRadiusPolicy));
533 void Visual::Base::CreateInstancePropertyMap(Property::Map& map) const
535 DoCreateInstancePropertyMap(map);
537 if(mImpl->mCustomShader)
539 mImpl->mCustomShader->CreatePropertyMap(map);
543 void Visual::Base::EnablePreMultipliedAlpha(bool preMultiplied)
547 mImpl->mFlags |= Impl::IS_PREMULTIPLIED_ALPHA;
551 mImpl->mFlags &= ~Impl::IS_PREMULTIPLIED_ALPHA;
556 mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, preMultiplied);
557 mImpl->mRenderer.RegisterProperty(PRE_MULTIPLIED_ALPHA_PROPERTY, static_cast<float>(preMultiplied));
561 bool Visual::Base::IsPreMultipliedAlphaEnabled() const
563 return mImpl->mFlags & Impl::IS_PREMULTIPLIED_ALPHA;
566 void Visual::Base::DoSetOffScene(Actor& actor)
568 actor.RemoveRenderer(mImpl->mRenderer);
571 bool Visual::Base::IsOnScene() const
573 return mImpl->mFlags & Impl::IS_ON_SCENE;
576 bool Visual::Base::IsRoundedCornerRequired() const
578 // If VisualType doesn't support rounded corner, always return false.
579 if(IsTypeAvailableForCornerRadius(mImpl->mType))
581 if(mImpl->mRenderer && mImpl->mCornerRadiusIndex != Property::INVALID_INDEX)
583 // Update values from Renderer
584 mImpl->mCornerRadius = mImpl->mRenderer.GetProperty<Vector4>(mImpl->mCornerRadiusIndex);
586 return !(mImpl->mCornerRadius == Vector4::ZERO) || mImpl->mNeedCornerRadius;
591 bool Visual::Base::IsBorderlineRequired() const
593 // If VisualType doesn't support borderline, always return false.
594 if(IsTypeAvailableForBorderline(mImpl->mType))
596 if(mImpl->mRenderer && mImpl->mBorderlineWidthIndex != Property::INVALID_INDEX)
598 // Update values from Renderer
599 mImpl->mBorderlineWidth = mImpl->mRenderer.GetProperty<float>(mImpl->mBorderlineWidthIndex);
601 return !EqualsZero(mImpl->mBorderlineWidth) || mImpl->mNeedBorderline;
606 void Visual::Base::OnDoAction(const Property::Index actionId, const Property::Value& attributes)
608 // May be overriden by derived class
611 void Visual::Base::RegisterMixColor()
613 // Only register if not already registered.
614 // (Color and Primitive visuals will register their own and save to this index)
615 if(mImpl->mMixColorIndex == Property::INVALID_INDEX)
617 mImpl->mMixColorIndex = mImpl->mRenderer.RegisterProperty(
618 Toolkit::Visual::Property::MIX_COLOR,
620 Vector3(mImpl->mMixColor));
623 mImpl->mRenderer.SetProperty(DevelRenderer::Property::OPACITY, mImpl->mMixColor.a);
625 float preMultipliedAlpha = 0.0f;
626 if(IsPreMultipliedAlphaEnabled())
628 preMultipliedAlpha = 1.0f;
630 mImpl->mRenderer.RegisterProperty(PRE_MULTIPLIED_ALPHA_PROPERTY, preMultipliedAlpha);
633 void Visual::Base::SetMixColor(const Vector4& color)
635 mImpl->mMixColor = color;
639 mImpl->mRenderer.SetProperty(mImpl->mMixColorIndex, Vector3(color));
640 mImpl->mRenderer.SetProperty(DevelRenderer::Property::OPACITY, color.a);
644 void Visual::Base::SetMixColor(const Vector3& color)
646 mImpl->mMixColor.r = color.r;
647 mImpl->mMixColor.g = color.g;
648 mImpl->mMixColor.b = color.b;
652 mImpl->mRenderer.SetProperty(mImpl->mMixColorIndex, color);
656 void Visual::Base::AddEventObserver(Visual::EventObserver& observer)
658 mImpl->mEventObserver = &observer;
661 void Visual::Base::RemoveEventObserver(Visual::EventObserver& observer)
663 mImpl->mEventObserver = NULL;
666 void Visual::Base::ResourceReady(Toolkit::Visual::ResourceStatus resourceStatus)
668 if(mImpl->mResourceStatus != resourceStatus)
670 mImpl->mResourceStatus = resourceStatus;
672 if(mImpl->mEventObserver)
674 // observer is currently a control impl
675 mImpl->mEventObserver->ResourceReady(*this);
680 bool Visual::Base::IsResourceReady() const
682 return (mImpl->mResourceStatus == Toolkit::Visual::ResourceStatus::READY);
685 bool Visual::Base::IsSynchronousLoadingRequired() const
687 return (mImpl->mFlags & Impl::IS_SYNCHRONOUS_RESOURCE_LOADING);
690 Toolkit::Visual::Type Visual::Base::GetType() const
695 Toolkit::Visual::ResourceStatus Visual::Base::GetResourceStatus() const
697 return mImpl->mResourceStatus;
700 Visual::FittingMode Visual::Base::GetFittingMode() const
702 return mImpl->mFittingMode;
705 Visual::Base& Visual::Base::GetVisualObject()
710 Renderer Visual::Base::GetRenderer()
712 return mImpl->mRenderer;
715 Property::Index Visual::Base::GetPropertyIndex(Property::Key key)
717 Property::Index index = mImpl->mRenderer.GetPropertyIndex(key);
719 if(index == Property::INVALID_INDEX)
721 // Is it a shader property?
722 Shader shader = mImpl->mRenderer.GetShader();
723 index = shader.GetPropertyIndex(key);
724 if(index != Property::INVALID_INDEX)
726 // Yes - we should register it in the Renderer so it can be set / animated
727 // independently, as shaders are shared across multiple renderers.
729 Property::Index keyIndex(Property::INVALID_KEY);
730 if(key.type == Property::Key::INDEX)
732 keyName = shader.GetPropertyName(index);
733 keyIndex = key.indexKey;
737 keyName = key.stringKey;
738 // Leave keyIndex as INVALID_KEY - it can still be registered against the string key.
740 Property::Value value = shader.GetProperty(index);
741 index = mImpl->mRenderer.RegisterProperty(keyIndex, keyName, value);
747 void Visual::Base::SetupTransition(
748 Dali::Animation& transition,
749 Internal::TransitionData::Animator& animator,
750 Property::Index index,
751 Property::Value& initialValue,
752 Property::Value& targetValue)
754 if(index != Property::INVALID_INDEX)
758 if(animator.animate == false)
760 mImpl->mRenderer.SetProperty(index, targetValue);
764 if(animator.initialValue.GetType() != Property::NONE)
766 mImpl->mRenderer.SetProperty(index, initialValue);
771 transition = Dali::Animation::New(0.1f);
774 transition.AnimateTo(Property(mImpl->mRenderer, index),
776 animator.alphaFunction,
777 TimePeriod(animator.timePeriodDelay,
778 animator.timePeriodDuration));
784 void Visual::Base::AnimateProperty(
785 Dali::Animation& transition,
786 Internal::TransitionData::Animator& animator)
788 #if defined(DEBUG_ENABLED)
790 std::ostringstream oss;
791 oss << "Visual::Base::AnimateProperty(Visual:" << mImpl->mName << " Property:" << animator.propertyKey << " Target: " << animator.targetValue << std::endl;
792 DALI_LOG_INFO(gVisualBaseLogFilter, Debug::General, oss.str().c_str());
796 if(animator.propertyKey == Toolkit::Visual::Property::MIX_COLOR ||
797 animator.propertyKey == MIX_COLOR ||
798 (mImpl->mType == Toolkit::Visual::COLOR &&
799 animator.propertyKey == ColorVisual::Property::MIX_COLOR) ||
800 (mImpl->mType == Toolkit::Visual::PRIMITIVE &&
801 animator.propertyKey == PrimitiveVisual::Property::MIX_COLOR))
803 AnimateMixColorProperty(transition, animator);
805 else if(animator.propertyKey == Toolkit::Visual::Property::OPACITY ||
806 animator.propertyKey == OPACITY)
808 AnimateOpacityProperty(transition, animator);
810 else if(mImpl->mRenderer)
812 AnimateRendererProperty(transition, animator);
816 void Visual::Base::AnimateOpacityProperty(
817 Dali::Animation& transition,
818 Internal::TransitionData::Animator& animator)
821 if(animator.targetValue.Get(targetOpacity))
823 mImpl->mMixColor.a = targetOpacity;
826 SetupTransition(transition, animator, DevelRenderer::Property::OPACITY, animator.initialValue, animator.targetValue);
829 void Visual::Base::AnimateRendererProperty(
830 Dali::Animation& transition,
831 Internal::TransitionData::Animator& animator)
833 Property::Index index = GetPropertyIndex(animator.propertyKey);
834 if(index != Property::INVALID_INDEX)
836 if(animator.targetValue.GetType() != Property::NONE)
838 // Try writing target value into transform property map
839 // if it's not a valid key, then it won't alter mTransform
841 if(animator.propertyKey.type == Property::Key::INDEX)
843 map.Add(animator.propertyKey.indexKey, animator.targetValue);
847 map.Add(animator.propertyKey.stringKey, animator.targetValue);
850 mImpl->mTransform.UpdatePropertyMap(map);
853 SetupTransition(transition, animator, index, animator.initialValue, animator.targetValue);
857 void Visual::Base::AnimateMixColorProperty(
858 Dali::Animation& transition,
859 Internal::TransitionData::Animator& animator)
861 Property::Index index = mImpl->mMixColorIndex;
862 bool animateOpacity = false;
864 Property::Value initialOpacity;
865 Property::Value targetOpacity;
866 Property::Value initialMixColor;
867 Property::Value targetMixColor;
869 if(index != Property::INVALID_INDEX)
871 Vector4 initialColor;
872 if(animator.initialValue.Get(initialColor))
874 if(animator.initialValue.GetType() == Property::VECTOR4)
876 // if there is an initial color specifying alpha, test it
877 initialOpacity = initialColor.a;
879 initialMixColor = Vector3(initialColor);
882 // Set target value into data store
883 if(animator.targetValue.GetType() != Property::NONE)
886 animator.targetValue.Get(mixColor);
887 if(animator.targetValue.GetType() == Property::VECTOR4)
889 mImpl->mMixColor.a = mixColor.a;
890 targetOpacity = mixColor.a;
891 animateOpacity = true;
894 mImpl->mMixColor.r = mixColor.r;
895 mImpl->mMixColor.g = mixColor.g;
896 mImpl->mMixColor.b = mixColor.b;
897 targetMixColor = Vector3(mixColor);
900 SetupTransition(transition, animator, index, initialMixColor, targetMixColor);
903 SetupTransition(transition, animator, DevelRenderer::Property::OPACITY, initialOpacity, targetOpacity);
908 Dali::Property Visual::Base::GetPropertyObject(Dali::Property::Key key)
910 if(!mImpl->mRenderer)
913 return Dali::Property(handle, Property::INVALID_INDEX);
916 // Mix color or opacity cases
917 if(key.type == Property::Key::INDEX)
919 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))
921 return Dali::Property(mImpl->mRenderer, mImpl->mMixColorIndex);
923 else if(key.indexKey == Toolkit::Visual::Property::OPACITY)
925 return Dali::Property(mImpl->mRenderer, DevelRenderer::Property::OPACITY);
927 else if(key.indexKey == Toolkit::Visual::Transform::Property::OFFSET)
929 return Dali::Property(mImpl->mRenderer, OFFSET);
931 else if(key.indexKey == Toolkit::Visual::Transform::Property::SIZE)
933 return Dali::Property(mImpl->mRenderer, SIZE);
938 if(key.stringKey == MIX_COLOR)
940 return Dali::Property(mImpl->mRenderer, mImpl->mMixColorIndex);
942 else if(key.stringKey == OPACITY)
944 return Dali::Property(mImpl->mRenderer, DevelRenderer::Property::OPACITY);
946 else if(key.stringKey == OFFSET)
948 return Dali::Property(mImpl->mRenderer, OFFSET);
950 else if(key.stringKey == SIZE)
952 return Dali::Property(mImpl->mRenderer, SIZE);
957 Property::Index index = GetPropertyIndex(key);
958 if(index == Property::INVALID_INDEX)
960 if(IsTypeAvailableForBorderline(mImpl->mType) &&
961 ((key.type == Property::Key::INDEX && key.indexKey == DevelVisual::Property::BORDERLINE_WIDTH) || (key.type == Property::Key::STRING && key.stringKey == BORDERLINE_WIDTH) ||
962 (key.type == Property::Key::INDEX && key.indexKey == DevelVisual::Property::BORDERLINE_COLOR) || (key.type == Property::Key::STRING && key.stringKey == BORDERLINE_COLOR) ||
963 (key.type == Property::Key::INDEX && key.indexKey == DevelVisual::Property::BORDERLINE_OFFSET) || (key.type == Property::Key::STRING && key.stringKey == BORDERLINE_OFFSET)))
965 mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON_WITHOUT_CULL);
967 // Register borderline properties
968 mImpl->mBorderlineWidthIndex = mImpl->mRenderer.RegisterProperty(DevelVisual::Property::BORDERLINE_WIDTH, BORDERLINE_WIDTH, mImpl->mBorderlineWidth);
969 mImpl->mBorderlineColorIndex = mImpl->mRenderer.RegisterProperty(DevelVisual::Property::BORDERLINE_COLOR, BORDERLINE_COLOR, mImpl->mBorderlineColor);
970 mImpl->mBorderlineOffsetIndex = mImpl->mRenderer.RegisterProperty(DevelVisual::Property::BORDERLINE_OFFSET, BORDERLINE_OFFSET, mImpl->mBorderlineOffset);
971 mImpl->mNeedBorderline = true;
973 index = mImpl->mRenderer.GetPropertyIndex(key);
978 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)))
980 // Register CORNER_RADIUS property
981 mImpl->mCornerRadiusIndex = mImpl->mRenderer.RegisterProperty(DevelVisual::Property::CORNER_RADIUS, CORNER_RADIUS, mImpl->mCornerRadius);
982 mImpl->mRenderer.RegisterProperty(CORNER_RADIUS_POLICY, mImpl->mCornerRadiusPolicy);
984 if(!mImpl->mNeedBorderline)
986 // If mNeedBorderline is true, BLEND_MODE is already BlendMode::ON_WITHOUT_CULL. So we don't overwrite it.
987 mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON);
990 index = mImpl->mCornerRadiusIndex;
991 mImpl->mNeedCornerRadius = true;
998 // We can't find the property in the base class.
999 // Request to child class
1000 return OnGetPropertyObject(key);
1004 return Dali::Property(mImpl->mRenderer, index);
1007 } // namespace Internal
1009 } // namespace Toolkit