Animated control background color of text label 82/84082/1
authorDavid Steele <david.steele@samsung.com>
Tue, 16 Aug 2016 12:46:19 +0000 (13:46 +0100)
committerDavid Steele <david.steele@samsung.com>
Tue, 16 Aug 2016 12:46:19 +0000 (13:46 +0100)
Change-Id: I9126b77e2b711604d78af73ba549e978746f9b14

examples/text-label/text-label-example.cpp

index b2ad9a5..c035ed6 100644 (file)
@@ -34,42 +34,69 @@ using namespace MultiLanguageStrings;
 
 namespace
 {
-  const char* const BACKGROUND_IMAGE = DEMO_IMAGE_DIR "grab-handle.png";
-
-  const unsigned int KEY_ZERO = 10;
-  const unsigned int KEY_ONE = 11;
-  const unsigned int KEY_F = 41;
-  const unsigned int KEY_H = 43;
-  const unsigned int KEY_V = 55;
-  const unsigned int KEY_M = 58;
-  const unsigned int KEY_L = 46;
-  const unsigned int KEY_S = 39;
-  const unsigned int KEY_PLUS = 21;
-  const unsigned int KEY_MINUS = 20;
-
-  const char* H_ALIGNMENT_STRING_TABLE[] =
-  {
-    "BEGIN",
-    "CENTER",
-    "END"
-  };
+const char* const BACKGROUND_IMAGE = DEMO_IMAGE_DIR "grab-handle.png";
+
+const unsigned int KEY_ZERO = 10;
+const unsigned int KEY_ONE = 11;
+const unsigned int KEY_F = 41;
+const unsigned int KEY_H = 43;
+const unsigned int KEY_V = 55;
+const unsigned int KEY_M = 58;
+const unsigned int KEY_L = 46;
+const unsigned int KEY_S = 39;
+const unsigned int KEY_PLUS = 21;
+const unsigned int KEY_MINUS = 20;
+
+const char* H_ALIGNMENT_STRING_TABLE[] =
+{
+  "BEGIN",
+  "CENTER",
+  "END"
+};
+
+const unsigned int H_ALIGNMENT_STRING_COUNT = sizeof( H_ALIGNMENT_STRING_TABLE ) / sizeof( H_ALIGNMENT_STRING_TABLE[0u] );
+
+const char* V_ALIGNMENT_STRING_TABLE[] =
+{
+  "TOP",
+  "CENTER",
+  "BOTTOM"
+};
+
+const unsigned int V_ALIGNMENT_STRING_COUNT = sizeof( V_ALIGNMENT_STRING_TABLE ) / sizeof( V_ALIGNMENT_STRING_TABLE[0u] );
 
-  const unsigned int H_ALIGNMENT_STRING_COUNT = sizeof( H_ALIGNMENT_STRING_TABLE ) / sizeof( H_ALIGNMENT_STRING_TABLE[0u] );
+int ConvertToEven(int value)
+{
+  return (value % 2 == 0) ? value : (value + 1);
+}
 
-  const char* V_ALIGNMENT_STRING_TABLE[] =
+struct HSVColorConstraint
+{
+  HSVColorConstraint(float hue, float saturation, float value)
+  : hue(hue),
+    saturation(saturation),
+    value(value)
   {
-    "TOP",
-    "CENTER",
-    "BOTTOM"
-  };
+  }
 
-  const unsigned int V_ALIGNMENT_STRING_COUNT = sizeof( V_ALIGNMENT_STRING_TABLE ) / sizeof( V_ALIGNMENT_STRING_TABLE[0u] );
+  void operator()(Vector4& current, const PropertyInputContainer& inputs )
+  {
+    current = hsv2rgb(Vector4(inputs[0]->GetFloat(), saturation, value, current.a));
+  }
 
-  int ConvertToEven(int value)
+  Vector4 hsv2rgb(Vector4 colorHSV)
   {
-    return (value % 2 == 0) ? value : (value + 1);
+    float r=colorHSV.z*(1+colorHSV.y*(cos(colorHSV.x)-1));
+    float g=colorHSV.z*(1+colorHSV.y*(cos(colorHSV.x-2.09439)-1));
+    float b=colorHSV.z*(1+colorHSV.y*(cos(colorHSV.x+2.09439)-1));
+    return Vector4(r, g, b, colorHSV.a);
   }
-}
+  float hue;
+  float saturation;
+  float value;
+};
+
+} // anonymous namespace
 
 /**
  * @brief The main class of the demo.
@@ -134,6 +161,20 @@ public:
     mLabel.SetBackgroundColor( Color::WHITE );
     mContainer.Add( mLabel );
 
+    mHueAngleIndex = mLabel.RegisterProperty( "hue", 0.0f );
+    Renderer bgRenderer = mLabel.GetRendererAt(0);
+    mOverrideMixColorIndex = bgRenderer.GetPropertyIndex( ColorVisual::Property::MIX_COLOR );
+
+    Constraint constraint = Constraint::New<Vector4>( bgRenderer, mOverrideMixColorIndex, HSVColorConstraint(0.0f, 0.5f, 0.8f));
+    constraint.AddSource( Source( mLabel, mHueAngleIndex ) );
+    constraint.SetRemoveAction( Constraint::Discard );
+    constraint.Apply();
+
+    Animation anim = Animation::New(50.0f);
+    anim.AnimateTo(Property(mLabel, mHueAngleIndex), 6.28318f);
+    anim.SetLooping(true);
+    anim.Play();
+
     Property::Value labelText = mLabel.GetProperty( TextLabel::Property::TEXT );
     std::cout << "Displaying text: \"" << labelText.Get< std::string >() << "\"" << std::endl;
   }
@@ -284,6 +325,8 @@ private:
 
   unsigned int mLanguageId;
   unsigned int mAlignment;
+  Property::Index mHueAngleIndex;
+  Property::Index mOverrideMixColorIndex;
 };
 
 void RunTest( Application& application )