From 50a6c0040f45569ffa098042607582015fb1b137 Mon Sep 17 00:00:00 2001 From: Richard Huang Date: Wed, 8 Mar 2017 15:03:52 +0000 Subject: [PATCH] Fix BackgroundImage and BackgroudColor properties in C# View Change-Id: I3990cf1c5a3835e261142377f8e2ea4d60a44403 --- .../src/dali-toolkit/utc-Dali-Control.cpp | 7 ++++ .../public-api/controls/control-impl.cpp | 5 +++ dali-toolkit/public-api/controls/control.h | 2 +- plugins/dali-swig/examples/dali-test.cs | 13 ++++++- plugins/dali-swig/manual/csharp/View.cs | 34 ++++++++++++++----- 5 files changed, 50 insertions(+), 11 deletions(-) diff --git a/automated-tests/src/dali-toolkit/utc-Dali-Control.cpp b/automated-tests/src/dali-toolkit/utc-Dali-Control.cpp index 376ad0d446..9de7101020 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-Control.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-Control.cpp @@ -486,6 +486,13 @@ int UtcDaliControlBackgroundProperties(void) DALI_TEST_EQUALS( resultMap->Find( Visual::Property::TYPE )->Get(), (int)Visual::IMAGE, TEST_LOCATION ); DALI_TEST_EQUALS( resultMap->Find( ImageVisual::Property::URL )->Get(), "Foobar.png", TEST_LOCATION ); + // set as Color + control.SetProperty( Control::Property::BACKGROUND, Color::RED ); + propValue = control.GetProperty( Control::Property::BACKGROUND ); + resultMap = propValue.GetMap(); + DALI_TEST_EQUALS( resultMap->Find( Visual::Property::TYPE )->Get(), (int)Visual::COLOR, TEST_LOCATION ); + DALI_TEST_EQUALS( resultMap->Find( ColorVisual::Property::MIX_COLOR )->Get(), Color::RED, TEST_LOCATION ); + // Deprecated Properties control.SetProperty( Control::Property::BACKGROUND_COLOR, Color::YELLOW ); DALI_TEST_EQUALS( control.GetProperty( Control::Property::BACKGROUND_COLOR ).Get< Vector4 >(), Color::YELLOW, TEST_LOCATION ); diff --git a/dali-toolkit/public-api/controls/control-impl.cpp b/dali-toolkit/public-api/controls/control-impl.cpp index c89ae0ca56..d45c8dde97 100644 --- a/dali-toolkit/public-api/controls/control-impl.cpp +++ b/dali-toolkit/public-api/controls/control-impl.cpp @@ -409,6 +409,7 @@ public: case Toolkit::Control::Property::BACKGROUND: { std::string url; + Vector4 color; const Property::Map* map = value.GetMap(); if( map && !map->Empty() ) { @@ -424,6 +425,10 @@ public: visual.SetDepthIndex( DepthIndex::BACKGROUND ); } } + else if( value.Get( color ) ) + { + controlImpl.SetBackgroundColor(color); + } else { // The background is an empty property map, so we should clear the background diff --git a/dali-toolkit/public-api/controls/control.h b/dali-toolkit/public-api/controls/control.h index 3f2f169c78..cd72a0fdce 100644 --- a/dali-toolkit/public-api/controls/control.h +++ b/dali-toolkit/public-api/controls/control.h @@ -121,7 +121,7 @@ public: */ KEY_INPUT_FOCUS, /** - * @brief name "background", mutually exclusive with BACKGROUND_COLOR & BACKGROUND_IMAGE, type Map or std::string for URL. + * @brief name "background", mutually exclusive with BACKGROUND_COLOR & BACKGROUND_IMAGE, type Map or std::string for URL or Vector4 for Color. * @SINCE_1_1.3 */ BACKGROUND, diff --git a/plugins/dali-swig/examples/dali-test.cs b/plugins/dali-swig/examples/dali-test.cs index 856a4dde14..73b7fb31f5 100644 --- a/plugins/dali-swig/examples/dali-test.cs +++ b/plugins/dali-swig/examples/dali-test.cs @@ -445,7 +445,7 @@ namespace MyCSharpExample // Background property Property.Map background = new Property.Map(); background.Add( Dali.Constants.Visual.Property.Type, new Property.Value((int)Dali.Constants.Visual.Type.Color) ) - .Add( Dali.Constants.ColorVisualProperty.MixColor, new Property.Value(Color.Red) ); + .Add( Dali.Constants.ColorVisualProperty.MixColor, new Property.Value(Color.Red) ); spin.Background = background; background = spin.Background; @@ -471,6 +471,17 @@ namespace MyCSharpExample Console.WriteLine ("Custom View BackgroundColor property : test failed"); } + // BackgroundImage property + spin.BackgroundImage = "background-image.jpg"; + if(spin.BackgroundImage == "background-image.jpg") + { + Console.WriteLine ("Custom View BackgroundImage property : test passed"); + } + else + { + Console.WriteLine ("Custom View BackgroundImage property : test failed"); + } + // StyleName property spin.StyleName = "MyCustomStyle"; if(spin.StyleName == "MyCustomStyle") diff --git a/plugins/dali-swig/manual/csharp/View.cs b/plugins/dali-swig/manual/csharp/View.cs index b48f779956..1b4fbec5ca 100644 --- a/plugins/dali-swig/manual/csharp/View.cs +++ b/plugins/dali-swig/manual/csharp/View.cs @@ -1110,27 +1110,43 @@ public class View : CustomActor { { get { - Vector4 temp = new Vector4(0.0f,0.0f,0.0f,0.0f); - GetProperty( View.Property.BACKGROUND_COLOR).Get( temp ); - return temp; + Vector4 backgroundColor = new Vector4(0.0f,0.0f,0.0f,0.0f); + + Dali.Property.Map background = Background; + int visualType = 0; + background.Find( Dali.Constants.Visual.Property.Type ).Get( ref visualType ); + if(visualType == (int)Dali.Constants.Visual.Type.Color) + { + background.Find( Dali.Constants.ColorVisualProperty.MixColor ).Get( backgroundColor ); + } + + return backgroundColor; } set { - SetProperty( View.Property.BACKGROUND_COLOR, new Dali.Property.Value( value ) ); + SetProperty( View.Property.BACKGROUND, new Dali.Property.Value( value ) ); } } - public Dali.Property.Map BackgroundImage + public string BackgroundImage { get { - Dali.Property.Map temp = new Dali.Property.Map(); - GetProperty( View.Property.BACKGROUND_IMAGE).Get( temp ); - return temp; + string backgroundImage = ""; + + Dali.Property.Map background = Background; + int visualType = 0; + background.Find( Dali.Constants.Visual.Property.Type ).Get( ref visualType ); + if(visualType == (int)Dali.Constants.Visual.Type.Image) + { + background.Find( Dali.Constants.ImageVisualProperty.URL ).Get( out backgroundImage ); + } + + return backgroundImage; } set { - SetProperty( View.Property.BACKGROUND_IMAGE, new Dali.Property.Value( value ) ); + SetProperty( View.Property.BACKGROUND, new Dali.Property.Value( value ) ); } } -- 2.34.1