From 564e9d67ee51b52b668e9791c13e14beeb63220e Mon Sep 17 00:00:00 2001 From: Heeyong Song Date: Mon, 8 Jun 2020 14:16:47 +0900 Subject: [PATCH] (ArcVisual) Add UPDATE_PROPERTY action Change-Id: I686d24237403a7b70b94d1092d86ba72dabd3ea5 --- .../src/dali-toolkit/utc-Dali-ArcVisual.cpp | 78 +++++++++++++++++++++- dali-toolkit/devel-api/file.list | 1 + .../devel-api/visuals/arc-visual-actions-devel.h | 55 +++++++++++++++ dali-toolkit/internal/visuals/arc/arc-visual.cpp | 52 +++++++++++++-- dali-toolkit/internal/visuals/arc/arc-visual.h | 8 +++ 5 files changed, 187 insertions(+), 7 deletions(-) create mode 100644 dali-toolkit/devel-api/visuals/arc-visual-actions-devel.h diff --git a/automated-tests/src/dali-toolkit/utc-Dali-ArcVisual.cpp b/automated-tests/src/dali-toolkit/utc-Dali-ArcVisual.cpp index 2476e0b..d6c992e 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-ArcVisual.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-ArcVisual.cpp @@ -16,15 +16,13 @@ #include #include -//#include -//#include #include -//#include #include #include #include #include #include +#include #include #include "dummy-control.h" @@ -199,3 +197,77 @@ int UtcDaliArcVisualGetPropertyMap01(void) END_TEST; } + +int UtcDaliArcVisualUpdateProperty(void) +{ + ToolkitTestApplication application; + tet_infoline( "UtcDaliArcVisualUpdateProperty" ); + + TestGlAbstraction& gl = application.GetGlAbstraction(); + + float thickness = 20.0f; + float startAngle = 0.0f; + float sweepAngle = 90.0f; + + Property::Map propertyMap; + propertyMap.Add( Toolkit::Visual::Property::TYPE, DevelVisual::ARC ) + .Add( Visual::Property::MIX_COLOR, Color::RED ) + .Add( DevelArcVisual::Property::THICKNESS, thickness ) + .Add( DevelArcVisual::Property::START_ANGLE, startAngle ) + .Add( DevelArcVisual::Property::SWEEP_ANGLE, sweepAngle ); + + Visual::Base visual = VisualFactory::Get().CreateVisual( propertyMap ); + DALI_TEST_CHECK( visual ); + + DummyControl actor = DummyControl::New( true ); + DummyControlImpl& dummyImpl = static_cast< DummyControlImpl& >( actor.GetImplementation() ); + dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual ); + + actor.SetProperty( Actor::Property::SIZE, Vector2( 200.0f, 200.0f ) ); + Stage::GetCurrent().Add( actor ); + + application.SendNotification(); + application.Render(); + + Property::Map map = actor.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL ); + Property::Value* value = map.Find( DevelArcVisual::Property::THICKNESS, Property::FLOAT ); + DALI_TEST_EQUALS( value->Get< float >(), thickness, TEST_LOCATION ); + DALI_TEST_EQUALS( gl.CheckUniformValue< float >( "thickness", thickness ), true, TEST_LOCATION ); + + value = map.Find( DevelArcVisual::Property::START_ANGLE, Property::FLOAT ); + DALI_TEST_EQUALS( value->Get< float >(), startAngle, TEST_LOCATION ); + DALI_TEST_EQUALS( gl.CheckUniformValue< float >( "startAngle", startAngle ), true, TEST_LOCATION ); + + value = map.Find( DevelArcVisual::Property::SWEEP_ANGLE, Property::FLOAT ); + DALI_TEST_EQUALS( value->Get< float >(), sweepAngle, TEST_LOCATION ); + DALI_TEST_EQUALS( gl.CheckUniformValue< float >( "sweepAngle", sweepAngle ), true, TEST_LOCATION ); + + thickness = 10.0f; + startAngle = 90.0f; + sweepAngle = 180.0f; + + Property::Map attributes; + attributes.Add( DevelArcVisual::Property::THICKNESS, thickness ) + .Add( DevelArcVisual::Property::START_ANGLE, startAngle ) + .Add( DevelArcVisual::Property::SWEEP_ANGLE, sweepAngle ); + + DevelControl::DoAction( actor, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::DevelArcVisual::Action::UPDATE_PROPERTY, attributes ); + + application.SendNotification(); + application.Render(); + + map = actor.GetProperty< Property::Map >( DummyControl::Property::TEST_VISUAL ); + value = map.Find( DevelArcVisual::Property::THICKNESS, Property::FLOAT ); + DALI_TEST_EQUALS( value->Get< float >(), thickness, TEST_LOCATION ); + DALI_TEST_EQUALS( gl.CheckUniformValue< float >( "thickness", thickness ), true, TEST_LOCATION ); + + value = map.Find( DevelArcVisual::Property::START_ANGLE, Property::FLOAT ); + DALI_TEST_EQUALS( value->Get< float >(), startAngle, TEST_LOCATION ); + DALI_TEST_EQUALS( gl.CheckUniformValue< float >( "startAngle", startAngle ), true, TEST_LOCATION ); + + value = map.Find( DevelArcVisual::Property::SWEEP_ANGLE, Property::FLOAT ); + DALI_TEST_EQUALS( value->Get< float >(), sweepAngle, TEST_LOCATION ); + DALI_TEST_EQUALS( gl.CheckUniformValue< float >( "sweepAngle", sweepAngle ), true, TEST_LOCATION ); + + END_TEST; +} diff --git a/dali-toolkit/devel-api/file.list b/dali-toolkit/devel-api/file.list index 48e3579..5eb6d82 100755 --- a/dali-toolkit/devel-api/file.list +++ b/dali-toolkit/devel-api/file.list @@ -131,6 +131,7 @@ SET( devel_api_visuals_header_files ${devel_api_src_dir}/visuals/animated-image-visual-actions-devel.h ${devel_api_src_dir}/visuals/animated-vector-image-visual-actions-devel.h ${devel_api_src_dir}/visuals/animated-vector-image-visual-signals-devel.h + ${devel_api_src_dir}/visuals/arc-visual-actions-devel.h ${devel_api_src_dir}/visuals/arc-visual-properties-devel.h ${devel_api_src_dir}/visuals/color-visual-properties-devel.h ${devel_api_src_dir}/visuals/image-visual-properties-devel.h diff --git a/dali-toolkit/devel-api/visuals/arc-visual-actions-devel.h b/dali-toolkit/devel-api/visuals/arc-visual-actions-devel.h new file mode 100644 index 0000000..306821c --- /dev/null +++ b/dali-toolkit/devel-api/visuals/arc-visual-actions-devel.h @@ -0,0 +1,55 @@ +#ifndef DALI_TOOLKIT_DEVEL_API_VISUALS_ARC_VISUAL_ACTIONS_DEVEL_H +#define DALI_TOOLKIT_DEVEL_API_VISUALS_ARC_VISUAL_ACTIONS_DEVEL_H + +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +namespace Dali +{ + +namespace Toolkit +{ + +namespace DevelArcVisual +{ + +/** + * @brief Actions that the arc visual can perform. These actions are called through the Visual::Base::DoAction API. + */ +namespace Action +{ +/** + * @brief The available actions for this visual + */ +enum Type +{ + /** + * @brief Update the properties of the visual. + * @note DevelArcVisual::Property::THICKNESS, DevelArcVisual::Property::START_ANGLE and DevelArcVisual::Property::SWEEP_ANGLE can be updated. + */ + UPDATE_PROPERTY = 0 +}; + +} // namespace Actions + +} // namespace DevelArcVisual + +} // namespace Toolkit + +} // namespace Dali + +#endif // DALI_TOOLKIT_DEVEL_API_VISUALS_ARC_VISUAL_ACTIONS_DEVEL_H diff --git a/dali-toolkit/internal/visuals/arc/arc-visual.cpp b/dali-toolkit/internal/visuals/arc/arc-visual.cpp index 618b75d..71bb538 100644 --- a/dali-toolkit/internal/visuals/arc/arc-visual.cpp +++ b/dali-toolkit/internal/visuals/arc/arc-visual.cpp @@ -23,6 +23,7 @@ //INTERNAL INCLUDES #include +#include #include #include #include @@ -159,6 +160,9 @@ ArcVisual::ArcVisual( VisualFactoryCache& factoryCache ) mStartAngle( 0.0f ), mSweepAngle( 360.0f ), mRadiusIndex( Property::INVALID_INDEX ), + mThicknessIndex( Property::INVALID_INDEX ), + mStartAngleIndex( Property::INVALID_INDEX ), + mSweepAngleIndex( Property::INVALID_INDEX ), mCapType( DevelArcVisual::Cap::BUTT ) { } @@ -176,6 +180,16 @@ void ArcVisual::DoSetProperties( const Property::Map& propertyMap ) { DALI_LOG_ERROR( "ArcVisual:DoSetProperties:: THICKNESS property has incorrect type: %d\n", thicknessValue->GetType() ); } + else + { + if( mImpl->mRenderer ) + { + mImpl->mRenderer.SetProperty( mThicknessIndex, mThickness ); + + // Need to calculate radius again + OnSetTransform(); + } + } } Property::Value* startAngleValue = propertyMap.Find( Toolkit::DevelArcVisual::Property::START_ANGLE, START_ANGLE_NAME ); @@ -185,6 +199,13 @@ void ArcVisual::DoSetProperties( const Property::Map& propertyMap ) { DALI_LOG_ERROR( "ArcVisual:DoSetProperties:: START_ANGLE property has incorrect type: %d\n", startAngleValue->GetType() ); } + else + { + if( mImpl->mRenderer ) + { + mImpl->mRenderer.SetProperty( mStartAngleIndex, mStartAngle ); + } + } } Property::Value* sweepAngleValue = propertyMap.Find( Toolkit::DevelArcVisual::Property::SWEEP_ANGLE, SWEEP_ANGLE_NAME ); @@ -194,6 +215,13 @@ void ArcVisual::DoSetProperties( const Property::Map& propertyMap ) { DALI_LOG_ERROR( "ArcVisual:DoSetProperties:: SWEEP_ANGLE property has incorrect type: %d\n", sweepAngleValue->GetType() ); } + else + { + if( mImpl->mRenderer ) + { + mImpl->mRenderer.SetProperty( mSweepAngleIndex, mSweepAngle ); + } + } } Property::Value* capValue = propertyMap.Find( Toolkit::DevelArcVisual::Property::CAP, CAP_NAME ); @@ -241,6 +269,23 @@ void ArcVisual::OnSetTransform() } } +void ArcVisual::OnDoAction( const Property::Index actionId, const Property::Value& attributes ) +{ + // Check if action is valid for this visual type and perform action if possible + switch( actionId ) + { + case DevelArcVisual::Action::UPDATE_PROPERTY: + { + Property::Map* map = attributes.GetMap(); + if( map ) + { + DoSetProperties( *map ); + } + break; + } + } +} + void ArcVisual::InitializeRenderer() { Geometry geometry = mFactoryCache.GetGeometry( VisualFactoryCache::QUAD_GEOMETRY ); @@ -267,10 +312,9 @@ void ArcVisual::InitializeRenderer() mImpl->mRenderer = Renderer::New( geometry, shader ); - mImpl->mRenderer.RegisterProperty( THICKNESS_NAME, mThickness ); - mImpl->mRenderer.RegisterProperty( START_ANGLE_NAME, mStartAngle ); - mImpl->mRenderer.RegisterProperty( SWEEP_ANGLE_NAME, mSweepAngle ); - mImpl->mRenderer.RegisterProperty( CAP_NAME, 0.0f ); + mThicknessIndex = mImpl->mRenderer.RegisterProperty( THICKNESS_NAME, mThickness ); + mStartAngleIndex = mImpl->mRenderer.RegisterProperty( START_ANGLE_NAME, mStartAngle ); + mSweepAngleIndex = mImpl->mRenderer.RegisterProperty( SWEEP_ANGLE_NAME, mSweepAngle ); mRadiusIndex = mImpl->mRenderer.RegisterProperty( RADIUS_NAME, mRadius ); diff --git a/dali-toolkit/internal/visuals/arc/arc-visual.h b/dali-toolkit/internal/visuals/arc/arc-visual.h index e9fa083..3de0473 100644 --- a/dali-toolkit/internal/visuals/arc/arc-visual.h +++ b/dali-toolkit/internal/visuals/arc/arc-visual.h @@ -103,6 +103,11 @@ protected: */ void OnSetTransform() override; + /** + * @copydoc Visual::Base::OnDoAction + */ + void OnDoAction( const Property::Index actionId, const Property::Value& attributes ) override; + private: /** @@ -125,6 +130,9 @@ private: float mStartAngle; ///< The start angle of the arc. float mSweepAngle; ///< The sweep angle of the arc. Property::Index mRadiusIndex; ///< The index of the radius property. + Property::Index mThicknessIndex; ///< The index of the thickness property. + Property::Index mStartAngleIndex; ///< The index of the start angle property. + Property::Index mSweepAngleIndex; ///< The index of the sweep angle property. DevelArcVisual::Cap::Type mCapType; ///< The cap type. }; -- 2.7.4