Fix Image.Color behavior correctly
authorKangho Hur <kangho.hur@samsung.com>
Tue, 27 Dec 2016 01:10:23 +0000 (10:10 +0900)
committerKangho Hur <kangho.hur@samsung.com>
Wed, 28 Dec 2016 04:13:05 +0000 (13:13 +0900)
- Color.Default is now available on Image.Color
- ImageTest3 which is to test Image.color has been added.

Change-Id: I5ad9042e49d124b36bff3227bec007659734fc28

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

index fece740..89d1aad 100644 (file)
@@ -26,6 +26,7 @@ namespace ElmSharp
         bool _canScaleUp = true;
         bool _canScaleDown = true;
         SmartEvent _clicked;
+        Color _color = Color.Default;
 
         public Image(EvasObject parent) : base(parent)
         {
@@ -222,21 +223,25 @@ namespace ElmSharp
         {
             get
             {
-                int r = 255, g = 255, b = 255, a = 255;
-                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);
-                }
-                return Color.FromRgba(r, g, b, a);
+                return _color;
             }
             set
             {
                 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);
+                    if (value.IsDefault)
+                    {
+                        // Currently, we assume the Image.Color property as a blending color (actually, multiply blending).
+                        // Thus we are using Color.White (255,255,255,255) as a default color to ensure original image color. (255/255 * original = original)
+                        Interop.Evas.evas_object_color_set(evasObj, 255, 255, 255, 255);
+                    }
+                    else
+                    {
+                        Interop.Evas.SetPremultipliedColor(evasObj, value.R, value.G, value.B, value.A);
+                    }
                 }
+                _color = value;
             }
         }
 
index e89c87a..b874efe 100644 (file)
@@ -63,6 +63,7 @@
     <Compile Include="TC\GenListTest3.cs" />
     <Compile Include="TC\GenListTest4.cs" />
     <Compile Include="TC\GenListTest6.cs" />
+    <Compile Include="TC\ImageTest3.cs" />
     <Compile Include="TC\ImageTest2.cs" />
     <Compile Include="TC\TableTest1.cs" />
     <Compile Include="TC\GenListTest8.cs" />
     </ProjectReference>
   </ItemGroup>
   <ItemGroup>
+    <Content Include="res\btn_delete.png" />
     <Content Include="res\picture.png">
       <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
     </Content>
       </FlavorProperties>
     </VisualStudio>
   </ProjectExtensions>
-</Project>
+</Project>
\ No newline at end of file
index 3243c24..b82f357 100644 (file)
@@ -118,7 +118,7 @@ namespace ElmSharp.Test
 
         void UpdateLabelText(string text)
         {
-            lbInfo.Text = "<span color=#ffffff font_size=20>" + text + "</span>";
+            lbInfo.Text = "<span color=#ffffff font_size=20> BackgroundColor => " + text + "</span>";
         }
     }
 }
diff --git a/test/ElmSharp.Test/TC/ImageTest3.cs b/test/ElmSharp.Test/TC/ImageTest3.cs
new file mode 100644 (file)
index 0000000..db3617b
--- /dev/null
@@ -0,0 +1,135 @@
+/*
+ * 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 ImageTest3 : TestCaseBase
+    {
+        public override string TestName => "ImageTest3";
+        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();
+
+            Box buttonBox2 = new Box(window) {
+                IsHorizontal = true,
+                AlignmentX = -1,
+                AlignmentY = 0,
+            };
+            buttonBox2.Show();
+
+            Button btnFile1 = new Button(window) {
+                Text = "Blue (BG)",
+                AlignmentX = -1,
+                AlignmentY = -1,
+                WeightX = 1,
+                WeightY = 1
+            };
+            btnFile1.Show();
+
+            Button btnFile2 = new Button(window) {
+                Text = "Default (BG)",
+                AlignmentX = -1,
+                AlignmentY = -1,
+                WeightX = 1,
+                WeightY = 1
+            };
+            btnFile2.Show();
+
+            Button btnFile3 = new Button(window) {
+                Text = "Blue (FG)",
+                AlignmentX = -1,
+                AlignmentY = -1,
+                WeightX = 1,
+                WeightY = 1
+            };
+            btnFile3.Show();
+
+            Button btnFile4 = new Button(window) {
+                Text = "Default (FG)",
+                AlignmentX = -1,
+                AlignmentY = -1,
+                WeightX = 1,
+                WeightY = 1
+            };
+            btnFile4.Show();
+
+            buttonBox1.PackEnd(btnFile1);
+            buttonBox1.PackEnd(btnFile2);
+            buttonBox2.PackEnd(btnFile3);
+            buttonBox2.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, "btn_delete.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.Color = Color.Blue; UpdateLabelText(image.Color.ToString(), false); };
+            btnFile4.Clicked += (s, e) => { image.Color = Color.Default; UpdateLabelText(image.Color.ToString(), false); };
+
+            box.PackEnd(buttonBox1);
+            box.PackEnd(buttonBox2);
+            box.PackEnd(lbInfo);
+            box.PackEnd(image);
+        }
+
+        void UpdateLabelText(string text, bool isBackground = true)
+        {
+            if(isBackground)
+                lbInfo.Text = "<span color=#ffffff font_size=20> Background Color => " + text + "</span>";
+            else
+                lbInfo.Text = "<span color=#ffffff font_size=20> Foreground Color => " + text + "</span>";
+        }
+    }
+}
diff --git a/test/ElmSharp.Test/res/btn_delete.png b/test/ElmSharp.Test/res/btn_delete.png
new file mode 100644 (file)
index 0000000..7bafac6
Binary files /dev/null and b/test/ElmSharp.Test/res/btn_delete.png differ