Support Image.BackgroundColor
authorKangho Hur <kangho.hur@samsung.com>
Mon, 12 Dec 2016 12:06:08 +0000 (21:06 +0900)
committerKangho Hur <kangho.hur@samsung.com>
Tue, 13 Dec 2016 01:38:05 +0000 (10:38 +0900)
Change-Id: I4cd5296f2849bf6f4abeeea7997ce2703d835547

src/ElmSharp/ElmSharp/Image.cs
test/ElmSharp.Test/ElmSharp.Test.csproj
test/ElmSharp.Test/TC/ImageTest2.cs [new file with mode: 0644]

index 9268c1bb505e3385459afc4db99bfd949ae1114f..2c99bcbe5518a93afd2b08f2c54935c4ec95801b 100644 (file)
@@ -41,7 +41,7 @@ namespace ElmSharp
         {
             get
             {
-                return Interop.Elementary.elm_image_file_get(Handle);
+                return Interop.Elementary.elm_image_file_get(RealHandle);
             }
         }
 
@@ -49,11 +49,11 @@ namespace ElmSharp
         {
             get
             {
-                return Interop.Elementary.elm_image_smooth_get(Handle);
+                return Interop.Elementary.elm_image_smooth_get(RealHandle);
             }
             set
             {
-                Interop.Elementary.elm_image_smooth_set(Handle, value);
+                Interop.Elementary.elm_image_smooth_set(RealHandle, value);
             }
         }
 
@@ -61,11 +61,11 @@ namespace ElmSharp
         {
             get
             {
-                return !Interop.Elementary.elm_image_no_scale_get(Handle);
+                return !Interop.Elementary.elm_image_no_scale_get(RealHandle);
             }
             set
             {
-                Interop.Elementary.elm_image_no_scale_set(Handle, !value);
+                Interop.Elementary.elm_image_no_scale_set(RealHandle, !value);
             }
         }
 
@@ -78,7 +78,7 @@ namespace ElmSharp
             set
             {
                 _canScaleDown = value;
-                Interop.Elementary.elm_image_resizable_set(Handle, _canScaleUp, _canScaleDown);
+                Interop.Elementary.elm_image_resizable_set(RealHandle, _canScaleUp, _canScaleDown);
             }
         }
 
@@ -91,7 +91,7 @@ namespace ElmSharp
             set
             {
                 _canScaleUp = value;
-                Interop.Elementary.elm_image_resizable_set(Handle, _canScaleUp, _canScaleDown);
+                Interop.Elementary.elm_image_resizable_set(RealHandle, _canScaleUp, _canScaleDown);
             }
         }
 
@@ -99,11 +99,11 @@ namespace ElmSharp
         {
             get
             {
-                return Interop.Elementary.elm_image_fill_outside_get(Handle);
+                return Interop.Elementary.elm_image_fill_outside_get(RealHandle);
             }
             set
             {
-                Interop.Elementary.elm_image_fill_outside_set(Handle, value);
+                Interop.Elementary.elm_image_fill_outside_set(RealHandle, value);
             }
         }
 
@@ -111,11 +111,11 @@ namespace ElmSharp
         {
             get
             {
-                return Interop.Elementary.elm_image_prescale_get(Handle);
+                return Interop.Elementary.elm_image_prescale_get(RealHandle);
             }
             set
             {
-                Interop.Elementary.elm_image_prescale_set(Handle, value);
+                Interop.Elementary.elm_image_prescale_set(RealHandle, value);
             }
         }
 
@@ -123,11 +123,11 @@ namespace ElmSharp
         {
             get
             {
-                return Interop.Elementary.elm_image_aspect_fixed_get(Handle);
+                return Interop.Elementary.elm_image_aspect_fixed_get(RealHandle);
             }
             set
             {
-                Interop.Elementary.elm_image_aspect_fixed_set(Handle, value);
+                Interop.Elementary.elm_image_aspect_fixed_set(RealHandle, value);
             }
         }
 
@@ -135,11 +135,11 @@ namespace ElmSharp
         {
             get
             {
-                return Interop.Elementary.elm_image_animated_get(Handle);
+                return Interop.Elementary.elm_image_animated_get(RealHandle);
             }
             set
             {
-                Interop.Elementary.elm_image_animated_set(Handle, value);
+                Interop.Elementary.elm_image_animated_set(RealHandle, value);
             }
         }
 
