Add Opacity property for Actor 24/115624/7
authorRichard Huang <r.huang@samsung.com>
Mon, 20 Feb 2017 17:58:28 +0000 (17:58 +0000)
committerRichard Huang <r.huang@samsung.com>
Wed, 22 Feb 2017 14:10:51 +0000 (14:10 +0000)
Change-Id: I7fefcf77e512b4d0954666d4187d116dc5d518bd

automated-tests/src/dali/utc-Dali-Actor.cpp
automated-tests/src/dali/utc-Dali-Animation.cpp
automated-tests/src/dali/utc-Dali-Handle.cpp
dali/devel-api/actors/actor-devel.h
dali/internal/event/actors/actor-impl.cpp

index e233b1b..cb353df 100644 (file)
@@ -1991,6 +1991,14 @@ int UtcDaliActorSetColorIndividual(void)
 
   DALI_TEST_EQUALS( vector.a, actor.GetCurrentColor().a, TEST_LOCATION );
 
+  actor.SetProperty( DevelActor::Property::OPACITY, 0.2f );
+
+  // flush the queue and render once
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS( 0.2f, actor.GetCurrentColor().a, TEST_LOCATION );
+
   END_TEST;
 }
 
@@ -2779,6 +2787,41 @@ int UtcDaliActorConstrainedToOrientation(void)
   END_TEST;
 }
 
+int UtcDaliActorConstrainedToOpacity(void)
+{
+  TestApplication app;
+  tet_infoline(" UtcDaliActorConstrainedToOpacity");
+
+  Actor parent = Actor::New();
+  parent.SetOpacity( 0.7f );
+  Stage::GetCurrent().Add( parent );
+
+  Actor child = Actor::New();
+  Constraint opacityConstraint = Constraint::New<float>( child, DevelActor::Property::OPACITY, EqualToConstraint() );
+  opacityConstraint.AddSource( Source( parent, DevelActor::Property::OPACITY ) );
+  opacityConstraint.Apply();
+
+  Stage::GetCurrent().Add( child );
+
+  app.SendNotification();
+  app.Render(0);
+  app.Render();
+  app.SendNotification();
+
+  DALI_TEST_EQUALS( child.GetCurrentOpacity(), parent.GetCurrentOpacity(), 0.001f, TEST_LOCATION );
+
+  parent.SetOpacity( 0.3f );
+
+  app.SendNotification();
+  app.Render(0);
+  app.Render();
+  app.SendNotification();
+
+  DALI_TEST_EQUALS( child.GetCurrentOpacity(), parent.GetCurrentOpacity(), 0.001f, TEST_LOCATION );
+
+  END_TEST;
+}
+
 int UtcDaliActorUnparent(void)
 {
   TestApplication app;
@@ -2935,6 +2978,7 @@ const PropertyStringIndex PROPERTY_TABLE[] =
   { "maximumSize",              Actor::Property::MAXIMUM_SIZE,             Property::VECTOR2     },
   { "inheritPosition",          Actor::Property::INHERIT_POSITION,         Property::BOOLEAN     },
   { "clippingMode",             Actor::Property::CLIPPING_MODE,            Property::STRING      },
+  { "opacity",                  DevelActor::Property::OPACITY,             Property::FLOAT       },
 };
 const unsigned int PROPERTY_TABLE_COUNT = sizeof( PROPERTY_TABLE ) / sizeof( PROPERTY_TABLE[0] );
 } // unnamed namespace
index 860a01e..8e617de 100644 (file)
@@ -20,6 +20,7 @@
 
 #include <stdlib.h>
 #include <dali/public-api/dali-core.h>
+#include <dali/devel-api/actors/actor-devel.h>
 #include <dali-test-suite-utils.h>
 
 using std::max;
@@ -9860,6 +9861,7 @@ int UtcDaliAnimationUpdateManagerP(void)
 
   // Apply animation to actor
   animation.AnimateTo( Property(actor, Actor::Property::POSITION), Vector3( 100.f, 90.f, 80.f ), AlphaFunction::LINEAR );
+  animation.AnimateTo( Property(actor, DevelActor::Property::OPACITY), 0.3f, AlphaFunction::LINEAR );
 
   animation.Play();
 
index 464f504..e8662e7 100644 (file)
@@ -19,6 +19,7 @@
 
 #include <stdlib.h>
 #include <dali/public-api/dali-core.h>
+#include <dali/devel-api/actors/actor-devel.h>
 #include <dali/devel-api/object/handle-devel.h>
 #include "dali-test-suite-utils/dali-test-suite-utils.h"
 #include <mesh-builder.h>
@@ -297,6 +298,7 @@ int UtcDaliHandleIsPropertyWritable(void)
   DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::COLOR_GREEN ) );
   DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::COLOR_BLUE ) );
   DALI_TEST_CHECK( true == actor.IsPropertyWritable( Actor::Property::COLOR_ALPHA ) );
