[Tizen] Add value check to color.
authordongsug.song <dongsug.song@samsung.com>
Wed, 21 Jun 2017 06:19:53 +0000 (15:19 +0900)
committerdongsug.song <dongsug.song@samsung.com>
Wed, 21 Jun 2017 06:20:00 +0000 (15:20 +0900)
This reverts commit a08e43de7fa7d61d6e967d9d2cfdeb2158034d6d.

Change-Id: Ic46abde963807b9c6f2a33b0f3db57bd17f0ec0f

src/Tizen.NUI/src/public/Color.cs

index 505feb6..9170658 100755 (executable)
@@ -116,7 +116,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>
@@ -127,7 +129,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>
@@ -137,7 +141,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>
@@ -148,12 +154,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>
@@ -164,12 +174,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>
@@ -210,6 +224,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();
         }
 
@@ -219,6 +237,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();
         }
 
@@ -355,6 +377,7 @@ namespace Tizen.NUI
         {
             set
             {
+                ValueCheck(ref value);
                 NDalicPINVOKE.Vector4_r_set(swigCPtr, value);
                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             }
@@ -373,6 +396,7 @@ namespace Tizen.NUI
         {
             set
             {
+                ValueCheck(ref value);
                 NDalicPINVOKE.Vector4_g_set(swigCPtr, value);
                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             }
@@ -391,6 +415,7 @@ namespace Tizen.NUI
         {
             set
             {
+                ValueCheck(ref value);
                 NDalicPINVOKE.Vector4_b_set(swigCPtr, value);
                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             }
@@ -409,6 +434,7 @@ namespace Tizen.NUI
         {
             set
             {
+                ValueCheck(ref value);
                 NDalicPINVOKE.Vector4_a_set(swigCPtr, value);
                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             }
@@ -564,6 +590,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].");
+            }
+        }
+
     }
 
 }