summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKangho Hur <kangho.hur@samsung.com>2016-12-06 19:03:53 +0900
committerKangho Hur <kangho.hur@samsung.com>2016-12-06 19:03:53 +0900
commit6f01d7a3aa7d564bc186a9d5e132d3b9eca79503 (patch)
tree2384ccca40ed6a179b264b3e3477360020ab0cb4
parentc9695a06e131368597a90fbaf59597f7e81220a0 (diff)
downloadelm-sharp-6f01d7a3aa7d564bc186a9d5e132d3b9eca79503.tar.gz
elm-sharp-6f01d7a3aa7d564bc186a9d5e132d3b9eca79503.tar.bz2
elm-sharp-6f01d7a3aa7d564bc186a9d5e132d3b9eca79503.zip
Support to Color.Default
- This change allow to set color as Color.Defalut. - Change-Id: Ieae82112b0609cac17808d8fc41a9d2db0d102ed
-rw-r--r--[-rwxr-xr-x]ElmSharp.Test/ElmSharp.Test.csproj1
-rw-r--r--ElmSharp.Test/TC/BackgroundColorTest1.cs101
-rw-r--r--ElmSharp/ElmSharp/Button.cs13
-rw-r--r--ElmSharp/ElmSharp/Color.cs42
-rw-r--r--ElmSharp/ElmSharp/Layout.cs17
-rw-r--r--ElmSharp/ElmSharp/Widget.cs27
6 files changed, 190 insertions, 11 deletions
diff --git a/ElmSharp.Test/ElmSharp.Test.csproj b/ElmSharp.Test/ElmSharp.Test.csproj
index 22fb426..832a052 100755..100644
--- a/ElmSharp.Test/ElmSharp.Test.csproj
+++ b/ElmSharp.Test/ElmSharp.Test.csproj
@@ -45,6 +45,7 @@
<Compile Include="TC\BackgroundTest3.cs" />
<Compile Include="TC\BoxLayoutTest1.cs" />
<Compile Include="TC\BoxTest1.cs" />
+ <Compile Include="TC\BackgroundColorTest1.cs" />
<Compile Include="TC\ButtonTest1.cs" />
<Compile Include="TC\CalendarTest1.cs" />
<Compile Include="TC\CheckTest1.cs" />
diff --git a/ElmSharp.Test/TC/BackgroundColorTest1.cs b/ElmSharp.Test/TC/BackgroundColorTest1.cs
new file mode 100644
index 0000000..c8073f3
--- /dev/null
+++ b/ElmSharp.Test/TC/BackgroundColorTest1.cs
@@ -0,0 +1,101 @@
+/*
+ * 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 ElmSharp;
+
+namespace ElmSharp.Test
+{
+ class BackgroundColorTest1 : TestCaseBase
+ {
+ public override string TestName => "BackgroundColorTest1";
+ public override string TestDescription => "To test basic operation of Widget's background Color";
+
+
+
+ public override void Run(Window window)
+ {
+ Button button1 = new Button(window) {
+ Text = "Target Button",
+ };
+ button1.Resize(window.ScreenSize.Width, 100);
+ button1.Move(0, 0);
+ button1.Show();
+
+ Label label1 = new Label(window) {
+ Text = button1.BackgroundColor.ToString(),
+ BackgroundColor = Color.Black,
+ Color = Color.White
+ };
+ label1.Resize(window.ScreenSize.Width, 100);
+ label1.Move(0, 100);
+ label1.Show();
+
+ Button button2 = new Button(window) {
+ Text = "Set Color.Red",
+ BackgroundColor = Color.Red,
+ };
+ button2.Clicked += (e, o) =>
+ {
+ button1.BackgroundColor = Color.Red;
+ label1.Text = button1.BackgroundColor.ToString();
+ };
+ button2.Resize(window.ScreenSize.Width, 100);
+ button2.Move(0, 400);
+ button2.Show();
+
+ Button button3 = new Button(window) {
+ Text = "Set Color(125,200,255, 150)",
+ BackgroundColor = new Color(125,200,255, 150)
+ };
+ button3.Clicked += (e, o) =>
+ {
+ button1.BackgroundColor = button3.BackgroundColor;
+ label1.Text = button1.BackgroundColor.ToString();
+ };
+ button3.Resize(window.ScreenSize.Width, 100);
+ button3.Move(0, 500);
+ button3.Show();
+
+ Button button4 = new Button(window) {
+ Text = "Set Color(125, 200, 255, 10)",
+ BackgroundColor = new Color(125, 200, 255, 10)
+ };
+ button4.Clicked += (e,o) =>
+ {
+ button1.BackgroundColor = button4.BackgroundColor;
+ label1.Text = button1.BackgroundColor.ToString();
+ };
+ button4.Resize(window.ScreenSize.Width, 100);
+ button4.Move(0, 600);
+ button4.Show();
+
+ Button button5 = new Button(window) {
+ Text = "Set Color.Default",
+ BackgroundColor = Color.Default
+ };
+ button5.Clicked += (e, o) =>
+ {
+ button1.BackgroundColor = button5.BackgroundColor;
+ label1.Text = button1.BackgroundColor.ToString();
+ };
+ button5.Resize(window.ScreenSize.Width, 100);
+ button5.Move(0, 700);
+ button5.Show();
+ }
+
+ }
+}
diff --git a/ElmSharp/ElmSharp/Button.cs b/ElmSharp/ElmSharp/Button.cs
index 2292074..0b8edec 100644
--- a/ElmSharp/ElmSharp/Button.cs
+++ b/ElmSharp/ElmSharp/Button.cs
@@ -107,8 +107,17 @@ namespace ElmSharp
{
set
{
- SetPartColor("bg", value);
- SetPartColor("bg_pressed", value);
+ if (value.IsDefault)
+ {
+ EdjeObject.DeleteColorClass("button/bg");
+ EdjeObject.DeleteColorClass("button/bg_pressed");
+ }
+ else
+ {
+ SetPartColor("bg", value);
+ SetPartColor("bg_pressed", value);
+ }
+ _backgroundColor = value;
}
}
diff --git a/ElmSharp/ElmSharp/Color.cs b/ElmSharp/ElmSharp/Color.cs
index aba4410..f1730a3 100644
--- a/ElmSharp/ElmSharp/Color.cs
+++ b/ElmSharp/ElmSharp/Color.cs
@@ -26,6 +26,24 @@ namespace ElmSharp
readonly int _g;
readonly int _b;
+ readonly Mode _mode;
+
+ enum Mode
+ {
+ Default,
+ Rgb
+ }
+
+ public static Color Default
+ {
+ get { return new Color(-1, -1, -1, -1, Mode.Default); }
+ }
+
+ public bool IsDefault
+ {
+ get { return _mode == Mode.Default; }
+ }
+
public int A
{
get { return _a; }
@@ -50,12 +68,24 @@ namespace ElmSharp
{
}
- public Color(int r, int g, int b, int a)
+ public Color(int r, int g, int b, int a) : this(r,g,b,a, Mode.Rgb)
+ {
+ }
+
+ Color(int r, int g, int b, int a, Mode mode)
{
- _r = Clamp(r, 0, 255);
- _g = Clamp(g, 0, 255);
- _b = Clamp(b, 0, 255);
- _a = Clamp(a, 0, 255);
+ _mode = mode;
+ if (mode == Mode.Rgb)
+ {
+ _r = Clamp(r, 0, 255);
+ _g = Clamp(g, 0, 255);
+ _b = Clamp(b, 0, 255);
+ _a = Clamp(a, 0, 255);
+ }
+ else // Default
+ {
+ _r = _g = _b = _a = -1;
+ }
}
public override int GetHashCode()
@@ -78,6 +108,8 @@ namespace ElmSharp
static bool EqualsInner(Color color1, Color color2)
{
+ if (color1._mode == Mode.Default && color2._mode == Mode.Default)
+ return true;
return color1._r == color2._r && color1._g == color2._g && color1._b == color2._b && color1._a == color2._a;
}
diff --git a/ElmSharp/ElmSharp/Layout.cs b/ElmSharp/ElmSharp/Layout.cs
index c1678d9..4ae1fa6 100644
--- a/ElmSharp/ElmSharp/Layout.cs
+++ b/ElmSharp/ElmSharp/Layout.cs
@@ -63,6 +63,23 @@ namespace ElmSharp
Interop.Elementary.elm_layout_file_set(Handle, file, group);
}
+ public override Color BackgroundColor
+ {
+ set
+ {
+ if(value.IsDefault)
+ {
+ string part = ClassName.ToLower().Replace("elm_", "") + "/" + "bg";
+ EdjeObject.DeleteColorClass(part);
+ }
+ else
+ {
+ SetPartColor("bg", value);
+ }
+ _backgroundColor = value;
+ }
+ }
+
protected override IntPtr CreateHandle(EvasObject parent)
{
return Interop.Elementary.elm_layout_add(parent.Handle);
diff --git a/ElmSharp/ElmSharp/Widget.cs b/ElmSharp/ElmSharp/Widget.cs
index f7a7833..d258145 100644
--- a/ElmSharp/ElmSharp/Widget.cs
+++ b/ElmSharp/ElmSharp/Widget.cs
@@ -26,6 +26,8 @@ namespace ElmSharp
SmartEvent _focused;
SmartEvent _unfocused;
+ internal Color _backgroundColor = Color.Default;
+
protected Widget()
{
}
@@ -91,13 +93,23 @@ namespace ElmSharp
{
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);
+ if(!_backgroundColor.IsDefault)
+ {
+ _backgroundColor = GetPartColor("bg");
+ }
+ return _backgroundColor;
}
set
{
- SetPartColor("bg", value);
+ if (value.IsDefault)
+ {
+ Console.WriteLine("Widget instance doesn't support to set BackgroundColor to Color.Default.");
+ }
+ else
+ {
+ SetPartColor("bg", value);
+ _backgroundColor = value;
+ }
}
}
@@ -156,6 +168,13 @@ namespace ElmSharp
color.A);
}
+ public Color GetPartColor(string part)
+ {
+ int r, g, b, a;
+ Interop.Elementary.elm_object_color_class_color_get(Handle, part, 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);
+ }
+
internal IntPtr GetPartContent(string part)
{
return Interop.Elementary.elm_object_part_content_get(Handle, part);