From 20e731a76521493587125849a0390bea734a25a8 Mon Sep 17 00:00:00 2001 From: JEONGHYUN YUN Date: Thu, 24 Nov 2016 19:11:28 +0900 Subject: [PATCH] Added BackgroundColor property in Widget Change-Id: I6f8995cc2731492a905e6d2f43d6f80a9586934e Signed-off-by: JEONGHYUN YUN --- src/ElmSharp/ElmSharp/Button.cs | 9 ++++ src/ElmSharp/ElmSharp/Widget.cs | 14 +++++++ src/ElmSharp/Interop/Interop.Elementary.cs | 3 ++ test/ElmSharp.Test/TC/ButtonTest1.cs | 66 +++++++++++++++++++++--------- 4 files changed, 73 insertions(+), 19 deletions(-) mode change 100644 => 100755 src/ElmSharp/Interop/Interop.Elementary.cs diff --git a/src/ElmSharp/ElmSharp/Button.cs b/src/ElmSharp/ElmSharp/Button.cs index 1d69347..9d13db3 100644 --- a/src/ElmSharp/ElmSharp/Button.cs +++ b/src/ElmSharp/ElmSharp/Button.cs @@ -102,6 +102,15 @@ namespace ElmSharp Interop.Elementary.edje_object_color_class_del(Handle, part); } + public override Color BackgroundColor + { + set + { + SetPartColor("bg", value); + SetPartColor("bg_pressed", value); + } + } + protected override IntPtr CreateHandle(EvasObject parent) { return Interop.Elementary.elm_button_add(parent.Handle); diff --git a/src/ElmSharp/ElmSharp/Widget.cs b/src/ElmSharp/ElmSharp/Widget.cs index fabf249..f7a7833 100644 --- a/src/ElmSharp/ElmSharp/Widget.cs +++ b/src/ElmSharp/ElmSharp/Widget.cs @@ -87,6 +87,20 @@ namespace ElmSharp } } + public virtual Color BackgroundColor + { + get + { + int r, g, b, a; + Interop.Elementary.elm_object_color_class_color_get(Handle, "bg", out r, out g, out b, out a); + return new Color((int)(r/(a/255.0)), (int)(g/(a/255.0)), (int)(b/(a/255.0)), a); + } + set + { + SetPartColor("bg", value); + } + } + public void SetFocus(bool isFocus) { Interop.Elementary.elm_object_focus_set(Handle, isFocus); diff --git a/src/ElmSharp/Interop/Interop.Elementary.cs b/src/ElmSharp/Interop/Interop.Elementary.cs old mode 100644 new mode 100755 index 5a0b7bd..c96a471 --- a/src/ElmSharp/Interop/Interop.Elementary.cs +++ b/src/ElmSharp/Interop/Interop.Elementary.cs @@ -152,6 +152,9 @@ internal static partial class Interop } [DllImport(Libraries.Elementary)] + internal static extern void elm_object_color_class_color_get(IntPtr obj, string colorClass, out int r, out int g, out int b, out int a); + + [DllImport(Libraries.Elementary)] internal static extern void elm_object_color_class_color_set(IntPtr obj, string colorClass, int r, int g, int b, int a); [DllImport(Libraries.Elementary)] diff --git a/test/ElmSharp.Test/TC/ButtonTest1.cs b/test/ElmSharp.Test/TC/ButtonTest1.cs index 3f99a50..ab39a61 100644 --- a/test/ElmSharp.Test/TC/ButtonTest1.cs +++ b/test/ElmSharp.Test/TC/ButtonTest1.cs @@ -24,40 +24,68 @@ namespace ElmSharp.Test public override string TestName => "ButtonTest1"; public override string TestDescription => "To test basic operation of Button"; - public override void Run(Window window) + void SetButtonEventHandler(Button button) { - Button button1 = new Button(window) { - Text = "Button 1", - }; - - button1.SetPartColor("bg", Color.Red); - - button1.Clicked += (s, e) => + button.Clicked += (s, e) => { - Console.WriteLine("Button1 Clicked! : {0}", button1.ClassName); - Console.WriteLine("Button1 Clicked! : {0}", button1.ClassName.ToLower()); - Console.WriteLine("Button1 Clicked! : {0}", button1.ClassName.ToLower().Replace("elm_","")); - Console.WriteLine("Button1 Clicked! : {0}", button1.ClassName.ToLower().Replace("elm_", "")+ "/" + "bg"); + Console.WriteLine("{0} Clicked! : {1}", button.Text, button.BackgroundColor); + Console.WriteLine("{0} Clicked! : {1}", button.Text, button.ClassName); + Console.WriteLine("{0} Clicked! : {1}", button.Text, button.ClassName.ToLower()); + Console.WriteLine("{0} Clicked! : {1}", button.Text, button.ClassName.ToLower().Replace("elm_", "")); + Console.WriteLine("{0} Clicked! : {1}", button.Text, button.ClassName.ToLower().Replace("elm_", "") + "/" + "bg"); }; - button1.Pressed += (s, e) => + button.Pressed += (s, e) => { - Console.WriteLine("Button1 Pressed!"); + Console.WriteLine("{0} Pressed!", button.Text); }; - button1.Released += (s, e) => + button.Released += (s, e) => { - Console.WriteLine("Button1 Released!"); + Console.WriteLine("{0} Released!", button.Text); }; - button1.Repeated += (s, e) => + button.Repeated += (s, e) => { - Console.WriteLine("Button1 Repeated!"); + Console.WriteLine("{0} Repeated!", button.Text); }; - button1.Show(); + button.Show(); + } + + public override void Run(Window window) + { + Button button1 = new Button(window) { + Text = "Button 1", + }; + button1.SetPartColor("bg", Color.Red); + SetButtonEventHandler(button1); button1.Resize(500, 100); button1.Move(0, 0); + + Button button2 = new Button(window) { + Text = "Button 2", + BackgroundColor = Color.Red, + }; + SetButtonEventHandler(button2); + button2.Resize(500, 100); + button2.Move(0, 200); + + Button button3 = new Button(window) { + Text = "Button 3", + BackgroundColor = new Color(125,200,255, 150) + }; + SetButtonEventHandler(button3); + button3.Resize(500, 100); + button3.Move(0, 400); + + Button button4 = new Button(window) { + Text = "Button 4", + BackgroundColor = new Color(125, 200, 255, 10) + }; + SetButtonEventHandler(button4); + button4.Resize(500, 100); + button4.Move(0, 600); } } -- 2.7.4