Fix BackgroundImage and BackgroudColor properties in C# View 87/118087/2
authorRichard Huang <r.huang@samsung.com>
Wed, 8 Mar 2017 15:03:52 +0000 (15:03 +0000)
committerRichard Huang <r.huang@samsung.com>
Wed, 8 Mar 2017 15:45:32 +0000 (15:45 +0000)
Change-Id: I3990cf1c5a3835e261142377f8e2ea4d60a44403

automated-tests/src/dali-toolkit/utc-Dali-Control.cpp
dali-toolkit/public-api/controls/control-impl.cpp
dali-toolkit/public-api/controls/control.h
plugins/dali-swig/examples/dali-test.cs
plugins/dali-swig/manual/csharp/View.cs

index 376ad0d4466af26d2a26e2decf63df1174781709..9de71010201ab18e11be5b69a593580a5c475d63 100644 (file)
@@ -486,6 +486,13 @@ int UtcDaliControlBackgroundProperties(void)
   DALI_TEST_EQUALS( resultMap->Find( Visual::Property::TYPE )->Get<int>(), (int)Visual::IMAGE, TEST_LOCATION );
   DALI_TEST_EQUALS( resultMap->Find( ImageVisual::Property::URL )->Get<std::string>(), "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>(), (int)Visual::COLOR, TEST_LOCATION );
+  DALI_TEST_EQUALS( resultMap->Find( ColorVisual::Property::MIX_COLOR )->Get<Vector4>(), 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 );
index c89ae0ca5600da674d2034f8c3834ceb8f571400..d45c8dde97cfaeec13effa149f75fc03dcaec35b 100644 (file)
@@ -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
index 3f2f169c789a96f6c471059b771a08dc2aa2b51d..cd72a0fdce3d640f64622d9290f8a3dbe2338e99 100644 (file)
@@ -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,
index 856a4dde144f8647d468f0b39748feb6fbce59a5..73b7fb31f557d47ed4a7fa16c266d4f37aecc975 100644 (file)
@@ -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")
index b48f7799560796afd4f4111a4a9417d330fd4cba..1b4fbec5cae1a92a968bf7c2bbf8be0ea6cc5e2d 100644 (file)
@@ -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 ) );
     }
   }