From 299e8f55adab64025e446c5dcd1e87f050e43f82 Mon Sep 17 00:00:00 2001 From: Xiangyin Ma Date: Fri, 25 Sep 2015 17:08:33 +0100 Subject: [PATCH] Create property map from ControlRenderer and make SetOffStage API public Change-Id: Id0df6b9aa509c7add2d87619b22c043035a3b7ad --- .../src/dali-toolkit/utc-Dali-ControlRenderer.cpp | 339 ++++++++++++++++++++- .../src/dali-toolkit/utc-Dali-RendererFactory.cpp | 15 + .../controls/renderer-factory/control-renderer.cpp | 10 + .../controls/renderer-factory/control-renderer.h | 27 +- .../controls/renderer-factory/renderer-factory.h | 2 +- .../controls/renderers/border/border-renderer.cpp | 11 + .../controls/renderers/border/border-renderer.h | 5 + .../controls/renderers/color/color-renderer.cpp | 9 + .../controls/renderers/color/color-renderer.h | 5 + .../controls/renderers/control-renderer-impl.h | 12 +- .../renderers/gradient/gradient-renderer.cpp | 123 +++++++- .../renderers/gradient/gradient-renderer.h | 14 + .../controls/renderers/gradient/gradient.cpp | 5 + .../controls/renderers/gradient/gradient.h | 6 + .../controls/renderers/image/image-renderer.cpp | 141 ++++++++- .../controls/renderers/image/image-renderer.h | 5 + .../controls/renderers/npatch/npatch-renderer.cpp | 17 ++ .../controls/renderers/npatch/npatch-renderer.h | 6 + 18 files changed, 718 insertions(+), 34 deletions(-) diff --git a/automated-tests/src/dali-toolkit/utc-Dali-ControlRenderer.cpp b/automated-tests/src/dali-toolkit/utc-Dali-ControlRenderer.cpp index be623c2..abe2fb6 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-ControlRenderer.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-ControlRenderer.cpp @@ -25,6 +25,12 @@ using namespace Dali; using namespace Dali::Toolkit; +namespace +{ +const char* TEST_IMAGE_FILE_NAME = "gallery_image_01.jpg"; +const char* TEST_NPATCH_FILE_NAME = "gallery_image_01.9.jpg"; +} + void dali_control_renderer_startup(void) { test_return_value = TET_UNDEF; @@ -94,7 +100,7 @@ int UtcDaliControlRendererSetDepthIndex(void) END_TEST; } -int UtcDaliControlRendererSetOnStage(void) +int UtcDaliControlRendererSetOnOffStage(void) { ToolkitTestApplication application; tet_infoline( "UtcDaliControlRendererSetDepthIndex" ); @@ -114,10 +120,339 @@ int UtcDaliControlRendererSetOnStage(void) DALI_TEST_CHECK( actor.GetRendererCount() == 0u ); controlRenderer.SetOnStage( actor ); - application.SendNotification(); application.Render(0); DALI_TEST_CHECK( actor.GetRendererCount() == 1u ); + controlRenderer.SetOffStage( actor ); + application.SendNotification(); + application.Render(0); + DALI_TEST_CHECK( actor.GetRendererCount() == 0u ); + + END_TEST; +} + +int UtcDaliControlRendererGetPropertyMap1(void) +{ + ToolkitTestApplication application; + tet_infoline( "UtcDaliControlRendererGetPropertyMap1: ColorRenderer" ); + + RendererFactory factory = RendererFactory::Get(); + Property::Map propertyMap; + propertyMap.Insert("renderer-type", "color-renderer"); + propertyMap.Insert("blend-color", Color::BLUE); + ControlRenderer colorRenderer = factory.GetControlRenderer( propertyMap ); + + Property::Map resultMap; + colorRenderer.CreatePropertyMap( resultMap ); + + Property::Value* typeValue = resultMap.Find( "renderer-type", Property::STRING ); + DALI_TEST_CHECK( typeValue ); + DALI_TEST_CHECK( typeValue->Get() == "color-renderer" ); + + Property::Value* colorValue = resultMap.Find( "blend-color", Property::VECTOR4 ); + DALI_TEST_CHECK( colorValue ); + DALI_TEST_CHECK( colorValue->Get() == Color::BLUE ); + + // change the blend color + factory.ResetRenderer( colorRenderer, Color::CYAN ); + colorRenderer.CreatePropertyMap( resultMap ); + + colorValue = resultMap.Find( "blend-color", Property::VECTOR4 ); + DALI_TEST_CHECK( colorValue ); + DALI_TEST_CHECK( colorValue->Get() == Color::CYAN ); + + END_TEST; +} + +int UtcDaliControlRendererGetPropertyMap2(void) +{ + ToolkitTestApplication application; + tet_infoline( "UtcDaliControlRendererGetPropertyMap2: BorderRenderer" ); + + RendererFactory factory = RendererFactory::Get(); + Property::Map propertyMap; + propertyMap.Insert("renderer-type", "border-renderer"); + propertyMap.Insert("border-color", Color::BLUE); + propertyMap.Insert("border-size", 5.f); + ControlRenderer borderRenderer = factory.GetControlRenderer( propertyMap ); + + Property::Map resultMap; + borderRenderer.CreatePropertyMap( resultMap ); + + // check the property values from the returned map from control renderer + Property::Value* typeValue = resultMap.Find( "renderer-type", Property::STRING ); + DALI_TEST_CHECK( typeValue ); + DALI_TEST_CHECK( typeValue->Get() == "border-renderer" ); + + Property::Value* colorValue = resultMap.Find( "border-color", Property::VECTOR4 ); + DALI_TEST_CHECK( colorValue ); + DALI_TEST_CHECK( colorValue->Get() == Color::BLUE ); + + Property::Value* sizeValue = resultMap.Find( "border-size", Property::FLOAT ); + DALI_TEST_CHECK( sizeValue ); + DALI_TEST_CHECK( sizeValue->Get() == 5.f ); + + borderRenderer = factory.GetControlRenderer( 10.f, Color::CYAN ); + borderRenderer.CreatePropertyMap( resultMap ); + + typeValue = resultMap.Find( "renderer-type", Property::STRING ); + DALI_TEST_CHECK( typeValue ); + DALI_TEST_CHECK( typeValue->Get() == "border-renderer" ); + + colorValue = resultMap.Find( "border-color", Property::VECTOR4 ); + DALI_TEST_CHECK( colorValue ); + DALI_TEST_CHECK( colorValue->Get() == Color::CYAN ); + + colorValue = resultMap.Find( "border-size", Property::FLOAT ); + DALI_TEST_CHECK( colorValue ); + DALI_TEST_CHECK( colorValue->Get() == 10.f ); + + END_TEST; +} + +int UtcDaliControlRendererGetPropertyMap3(void) +{ + ToolkitTestApplication application; + tet_infoline( "UtcDaliControlRendererGetPropertyMap3: linear GradientRenderer" ); + + RendererFactory factory = RendererFactory::Get(); + DALI_TEST_CHECK( factory ); + + Property::Map propertyMap; + propertyMap.Insert("renderer-type", "gradient-renderer"); + + Vector2 start(-1.f, -1.f); + Vector2 end(1.f, 1.f); + propertyMap.Insert("gradient-start-position", start); + propertyMap.Insert("gradient-end-position", end); + propertyMap.Insert("gradient-spread-method", "repeat"); + + propertyMap.Insert("gradient-stop-offset", Vector2(0.2f, 0.8f)); + + Property::Array stopColors; + stopColors.PushBack( Color::RED ); + stopColors.PushBack( Color::GREEN ); + propertyMap.Insert("gradient-stop-color", stopColors); + + ControlRenderer gradientRenderer = factory.GetControlRenderer(propertyMap); + + Property::Map resultMap; + gradientRenderer.CreatePropertyMap( resultMap ); + + // check the property values from the returned map from control renderer + Property::Value* value = resultMap.Find( "renderer-type", Property::STRING ); + DALI_TEST_CHECK( value ); + DALI_TEST_CHECK( value->Get() == "gradient-renderer" ); + + value = resultMap.Find( "gradient-units", Property::STRING ); + DALI_TEST_CHECK( value ); + DALI_TEST_CHECK( value->Get() == "object-bounding-box" ); + + value = resultMap.Find( "gradient-spread-method", Property::STRING ); + DALI_TEST_CHECK( value ); + DALI_TEST_CHECK( value->Get() == "repeat" ); + + value = resultMap.Find( "gradient-start-position", Property::VECTOR2 ); + DALI_TEST_CHECK( value ); + DALI_TEST_EQUALS( value->Get(), start , Math::MACHINE_EPSILON_100, TEST_LOCATION ); + + value = resultMap.Find( "gradient-end-position", Property::VECTOR2 ); + DALI_TEST_CHECK( value ); + DALI_TEST_EQUALS( value->Get(), end , Math::MACHINE_EPSILON_100, TEST_LOCATION ); + + value = resultMap.Find( "gradient-stop-offset", Property::ARRAY ); + DALI_TEST_CHECK( value ); + Property::Array* offsetArray = value->GetArray(); + DALI_TEST_CHECK( offsetArray->Count() == 2 ); + DALI_TEST_EQUALS( offsetArray->GetElementAt(0).Get(), 0.2f , Math::MACHINE_EPSILON_100, TEST_LOCATION ); + DALI_TEST_EQUALS( offsetArray->GetElementAt(1).Get(), 0.8f , Math::MACHINE_EPSILON_100, TEST_LOCATION ); + + value = resultMap.Find( "gradient-stop-color", Property::ARRAY ); + DALI_TEST_CHECK( value ); + Property::Array* colorArray = value->GetArray(); + DALI_TEST_CHECK( colorArray->Count() == 2 ); + DALI_TEST_EQUALS( colorArray->GetElementAt(0).Get(), Color::RED , Math::MACHINE_EPSILON_100, TEST_LOCATION ); + DALI_TEST_EQUALS( colorArray->GetElementAt(1).Get(), Color::GREEN , Math::MACHINE_EPSILON_100, TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliControlRendererGetPropertyMap4(void) +{ + ToolkitTestApplication application; + tet_infoline( "UtcDaliControlRendererGetPropertyMap4: radial GradientRenderer" ); + + RendererFactory factory = RendererFactory::Get(); + DALI_TEST_CHECK( factory ); + + Property::Map propertyMap; + propertyMap.Insert("renderer-type", "gradient-renderer"); + + Vector2 center(100.f, 100.f); + float radius = 100.f; + propertyMap.Insert("gradient-units", "user-space"); + propertyMap.Insert("gradient-center", center); + propertyMap.Insert("gradient-radius", radius); + propertyMap.Insert("gradient-stop-offset", Vector3(0.1f, 0.3f, 1.1f)); + + Property::Array stopColors; + stopColors.PushBack( Color::RED ); + stopColors.PushBack( Color::BLACK ); + stopColors.PushBack( Color::GREEN ); + propertyMap.Insert("gradient-stop-color", stopColors); + + ControlRenderer gradientRenderer = factory.GetControlRenderer(propertyMap); + DALI_TEST_CHECK( gradientRenderer ); + + Property::Map resultMap; + gradientRenderer.CreatePropertyMap( resultMap ); + + // check the property values from the returned map from control renderer + Property::Value* value = resultMap.Find( "renderer-type", Property::STRING ); + DALI_TEST_CHECK( value ); + DALI_TEST_CHECK( value->Get() == "gradient-renderer" ); + + value = resultMap.Find( "gradient-units", Property::STRING ); + DALI_TEST_CHECK( value ); + DALI_TEST_CHECK( value->Get() == "user-space" ); + + value = resultMap.Find( "gradient-spread-method", Property::STRING ); + DALI_TEST_CHECK( value ); + DALI_TEST_CHECK( value->Get() == "pad" ); + + value = resultMap.Find( "gradient-center", Property::VECTOR2 ); + DALI_TEST_CHECK( value ); + DALI_TEST_EQUALS( value->Get(), center , Math::MACHINE_EPSILON_100, TEST_LOCATION ); + + value = resultMap.Find( "gradient-radius", Property::FLOAT ); + DALI_TEST_CHECK( value ); + DALI_TEST_EQUALS( value->Get(), radius , Math::MACHINE_EPSILON_100, TEST_LOCATION ); + + value = resultMap.Find( "gradient-stop-offset", Property::ARRAY ); + DALI_TEST_CHECK( value ); + Property::Array* offsetArray = value->GetArray(); + DALI_TEST_CHECK( offsetArray->Count() == 3 ); + DALI_TEST_EQUALS( offsetArray->GetElementAt(0).Get(), 0.1f , Math::MACHINE_EPSILON_100, TEST_LOCATION ); + DALI_TEST_EQUALS( offsetArray->GetElementAt(1).Get(), 0.3f , Math::MACHINE_EPSILON_100, TEST_LOCATION ); + // any stop value will be clamped to [0.0, 1.0]; + DALI_TEST_EQUALS( offsetArray->GetElementAt(2).Get(), 1.0f , Math::MACHINE_EPSILON_100, TEST_LOCATION ); + + value = resultMap.Find( "gradient-stop-color", Property::ARRAY ); + DALI_TEST_CHECK( value ); + Property::Array* colorArray = value->GetArray(); + DALI_TEST_CHECK( colorArray->Count() == 3 ); + DALI_TEST_EQUALS( colorArray->GetElementAt(0).Get(), Color::RED , Math::MACHINE_EPSILON_100, TEST_LOCATION ); + DALI_TEST_EQUALS( colorArray->GetElementAt(1).Get(), Color::BLACK , Math::MACHINE_EPSILON_100, TEST_LOCATION ); + DALI_TEST_EQUALS( colorArray->GetElementAt(2).Get(), Color::GREEN , Math::MACHINE_EPSILON_100, TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliControlRendererGetPropertyMap5(void) +{ + ToolkitTestApplication application; + tet_infoline( "UtcDaliControlRendererGetPropertyMap5: ImageRenderer" ); + + RendererFactory factory = RendererFactory::Get(); + Property::Map propertyMap; + propertyMap.Insert( "renderer-type", "image-renderer" ); + propertyMap.Insert( "image-url", TEST_IMAGE_FILE_NAME ); + propertyMap.Insert( "image-desired-width", 20 ); + propertyMap.Insert( "image-desired-height", 30 ); + propertyMap.Insert( "image-fitting-mode", "fit-height" ); + propertyMap.Insert( "image-sampling-mode", "box-then-nearest" ); + + ControlRenderer imageRenderer = factory.GetControlRenderer(propertyMap); + DALI_TEST_CHECK( imageRenderer ); + + Property::Map resultMap; + imageRenderer.CreatePropertyMap( resultMap ); + + // check the property values from the returned map from control renderer + Property::Value* value = resultMap.Find( "renderer-type", Property::STRING ); + DALI_TEST_CHECK( value ); + DALI_TEST_CHECK( value->Get() == "image-renderer" ); + + value = resultMap.Find( "image-url", Property::STRING ); + DALI_TEST_CHECK( value ); + DALI_TEST_CHECK( value->Get() == TEST_IMAGE_FILE_NAME ); + + value = resultMap.Find( "image-fitting-mode", Property::STRING ); + DALI_TEST_CHECK( value ); + DALI_TEST_CHECK( value->Get() == "fit-height" ); + + value = resultMap.Find( "image-sampling-mode", Property::STRING ); + DALI_TEST_CHECK( value ); + DALI_TEST_CHECK( value->Get() == "box-then-nearest" ); + + value = resultMap.Find( "image-desired-width", Property::INTEGER ); + DALI_TEST_CHECK( value ); + DALI_TEST_CHECK( value->Get() == 20 ); + + value = resultMap.Find( "image-desired-height", Property::INTEGER ); + DALI_TEST_CHECK( value ); + DALI_TEST_CHECK( value->Get() == 30 ); + + // Get an image renderer with an image handle, and test the default property values + Image image = ResourceImage::New(TEST_IMAGE_FILE_NAME, ImageDimensions(100, 200)); + imageRenderer = factory.GetControlRenderer(image); + imageRenderer.CreatePropertyMap( resultMap ); + + value = resultMap.Find( "renderer-type", Property::STRING ); + DALI_TEST_CHECK( value ); + DALI_TEST_CHECK( value->Get() == "image-renderer" ); + + value = resultMap.Find( "image-url", Property::STRING ); + DALI_TEST_CHECK( value ); + DALI_TEST_CHECK( value->Get() == TEST_IMAGE_FILE_NAME ); + + value = resultMap.Find( "image-fitting-mode", Property::STRING ); + DALI_TEST_CHECK( value ); + DALI_TEST_CHECK( value->Get() == "shrink-to-fit" ); + + value = resultMap.Find( "image-sampling-mode", Property::STRING ); + DALI_TEST_CHECK( value ); + DALI_TEST_CHECK( value->Get() == "box" ); + + value = resultMap.Find( "image-desired-width", Property::INTEGER ); + DALI_TEST_CHECK( value ); + DALI_TEST_CHECK( value->Get() == 100 ); + + value = resultMap.Find( "image-desired-height", Property::INTEGER ); + DALI_TEST_CHECK( value ); + DALI_TEST_CHECK( value->Get() == 200 ); + + END_TEST; +} + +int UtcDaliControlRendererGetPropertyMap6(void) +{ + ToolkitTestApplication application; + tet_infoline( "UtcDaliControlRendererGetPropertyMap6: NPatchRenderer" ); + + RendererFactory factory = RendererFactory::Get(); + Property::Map propertyMap; + propertyMap.Insert( "renderer-type", "n-patch-renderer" ); + propertyMap.Insert( "image-url", TEST_NPATCH_FILE_NAME ); + propertyMap.Insert( "border-only", true ); + ControlRenderer nPatchRenderer = factory.GetControlRenderer( propertyMap ); + + Property::Map resultMap; + nPatchRenderer.CreatePropertyMap( resultMap ); + + // check the property values from the returned map from control renderer + Property::Value* value = resultMap.Find( "renderer-type", Property::STRING ); + DALI_TEST_CHECK( value ); + DALI_TEST_CHECK( value->Get() == "n-patch-renderer" ); + + value = resultMap.Find( "image-url", Property::STRING ); + DALI_TEST_CHECK( value ); + DALI_TEST_CHECK( value->Get() == TEST_NPATCH_FILE_NAME ); + + value = resultMap.Find( "border-only", Property::BOOLEAN ); + DALI_TEST_CHECK( value ); + DALI_TEST_CHECK( value->Get() ); + END_TEST; } diff --git a/automated-tests/src/dali-toolkit/utc-Dali-RendererFactory.cpp b/automated-tests/src/dali-toolkit/utc-Dali-RendererFactory.cpp index c132161..a570b72 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-RendererFactory.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-RendererFactory.cpp @@ -282,6 +282,9 @@ int UtcDaliRendererFactoryGetColorRenderer2(void) DALI_TEST_CHECK( gl.GetUniformValue( "uBlendColor", actualValue ) ); DALI_TEST_EQUALS( actualValue, testColor, TEST_LOCATION ); + controlRenderer.SetOffStage( actor ); + DALI_TEST_CHECK( actor.GetRendererCount() == 0u ); + END_TEST; } @@ -324,6 +327,9 @@ int UtcDaliRendererFactoryGetBorderRenderer1(void) DALI_TEST_CHECK( gl.GetUniformValue( "uBorderSize", actualSize ) ); DALI_TEST_EQUALS( actualSize, testSize, TEST_LOCATION ); + controlRenderer.SetOffStage( actor ); + DALI_TEST_CHECK( actor.GetRendererCount() == 0u ); + END_TEST; } @@ -411,6 +417,9 @@ int UtcDaliRendererFactoryGetLinearGradientRenderer(void) application.SendNotification(); application.Render(0); + controlRenderer.SetOffStage( actor ); + DALI_TEST_CHECK( actor.GetRendererCount() == 0u ); + END_TEST; } @@ -515,6 +524,9 @@ int UtcDaliRendererFactoryGetImageRenderer1(void) DALI_TEST_CHECK( gl.GetUniformValue< int >( "sTexture", textureUnit ) ); DALI_TEST_EQUALS( textureUnit, 0, TEST_LOCATION ); + controlRenderer.SetOffStage( actor ); + DALI_TEST_CHECK( actor.GetRendererCount() == 0u ); + END_TEST; } @@ -610,6 +622,9 @@ int UtcDaliRendererFactoryGetNPatchRenderer1(void) DALI_TEST_CHECK( gl.GetUniformValue< int >( "sTexture", textureUnit ) ); DALI_TEST_EQUALS( textureUnit, 0, TEST_LOCATION ); + controlRenderer.SetOffStage( actor ); + DALI_TEST_CHECK( actor.GetRendererCount() == 0u ); + END_TEST; } diff --git a/dali-toolkit/devel-api/controls/renderer-factory/control-renderer.cpp b/dali-toolkit/devel-api/controls/renderer-factory/control-renderer.cpp index e460b77..30e8b58 100644 --- a/dali-toolkit/devel-api/controls/renderer-factory/control-renderer.cpp +++ b/dali-toolkit/devel-api/controls/renderer-factory/control-renderer.cpp @@ -66,6 +66,16 @@ void ControlRenderer::SetOnStage( Actor& actor ) GetImplementation( *this ).SetOnStage(actor); } +void ControlRenderer::SetOffStage( Actor& actor ) +{ + GetImplementation( *this ).SetOffStage(actor); +} + +void ControlRenderer::CreatePropertyMap( Property::Map& map ) const +{ + GetImplementation( *this ).CreatePropertyMap( map ); +} + } // namespace Toolkit } // namespace Dali diff --git a/dali-toolkit/devel-api/controls/renderer-factory/control-renderer.h b/dali-toolkit/devel-api/controls/renderer-factory/control-renderer.h index d5f0df4..3a44603 100644 --- a/dali-toolkit/devel-api/controls/renderer-factory/control-renderer.h +++ b/dali-toolkit/devel-api/controls/renderer-factory/control-renderer.h @@ -33,7 +33,8 @@ class ControlRenderer; } /** - * ControlRenderer provides renderer for rendering the controls. A control may have multiple ControlRenders. + * @brief ControlRenderer provides renderer for rendering the controls. A control may have multiple ControlRenders. + * * ControlRenderers reuses geometry, shader etc. across controls and manages the renderer and material to exist only when control is on-stage. * It also responds to actor size and color change, and provides the clipping at the renderer level. * Note: The control renderer responds to the the Actor::COLOR by blending it with the 'Multiply' operator. @@ -70,14 +71,15 @@ public: ControlRenderer& operator=( const ControlRenderer& handle ); /** - * Set the size of the painting area. + * @brief Set the size of the painting area. * * @param[in] size The size of the painting area. */ void SetSize( const Vector2& size ); /** - * Set the depth index of this renderer. + * @brief Set the depth index of this renderer. + * * Depth-index controls draw-order for overlapping renderers. * Renderer with higher depth indices are rendered in front of other renderer with smaller values * @@ -86,13 +88,30 @@ public: void SetDepthIndex( float index ); /** - * Renderer only exists when control is on stage. + * @brief Renderer only exists when control is on stage. + * * This function should be called when the control put on stage. * * @param[in] actor The actor applying this renderer. */ void SetOnStage( Actor& actor ); + /** + * @brief Renderer is destroyed when control is off stage. + * + * This function should be called when the control removes from stage + * + * @param[in] actor The actor applying this renderer. + */ + void SetOffStage( Actor& actor ); + + /** + * @brief Create the property map representing this renderer. + * + * @param[out] map The renderer property map. + */ + void CreatePropertyMap( Property::Map& map ) const; + public: // Not intended for application developers explicit DALI_INTERNAL ControlRenderer(Internal::ControlRenderer *impl); diff --git a/dali-toolkit/devel-api/controls/renderer-factory/renderer-factory.h b/dali-toolkit/devel-api/controls/renderer-factory/renderer-factory.h index da948db..c4ac6a4 100644 --- a/dali-toolkit/devel-api/controls/renderer-factory/renderer-factory.h +++ b/dali-toolkit/devel-api/controls/renderer-factory/renderer-factory.h @@ -37,7 +37,7 @@ class RendererFactory; } /** - * RendererFactory is a singleton object that provides and shares renderers for controls + * @brief RendererFactory is a singleton object that provides and shares renderers for controls * * The renderer type is required in the property map for requesting a control renderer. * diff --git a/dali-toolkit/internal/controls/renderers/border/border-renderer.cpp b/dali-toolkit/internal/controls/renderers/border/border-renderer.cpp index 1450460..423afc2 100644 --- a/dali-toolkit/internal/controls/renderers/border/border-renderer.cpp +++ b/dali-toolkit/internal/controls/renderers/border/border-renderer.cpp @@ -37,6 +37,9 @@ namespace Internal namespace { +const char * const RENDERER_TYPE("renderer-type"); +const char * const RENDERER_TYPE_VALUE("border-renderer"); + const char * const COLOR_NAME("border-color"); const char * const COLOR_UNIFORM_NAME("uBorderColor"); const char * const SIZE_NAME("border-size"); @@ -119,6 +122,14 @@ void BorderRenderer::DoSetOnStage( Actor& actor ) mBorderSizeIndex = (mImpl->mRenderer).RegisterProperty( SIZE_UNIFORM_NAME, mBorderSize ); } +void BorderRenderer::CreatePropertyMap( Property::Map& map ) const +{ + map.Clear(); + map.Insert( RENDERER_TYPE, RENDERER_TYPE_VALUE ); + map.Insert( COLOR_NAME, mBorderColor ); + map.Insert( SIZE_NAME, mBorderSize ); +} + void BorderRenderer::Initialize( RendererFactoryCache& factoryCache) { mImpl->mGeometry = factoryCache.GetGeometry( RendererFactoryCache::BORDER_GEOMETRY ); diff --git a/dali-toolkit/internal/controls/renderers/border/border-renderer.h b/dali-toolkit/internal/controls/renderers/border/border-renderer.h index 5a1f575..c05ea1c 100644 --- a/dali-toolkit/internal/controls/renderers/border/border-renderer.h +++ b/dali-toolkit/internal/controls/renderers/border/border-renderer.h @@ -75,6 +75,11 @@ protected: */ virtual void DoSetOnStage( Actor& actor ); + /** + * @copydoc ControlRenderer::CreatePropertyMap + */ + virtual void CreatePropertyMap( Property::Map& map ) const; + public: /** diff --git a/dali-toolkit/internal/controls/renderers/color/color-renderer.cpp b/dali-toolkit/internal/controls/renderers/color/color-renderer.cpp index 7b3ae1c..0da8112 100644 --- a/dali-toolkit/internal/controls/renderers/color/color-renderer.cpp +++ b/dali-toolkit/internal/controls/renderers/color/color-renderer.cpp @@ -37,6 +37,8 @@ namespace Internal namespace { +const char * const RENDERER_TYPE("renderer-type"); +const char * const RENDERER_TYPE_VALUE("color-renderer"); const char * const COLOR_NAME("blend-color"); const char * const COLOR_UNIFORM_NAME("uBlendColor"); @@ -105,6 +107,13 @@ void ColorRenderer::SetOffset( const Vector2& offset ) //ToDo: renderer applies the offset } +void ColorRenderer::CreatePropertyMap( Property::Map& map ) const +{ + map.Clear(); + map.Insert( RENDERER_TYPE, RENDERER_TYPE_VALUE ); + map.Insert( COLOR_NAME, mBlendColor ); +} + void ColorRenderer::DoSetOnStage( Actor& actor ) { mBlendColorIndex = (mImpl->mRenderer).RegisterProperty( COLOR_UNIFORM_NAME, mBlendColor ); diff --git a/dali-toolkit/internal/controls/renderers/color/color-renderer.h b/dali-toolkit/internal/controls/renderers/color/color-renderer.h index 5f5dd27..cec5b3a 100644 --- a/dali-toolkit/internal/controls/renderers/color/color-renderer.h +++ b/dali-toolkit/internal/controls/renderers/color/color-renderer.h @@ -75,6 +75,11 @@ public: // from ControlRenderer */ virtual void SetOffset( const Vector2& offset ); + /** + * @copydoc ControlRenderer::CreatePropertyMap + */ + virtual void CreatePropertyMap( Property::Map& map ) const; + protected: /** * @copydoc ControlRenderer::DoSetOnStage diff --git a/dali-toolkit/internal/controls/renderers/control-renderer-impl.h b/dali-toolkit/internal/controls/renderers/control-renderer-impl.h index 7c72734..86620f8 100644 --- a/dali-toolkit/internal/controls/renderers/control-renderer-impl.h +++ b/dali-toolkit/internal/controls/renderers/control-renderer-impl.h @@ -91,15 +91,15 @@ public: void SetOnStage( Actor& actor ); /** - * ToDo: Add this function to Toolkit::ControlRenderer when the Renderer can be removed from actor properly. - * - * Renderer is destroyed when control is off stage. - * This function should be called when the control removes from stage - * - * @param[in] actor The actor applying this renderer. + * @copydoc Toolkit::ControlRenderer::SetOffStage */ void SetOffStage( Actor& actor ); + /** + * @copydoc Toolkit::ControlRenderer::CreatePropertyMap + */ + virtual void CreatePropertyMap( Property::Map& map ) const = 0; + protected: /** diff --git a/dali-toolkit/internal/controls/renderers/gradient/gradient-renderer.cpp b/dali-toolkit/internal/controls/renderers/gradient/gradient-renderer.cpp index 85beb72..396ded3 100644 --- a/dali-toolkit/internal/controls/renderers/gradient/gradient-renderer.cpp +++ b/dali-toolkit/internal/controls/renderers/gradient/gradient-renderer.cpp @@ -19,6 +19,7 @@ #include "gradient-renderer.h" // EXTERNAL INCLUDES +#include #include #include #include @@ -42,6 +43,9 @@ namespace Internal namespace { +const char * const RENDERER_TYPE("renderer-type"); +const char * const RENDERER_TYPE_VALUE("gradient-renderer"); + // properties: linear gradient const char * const GRADIENT_START_POSITION_NAME("gradient-start-position"); // Property::VECTOR2 const char * const GRADIENT_END_POSITION_NAME("gradient-end-position"); // Property::VECTOR2 @@ -58,6 +62,8 @@ const char * const GRADIENT_SPREAD_METHOD_NAME("gradient-spread-method"); // Pro // string values const char * const UNIT_USER_SPACE("user-space"); +const char * const UNIT_BOUNDING_BOX("object-bounding-box"); +const char * const SPREAD_PAD("pad"); const char * const SPREAD_REFLECT("reflect"); const char * const SPREAD_REPEAT("repeat"); @@ -208,6 +214,61 @@ void GradientRenderer::SetOffset( const Vector2& offset ) //ToDo: renderer applies the offset } +void GradientRenderer::CreatePropertyMap( Property::Map& map ) const +{ + map.Clear(); + map.Insert( RENDERER_TYPE, RENDERER_TYPE_VALUE ); + + Gradient::GradientUnits units = mGradient->GetGradientUnits(); + if( units == Gradient::USER_SPACE_ON_USE ) + { + map.Insert( GRADIENT_UNITS_NAME, UNIT_USER_SPACE ); + } + else // if( units == Gradient::OBJECT_BOUNDING_BOX ) + { + map.Insert( GRADIENT_UNITS_NAME, UNIT_BOUNDING_BOX ); + } + + Gradient::SpreadMethod spread = mGradient->GetSpreadMethod(); + if( spread == Gradient::PAD ) + { + map.Insert( GRADIENT_SPREAD_METHOD_NAME, SPREAD_PAD ); + } + else if( spread == Gradient::REFLECT ) + { + map.Insert( GRADIENT_SPREAD_METHOD_NAME, SPREAD_REFLECT ); + } + else // if( units == Gradient::REPEAT ) + { + map.Insert( GRADIENT_SPREAD_METHOD_NAME, SPREAD_REPEAT ); + } + + const Vector& stops( mGradient->GetStops() ); + Property::Array offsets; + Property::Array colors; + for( unsigned int i=0; i( mGradient.Get() ); + map.Insert( GRADIENT_START_POSITION_NAME, gradient->GetStartPosition() ); + map.Insert( GRADIENT_END_POSITION_NAME, gradient->GetEndPosition() ); + } + else // if( &typeid( *mGradient ) == &typeid(RadialGradient) ) + { + RadialGradient* gradient = static_cast( mGradient.Get() ); + map.Insert( GRADIENT_CENTER_NAME, gradient->GetCenter() ); + map.Insert( GRADIENT_RADIUS_NAME, gradient->GetRadius() ); + } +} + void GradientRenderer::DoSetOnStage( Actor& actor ) { mGradientTransformIndex = (mImpl->mRenderer).RegisterProperty( UNIFORM_ALIGNMENT_MATRIX_NAME, mGradientTransform ); @@ -265,25 +326,24 @@ bool GradientRenderer::NewGradient(Type gradientType, const Property::Map& prope Property::Value* stopColorValue = propertyMap.Find( GRADIENT_STOP_COLOR_NAME ); if( stopOffsetValue && stopColorValue ) { - Property::Array* offsetArray = stopOffsetValue->GetArray(); + Vector offsetArray; Property::Array* colorArray = stopColorValue->GetArray(); - if( offsetArray && colorArray ) + if( colorArray && GetStopOffsets( stopOffsetValue, offsetArray )) { - unsigned int numStop = offsetArray->Count() < colorArray->Count() ? - offsetArray->Count() : colorArray->Count(); - float offset; + unsigned int numStop = offsetArray.Count() < colorArray->Count() ? + offsetArray.Count() : colorArray->Count(); Vector4 color; for( unsigned int i=0; iGetElementAt(i)).Get(offset) - && (colorArray->GetElementAt(i)).Get(color) ) + if( (colorArray->GetElementAt(i)).Get(color) ) { - mGradient->AddStop( offset, color); + mGradient->AddStop( offsetArray[i], color); numValidStop++; } } } } + if( numValidStop < 1u ) // no valid stop { return false; @@ -317,6 +377,53 @@ bool GradientRenderer::NewGradient(Type gradientType, const Property::Map& prope return true; } +bool GradientRenderer::GetStopOffsets(const Property::Value* value, Vector& stopOffsets) +{ + Vector2 offset2; + if( value->Get( offset2 ) ) + { + stopOffsets.PushBack( offset2.x ); + stopOffsets.PushBack( offset2.y ); + return true; + } + + Vector3 offset3; + if( value->Get( offset3 ) ) + { + stopOffsets.PushBack( offset3.x ); + stopOffsets.PushBack( offset3.y ); + stopOffsets.PushBack( offset3.z ); + return true; + } + + Vector4 offset4; + if( value->Get( offset4 ) ) + { + stopOffsets.PushBack( offset4.x ); + stopOffsets.PushBack( offset4.y ); + stopOffsets.PushBack( offset4.z ); + stopOffsets.PushBack( offset4.w ); + return true; + } + + Property::Array* offsetArray = value->GetArray(); + if( offsetArray ) + { + unsigned int numStop = offsetArray->Count(); + float offset; + for( unsigned int i=0; iGetElementAt(i).Get(offset) ) + { + stopOffsets.PushBack( offset ); + } + } + return true; + } + + return false; +} + } // namespace Internal } // namespace Toolkit diff --git a/dali-toolkit/internal/controls/renderers/gradient/gradient-renderer.h b/dali-toolkit/internal/controls/renderers/gradient/gradient-renderer.h index 4d595db..e35b5db 100644 --- a/dali-toolkit/internal/controls/renderers/gradient/gradient-renderer.h +++ b/dali-toolkit/internal/controls/renderers/gradient/gradient-renderer.h @@ -103,6 +103,11 @@ public: // from ControlRenderer */ virtual void SetOffset( const Vector2& offset ); + /** + * @copydoc ControlRenderer::CreatePropertyMap + */ + virtual void CreatePropertyMap( Property::Map& map ) const; + protected: /** * @copydoc ControlRenderer::DoSetOnStage @@ -127,6 +132,15 @@ private: */ bool NewGradient(Type gradientType, const Property::Map& propertyMap); + /** + * Get the stop-offsets from the property. + * The valid property type are ARRAY, VECTOR2, VECTOR3, VECTOR4. + * + * @param[in] value The property value of stop-offsets + * @param[out] stopOffsets The vector contains the stop offset values. + */ + static bool GetStopOffsets(const Property::Value* value, Vector& stopOffsets); + // Undefined GradientRenderer( const GradientRenderer& gradientRenderer ); diff --git a/dali-toolkit/internal/controls/renderers/gradient/gradient.cpp b/dali-toolkit/internal/controls/renderers/gradient/gradient.cpp index 920fddd..d87d132 100644 --- a/dali-toolkit/internal/controls/renderers/gradient/gradient.cpp +++ b/dali-toolkit/internal/controls/renderers/gradient/gradient.cpp @@ -49,6 +49,11 @@ void Gradient::AddStop( float offset, const Vector4& color ) mGradientStops.PushBack( GradientStop( Clamp( offset, 0.f, 1.f ), color) ); } +const Vector& Gradient::GetStops() +{ + return mGradientStops; +} + void Gradient::SetGradientUnits( GradientUnits gradientUnits ) { mGradientUnits = gradientUnits; diff --git a/dali-toolkit/internal/controls/renderers/gradient/gradient.h b/dali-toolkit/internal/controls/renderers/gradient/gradient.h index 82b58cb..36e6ee4 100644 --- a/dali-toolkit/internal/controls/renderers/gradient/gradient.h +++ b/dali-toolkit/internal/controls/renderers/gradient/gradient.h @@ -91,6 +91,12 @@ public: void AddStop(float offset, const Vector4& color); /** + * Get the gradient stops. + * @return The vector of gradient stops. + */ + const Vector& GetStops(); + + /** * Set the coordinate system used by the gradient attributes. * @param[in] gradientUnits The the attributes are defined using the current user coordinate system or the bounding box of the shape. */ diff --git a/dali-toolkit/internal/controls/renderers/image/image-renderer.cpp b/dali-toolkit/internal/controls/renderers/image/image-renderer.cpp index 50fa5b8..93c5c9a 100644 --- a/dali-toolkit/internal/controls/renderers/image/image-renderer.cpp +++ b/dali-toolkit/internal/controls/renderers/image/image-renderer.cpp @@ -35,13 +35,32 @@ namespace Internal namespace { +const char * const RENDERER_TYPE("renderer-type"); +const char * const RENDERER_TYPE_VALUE("image-renderer"); +// property names const char * const IMAGE_URL_NAME("image-url"); const char * const IMAGE_FITTING_MODE("image-fitting-mode"); const char * const IMAGE_SAMPLING_MODE("image-sampling-mode"); const char * const IMAGE_DESIRED_WIDTH("image-desired-width"); const char * const IMAGE_DESIRED_HEIGHT("image-desired-height"); +// fitting modes +const char * const SHRINK_TO_FIT("shrink-to-fit"); +const char * const SCALE_TO_FILL("scale-to-fill"); +const char * const FIT_WIDTH("fit-width"); +const char * const FIT_HEIGHT("fit-height"); +const char * const DEFAULT("default"); + +// sampling modes +const char * const BOX("box"); +const char * const NEAREST("nearest"); +const char * const LINEAR("linear"); +const char * const BOX_THEN_NEAREST("box-then-nearest"); +const char * const BOX_THEN_LINEAR("box-then-linear"); +const char * const NO_FILTER("no-filter"); +const char * const DONT_CARE("dont-care"); + std::string TEXTURE_UNIFORM_NAME = "sTexture"; const char* VERTEX_SHADER = DALI_COMPOSE_SHADER( @@ -102,23 +121,23 @@ void ImageRenderer::Initialize( RendererFactoryCache& factoryCache, const Proper fittingValue->Get( fitting ); mFittingMode = FittingMode::DEFAULT; - if( fitting == "shrink-to-fit" ) + if( fitting == SHRINK_TO_FIT ) { mFittingMode = FittingMode::SHRINK_TO_FIT; } - else if( fitting == "scale-to-fill" ) + else if( fitting == SCALE_TO_FILL ) { mFittingMode = FittingMode::SCALE_TO_FILL; } - else if( fitting == "fit-width" ) + else if( fitting == FIT_WIDTH ) { mFittingMode = FittingMode::FIT_WIDTH; } - else if( fitting == "fit-height" ) + else if( fitting == FIT_HEIGHT ) { mFittingMode = FittingMode::FIT_HEIGHT; } - else if( fitting == "default" ) + else if( fitting == DEFAULT ) { mFittingMode = FittingMode::DEFAULT; } @@ -135,35 +154,35 @@ void ImageRenderer::Initialize( RendererFactoryCache& factoryCache, const Proper samplingValue->Get( sampling ); mSamplingMode = SamplingMode::DEFAULT; - if( sampling == "box" ) + if( sampling == BOX ) { mSamplingMode = SamplingMode::BOX; } - else if( sampling == "nearest" ) + else if( sampling == NEAREST ) { mSamplingMode = SamplingMode::NEAREST; } - else if( sampling == "linear" ) + else if( sampling == LINEAR ) { mSamplingMode = SamplingMode::LINEAR; } - else if( sampling == "box-then-nearest" ) + else if( sampling == BOX_THEN_NEAREST ) { mSamplingMode = SamplingMode::BOX_THEN_NEAREST; } - else if( sampling == "box-then-linear" ) + else if( sampling == BOX_THEN_LINEAR ) { mSamplingMode = SamplingMode::BOX_THEN_LINEAR; } - else if( sampling == "no-filter" ) + else if( sampling == NO_FILTER ) { mSamplingMode = SamplingMode::NO_FILTER; } - else if( sampling == "dont-care" ) + else if( sampling == DONT_CARE ) { mSamplingMode = SamplingMode::DONT_CARE; } - else if( sampling == "default" ) + else if( sampling == DEFAULT ) { mSamplingMode = SamplingMode::DEFAULT; } @@ -229,6 +248,102 @@ void ImageRenderer::DoSetOffStage( Actor& actor ) } } +void ImageRenderer::CreatePropertyMap( Property::Map& map ) const +{ + map.Clear(); + map.Insert( RENDERER_TYPE, RENDERER_TYPE_VALUE ); + if( !mImageUrl.empty() ) + { + map.Insert( IMAGE_URL_NAME, mImageUrl ); + map.Insert( IMAGE_DESIRED_WIDTH, mDesiredSize.GetWidth() ); + map.Insert( IMAGE_DESIRED_HEIGHT, mDesiredSize.GetHeight() ); + } + else if( mImage ) + { + map.Insert( IMAGE_DESIRED_WIDTH, static_cast(mImage.GetWidth()) ); + map.Insert( IMAGE_DESIRED_HEIGHT, static_cast(mImage.GetHeight()) ); + + ResourceImage resourceImage = ResourceImage::DownCast(mImage); + if( resourceImage ) + { + map.Insert( IMAGE_URL_NAME, resourceImage.GetUrl() ); + } + } + + switch( mFittingMode ) + { + case Dali::FittingMode::FIT_HEIGHT: + { + map.Insert( IMAGE_FITTING_MODE, FIT_HEIGHT ); + break; + } + case Dali::FittingMode::FIT_WIDTH: + { + map.Insert( IMAGE_FITTING_MODE, FIT_WIDTH ); + break; + } + case Dali::FittingMode::SCALE_TO_FILL: + { + map.Insert( IMAGE_FITTING_MODE, SCALE_TO_FILL ); + break; + } + case Dali::FittingMode::SHRINK_TO_FIT: + { + map.Insert( IMAGE_FITTING_MODE, SHRINK_TO_FIT ); + break; + } + default: + { + map.Insert( IMAGE_FITTING_MODE, DEFAULT ); + break; + } + } + + switch( mSamplingMode ) + { + case Dali::SamplingMode::BOX: + { + map.Insert( IMAGE_SAMPLING_MODE, BOX ); + break; + } + case Dali::SamplingMode::NEAREST: + { + map.Insert( IMAGE_SAMPLING_MODE, NEAREST ); + break; + } + case Dali::SamplingMode::LINEAR: + { + map.Insert( IMAGE_SAMPLING_MODE, LINEAR ); + break; + } + case Dali::SamplingMode::BOX_THEN_LINEAR: + { + map.Insert( IMAGE_SAMPLING_MODE, BOX_THEN_LINEAR ); + break; + } + case Dali::SamplingMode::BOX_THEN_NEAREST: + { + map.Insert( IMAGE_SAMPLING_MODE, BOX_THEN_NEAREST ); + break; + } + case Dali::SamplingMode::NO_FILTER: + { + map.Insert( IMAGE_SAMPLING_MODE, NO_FILTER ); + break; + } + case Dali::SamplingMode::DONT_CARE: + { + map.Insert( IMAGE_SAMPLING_MODE, DONT_CARE ); + break; + } + default: + { + map.Insert( IMAGE_SAMPLING_MODE, DEFAULT ); + break; + } + } +} + void ImageRenderer::Initialize( RendererFactoryCache& factoryCache ) { mImpl->mGeometry = factoryCache.GetGeometry( RendererFactoryCache::QUAD_GEOMETRY ); diff --git a/dali-toolkit/internal/controls/renderers/image/image-renderer.h b/dali-toolkit/internal/controls/renderers/image/image-renderer.h index be9c2af..bbaa139 100644 --- a/dali-toolkit/internal/controls/renderers/image/image-renderer.h +++ b/dali-toolkit/internal/controls/renderers/image/image-renderer.h @@ -104,6 +104,11 @@ public: // from ControlRenderer */ virtual void SetOffset( const Vector2& offset ); + /** + * @copydoc ControlRenderer::CreatePropertyMap + */ + virtual void CreatePropertyMap( Property::Map& map ) const; + protected: /** * @copydoc ControlRenderer::DoSetOnStage diff --git a/dali-toolkit/internal/controls/renderers/npatch/npatch-renderer.cpp b/dali-toolkit/internal/controls/renderers/npatch/npatch-renderer.cpp index d757712..d49f3d3 100644 --- a/dali-toolkit/internal/controls/renderers/npatch/npatch-renderer.cpp +++ b/dali-toolkit/internal/controls/renderers/npatch/npatch-renderer.cpp @@ -41,6 +41,8 @@ namespace Internal namespace { +const char * const RENDERER_TYPE("renderer-type"); +const char * const RENDERER_TYPE_VALUE("n-patch-renderer"); const char * const IMAGE_URL_NAME("image-url"); const char * const BORDER_ONLY("border-only"); @@ -222,6 +224,21 @@ void NPatchRenderer::DoSetOffStage( Actor& actor ) mCroppedImage.Reset(); } +void NPatchRenderer::CreatePropertyMap( Property::Map& map ) const +{ + map.Clear(); + map.Insert( RENDERER_TYPE, RENDERER_TYPE_VALUE ); + if( !mImageUrl.empty() ) + { + map.Insert( IMAGE_URL_NAME, mImageUrl ); + } + else if( mImage ) + { + map.Insert( IMAGE_URL_NAME, mImage.GetUrl() ); + } + map.Insert( BORDER_ONLY, mBorderOnly ); +} + void NPatchRenderer::Initialize( RendererFactoryCache& factoryCache ) { mNinePatchGeometry = factoryCache.GetGeometry( RendererFactoryCache::NINE_PATCH_GEOMETRY ); diff --git a/dali-toolkit/internal/controls/renderers/npatch/npatch-renderer.h b/dali-toolkit/internal/controls/renderers/npatch/npatch-renderer.h index b2ead54..6bdb696 100644 --- a/dali-toolkit/internal/controls/renderers/npatch/npatch-renderer.h +++ b/dali-toolkit/internal/controls/renderers/npatch/npatch-renderer.h @@ -46,6 +46,7 @@ namespace Internal * | %Property Name | Type | * |---------------------------|------------------| * | image-url | STRING | + * | border-only | BOOLEAN * */ class NPatchRenderer: public ControlRenderer @@ -79,6 +80,11 @@ public: // from ControlRenderer */ virtual void SetOffset( const Vector2& offset ); + /** + * @copydoc ControlRenderer::CreatePropertyMap + */ + virtual void CreatePropertyMap( Property::Map& map ) const; + protected: /** * @copydoc ControlRenderer::DoSetOnStage -- 2.7.4