@@ -147,7 +147,7 @@ namespace ElmSharp
         {
             get
             {
-                return Interop.Elementary.elm_image_animated_available_get(Handle);
+                return Interop.Elementary.elm_image_animated_available_get(RealHandle);
             }
         }
 
@@ -155,11 +155,11 @@ namespace ElmSharp
         {
             get
             {
-                return Interop.Elementary.elm_image_animated_play_get(Handle);
+                return Interop.Elementary.elm_image_animated_play_get(RealHandle);
             }
             set
             {
-                Interop.Elementary.elm_image_animated_play_set(Handle, value);
+                Interop.Elementary.elm_image_animated_play_set(RealHandle, value);
             }
         }
 
@@ -167,11 +167,11 @@ namespace ElmSharp
         {
             get
             {
-                return Interop.Elementary.elm_image_editable_get(Handle);
+                return Interop.Elementary.elm_image_editable_get(RealHandle);
             }
             set
             {
-                Interop.Elementary.elm_image_editable_set(Handle, value);
+                Interop.Elementary.elm_image_editable_set(RealHandle, value);
             }
         }
 
@@ -180,7 +180,7 @@ namespace ElmSharp
             get
             {
                 int w, h;
-                Interop.Elementary.elm_image_object_size_get(Handle, out w, out h);
+                Interop.Elementary.elm_image_object_size_get(RealHandle, out w, out h);
                 return new Size(w, h);
             }
         }
@@ -189,7 +189,7 @@ namespace ElmSharp
         {
             get
             {
-                IntPtr evasObj = Interop.Elementary.elm_image_object_get(Handle);
+                IntPtr evasObj = Interop.Elementary.elm_image_object_get(RealHandle);
                 if (evasObj != IntPtr.Zero)
                 {
                     return !Interop.Evas.evas_object_image_alpha_get(evasObj);
@@ -198,7 +198,7 @@ namespace ElmSharp
             }
             set
             {
-                IntPtr evasObj = Interop.Elementary.elm_image_object_get(Handle);
+                IntPtr evasObj = Interop.Elementary.elm_image_object_get(RealHandle);
                 if (evasObj != IntPtr.Zero)
                 {
                     Interop.Evas.evas_object_image_alpha_set(evasObj, !value);
@@ -210,11 +210,11 @@ namespace ElmSharp
         {
             get
             {
-                return (ImageOrientation)Interop.Elementary.elm_image_orient_get(Handle);
+                return (ImageOrientation)Interop.Elementary.elm_image_orient_get(RealHandle);
             }
             set
             {
-                Interop.Elementary.elm_image_orient_set(Handle, (int)value);
+                Interop.Elementary.elm_image_orient_set(RealHandle, (int)value);
             }
         }
 
@@ -223,7 +223,7 @@ namespace ElmSharp
             get
             {
                 int r = 255, g = 255, b = 255, a = 255;
-                IntPtr evasObj = Interop.Elementary.elm_image_object_get(Handle);
+                IntPtr evasObj = Interop.Elementary.elm_image_object_get(RealHandle);
                 if (evasObj != IntPtr.Zero)
                 {
                     Interop.Evas.evas_object_color_get(evasObj, out r, out g, out b, out a);
@@ -232,7 +232,7 @@ namespace ElmSharp
             }
             set
             {
-                IntPtr evasObj = Interop.Elementary.elm_image_object_get(Handle);
+                IntPtr evasObj = Interop.Elementary.elm_image_object_get(RealHandle);
                 if (evasObj != IntPtr.Zero)
                 {
                     Interop.Evas.evas_object_color_set(evasObj, value.R, value.G, value.B, value.A);
@@ -240,14 +240,30 @@ namespace ElmSharp
             }
         }
 
+        public override Color BackgroundColor
+        {
+            set
+            {
+                if (value.IsDefault)
+                {
+                    SetPartColor("bg", Color.Transparent);
+                }
+                else
+                {
+                    SetPartColor("bg", value);
+                }
+                _backgroundColor = value;
+            }
+        }
+
         public bool Load(string file)
         {
             if (file == null)
                 throw new ArgumentNullException("file");
 
-            Interop.Elementary.elm_image_async_open_set(Handle, false);
-            Interop.Elementary.elm_image_preload_disabled_set(Handle, true);
-            return Interop.Elementary.elm_image_file_set(Handle, file, null);
+            Interop.Elementary.elm_image_async_open_set(RealHandle, false);
+            Interop.Elementary.elm_image_preload_disabled_set(RealHandle, true);
+            return Interop.Elementary.elm_image_file_set(RealHandle, file, null);
         }
 
         public bool Load(Uri uri)
@@ -265,9 +281,9 @@ namespace ElmSharp
             if (img == null)
                 throw new ArgumentNullException("img");
 
-            Interop.Elementary.elm_image_async_open_set(Handle, false);
-            Interop.Elementary.elm_image_preload_disabled_set(Handle, true);
-            return Interop.Elementary.elm_image_memfile_set(Handle, img, size, IntPtr.Zero, IntPtr.Zero);
+            Interop.Elementary.elm_image_async_open_set(RealHandle, false);
+            Interop.Elementary.elm_image_preload_disabled_set(RealHandle, true);
+            return Interop.Elementary.elm_image_memfile_set(RealHandle, img, size, IntPtr.Zero, IntPtr.Zero);
         }
 
         public bool Load(Stream stream)
@@ -275,8 +291,8 @@ namespace ElmSharp
             if (stream == null)
                 throw new ArgumentNullException("stream");
 
-            Interop.Elementary.elm_image_async_open_set(Handle, false);
-            Interop.Elementary.elm_image_preload_disabled_set(Handle, true);
+            Interop.Elementary.elm_image_async_open_set(RealHandle, false);
+            Interop.Elementary.elm_image_preload_disabled_set(RealHandle, true);
             MemoryStream memstream = new MemoryStream();
             stream.CopyTo(memstream);
             unsafe
@@ -284,7 +300,7 @@ namespace ElmSharp
                 byte[] dataArr = memstream.ToArray();
                 fixed (byte* data = &dataArr[0])
                 {
-                    return Interop.Elementary.elm_image_memfile_set(Handle, data, dataArr.Length, IntPtr.Zero, IntPtr.Zero);
+                    return Interop.Elementary.elm_image_memfile_set(RealHandle, data, dataArr.Length, IntPtr.Zero, IntPtr.Zero);
                 }
             }
         }
@@ -294,8 +310,8 @@ namespace ElmSharp
             if (file == null)
                 throw new ArgumentNullException("file");
 
-            Interop.Elementary.elm_image_async_open_set(Handle, true);
-            Interop.Elementary.elm_image_preload_disabled_set(Handle, false);
+            Interop.Elementary.elm_image_async_open_set(RealHandle, true);
+            Interop.Elementary.elm_image_preload_disabled_set(RealHandle, false);
 
             var tcs = new TaskCompletionSource<bool>();
 
@@ -329,7 +345,7 @@ namespace ElmSharp
                 }
             };
 
