diff options
author | David Steele <david.steele@samsung.com> | 2017-09-25 10:19:05 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@review.ap-northeast-2.compute.internal> | 2017-09-25 10:19:05 +0000 |
commit | 9de4de1565df8da13e7c3b071e659de7ddc0c376 (patch) | |
tree | 20ac2be29fc176b2fb6338ecd859c48531245204 | |
parent | 59a2a370611b0512e90545b6e5c5a7eadc7d3c98 (diff) | |
parent | 2a4b8eba3ac3069937fe5c2e00e06e5ed90f195d (diff) | |
download | nui-9de4de1565df8da13e7c3b071e659de7ddc0c376.tar.gz nui-9de4de1565df8da13e7c3b071e659de7ddc0c376.tar.bz2 nui-9de4de1565df8da13e7c3b071e659de7ddc0c376.zip |
Merge "Add value check to color." into devel/master
-rwxr-xr-x | Tizen.NUI/src/public/Color.cs | 98 |
1 files changed, 91 insertions, 7 deletions
diff --git a/Tizen.NUI/src/public/Color.cs b/Tizen.NUI/src/public/Color.cs index 5a72491..1d3d55c 100755 --- a/Tizen.NUI/src/public/Color.cs +++ b/Tizen.NUI/src/public/Color.cs @@ -114,7 +114,9 @@ namespace Tizen.NUI /// <returns>A Color containing the result of the addition</returns> public static Color operator +(Color arg1, Color arg2) { - return arg1.Add(arg2); + Color result = arg1.Add(arg2); + ValueCheck(result); + return result; } /// <summary> @@ -125,7 +127,9 @@ namespace Tizen.NUI /// <returns>A Color containing the result of the subtraction</returns> public static Color operator -(Color arg1, Color arg2) { - return arg1.Subtract(arg2); + Color result = arg1.Subtract(arg2); + ValueCheck(result); + return result; } /// <summary> @@ -135,7 +139,9 @@ namespace Tizen.NUI /// <returns>A Color containg the negation</returns> public static Color operator -(Color arg1) { - return arg1.Subtract(); + Color result = arg1.Subtract(); + ValueCheck(result); + return result; } /// <summary> @@ -146,12 +152,16 @@ namespace Tizen.NUI /// <returns>A Color containing the result of the multiplication</returns> public static Color operator *(Color arg1, Color arg2) { - return arg1.Multiply(arg2); + Color result = arg1.Multiply(arg2); + ValueCheck(result); + return result; } public static Color operator*(Color arg1, float arg2) { - return arg1.Multiply(arg2); + Color result = arg1.Multiply(arg2); + ValueCheck(result); + return result; } /// <summary> @@ -162,12 +172,16 @@ namespace Tizen.NUI /// <returns>A Color containing the result of the division</returns> public static Color operator /(Color arg1, Color arg2) { - return arg1.Divide(arg2); + Color result = arg1.Divide(arg2); + ValueCheck(result); + return result; } public static Color operator/(Color arg1, float arg2) { - return arg1.Divide(arg2); + Color result = arg1.Divide(arg2); + ValueCheck(result); + return result; } /// <summary> @@ -208,6 +222,10 @@ namespace Tizen.NUI /// <param name="a">alpha component</param> public Color(float r, float g, float b, float a) : this(NDalicPINVOKE.new_Vector4__SWIG_1(r, g, b, a), true) { + ValueCheck(ref r); + ValueCheck(ref g); + ValueCheck(ref b); + ValueCheck(ref a); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } @@ -217,6 +235,10 @@ namespace Tizen.NUI /// <param name="array">array Array of R,G,B,A</param> public Color(float[] array) : this(NDalicPINVOKE.new_Vector4__SWIG_2(array), true) { + ValueCheck(ref array[0]); + ValueCheck(ref array[1]); + ValueCheck(ref array[2]); + ValueCheck(ref array[3]); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } @@ -353,6 +375,7 @@ namespace Tizen.NUI { set { + ValueCheck(ref value); NDalicPINVOKE.Vector4_r_set(swigCPtr, value); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } @@ -371,6 +394,7 @@ namespace Tizen.NUI { set { + ValueCheck(ref value); NDalicPINVOKE.Vector4_g_set(swigCPtr, value); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } @@ -389,6 +413,7 @@ namespace Tizen.NUI { set { + ValueCheck(ref value); NDalicPINVOKE.Vector4_b_set(swigCPtr, value); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } @@ -407,6 +432,7 @@ namespace Tizen.NUI { set { + ValueCheck(ref value); NDalicPINVOKE.Vector4_a_set(swigCPtr, value); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } @@ -481,6 +507,64 @@ namespace Tizen.NUI return new Color(vec.R, vec.G, vec.B, vec.A); } + internal static void ValueCheck(Color color) + { + if (color.R < 0.0f) + { + color.R = 0.0f; + Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1]."); + } + else if (color.R > 1.0f) + { + color.R = 1.0f; + Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1]."); + } + if (color.G < 0.0f) + { + color.G = 0.0f; + Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1]."); + } + else if (color.G > 1.0f) + { + color.G = 1.0f; + Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1]."); + } + if (color.B < 0.0f) + { + color.B = 0.0f; + Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1]."); + } + else if (color.B > 1.0f) + { + color.B = 1.0f; + Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1]."); + } + if (color.A < 0.0f) + { + color.A = 0.0f; + Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1]."); + } + else if (color.A > 1.0f) + { + color.A = 1.0f; + Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1]."); + } + } + + internal static void ValueCheck(ref float value) + { + if (value < 0.0f) + { + value = 0.0f; + Tizen.Log.Fatal("NUI", "The value of Parameters is invalid! Should be between [0, 1]."); + } + else if (value > 1.0f) + { + value = 1.0f; + Tizen.Log.Fatal("NUI", "The value of Parameters is invalid! Should be between [0, 1]."); + } + } + } } |