Commit 3da1423d03d3bd5b323bc7a18b18c01d592d96cc
Committed by
Gerrit Code Review
Merge "Animated control background color of text label" into devel/master
Showing
1 changed file
with
72 additions
and
29 deletions
examples/text-label/text-label-example.cpp
| ... | ... | @@ -34,42 +34,69 @@ using namespace MultiLanguageStrings; |
| 34 | 34 | |
| 35 | 35 | namespace |
| 36 | 36 | { |
| 37 | - const char* const BACKGROUND_IMAGE = DEMO_IMAGE_DIR "grab-handle.png"; | |
| 38 | - | |
| 39 | - const unsigned int KEY_ZERO = 10; | |
| 40 | - const unsigned int KEY_ONE = 11; | |
| 41 | - const unsigned int KEY_F = 41; | |
| 42 | - const unsigned int KEY_H = 43; | |
| 43 | - const unsigned int KEY_V = 55; | |
| 44 | - const unsigned int KEY_M = 58; | |
| 45 | - const unsigned int KEY_L = 46; | |
| 46 | - const unsigned int KEY_S = 39; | |
| 47 | - const unsigned int KEY_PLUS = 21; | |
| 48 | - const unsigned int KEY_MINUS = 20; | |
| 49 | - | |
| 50 | - const char* H_ALIGNMENT_STRING_TABLE[] = | |
| 51 | - { | |
| 52 | - "BEGIN", | |
| 53 | - "CENTER", | |
| 54 | - "END" | |
| 55 | - }; | |
| 37 | +const char* const BACKGROUND_IMAGE = DEMO_IMAGE_DIR "grab-handle.png"; | |
| 38 | + | |
| 39 | +const unsigned int KEY_ZERO = 10; | |
| 40 | +const unsigned int KEY_ONE = 11; | |
| 41 | +const unsigned int KEY_F = 41; | |
| 42 | +const unsigned int KEY_H = 43; | |
| 43 | +const unsigned int KEY_V = 55; | |
| 44 | +const unsigned int KEY_M = 58; | |
| 45 | +const unsigned int KEY_L = 46; | |
| 46 | +const unsigned int KEY_S = 39; | |
| 47 | +const unsigned int KEY_PLUS = 21; | |
| 48 | +const unsigned int KEY_MINUS = 20; | |
| 49 | + | |
| 50 | +const char* H_ALIGNMENT_STRING_TABLE[] = | |
| 51 | +{ | |
| 52 | + "BEGIN", | |
| 53 | + "CENTER", | |
| 54 | + "END" | |
| 55 | +}; | |
| 56 | + | |
| 57 | +const unsigned int H_ALIGNMENT_STRING_COUNT = sizeof( H_ALIGNMENT_STRING_TABLE ) / sizeof( H_ALIGNMENT_STRING_TABLE[0u] ); | |
| 58 | + | |
| 59 | +const char* V_ALIGNMENT_STRING_TABLE[] = | |
| 60 | +{ | |
| 61 | + "TOP", | |
| 62 | + "CENTER", | |
| 63 | + "BOTTOM" | |
| 64 | +}; | |
| 65 | + | |
| 66 | +const unsigned int V_ALIGNMENT_STRING_COUNT = sizeof( V_ALIGNMENT_STRING_TABLE ) / sizeof( V_ALIGNMENT_STRING_TABLE[0u] ); | |
| 56 | 67 | |
| 57 | - const unsigned int H_ALIGNMENT_STRING_COUNT = sizeof( H_ALIGNMENT_STRING_TABLE ) / sizeof( H_ALIGNMENT_STRING_TABLE[0u] ); | |
| 68 | +int ConvertToEven(int value) | |
| 69 | +{ | |
| 70 | + return (value % 2 == 0) ? value : (value + 1); | |
| 71 | +} | |
| 58 | 72 | |
| 59 | - const char* V_ALIGNMENT_STRING_TABLE[] = | |
| 73 | +struct HSVColorConstraint | |
| 74 | +{ | |
| 75 | + HSVColorConstraint(float hue, float saturation, float value) | |
| 76 | + : hue(hue), | |
| 77 | + saturation(saturation), | |
| 78 | + value(value) | |
| 60 | 79 | { |
| 61 | - "TOP", | |
| 62 | - "CENTER", | |
| 63 | - "BOTTOM" | |
| 64 | - }; | |
| 80 | + } | |
| 65 | 81 | |
| 66 | - const unsigned int V_ALIGNMENT_STRING_COUNT = sizeof( V_ALIGNMENT_STRING_TABLE ) / sizeof( V_ALIGNMENT_STRING_TABLE[0u] ); | |
| 82 | + void operator()(Vector4& current, const PropertyInputContainer& inputs ) | |
| 83 | + { | |
| 84 | + current = hsv2rgb(Vector4(inputs[0]->GetFloat(), saturation, value, current.a)); | |
| 85 | + } | |
| 67 | 86 | |
| 68 | - int ConvertToEven(int value) | |
| 87 | + Vector4 hsv2rgb(Vector4 colorHSV) | |
| 69 | 88 | { |
| 70 | - return (value % 2 == 0) ? value : (value + 1); | |
| 89 | + float r=colorHSV.z*(1+colorHSV.y*(cos(colorHSV.x)-1)); | |
| 90 | + float g=colorHSV.z*(1+colorHSV.y*(cos(colorHSV.x-2.09439)-1)); | |
| 91 | + float b=colorHSV.z*(1+colorHSV.y*(cos(colorHSV.x+2.09439)-1)); | |
| 92 | + return Vector4(r, g, b, colorHSV.a); | |
| 71 | 93 | } |
| 72 | -} | |
| 94 | + float hue; | |
| 95 | + float saturation; | |
| 96 | + float value; | |
| 97 | +}; | |
| 98 | + | |
| 99 | +} // anonymous namespace | |
| 73 | 100 | |
| 74 | 101 | /** |
| 75 | 102 | * @brief The main class of the demo. |
| ... | ... | @@ -134,6 +161,20 @@ public: |
| 134 | 161 | mLabel.SetBackgroundColor( Color::WHITE ); |
| 135 | 162 | mContainer.Add( mLabel ); |
| 136 | 163 | |
| 164 | + mHueAngleIndex = mLabel.RegisterProperty( "hue", 0.0f ); | |
| 165 | + Renderer bgRenderer = mLabel.GetRendererAt(0); | |
| 166 | + mOverrideMixColorIndex = bgRenderer.GetPropertyIndex( ColorVisual::Property::MIX_COLOR ); | |
| 167 | + | |
| 168 | + Constraint constraint = Constraint::New<Vector4>( bgRenderer, mOverrideMixColorIndex, HSVColorConstraint(0.0f, 0.5f, 0.8f)); | |
| 169 | + constraint.AddSource( Source( mLabel, mHueAngleIndex ) ); | |
| 170 | + constraint.SetRemoveAction( Constraint::Discard ); | |
| 171 | + constraint.Apply(); | |
| 172 | + | |
| 173 | + Animation anim = Animation::New(50.0f); | |
| 174 | + anim.AnimateTo(Property(mLabel, mHueAngleIndex), 6.28318f); | |
| 175 | + anim.SetLooping(true); | |
| 176 | + anim.Play(); | |
| 177 | + | |
| 137 | 178 | Property::Value labelText = mLabel.GetProperty( TextLabel::Property::TEXT ); |
| 138 | 179 | std::cout << "Displaying text: \"" << labelText.Get< std::string >() << "\"" << std::endl; |
| 139 | 180 | } |
| ... | ... | @@ -284,6 +325,8 @@ private: |
| 284 | 325 | |
| 285 | 326 | unsigned int mLanguageId; |
| 286 | 327 | unsigned int mAlignment; |
| 328 | + Property::Index mHueAngleIndex; | |
| 329 | + Property::Index mOverrideMixColorIndex; | |
| 287 | 330 | }; |
| 288 | 331 | |
| 289 | 332 | void RunTest( Application& application ) | ... | ... |