From 33d3f72e60fc62db3718791f906dc843f1edeeb3 Mon Sep 17 00:00:00 2001 From: David Steele Date: Mon, 15 Aug 2016 18:10:49 +0100 Subject: [PATCH 1/1] Added int keys to animatable visual properties. Added test cases to test animating Visual properties directly. Change-Id: Iee884a8570a5ec65870e7b9556e14df4385a71b6 Signed-off-by: David Steele --- .../src/dali-toolkit/utc-Dali-Visual.cpp | 184 +++++++++++++++++++++ .../internal/visuals/border/border-visual.cpp | 4 +- .../internal/visuals/color/color-visual.cpp | 2 +- .../visuals/primitive/primitive-visual.cpp | 2 +- 4 files changed, 188 insertions(+), 4 deletions(-) diff --git a/automated-tests/src/dali-toolkit/utc-Dali-Visual.cpp b/automated-tests/src/dali-toolkit/utc-Dali-Visual.cpp index f3667bc..7bc228d 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-Visual.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-Visual.cpp @@ -883,3 +883,187 @@ int UtcDaliVisualGetPropertyMapBatchImageVisualNoAtlas(void) END_TEST; } + +int UtcDaliVisualAnimateBorderVisual01(void) +{ + ToolkitTestApplication application; + tet_infoline( "UtcDaliAnimateBorderVisual Color" ); + + VisualFactory factory = VisualFactory::Get(); + Property::Map propertyMap; + propertyMap.Insert(Visual::Property::TYPE, Visual::BORDER); + propertyMap.Insert(BorderVisual::Property::COLOR, Color::BLUE); + propertyMap.Insert(BorderVisual::Property::SIZE, 5.f); + Visual::Base borderVisual = factory.CreateVisual( propertyMap ); + + Actor actor = Actor::New(); + actor.SetSize(2000, 2000); + actor.SetParentOrigin(ParentOrigin::CENTER); + Stage::GetCurrent().Add(actor); + borderVisual.SetOnStage( actor ); + + DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION); + + Renderer renderer = actor.GetRendererAt(0); + Property::Index index = renderer.GetPropertyIndex( BorderVisual::Property::COLOR ); + + Animation animation = Animation::New(4.0f); + animation.AnimateTo( Property(renderer, index), Color::WHITE ); + animation.Play(); + + application.SendNotification(); + application.Render(0); + application.Render(2000u); // halfway point between blue and white + + Vector4 color = renderer.GetProperty( index ); + Vector4 testColor = (Color::BLUE + Color::WHITE)*0.5f; + DALI_TEST_EQUALS( color, testColor, TEST_LOCATION ); + DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue("borderColor", testColor ), true, TEST_LOCATION ); + + application.Render(2000u); // halfway point between blue and white + + color = renderer.GetProperty( index ); + DALI_TEST_EQUALS( color, Color::WHITE, TEST_LOCATION ); + DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue("borderColor", Color::WHITE ), true, TEST_LOCATION ); + + END_TEST; +} + + +int UtcDaliVisualAnimateBorderVisual02(void) +{ + ToolkitTestApplication application; + tet_infoline( "UtcDaliAnimateBorderVisual Size" ); + + VisualFactory factory = VisualFactory::Get(); + Property::Map propertyMap; + propertyMap.Insert(Visual::Property::TYPE, Visual::BORDER); + propertyMap.Insert(BorderVisual::Property::COLOR, Color::BLUE); + propertyMap.Insert(BorderVisual::Property::SIZE, 5.f); + Visual::Base borderVisual = factory.CreateVisual( propertyMap ); + + Actor actor = Actor::New(); + actor.SetSize(2000, 2000); + actor.SetParentOrigin(ParentOrigin::CENTER); + Stage::GetCurrent().Add(actor); + borderVisual.SetOnStage( actor ); + + DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION); + + Renderer renderer = actor.GetRendererAt(0); + Property::Index index = renderer.GetPropertyIndex( BorderVisual::Property::SIZE ); + + Animation animation = Animation::New(4.0f); + animation.AnimateTo( Property(renderer, index), 9.0f ); + animation.Play(); + + application.SendNotification(); + application.Render(0); + application.Render(2000u); // halfway point + + float size = renderer.GetProperty( index ); + DALI_TEST_EQUALS( size, 7.0f, 0.0001f, TEST_LOCATION ); + DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue("borderSize", 7.0f ), true, TEST_LOCATION ); + + application.Render(2000u); // halfway point between blue and white + + size = renderer.GetProperty( index ); + DALI_TEST_EQUALS( size, 9.0f, 0.0001f, TEST_LOCATION ); + DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue("borderSize", 9.0f ), true, TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliVisualAnimateColorVisual(void) +{ + ToolkitTestApplication application; + tet_infoline( "UtcDaliAnimateColorVisual mixColor" ); + + VisualFactory factory = VisualFactory::Get(); + Property::Map propertyMap; + propertyMap.Insert(Visual::Property::TYPE, Visual::COLOR); + propertyMap.Insert(ColorVisual::Property::MIX_COLOR, Color::BLUE); + Visual::Base borderVisual = factory.CreateVisual( propertyMap ); + + Actor actor = Actor::New(); + actor.SetSize(2000, 2000); + actor.SetParentOrigin(ParentOrigin::CENTER); + Stage::GetCurrent().Add(actor); + borderVisual.SetOnStage( actor ); + + DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION); + + Renderer renderer = actor.GetRendererAt(0); + Property::Index index = renderer.GetPropertyIndex( ColorVisual::Property::MIX_COLOR ); + + Animation animation = Animation::New(4.0f); + animation.AnimateTo( Property(renderer, index), Color::WHITE ); + animation.Play(); + + application.SendNotification(); + application.Render(0); + application.Render(2000u); // halfway point + + Vector4 color = renderer.GetProperty( index ); + Vector4 testColor = (Color::BLUE + Color::WHITE)*0.5f; + DALI_TEST_EQUALS( color, testColor, TEST_LOCATION ); + + DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue("mixColor", testColor ), true, TEST_LOCATION ); + + application.Render(2000u); // halfway point between blue and white + + color = renderer.GetProperty( index ); + DALI_TEST_EQUALS( color, Color::WHITE, TEST_LOCATION ); + + DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue("mixColor", Color::WHITE ), true, TEST_LOCATION ); + + + END_TEST; +} + + +int UtcDaliVisualAnimatePrimitiveVisual(void) +{ + ToolkitTestApplication application; + tet_infoline( "UtcDaliAnimatePrimitiveVisual color" ); + + VisualFactory factory = VisualFactory::Get(); + Property::Map propertyMap; + propertyMap.Insert(Visual::Property::TYPE, Visual::COLOR); + propertyMap.Insert(ColorVisual::Property::MIX_COLOR, Color::BLUE); + Visual::Base borderVisual = factory.CreateVisual( propertyMap ); + + Actor actor = Actor::New(); + actor.SetSize(2000, 2000); + actor.SetParentOrigin(ParentOrigin::CENTER); + actor.SetColor(Color::BLACK); + Stage::GetCurrent().Add(actor); + borderVisual.SetOnStage( actor ); + + DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION); + + Renderer renderer = actor.GetRendererAt(0); + Property::Index index = renderer.GetPropertyIndex( PrimitiveVisual::Property::COLOR ); + + // The property isn't registered on the renderer, it's instead registered on the shader. + DALI_TEST_EQUALS( index, Property::INVALID_INDEX, TEST_LOCATION ); + + Animation animation = Animation::New(4.0f); + animation.AnimateTo( Property(actor, Actor::Property::COLOR), Color::WHITE ); + animation.Play(); + + application.SendNotification(); + application.Render(0); + application.Render(2000u); // halfway point + + // Actor color overrides renderer color. + DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue("uColor", Vector4(0.5f, 0.5f, 0.5f, 1.0f )), true, TEST_LOCATION ); + + application.Render(2000u); // halfway point between blue and white + + DALI_TEST_EQUALS( actor.GetCurrentColor(), Color::WHITE, TEST_LOCATION ); + DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue("uColor", Color::WHITE ), true, TEST_LOCATION ); + + + END_TEST; +} diff --git a/dali-toolkit/internal/visuals/border/border-visual.cpp b/dali-toolkit/internal/visuals/border/border-visual.cpp index a56402f..cc00fc7 100644 --- a/dali-toolkit/internal/visuals/border/border-visual.cpp +++ b/dali-toolkit/internal/visuals/border/border-visual.cpp @@ -148,12 +148,12 @@ void BorderVisual::DoSetOnStage( Actor& actor ) { InitializeRenderer(); - mBorderColorIndex = (mImpl->mRenderer).RegisterProperty( COLOR_NAME, mBorderColor ); + mBorderColorIndex = (mImpl->mRenderer).RegisterProperty( Toolkit::BorderVisual::Property::COLOR, COLOR_NAME, mBorderColor ); if( mBorderColor.a < 1.f || mAntiAliasing) { mImpl->mRenderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::ON ); } - mBorderSizeIndex = (mImpl->mRenderer).RegisterProperty( SIZE_NAME, mBorderSize ); + mBorderSizeIndex = (mImpl->mRenderer).RegisterProperty( Toolkit::BorderVisual::Property::SIZE, SIZE_NAME, mBorderSize ); } void BorderVisual::DoCreatePropertyMap( Property::Map& map ) const diff --git a/dali-toolkit/internal/visuals/color/color-visual.cpp b/dali-toolkit/internal/visuals/color/color-visual.cpp index 17cf68a..9f0dc4e 100644 --- a/dali-toolkit/internal/visuals/color/color-visual.cpp +++ b/dali-toolkit/internal/visuals/color/color-visual.cpp @@ -133,7 +133,7 @@ void ColorVisual::InitializeRenderer() mImpl->mRenderer = Renderer::New( geometry, shader ); - mMixColorIndex = mImpl->mRenderer.RegisterProperty( COLOR_NAME, mMixColor ); + mMixColorIndex = mImpl->mRenderer.RegisterProperty( Toolkit::ColorVisual::Property::MIX_COLOR, COLOR_NAME, mMixColor ); if( mMixColor.a < 1.f ) { mImpl->mRenderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::ON ); diff --git a/dali-toolkit/internal/visuals/primitive/primitive-visual.cpp b/dali-toolkit/internal/visuals/primitive/primitive-visual.cpp index fe14601..6a02087 100644 --- a/dali-toolkit/internal/visuals/primitive/primitive-visual.cpp +++ b/dali-toolkit/internal/visuals/primitive/primitive-visual.cpp @@ -431,7 +431,7 @@ void PrimitiveVisual::UpdateShaderUniforms() mShader.RegisterProperty( STAGE_OFFSET_UNIFORM_NAME, Vector2( width, height ) / 2.0f ); mShader.RegisterProperty( LIGHT_POSITION_UNIFORM_NAME, mLightPosition ); mShader.RegisterProperty( OBJECT_MATRIX_UNIFORM_NAME, scaleMatrix ); - mShader.RegisterProperty( COLOR_UNIFORM_NAME, mColor ); + mShader.RegisterProperty( Toolkit::PrimitiveVisual::Property::COLOR, COLOR_UNIFORM_NAME, mColor ); mShader.RegisterProperty( OBJECT_DIMENSIONS_UNIFORM_NAME, mObjectDimensions ); } -- 2.7.4