+  DALI_TEST_CHECK( true == actor.IsPropertyWritable( DevelActor::Property::OPACITY ) );
 
   // World-properties are not writable:
   DALI_TEST_CHECK( false == actor.IsPropertyWritable( Actor::Property::WORLD_POSITION ) );
@@ -345,6 +347,7 @@ int UtcDaliHandleIsPropertyAnimatable(void)
   DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::COLOR_GREEN ) );
   DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::COLOR_BLUE ) );
   DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( Actor::Property::COLOR_ALPHA ) );
+  DALI_TEST_CHECK( true == actor.IsPropertyAnimatable( DevelActor::Property::OPACITY ) );
 
   // World-properties can not be animated
   DALI_TEST_CHECK( false == actor.IsPropertyAnimatable( Actor::Property::WORLD_POSITION ) );
@@ -392,6 +395,7 @@ int UtcDaliHandleIsPropertyAConstraintInput(void)
   DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::COLOR_GREEN ) );
   DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::COLOR_BLUE ) );
   DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::COLOR_ALPHA ) );
+  DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( DevelActor::Property::OPACITY ) );
   DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::WORLD_POSITION ) );
   DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::WORLD_ORIENTATION ) );
   DALI_TEST_CHECK( true == actor.IsPropertyAConstraintInput( Actor::Property::WORLD_SCALE ) );
index 3e9fdc2..270767e 100644 (file)
@@ -87,7 +87,14 @@ enum Type
   INHERIT_POSITION     = Dali::Actor::Property::INHERIT_POSITION,
   CLIPPING_MODE        = Dali::Actor::Property::CLIPPING_MODE,
 
-  SIBLING_ORDER          = CLIPPING_MODE + 1,
+  SIBLING_ORDER        = CLIPPING_MODE + 1,
+
+  /**
+   * @brief The opacity of the actor.
+   * @details Name "opacity", type Property::FLOAT.
+   * @SINCE_1_2.28
+   */
+  OPACITY              = CLIPPING_MODE + 2,
 };
 
 } // namespace Property
index 68d81d4..9f6b86d 100644 (file)
@@ -201,6 +201,7 @@ DALI_PROPERTY( "maximumSize",         VECTOR2,  true,  false, false, Dali::Actor
 DALI_PROPERTY( "inheritPosition",     BOOLEAN,  true,  false, false, Dali::Actor::Property::INHERIT_POSITION )
 DALI_PROPERTY( "clippingMode",        STRING,   true,  false, false, Dali::Actor::Property::CLIPPING_MODE )
 DALI_PROPERTY( "siblingOrder",        INTEGER,  true,  false, false, Dali::DevelActor::Property::SIBLING_ORDER )
+DALI_PROPERTY( "opacity",             FLOAT,    true,  true,  true,  Dali::DevelActor::Property::OPACITY )
 DALI_PROPERTY_TABLE_END( DEFAULT_ACTOR_PROPERTY_START_INDEX )
 
 // Signals
@@ -2536,8 +2537,13 @@ void Actor::SetDefaultProperty( Property::Index index, const Property::Value& pr
     }
 
     case Dali::Actor::Property::COLOR_ALPHA:
+    case Dali::DevelActor::Property::OPACITY:
     {
-      SetOpacity( property.Get< float >() );
+      float value;
+      if( property.Get( value ) )
+      {
+        SetOpacity( value );
+      }
       break;
     }
 
@@ -3114,6 +3120,7 @@ Property::Value Actor::GetDefaultProperty( Property::Index index ) const
     }
 
     case Dali::Actor::Property::COLOR_ALPHA:
+    case Dali::DevelActor::Property::OPACITY:
     {
       value = GetCurrentColor().a;
       break;
@@ -3372,6 +3379,7 @@ const PropertyBase* Actor::GetSceneObjectAnimatableProperty( Property::Index ind
         break;
 
       case Dali::Actor::Property::COLOR_ALPHA:
+      case Dali::DevelActor::Property::OPACITY:
         property = &mNode->mColor;
         break;
 
@@ -3540,8 +3548,11 @@ const PropertyInputImpl* Actor::GetSceneObjectInputProperty( Property::Index ind
         break;
 
       case Dali::Actor::Property::COLOR_ALPHA:
+      case Dali::DevelActor::Property::OPACITY:
+      {
         property = &mNode->mColor;
         break;
+      }
 
       case Dali::Actor::Property::WORLD_COLOR:
         property = &mNode->mWorldColor;
@@ -3613,6 +3624,7 @@ int Actor::GetPropertyComponentIndex( Property::Index index ) const
       }
 
       case Dali::Actor::Property::COLOR_ALPHA:
+      case Dali::DevelActor::Property::OPACITY:
       {
         componentIndex = 3;
         break;