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