X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2FTizen.NUI%2Fsrc%2Fpublic%2FColor.cs;h=13f59f6d7c718d781bf873a76bf0fe6b4084f3f6;hb=27340f2a2fd2215c9dd36c81af3a66f9c57b42cf;hp=5a72491ccfc0f679369fd9c0f6d0ed09e963dce2;hpb=fe95b7a76792049e2417dc6dfb8f159264c31698;p=platform%2Fcore%2Fcsapi%2Ftizenfx.git diff --git a/src/Tizen.NUI/src/public/Color.cs b/src/Tizen.NUI/src/public/Color.cs index 5a72491..13f59f6 100755 --- a/src/Tizen.NUI/src/public/Color.cs +++ b/src/Tizen.NUI/src/public/Color.cs @@ -1,53 +1,153 @@ -// Copyright (c) 2017 Samsung Electronics Co., Ltd. -// -// 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. -// -// -// This File has been auto-generated by SWIG and then modified using DALi Ruby Scripts -// Some have been manually changed +/* + * Copyright(c) 2017 Samsung Electronics Co., Ltd. + * + * 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 Tizen.NUI.Binding; +using System.ComponentModel; namespace Tizen.NUI { - using System; - /// - /// Color class. + /// The Color class. /// + [Tizen.NUI.Binding.TypeConverter(typeof(ColorTypeConverter))] public class Color : global::System.IDisposable { - private global::System.Runtime.InteropServices.HandleRef swigCPtr; + + /// + /// Gets the black colored Color class. + /// + /// 3 + public static readonly Color Black = new Color(0.0f, 0.0f, 0.0f, 1.0f); + + /// + /// Gets the white colored Color class. + /// + /// 3 + public static readonly Color White = new Color(1.0f, 1.0f, 1.0f, 1.0f); + + /// + /// Gets the red colored Color class. + /// + /// 3 + public static readonly Color Red = new Color(1.0f, 0.0f, 0.0f, 1.0f); + + /// + /// Gets the green colored Color class. + /// + /// 3 + public static readonly Color Green = new Color(0.0f, 1.0f, 0.0f, 1.0f); + + /// + /// Gets the blue colored Color class. + /// + /// 3 + public static readonly Color Blue = new Color(0.0f, 0.0f, 1.0f, 1.0f); + + /// + /// Gets the yellow colored Color class. + /// + /// 3 + public static readonly Color Yellow = new Color(1.0f, 1.0f, 0.0f, 1.0f); + + /// + /// Gets the magenta colored Color class. + /// + /// 3 + public static readonly Color Magenta = new Color(1.0f, 0.0f, 1.0f, 1.0f); + + /// + /// Gets the cyan colored Color class. + /// + /// 3 + public static readonly Color Cyan = new Color(0.0f, 1.0f, 1.0f, 1.0f); + + /// + /// Gets the transparent colored Color class. + /// + /// 3 + public static readonly Color Transparent = new Color(0.0f, 0.0f, 0.0f, 0.0f); + + /// + /// swigCMemOwn + /// + /// 3 protected bool swigCMemOwn; - internal Color(global::System.IntPtr cPtr, bool cMemoryOwn) + /// + /// A Flat to check if it is already disposed. + /// + /// 3 + protected bool disposed = false; + + private global::System.Runtime.InteropServices.HandleRef swigCPtr; + //A Flag to check who called Dispose(). (By User or DisposeQueue) + private bool isDisposeQueued = false; + + private readonly bool hashDummy; + + /// + /// Default constructor + /// + /// 3 + public Color() : this(NDalicPINVOKE.new_Vector4__SWIG_0(), true) { - swigCMemOwn = cMemoryOwn; - swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } - internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Color obj) + + /// + /// The constructor. + /// + /// The red component. + /// The green component. + /// The blue component. + /// The alpha component. + /// 3 + public Color(float r, float g, float b, float a) : this(NDalicPINVOKE.new_Vector4__SWIG_1(ValueCheck(r), ValueCheck(g), ValueCheck(b), ValueCheck(a)), true) { - return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr; + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } - //A Flag to check who called Dispose(). (By User or DisposeQueue) - private bool isDisposeQueued = false; - //A Flat to check if it is already disposed. - protected bool disposed = false; + /// + /// The conversion constructor from an array of four floats. + /// + /// array Array of R,G,B,A. + /// 3 + public Color(float[] array) : this(NDalicPINVOKE.new_Vector4__SWIG_2(ValueCheck(array)), true) + { + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + + internal Color(global::System.IntPtr cPtr, bool cMemoryOwn) + { + swigCMemOwn = cMemoryOwn; + swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr); + hashDummy = false; + } + /// + /// Dispose. + /// + /// 3 ~Color() { - if(!isDisposeQueued) + if (!isDisposeQueued) { isDisposeQueued = true; DisposeQueue.Instance.Add(this); @@ -55,169 +155,379 @@ namespace Tizen.NUI } /// - /// To make Color instance be disposed. + /// The red component. /// - public void Dispose() + /// 3 + public float R { - //Throw excpetion if Dispose() is called in separate thread. - if (!Window.IsInstalled()) + set { - throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread."); + NDalicPINVOKE.Vector4_r_set(swigCPtr, ValueCheck(value)); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } + get + { + float ret = NDalicPINVOKE.Vector4_r_get(swigCPtr); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; + } + } - if (isDisposeQueued) + /// + /// The green component. + /// + /// 3 + public float G + { + set { - Dispose(DisposeTypes.Implicit); + NDalicPINVOKE.Vector4_g_set(swigCPtr, ValueCheck(value)); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } - else + get { - Dispose(DisposeTypes.Explicit); - System.GC.SuppressFinalize(this); + float ret = NDalicPINVOKE.Vector4_g_get(swigCPtr); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; } } - protected virtual void Dispose(DisposeTypes type) + /// + /// The blue component. + /// + /// 3 + public float B { - if (disposed) + set { - return; + NDalicPINVOKE.Vector4_b_set(swigCPtr, ValueCheck(value)); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } - - if(type == DisposeTypes.Explicit) + get { - //Called by User - //Release your own managed resources here. - //You should release all of your own disposable objects here. + float ret = NDalicPINVOKE.Vector4_b_get(swigCPtr); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; } + } - //Release your own unmanaged resources here. - //You should not access any managed member here except static instance. - //because the execution order of Finalizes is non-deterministic. + /// + /// The alpha component. + /// + /// 3 + public float A + { + set + { + NDalicPINVOKE.Vector4_a_set(swigCPtr, ValueCheck(value)); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + get + { + float ret = NDalicPINVOKE.Vector4_a_get(swigCPtr); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; + } + } - if (swigCPtr.Handle != global::System.IntPtr.Zero) + /// + /// The array subscript operator overload. + /// + /// The subscript index. + /// The float at the given index. + /// 3 + public float this[uint index] + { + get { - if (swigCMemOwn) - { - swigCMemOwn = false; - NDalicPINVOKE.delete_Vector4(swigCPtr); - } - swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero); + return ValueOfIndex(index); } - disposed = true; } /// - /// Addition operator. + /// Converts the Color class to Vector4 class implicitly. /// - /// First value - /// Second value - /// A Color containing the result of the addition + /// A color to be converted to Vector4 + /// 3 + public static implicit operator Vector4(Color color) + { + return new Vector4(color.R, color.G, color.B, color.A); + } + + /// + /// Converts Vector4 class to Color class implicitly. + /// + /// A Vector4 to be converted to color. + /// 3 + public static implicit operator Color(Vector4 vec) + { + return new Color(vec.R, vec.G, vec.B, vec.A); + } + + /// + /// The addition operator. + /// + /// The first value. + /// The second value. + /// The color containing the result of the addition. + /// 3 public static Color operator +(Color arg1, Color arg2) { - return arg1.Add(arg2); + Color result = arg1.Add(arg2); + return ValueCheck(result); } /// - /// Subtraction operator. + /// The subtraction operator. /// - /// First value - /// Second value - /// A Color containing the result of the subtraction + /// The first value. + /// The second value. + /// The color containing the result of the subtraction. + /// 3 public static Color operator -(Color arg1, Color arg2) { - return arg1.Subtract(arg2); + Color result = arg1.Subtract(arg2); + return ValueCheck(result); } /// - /// Unary negation operator. + /// The unary negation operator. /// - /// Target Value - /// A Color containg the negation + /// The target value. + /// The color containg the negation. + /// 3 public static Color operator -(Color arg1) { - return arg1.Subtract(); + Color result = arg1.Subtract(); + return ValueCheck(result); } /// - /// Multiplication operator. + /// The multiplication operator. /// - /// First Value - /// Second Value - /// A Color containing the result of the multiplication + /// The first value. + /// The second value. + /// The color containing the result of the multiplication. + /// 3 public static Color operator *(Color arg1, Color arg2) { - return arg1.Multiply(arg2); + Color result = arg1.Multiply(arg2); + return ValueCheck(result); } - public static Color operator*(Color arg1, float arg2) + /// + /// The multiplication operator. + /// + /// The first value. + /// The second value. + /// The color containing the result of the multiplication. + /// 3 + public static Color operator *(Color arg1, float arg2) { - return arg1.Multiply(arg2); + Color result = arg1.Multiply(arg2); + return ValueCheck(result); } /// - /// Division operator. + /// The division operator. /// - /// First Value - /// Second Value - /// A Color containing the result of the division + /// The first value. + /// The second value. + /// The color containing the result of the division. + /// 3 public static Color operator /(Color arg1, Color arg2) { - return arg1.Divide(arg2); + Color result = arg1.Divide(arg2); + return ValueCheck(result); } - public static Color operator/(Color arg1, float arg2) + /// + /// The division operator. + /// + /// The first value. + /// The second value. + /// The color containing the result of the division. + /// 3 + public static Color operator /(Color arg1, float arg2) { - return arg1.Divide(arg2); + Color result = arg1.Divide(arg2); + return ValueCheck(result); } /// - /// Array subscript operator overload. + /// To make a color instance be disposed. /// - /// Subscript index - /// The float at the given index - public float this[uint index] + /// 3 + public void Dispose() { - get + //Throw excpetion if Dispose() is called in separate thread. + if (!Window.IsInstalled()) { - return ValueOfIndex(index); + throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread."); + } + + if (isDisposeQueued) + { + Dispose(DisposeTypes.Implicit); + } + else + { + Dispose(DisposeTypes.Explicit); + System.GC.SuppressFinalize(this); } } - internal static Color GetColorFromPtr(global::System.IntPtr cPtr) + /// + /// Checks if two color classes are same. + /// + /// A color to be compared. + /// If two colors are are same, then true. + /// 3 + public bool EqualTo(Color rhs) { - Color ret = new Color(cPtr, false); + bool ret = NDalicPINVOKE.Vector4_EqualTo(swigCPtr, Color.getCPtr(rhs)); + + if (rhs == null) return false; + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } /// - /// Default constructor + /// Checks if two color classes are different. /// - public Color() : this(NDalicPINVOKE.new_Vector4__SWIG_0(), true) + /// A color to be compared. + /// If two colors are are different, then true. + /// 3 + public bool NotEqualTo(Color rhs) { + bool ret = NDalicPINVOKE.Vector4_NotEqualTo(swigCPtr, Color.getCPtr(rhs)); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; } + internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Color obj) + { + return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr; + } - /// - /// Constructor. - /// - /// red component - /// green component - /// blue component - /// alpha component - public Color(float r, float g, float b, float a) : this(NDalicPINVOKE.new_Vector4__SWIG_1(r, g, b, a), true) + internal static Color GetColorFromPtr(global::System.IntPtr cPtr) { + Color ret = new Color(cPtr, false); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; + } + + internal static Color ValueCheck(Color color) + { + if (color.R < 0.0f) + { + color.R = 0.0f; + NUILog.Error("The value of Result is invalid! Should be between [0, 1]."); + } + else if (color.R > 1.0f) + { + color.R = 1.0f; + NUILog.Error("The value of Result is invalid! Should be between [0, 1]."); + } + if (color.G < 0.0f) + { + color.G = 0.0f; + NUILog.Error("The value of Result is invalid! Should be between [0, 1]."); + } + else if (color.G > 1.0f) + { + color.G = 1.0f; + NUILog.Error("The value of Result is invalid! Should be between [0, 1]."); + } + if (color.B < 0.0f) + { + color.B = 0.0f; + NUILog.Error("The value of Result is invalid! Should be between [0, 1]."); + } + else if (color.B > 1.0f) + { + color.B = 1.0f; + NUILog.Error("The value of Result is invalid! Should be between [0, 1]."); + } + if (color.A < 0.0f) + { + color.A = 0.0f; + NUILog.Error("The value of Result is invalid! Should be between [0, 1]."); + } + else if (color.A > 1.0f) + { + color.A = 1.0f; + NUILog.Error("The value of Result is invalid! Should be between [0, 1]."); + } + return color; + } + + internal static float ValueCheck(float value) + { + if (value < 0.0f) + { + value = 0.0f; + NUILog.Error("The value of Parameters is invalid! Should be between [0, 1]."); + } + else if (value > 1.0f) + { + value = 1.0f; + NUILog.Error("The value of Parameters is invalid! Should be between [0, 1]."); + } + return value; + } + + internal static float[] ValueCheck(float[] arr) + { + for (int i = 0; i < arr.Length; i++) + { + if (arr[i] < 0.0f) + { + arr[i] = 0.0f; + NUILog.Error("The value of Parameters is invalid! Should be between [0, 1]."); + } + else if (arr[i] > 1.0f) + { + arr[i] = 1.0f; + NUILog.Error("The value of Parameters is invalid! Should be between [0, 1]."); + } + } + return arr; } /// - /// Conversion constructor from an array of four floats. + /// Dispose. /// - /// array Array of R,G,B,A - public Color(float[] array) : this(NDalicPINVOKE.new_Vector4__SWIG_2(array), true) + /// 3 + protected virtual void Dispose(DisposeTypes type) { - if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + if (disposed) + { + return; + } + + if(type == DisposeTypes.Explicit) + { + //Called by User + //Release your own managed resources here. + //You should release all of your own disposable objects here. + } + + //Release your own unmanaged resources here. + //You should not access any managed member here except static instance. + //because the execution order of Finalizes is non-deterministic. + + if (swigCPtr.Handle != global::System.IntPtr.Zero) + { + if (swigCMemOwn) + { + swigCMemOwn = false; + NDalicPINVOKE.delete_Vector4(swigCPtr); + } + swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero); + } + disposed = true; } private Color Add(Color rhs) @@ -311,174 +621,60 @@ namespace Tizen.NUI return ret; } - /// - /// Check if two Color classes are same. - /// - /// A Color to be compared - /// If two Colors are are same, then true. - public bool EqualTo(Color rhs) - { - bool ret = NDalicPINVOKE.Vector4_EqualTo(swigCPtr, Color.getCPtr(rhs)); - - if (rhs == null) return false; - - if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); - return ret; - } - - /// - /// Check if two Color classes are different. - /// - /// A Color to be compared - /// If two Colors are are different, then true. - public bool NotEqualTo(Color rhs) - { - bool ret = NDalicPINVOKE.Vector4_NotEqualTo(swigCPtr, Color.getCPtr(rhs)); - if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); - return ret; - } - - - private float ValueOfIndex(uint index) + private static bool EqualsColorValue(float f1, float f2) { - float ret = NDalicPINVOKE.Vector4_ValueOfIndex__SWIG_0(swigCPtr, index); - if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); - return ret; - } - - /// - /// red component. - /// - public float R - { - set + float EPS = (float)Math.Abs(f1 * .00001); + if(Math.Abs(f1 - f2) <= EPS) { - NDalicPINVOKE.Vector4_r_set(swigCPtr, value); - if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return true; } - get + else { - float ret = NDalicPINVOKE.Vector4_r_get(swigCPtr); - if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); - return ret; + return false; } } - /// - /// green component. - /// - public float G + private static bool EqualsColor(Color c1, Color c2) { - set - { - NDalicPINVOKE.Vector4_g_set(swigCPtr, value); - if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); - } - get - { - float ret = NDalicPINVOKE.Vector4_g_get(swigCPtr); - if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); - return ret; - } + return EqualsColorValue(c1.R, c2.R) && EqualsColorValue(c1.G, c2.G) + && EqualsColorValue(c1.B, c2.B) && EqualsColorValue(c1.A, c2.A); } /// - /// blue component. + /// Determines whether the specified object is equal to the current object. /// - public float B - { - set + /// The object to compare with the current object. + /// true if the specified object is equal to the current object; otherwise, false. + /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(System.Object obj) + { + Color color = obj as Color; + bool equal = false; + if (color == null) { - NDalicPINVOKE.Vector4_b_set(swigCPtr, value); - if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return equal; } - get - { - float ret = NDalicPINVOKE.Vector4_b_get(swigCPtr); - if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); - return ret; - } - } - /// - /// alpha component. - /// - public float A - { - set - { - NDalicPINVOKE.Vector4_a_set(swigCPtr, value); - if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); - } - get + if (EqualsColor(this, color)) { - float ret = NDalicPINVOKE.Vector4_a_get(swigCPtr); - if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); - return ret; + equal = true; } + return equal; } - /// - /// Get black colored Color class. - /// - public static readonly Color Black = new Color(0.0f, 0.0f, 0.0f, 1.0f); - - /// - /// Get white colored Color class. - /// - public static readonly Color White = new Color(1.0f, 1.0f, 1.0f, 1.0f); - - /// - /// Get red colored Color class. - /// - public static readonly Color Red = new Color(1.0f, 0.0f, 0.0f, 1.0f); - - /// - /// Get green colored Color class. - /// - public static readonly Color Green = new Color(0.0f, 1.0f, 0.0f, 1.0f); - - /// - /// Get blue colored Color class. - /// - public static readonly Color Blue = new Color(0.0f, 0.0f, 1.0f, 1.0f); - - /// - /// Get yellow colored Color class. - /// - public static readonly Color Yellow = new Color(1.0f, 1.0f, 0.0f, 1.0f); - - /// - /// Get magenta colored Color class. - /// - public static readonly Color Magenta = new Color(1.0f, 0.0f, 1.0f, 1.0f); - - /// - /// Get cyan colored Color class. - /// - public static readonly Color Cyan = new Color(0.0f, 1.0f, 1.0f, 1.0f); - - /// - /// Get transparent colored Color class. - /// - public static readonly Color Transparent = new Color(0.0f, 0.0f, 0.0f, 0.0f); - - /// - /// convert Color class to Vector4 class implicitly. - /// - /// A Color to be converted to Vector4 - public static implicit operator Vector4(Color color) + /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() { - return new Vector4(color.R, color.G, color.B, color.A); + return hashDummy.GetHashCode(); } - /// - /// convert Vector4 class to Color class implicitly. - /// - /// A Vector4 to be converted to Color - public static implicit operator Color(Vector4 vec) + private float ValueOfIndex(uint index) { - return new Color(vec.R, vec.G, vec.B, vec.A); + float ret = NDalicPINVOKE.Vector4_ValueOfIndex__SWIG_0(swigCPtr, index); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; } }