-            bool ret = Interop.Elementary.elm_image_file_set(Handle, file, null);
+            bool ret = Interop.Elementary.elm_image_file_set(RealHandle, file, null);
             if (!ret)
             {
                 throw new InvalidOperationException("Failed to set file to Image");
@@ -351,8 +367,8 @@ namespace ElmSharp
             if (stream == null)
                 throw new ArgumentNullException("stream");
 
-            Interop.Elementary.elm_image_async_open_set(Handle, true);
-            Interop.Elementary.elm_image_preload_disabled_set(Handle, false);
+            Interop.Elementary.elm_image_async_open_set(RealHandle, true);
+            Interop.Elementary.elm_image_preload_disabled_set(RealHandle, false);
 
             var tcs = new TaskCompletionSource<bool>();
 
@@ -394,7 +410,7 @@ namespace ElmSharp
                 byte[] dataArr = memstream.ToArray();
                 fixed (byte* data = &dataArr[0])
                 {
-                    bool ret = Interop.Elementary.elm_image_memfile_set(Handle, data, dataArr.Length, IntPtr.Zero, IntPtr.Zero);
+                    bool ret = Interop.Elementary.elm_image_memfile_set(RealHandle, data, dataArr.Length, IntPtr.Zero, IntPtr.Zero);
                     if (!ret)
                     {
                         return false;
@@ -407,7 +423,13 @@ namespace ElmSharp
 
         protected override IntPtr CreateHandle(EvasObject parent)
         {
-            return Interop.Elementary.elm_image_add(parent.Handle);
+            IntPtr handle = Interop.Elementary.elm_layout_add(parent);
+            Interop.Elementary.elm_layout_theme_set(handle, "layout", "background", "default");
+
+            RealHandle = Interop.Elementary.elm_image_add(handle);
+            Interop.Elementary.elm_object_part_content_set(handle, "elm.swallow.content", RealHandle);
+
+            return handle;
         }
     }
 
index a532bdc1475ec93cd75ceb762365874c92e92cd0..e89c87ab8517ae134f19d25cc93df617f2b28a57 100644 (file)
@@ -63,6 +63,7 @@
     <Compile Include="TC\GenListTest3.cs" />
     <Compile Include="TC\GenListTest4.cs" />
     <Compile Include="TC\GenListTest6.cs" />
+    <Compile Include="TC\ImageTest2.cs" />
     <Compile Include="TC\TableTest1.cs" />
     <Compile Include="TC\GenListTest8.cs" />
     <Compile Include="TC\PerformanceTest.cs" />
diff --git a/test/ElmSharp.Test/TC/ImageTest2.cs b/test/ElmSharp.Test/TC/ImageTest2.cs
new file mode 100644 (file)
index 0000000..3243c24
--- /dev/null
@@ -0,0 +1,124 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * 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.
+ */
+
+using System;
+using System.IO;
+
+namespace ElmSharp.Test
+{
+    public class ImageTest2 : TestCaseBase
+    {
+        public override string TestName => "ImageTest2";
+        public override string TestDescription => "To test basic operation of Image";
+
+        Image image;
+        Label lbInfo;
+
+        public override void Run(Window window)
+        {
+            Conformant conformant = new Conformant(window);
+            conformant.Show();
+            Box box = new Box(window);
+            conformant.SetContent(box);
+            box.Show();
+
+            Box buttonBox1 = new Box(window) {
+                IsHorizontal = true,
+                AlignmentX = -1,
+                AlignmentY = 0,
+            };
+            buttonBox1.Show();
+
+            Button btnFile1 = new Button(window) {
+                Text = "Blue",
+                AlignmentX = -1,
+                AlignmentY = -1,
+                WeightX = 1,
+                WeightY = 1
+            };
+            btnFile1.Show();
+
+            Button btnFile2 = new Button(window) {
+                Text = "Default",
+                AlignmentX = -1,
+                AlignmentY = -1,
+                WeightX = 1,
+                WeightY = 1
+            };
+            btnFile2.Show();
+
+            Button btnFile3 = new Button(window) {
+                Text = "Aspect",
+                AlignmentX = -1,
+                AlignmentY = -1,
+                WeightX = 1,
+                WeightY = 1
+            };
+            btnFile3.Show();
+
+            Button btnFile4 = new Button(window) {
+                Text = "Rotate",
+                AlignmentX = -1,
+                AlignmentY = -1,
+                WeightX = 1,
+                WeightY = 1
+            };
+            btnFile4.Show();
+
+            buttonBox1.PackEnd(btnFile1);
+            buttonBox1.PackEnd(btnFile2);
+            buttonBox1.PackEnd(btnFile3);
+            buttonBox1.PackEnd(btnFile4);
+
+            lbInfo = new Label(window) {
+                Color = Color.White,
+                AlignmentX = -1,
+                AlignmentY = 0,
+                WeightX = 1
+            };
+            lbInfo.Show();
+
+            image = new Image(window) {
+                IsFixedAspect = true,
+                AlignmentX = -1,
+                AlignmentY = -1,
+                WeightX = 1,
+                WeightY = 1
+            };
+            image.Show();
+            image.Load(Path.Combine(TestRunner.ResourceDir, "picture.png"));
+            image.Clicked += (s, e) =>
+            {
+                Console.WriteLine("Image has been clicked. (IsFixedAspect = {0}", image.IsFixedAspect);
+                image.IsFixedAspect = image.IsFixedAspect == true ? false : true;
+            };
+
+            btnFile1.Clicked += (s, e) => { image.BackgroundColor = Color.Blue; UpdateLabelText(image.BackgroundColor.ToString()); };
+            btnFile2.Clicked += (s, e) => { image.BackgroundColor = Color.Default; UpdateLabelText(image.BackgroundColor.ToString()); };
+            btnFile3.Clicked += (s, e) => { image.IsFixedAspect = image.IsFixedAspect == true ? false : true; };
+            btnFile4.Clicked += (s, e) => { image.Orientation = image.Orientation == ImageOrientation.None ? ImageOrientation.Rotate270 : ImageOrientation.None; };
+
+            box.PackEnd(buttonBox1);
+            box.PackEnd(lbInfo);
+            box.PackEnd(image);
+        }
+
+        void UpdateLabelText(string text)
+        {
+            lbInfo.Text = "<span color=#ffffff font_size=20>" + text + "</span>";
+        }
+    }
+}