Add TOUCH_FOCUSABLE property
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / visuals / visual-base-impl.cpp
1 /*
2  * Copyright (c) 2021 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 // CLASS HEADER
19 #include "visual-base-impl.h"
20
21 // EXTERNAL HEADER
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>
26
27 //INTERNAL HEARDER
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>
35
36 namespace
37 {
38 #if defined(DEBUG_ENABLED)
39 Debug::Filter* gVisualBaseLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_VISUAL_BASE");
40 #endif
41
42 const char* const PRE_MULTIPLIED_ALPHA_PROPERTY("preMultipliedAlpha");
43
44 } // namespace
45
46 namespace Dali
47 {
48 namespace Toolkit
49 {
50 namespace Internal
51 {
52 namespace
53 {
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)
62
63 } // namespace
64
65 Visual::Base::Base(VisualFactoryCache& factoryCache, FittingMode fittingMode, Toolkit::Visual::Type type)
66 : mImpl(new Impl(fittingMode, type)),
67   mFactoryCache(factoryCache)
68 {
69 }
70
71 Visual::Base::~Base()
72 {
73   delete mImpl;
74 }
75
76 void Visual::Base::Initialize()
77 {
78   // The Renderer should be created inside derived class here.
79   OnInitialize();
80
81   if(mImpl->mRenderer)
82   {
83     RegisterMixColor();
84
85     if(IsRoundedCornerRequired())
86     {
87       mImpl->mCornerRadiusIndex = mImpl->mRenderer.RegisterProperty(DevelVisual::Property::CORNER_RADIUS, CORNER_RADIUS, mImpl->mCornerRadius);
88       mImpl->mRenderer.RegisterProperty(CORNER_RADIUS_POLICY, mImpl->mCornerRadiusPolicy);
89
90       mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON);
91     }
92   }
93 }
94
95 void Visual::Base::SetCustomShader(const Property::Map& shaderMap)
96 {
97   if(mImpl->mCustomShader)
98   {
99     mImpl->mCustomShader->SetPropertyMap(shaderMap);
100   }
101   else
102   {
103     mImpl->mCustomShader = new Impl::CustomShader(shaderMap);
104   }
105
106   // Let derived class know
107   UpdateShader();
108 }
109
110 void Visual::Base::SetProperties(const Property::Map& propertyMap)
111 {
112   for(size_t i = 0; i < propertyMap.Count(); ++i)
113   {
114     const KeyValuePair&    pair  = propertyMap.GetKeyValue(i);
115     const Property::Key&   key   = pair.first;
116     const Property::Value& value = pair.second;
117
118     Property::Key matchKey = key;
119     if(matchKey.type == Property::Key::STRING)
120     {
121       if(matchKey == CUSTOM_SHADER)
122       {
123         matchKey = Property::Key(Toolkit::Visual::Property::SHADER);
124       }
125       else if(matchKey == TRANSFORM)
126       {
127         matchKey = Property::Key(Toolkit::Visual::Property::TRANSFORM);
128       }
129       else if(matchKey == PREMULTIPLIED_ALPHA)
130       {
131         matchKey = Property::Key(Toolkit::Visual::Property::PREMULTIPLIED_ALPHA);
132       }
133       else if(matchKey == MIX_COLOR)
134       {
135         matchKey = Property::Key(Toolkit::Visual::Property::MIX_COLOR);
136       }
137       else if(matchKey == OPACITY)
138       {
139         matchKey = Property::Key(Toolkit::Visual::Property::OPACITY);
140       }
141       else if(matchKey == VISUAL_FITTING_MODE)
142       {
143         matchKey = Property::Key(Toolkit::DevelVisual::Property::VISUAL_FITTING_MODE);
144       }
145       else if(matchKey == CORNER_RADIUS)
146       {
147         matchKey = Property::Key(Toolkit::DevelVisual::Property::CORNER_RADIUS);
148       }
149       else if(matchKey == CORNER_RADIUS_POLICY)
150       {
151         matchKey = Property::Key(Toolkit::DevelVisual::Property::CORNER_RADIUS_POLICY);
152       }
153     }
154
155     switch(matchKey.indexKey)
156     {
157       case Toolkit::Visual::Property::SHADER:
158       {
159         Property::Map shaderMap;
160         if(value.Get(shaderMap))
161         {
162           SetCustomShader(shaderMap);
163         }
164         break;
165       }
166
167       case Toolkit::Visual::Property::TRANSFORM:
168       {
169         Property::Map map;
170         if(value.Get(map))
171         {
172           mImpl->mTransform.SetPropertyMap(map);
173         }
174         break;
175       }
176
177       case Toolkit::Visual::Property::PREMULTIPLIED_ALPHA:
178       {
179         bool premultipliedAlpha = false;
180         if(value.Get(premultipliedAlpha))
181         {
182           EnablePreMultipliedAlpha(premultipliedAlpha);
183         }
184         break;
185       }
186
187       case Toolkit::Visual::Property::MIX_COLOR:
188       {
189         Vector4 mixColor;
190         if(value.Get(mixColor))
191         {
192           if(value.GetType() == Property::VECTOR4)
193           {
194             SetMixColor(mixColor);
195           }
196           else
197           {
198             Vector3 mixColor3(mixColor);
199             SetMixColor(mixColor3);
200           }
201         }
202         break;
203       }
204       case Toolkit::Visual::Property::OPACITY:
205       {
206         float opacity;
207         if(value.Get(opacity))
208         {
209           mImpl->mMixColor.a = opacity;
210           SetMixColor(mImpl->mMixColor);
211         }
212         break;
213       }
214       case Toolkit::DevelVisual::Property::VISUAL_FITTING_MODE:
215       {
216         Scripting::GetEnumerationProperty<Visual::FittingMode>(
217           value, VISUAL_FITTING_MODE_TABLE, VISUAL_FITTING_MODE_TABLE_COUNT, mImpl->mFittingMode);
218         break;
219       }
220       case Toolkit::DevelVisual::Property::CORNER_RADIUS:
221       {
222         if(value.GetType() == Property::VECTOR4)
223         {
224           // If CORNER_RADIUS Property is Vector4,
225           // Each values mean the radius of
226           // (top-left, top-right, bottom-right, bottom-left)
227           Vector4 radius;
228           if(value.Get(radius))
229           {
230             mImpl->mCornerRadius = radius;
231           }
232         }
233         else
234         {
235           // If CORNER_RADIUS Property is float,
236           // Every corner radius have same value
237           float radius;
238           if(value.Get(radius))
239           {
240             mImpl->mCornerRadius = Vector4(radius, radius, radius, radius);
241           }
242         }
243         break;
244       }
245       case Toolkit::DevelVisual::Property::CORNER_RADIUS_POLICY:
246       {
247         int policy;
248         if(value.Get(policy))
249         {
250           switch(policy)
251           {
252             case Toolkit::Visual::Transform::Policy::RELATIVE:
253             case Toolkit::Visual::Transform::Policy::ABSOLUTE:
254             {
255               mImpl->mCornerRadiusPolicy = policy;
256               break;
257             }
258             default:
259             {
260               DALI_LOG_ERROR("Unsupported policy: %d\n", policy);
261               break;
262             }
263           }
264         }
265         break;
266       }
267     }
268   }
269
270   DoSetProperties(propertyMap);
271 }
272
273 void Visual::Base::SetTransformAndSize(const Property::Map& transform, Size controlSize)
274 {
275   mImpl->mControlSize = controlSize;
276   mImpl->mTransform.UpdatePropertyMap(transform);
277
278 #if defined(DEBUG_ENABLED)
279   std::ostringstream oss;
280   oss << transform;
281   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);
282 #endif
283
284   OnSetTransform();
285 }
286
287 void Visual::Base::SetName(const std::string& name)
288 {
289   mImpl->mName = name;
290 }
291
292 const std::string& Visual::Base::GetName() const
293 {
294   return mImpl->mName;
295 }
296
297 float Visual::Base::GetHeightForWidth(float width)
298 {
299   float   aspectCorrectedHeight = 0.f;
300   Vector2 naturalSize;
301   GetNaturalSize(naturalSize);
302   if(naturalSize.width)
303   {
304     aspectCorrectedHeight = naturalSize.height * width / naturalSize.width;
305   }
306   return aspectCorrectedHeight;
307 }
308
309 float Visual::Base::GetWidthForHeight(float height)
310 {
311   float   aspectCorrectedWidth = 0.f;
312   Vector2 naturalSize;
313   GetNaturalSize(naturalSize);
314   if(naturalSize.height > 0.0f)
315   {
316     aspectCorrectedWidth = naturalSize.width * height / naturalSize.height;
317   }
318   return aspectCorrectedWidth;
319 }
320
321 void Visual::Base::GetNaturalSize(Vector2& naturalSize)
322 {
323   naturalSize = Vector2::ZERO;
324 }
325
326 void Visual::Base::DoAction(const Property::Index actionId, const Property::Value attributes)
327 {
328   OnDoAction(actionId, attributes);
329 }
330
331 void Visual::Base::SetDepthIndex(int index)
332 {
333   mImpl->mDepthIndex = index;
334   if(mImpl->mRenderer)
335   {
336     mImpl->mRenderer.SetProperty(Renderer::Property::DEPTH_INDEX, mImpl->mDepthIndex);
337   }
338 }
339
340 int Visual::Base::GetDepthIndex() const
341 {
342   return mImpl->mDepthIndex;
343 }
344
345 void Visual::Base::SetOnScene(Actor& actor)
346 {
347   if(!IsOnScene())
348   {
349     // To display the actor correctly, renderer should not be added to actor until all required resources are ready.
350     // Thus the calling of actor.AddRenderer() should happen inside derived class as base class does not know the exact timing.
351     DoSetOnScene(actor);
352
353     if(mImpl->mRenderer)
354     {
355       mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, IsPreMultipliedAlphaEnabled());
356       mImpl->mRenderer.SetProperty(Renderer::Property::DEPTH_INDEX, mImpl->mDepthIndex);
357     }
358
359     mImpl->mFlags |= Impl::IS_ON_SCENE;
360   }
361 }
362
363 void Visual::Base::SetOffScene(Actor& actor)
364 {
365   if(IsOnScene())
366   {
367     DoSetOffScene(actor);
368     mImpl->mFlags &= ~Impl::IS_ON_SCENE;
369   }
370 }
371
372 void Visual::Base::CreatePropertyMap(Property::Map& map) const
373 {
374   if(mImpl->mRenderer)
375   {
376     // Update values from Renderer
377     mImpl->mMixColor   = mImpl->mRenderer.GetProperty<Vector3>(mImpl->mMixColorIndex);
378     mImpl->mMixColor.a = mImpl->mRenderer.GetProperty<float>(DevelRenderer::Property::OPACITY);
379     if(mImpl->mTransform.mOffsetIndex != Property::INVALID_INDEX)
380     {
381       mImpl->mTransform.mOffset = mImpl->mRenderer.GetProperty<Vector2>(mImpl->mTransform.mOffsetIndex);
382     }
383     if(mImpl->mTransform.mSizeIndex != Property::INVALID_INDEX)
384     {
385       mImpl->mTransform.mSize = mImpl->mRenderer.GetProperty<Vector2>(mImpl->mTransform.mSizeIndex);
386     }
387     if(mImpl->mCornerRadiusIndex != Property::INVALID_INDEX)
388     {
389       mImpl->mCornerRadius = mImpl->mRenderer.GetProperty<Vector4>(mImpl->mCornerRadiusIndex);
390     }
391   }
392
393   DoCreatePropertyMap(map);
394
395   if(mImpl->mCustomShader)
396   {
397     mImpl->mCustomShader->CreatePropertyMap(map);
398   }
399
400   Property::Map transform;
401   mImpl->mTransform.GetPropertyMap(transform);
402   map.Insert(Toolkit::Visual::Property::TRANSFORM, transform);
403
404   bool premultipliedAlpha(IsPreMultipliedAlphaEnabled());
405   map.Insert(Toolkit::Visual::Property::PREMULTIPLIED_ALPHA, premultipliedAlpha);
406
407   // Note, Color and Primitive will also insert their own mix color into the map
408   // which is ok, because they have a different key value range.
409   map.Insert(Toolkit::Visual::Property::MIX_COLOR, mImpl->mMixColor); // vec4
410   map.Insert(Toolkit::Visual::Property::OPACITY, mImpl->mMixColor.a);
411
412   auto fittingModeString = Scripting::GetLinearEnumerationName<FittingMode>(
413     mImpl->mFittingMode, VISUAL_FITTING_MODE_TABLE, VISUAL_FITTING_MODE_TABLE_COUNT);
414   map.Insert(Toolkit::DevelVisual::Property::VISUAL_FITTING_MODE, fittingModeString);
415
416   map.Insert(Toolkit::DevelVisual::Property::CORNER_RADIUS, mImpl->mCornerRadius);
417   map.Insert(Toolkit::DevelVisual::Property::CORNER_RADIUS_POLICY, static_cast<int>(mImpl->mCornerRadiusPolicy));
418 }
419
420 void Visual::Base::CreateInstancePropertyMap(Property::Map& map) const
421 {
422   DoCreateInstancePropertyMap(map);
423
424   if(mImpl->mCustomShader)
425   {
426     mImpl->mCustomShader->CreatePropertyMap(map);
427   }
428 }
429
430 void Visual::Base::EnablePreMultipliedAlpha(bool preMultiplied)
431 {
432   if(preMultiplied)
433   {
434     mImpl->mFlags |= Impl::IS_PREMULTIPLIED_ALPHA;
435   }
436   else
437   {
438     mImpl->mFlags &= ~Impl::IS_PREMULTIPLIED_ALPHA;
439   }
440
441   if(mImpl->mRenderer)
442   {
443     mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, preMultiplied);
444     mImpl->mRenderer.RegisterProperty(PRE_MULTIPLIED_ALPHA_PROPERTY, static_cast<float>(preMultiplied));
445   }
446 }
447
448 bool Visual::Base::IsPreMultipliedAlphaEnabled() const
449 {
450   return mImpl->mFlags & Impl::IS_PREMULTIPLIED_ALPHA;
451 }
452
453 void Visual::Base::DoSetOffScene(Actor& actor)
454 {
455   actor.RemoveRenderer(mImpl->mRenderer);
456 }
457
458 bool Visual::Base::IsOnScene() const
459 {
460   return mImpl->mFlags & Impl::IS_ON_SCENE;
461 }
462
463 bool Visual::Base::IsRoundedCornerRequired() const
464 {
465   if(mImpl->mRenderer && mImpl->mCornerRadiusIndex != Property::INVALID_INDEX)
466   {
467     // Update values from Renderer
468     mImpl->mCornerRadius = mImpl->mRenderer.GetProperty<Vector4>(mImpl->mCornerRadiusIndex);
469   }
470   return !(mImpl->mCornerRadius == Vector4::ZERO) || mImpl->mNeedCornerRadius;
471 }
472
473 void Visual::Base::OnDoAction(const Property::Index actionId, const Property::Value& attributes)
474 {
475   // May be overriden by derived class
476 }
477
478 void Visual::Base::RegisterMixColor()
479 {
480   // Only register if not already registered.
481   // (Color and Primitive visuals will register their own and save to this index)
482   if(mImpl->mMixColorIndex == Property::INVALID_INDEX)
483   {
484     mImpl->mMixColorIndex = mImpl->mRenderer.RegisterProperty(
485       Toolkit::Visual::Property::MIX_COLOR,
486       MIX_COLOR,
487       Vector3(mImpl->mMixColor));
488   }
489
490   mImpl->mRenderer.SetProperty(DevelRenderer::Property::OPACITY, mImpl->mMixColor.a);
491
492   float preMultipliedAlpha = 0.0f;
493   if(IsPreMultipliedAlphaEnabled())
494   {
495     preMultipliedAlpha = 1.0f;
496   }
497   mImpl->mRenderer.RegisterProperty(PRE_MULTIPLIED_ALPHA_PROPERTY, preMultipliedAlpha);
498 }
499
500 void Visual::Base::SetMixColor(const Vector4& color)
501 {
502   mImpl->mMixColor = color;
503
504   if(mImpl->mRenderer)
505   {
506     mImpl->mRenderer.SetProperty(mImpl->mMixColorIndex, Vector3(color));
507     mImpl->mRenderer.SetProperty(DevelRenderer::Property::OPACITY, color.a);
508   }
509 }
510
511 void Visual::Base::SetMixColor(const Vector3& color)
512 {
513   mImpl->mMixColor.r = color.r;
514   mImpl->mMixColor.g = color.g;
515   mImpl->mMixColor.b = color.b;
516
517   if(mImpl->mRenderer)
518   {
519     mImpl->mRenderer.SetProperty(mImpl->mMixColorIndex, color);
520   }
521 }
522
523 void Visual::Base::AddEventObserver(Visual::EventObserver& observer)
524 {
525   mImpl->mEventObserver = &observer;
526 }
527
528 void Visual::Base::RemoveEventObserver(Visual::EventObserver& observer)
529 {
530   mImpl->mEventObserver = NULL;
531 }
532
533 void Visual::Base::ResourceReady(Toolkit::Visual::ResourceStatus resourceStatus)
534 {
535   if(mImpl->mResourceStatus != resourceStatus)
536   {
537     mImpl->mResourceStatus = resourceStatus;
538
539     if(mImpl->mEventObserver)
540     {
541       // observer is currently a control impl
542       mImpl->mEventObserver->ResourceReady(*this);
543     }
544   }
545 }
546
547 bool Visual::Base::IsResourceReady() const
548 {
549   return (mImpl->mResourceStatus == Toolkit::Visual::ResourceStatus::READY);
550 }
551
552 bool Visual::Base::IsSynchronousLoadingRequired() const
553 {
554   return (mImpl->mFlags & Impl::IS_SYNCHRONOUS_RESOURCE_LOADING);
555 }
556
557 Toolkit::Visual::Type Visual::Base::GetType() const
558 {
559   return mImpl->mType;
560 }
561
562 Toolkit::Visual::ResourceStatus Visual::Base::GetResourceStatus() const
563 {
564   return mImpl->mResourceStatus;
565 }
566
567 Visual::FittingMode Visual::Base::GetFittingMode() const
568 {
569   return mImpl->mFittingMode;
570 }
571
572 Visual::Base& Visual::Base::GetVisualObject()
573 {
574   return *this;
575 }
576
577 Renderer Visual::Base::GetRenderer()
578 {
579   return mImpl->mRenderer;
580 }
581
582 Property::Index Visual::Base::GetPropertyIndex(Property::Key key)
583 {
584   Property::Index index = mImpl->mRenderer.GetPropertyIndex(key);
585
586   if(index == Property::INVALID_INDEX)
587   {
588     // Is it a shader property?
589     Shader shader = mImpl->mRenderer.GetShader();
590     index         = shader.GetPropertyIndex(key);
591     if(index != Property::INVALID_INDEX)
592     {
593       // Yes - we should register it in the Renderer so it can be set / animated
594       // independently, as shaders are shared across multiple renderers.
595       std::string     keyName;
596       Property::Index keyIndex(Property::INVALID_KEY);
597       if(key.type == Property::Key::INDEX)
598       {
599         keyName  = shader.GetPropertyName(index);
600         keyIndex = key.indexKey;
601       }
602       else
603       {
604         keyName = key.stringKey;
605         // Leave keyIndex as INVALID_KEY - it can still be registered against the string key.
606       }
607       Property::Value value = shader.GetProperty(index);
608       index                 = mImpl->mRenderer.RegisterProperty(keyIndex, keyName, value);
609     }
610   }
611   return index;
612 }
613
614 void Visual::Base::SetupTransition(
615   Dali::Animation&                    transition,
616   Internal::TransitionData::Animator& animator,
617   Property::Index                     index,
618   Property::Value&                    initialValue,
619   Property::Value&                    targetValue)
620 {
621   if(index != Property::INVALID_INDEX)
622   {
623     if(mImpl->mRenderer)
624     {
625       if(animator.animate == false)
626       {
627         mImpl->mRenderer.SetProperty(index, targetValue);
628       }
629       else
630       {
631         if(animator.initialValue.GetType() != Property::NONE)
632         {
633           mImpl->mRenderer.SetProperty(index, initialValue);
634         }
635
636         if(!transition)
637         {
638           transition = Dali::Animation::New(0.1f);
639         }
640
641         transition.AnimateTo(Property(mImpl->mRenderer, index),
642                              targetValue,
643                              animator.alphaFunction,
644                              TimePeriod(animator.timePeriodDelay,
645                                         animator.timePeriodDuration));
646       }
647     }
648   }
649 }
650
651 void Visual::Base::AnimateProperty(
652   Dali::Animation&                    transition,
653   Internal::TransitionData::Animator& animator)
654 {
655 #if defined(DEBUG_ENABLED)
656   {
657     std::ostringstream oss;
658     oss << "Visual::Base::AnimateProperty(Visual:" << mImpl->mName << " Property:" << animator.propertyKey << " Target: " << animator.targetValue << std::endl;
659     DALI_LOG_INFO(gVisualBaseLogFilter, Debug::General, oss.str().c_str());
660   }
661 #endif
662
663   if(animator.propertyKey == Toolkit::Visual::Property::MIX_COLOR ||
664      animator.propertyKey == MIX_COLOR ||
665      (mImpl->mType == Toolkit::Visual::COLOR &&
666       animator.propertyKey == ColorVisual::Property::MIX_COLOR) ||
667      (mImpl->mType == Toolkit::Visual::PRIMITIVE &&
668       animator.propertyKey == PrimitiveVisual::Property::MIX_COLOR))
669   {
670     AnimateMixColorProperty(transition, animator);
671   }
672   else if(animator.propertyKey == Toolkit::Visual::Property::OPACITY ||
673           animator.propertyKey == OPACITY)
674   {
675     AnimateOpacityProperty(transition, animator);
676   }
677   else if(mImpl->mRenderer)
678   {
679     AnimateRendererProperty(transition, animator);
680   }
681 }
682
683 void Visual::Base::AnimateOpacityProperty(
684   Dali::Animation&                    transition,
685   Internal::TransitionData::Animator& animator)
686 {
687   float targetOpacity;
688   if(animator.targetValue.Get(targetOpacity))
689   {
690     mImpl->mMixColor.a = targetOpacity;
691   }
692
693   SetupTransition(transition, animator, DevelRenderer::Property::OPACITY, animator.initialValue, animator.targetValue);
694 }
695
696 void Visual::Base::AnimateRendererProperty(
697   Dali::Animation&                    transition,
698   Internal::TransitionData::Animator& animator)
699 {
700   Property::Index index = GetPropertyIndex(animator.propertyKey);
701   if(index != Property::INVALID_INDEX)
702   {
703     if(animator.targetValue.GetType() != Property::NONE)
704     {
705       // Try writing target value into transform property map
706       // if it's not a valid key, then it won't alter mTransform
707       Property::Map map;
708       if(animator.propertyKey.type == Property::Key::INDEX)
709       {
710         map.Add(animator.propertyKey.indexKey, animator.targetValue);
711       }
712       else
713       {
714         map.Add(animator.propertyKey.stringKey, animator.targetValue);
715       }
716
717       mImpl->mTransform.UpdatePropertyMap(map);
718     }
719
720     SetupTransition(transition, animator, index, animator.initialValue, animator.targetValue);
721   }
722 }
723
724 void Visual::Base::AnimateMixColorProperty(
725   Dali::Animation&                    transition,
726   Internal::TransitionData::Animator& animator)
727 {
728   Property::Index index          = mImpl->mMixColorIndex;
729   bool            animateOpacity = false;
730
731   Property::Value initialOpacity;
732   Property::Value targetOpacity;
733   Property::Value initialMixColor;
734   Property::Value targetMixColor;
735
736   if(index != Property::INVALID_INDEX)
737   {
738     Vector4 initialColor;
739     if(animator.initialValue.Get(initialColor))
740     {
741       if(animator.initialValue.GetType() == Property::VECTOR4)
742       {
743         // if there is an initial color specifying alpha, test it
744         initialOpacity = initialColor.a;
745       }
746       initialMixColor = Vector3(initialColor);
747     }
748
749     // Set target value into data store
750     if(animator.targetValue.GetType() != Property::NONE)
751     {
752       Vector4 mixColor;
753       animator.targetValue.Get(mixColor);
754       if(animator.targetValue.GetType() == Property::VECTOR4)
755       {
756         mImpl->mMixColor.a = mixColor.a;
757         targetOpacity      = mixColor.a;
758         animateOpacity     = true;
759       }
760
761       mImpl->mMixColor.r = mixColor.r;
762       mImpl->mMixColor.g = mixColor.g;
763       mImpl->mMixColor.b = mixColor.b;
764       targetMixColor     = Vector3(mixColor);
765     }
766
767     SetupTransition(transition, animator, index, initialMixColor, targetMixColor);
768     if(animateOpacity)
769     {
770       SetupTransition(transition, animator, DevelRenderer::Property::OPACITY, initialOpacity, targetOpacity);
771     }
772   }
773 }
774
775 Dali::Property Visual::Base::GetPropertyObject(Dali::Property::Key key)
776 {
777   if(!mImpl->mRenderer)
778   {
779     Handle handle;
780     return Dali::Property(handle, Property::INVALID_INDEX);
781   }
782
783   // Mix color or opacity cases
784   if(key.type == Property::Key::INDEX)
785   {
786     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))
787     {
788       return Dali::Property(mImpl->mRenderer, mImpl->mMixColorIndex);
789     }
790     else if(key.indexKey == Toolkit::Visual::Property::OPACITY)
791     {
792       return Dali::Property(mImpl->mRenderer, DevelRenderer::Property::OPACITY);
793     }
794     else if(key.indexKey == Toolkit::Visual::Transform::Property::OFFSET)
795     {
796       return Dali::Property(mImpl->mRenderer, OFFSET);
797     }
798     else if(key.indexKey == Toolkit::Visual::Transform::Property::SIZE)
799     {
800       return Dali::Property(mImpl->mRenderer, SIZE);
801     }
802   }
803   else
804   {
805     if(key.stringKey == MIX_COLOR)
806     {
807       return Dali::Property(mImpl->mRenderer, mImpl->mMixColorIndex);
808     }
809     else if(key.stringKey == OPACITY)
810     {
811       return Dali::Property(mImpl->mRenderer, DevelRenderer::Property::OPACITY);
812     }
813     else if(key.stringKey == OFFSET)
814     {
815       return Dali::Property(mImpl->mRenderer, OFFSET);
816     }
817     else if(key.stringKey == SIZE)
818     {
819       return Dali::Property(mImpl->mRenderer, SIZE);
820     }
821   }
822
823   // Other cases
824   Property::Index index = GetPropertyIndex(key);
825   if(index == Property::INVALID_INDEX)
826   {
827     if((key.type == Property::Key::INDEX && key.indexKey == DevelVisual::Property::CORNER_RADIUS) || (key.type == Property::Key::STRING && key.stringKey == CORNER_RADIUS))
828     {
829       // Register CORNER_RADIUS property
830       mImpl->mCornerRadiusIndex = mImpl->mRenderer.RegisterProperty(DevelVisual::Property::CORNER_RADIUS, CORNER_RADIUS, mImpl->mCornerRadius);
831       mImpl->mRenderer.RegisterProperty(CORNER_RADIUS_POLICY, mImpl->mCornerRadiusPolicy);
832
833       mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON);
834
835       index                    = mImpl->mCornerRadiusIndex;
836       mImpl->mNeedCornerRadius = true;
837
838       // Change shader
839       UpdateShader();
840     }
841     else
842     {
843       // We can't find the property in the base class.
844       // Request to child class
845       return OnGetPropertyObject(key);
846     }
847   }
848
849   return Dali::Property(mImpl->mRenderer, index);
850 }
851
852 } // namespace Internal
853
854 } // namespace Toolkit
855
856 } // namespace Dali