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; }
{
}
- 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()
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;
}
SmartEvent _focused;
SmartEvent _unfocused;
+ internal Color _backgroundColor = Color.Default;
+
protected Widget()
{
}
{
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;
+ }
}
}
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);
--- /dev/null
+/*
+ * 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();
+ }
+
+ }
+}