From: Feng Jin Date: Wed, 29 Mar 2017 16:33:47 +0000 (+0800) Subject: Implement normalized Vector2/3/4 class. X-Git-Tag: preview1-00180^2~315^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=acc218bf2ce0465d1f751054a39c77c2bd7b07df;p=platform%2Fcore%2Fcsapi%2Ftizenfx.git Implement normalized Vector2/3/4 class. Change-Id: I86b3a50bfd02cf00c246f1f57d80b96c66331127 Signed-off-by: Feng Jin --- diff --git a/NUISamples/NUISamples/NUISamples.TizenTV/examples/relative-vector.cs b/NUISamples/NUISamples/NUISamples.TizenTV/examples/relative-vector.cs new file mode 100755 index 0000000..35d8d87 --- /dev/null +++ b/NUISamples/NUISamples/NUISamples.TizenTV/examples/relative-vector.cs @@ -0,0 +1,106 @@ +/* + * Copyright (c) 2016 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 System.Runtime.InteropServices; +using Tizen.NUI; +//using Tizen.Applications; + +//------------------------------------------------------------------------------ +// +// +// This file can only run on Tizen target. You should compile it with DaliApplication.cs, and +// add tizen c# application related library as reference. +//------------------------------------------------------------------------------ +namespace RelativeVectorTest +{ + class Example : NUIApplication + { + private Animation _animation; + private ImageView _imageView; + private Stage _stage; + private const string resources = "/home/owner/apps_rw/NUISamples.TizenTV/res"; + + public Example():base() + { + } + + public Example(string stylesheet):base(stylesheet) + { + } + + public Example(string stylesheet, WindowMode windowMode):base(stylesheet, windowMode) + { + } + + protected override void OnCreate() + { + base.OnCreate(); + Initialize(); + } + + private void Initialize() + { + // Connect the signal callback for stage touched signal + InternalSetting.DefaultParentOriginAsTopLeft = false; + _stage = Stage.Instance; + _stage.Touch += OnStageTouched; + + _imageView = new ImageView(); + _imageView.ResourceUrl = resources+"/images/gallery-3.jpg"; + _imageView.ParentOrigin = ParentOrigin.Center; + _imageView.AnchorPoint = AnchorPoint.Center; + _imageView.PixelArea = new RelativeVector4(0.0f, 0.0f, 0.0f, 0.0f); + + _stage.GetDefaultLayer().Add(_imageView); + } + + // Callback for stage touched signal handling + private void OnStageTouched(object sender, Stage.TouchEventArgs e) + { + // Only animate the _text label when touch down happens + if (e.Touch.GetState(0) == PointStateType.Down) + { + // Create a new _animation + if (_animation) + { + _animation.Reset(); + } + + _animation = new Animation(1000); // 1 second of duration + _animation.AnimateTo(_imageView, "PixelArea", new RelativeVector4(0.0f, 0.0f, 1.0f, 1.0f), 0, 1000); + _animation.EndAction = Animation.EndActions.Discard; + _animation.PlayRange = new RelativeVector2(0.2f, 0.8f); + + // Play the _animation + _animation.Play(); + } + } + + /// + /// The main entry point for the application. + /// + + [STAThread] + static void _Main(string[] args) + { + Console.WriteLine("Hello mono world."); + Example example = new Example("stylesheet", WindowMode.Transparent); + example.Run(args); + } + } +} diff --git a/src/Tizen.NUI/src/public/Animation.cs b/src/Tizen.NUI/src/public/Animation.cs index 29bfffd..4eadee8 100755 --- a/src/Tizen.NUI/src/public/Animation.cs +++ b/src/Tizen.NUI/src/public/Animation.cs @@ -337,7 +337,7 @@ namespace Tizen.NUI /// Animation will play between the values specified. Both values(range.x and range.y ) should be between 0-1, /// otherwise they will be ignored.If the range provided is not in proper order(minimum, maximum ), it will be reordered. /// - public Vector2 PlayRange + public RelativeVector2 PlayRange { set { diff --git a/src/Tizen.NUI/src/public/ImageView.cs b/src/Tizen.NUI/src/public/ImageView.cs index 64c5aaa..60259da 100755 --- a/src/Tizen.NUI/src/public/ImageView.cs +++ b/src/Tizen.NUI/src/public/ImageView.cs @@ -247,7 +247,7 @@ namespace Tizen.NUI /// ImageView PixelArea, type Vector4 (Animatable property) /// Pixel area is a relative value with the whole image area as [0.0, 0.0, 1.0, 1.0]. /// - public Vector4 PixelArea + public RelativeVector4 PixelArea { get { diff --git a/src/Tizen.NUI/src/public/RelativeVector2.cs b/src/Tizen.NUI/src/public/RelativeVector2.cs new file mode 100755 index 0000000..0bd3e67 --- /dev/null +++ b/src/Tizen.NUI/src/public/RelativeVector2.cs @@ -0,0 +1,381 @@ +/* + * 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; + +namespace Tizen.NUI +{ + + /// + /// RelativeVector2 is a two dimensional vector. + /// Both values(x and y) should be between [0, 1]. + /// + public class RelativeVector2 : global::System.IDisposable + { + private global::System.Runtime.InteropServices.HandleRef swigCPtr; + protected bool swigCMemOwn; + + internal RelativeVector2(global::System.IntPtr cPtr, bool cMemoryOwn) + { + swigCMemOwn = cMemoryOwn; + swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr); + } + + internal static global::System.Runtime.InteropServices.HandleRef getCPtr(RelativeVector2 obj) + { + return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr; + } + + ~RelativeVector2() + { + DisposeQueue.Instance.Add(this); + } + + public virtual void Dispose() + { + if (!Stage.IsInstalled()) + { + DisposeQueue.Instance.Add(this); + return; + } + + lock (this) + { + if (swigCPtr.Handle != global::System.IntPtr.Zero) + { + if (swigCMemOwn) + { + swigCMemOwn = false; + NDalicPINVOKE.delete_Vector2(swigCPtr); + } + swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero); + } + global::System.GC.SuppressFinalize(this); + } + } + + + /// + /// Addition operator. + /// + /// Vector to add + /// Vector to add + /// A vector containing the result of the addition + public static RelativeVector2 operator +(RelativeVector2 arg1, RelativeVector2 arg2) + { + RelativeVector2 result = arg1.Add(arg2); + ValueCheck(result); + return result; + } + + /// + /// Subtraction operator. + /// + /// Vector to subtract + /// Vector to subtract + /// A vector containing the result of the subtraction + public static RelativeVector2 operator -(RelativeVector2 arg1, RelativeVector2 arg2) + { + RelativeVector2 result = arg1.Subtract(arg2); + ValueCheck(result); + return result; + } + + /// + /// Multiplication operator. + /// + /// The vector to multiply + /// The vector to multiply + /// A vector containing the result of the multiplication + public static RelativeVector2 operator *(RelativeVector2 arg1, RelativeVector2 arg2) + { + RelativeVector2 result = arg1.Multiply(arg2); + ValueCheck(result); + return result; + } + + /// + /// Multiplication operator. + /// + /// The vector to multiply + /// The float value to scale the vector + /// A vector containing the result of the scaling + public static RelativeVector2 operator *(RelativeVector2 arg1, float arg2) + { + RelativeVector2 result = arg1.Multiply(arg2); + ValueCheck(result); + return result; + } + + /// + /// Division operator. + /// + /// The vector to divide + /// The vector to divide + /// A vector containing the result of the division + public static RelativeVector2 operator /(RelativeVector2 arg1, RelativeVector2 arg2) + { + RelativeVector2 result = arg1.Divide(arg2); + ValueCheck(result); + return result; + } + + /// + /// Division operator. + /// + /// The vector to divide + /// The float value to scale the vector by + /// A vector containing the result of the scaling + public static RelativeVector2 operator /(RelativeVector2 arg1, float arg2) + { + RelativeVector2 result = arg1.Divide(arg2); + ValueCheck(result); + return result; + } + + + /// + /// Const array subscript operator overload. Should be 0, 1. + /// + /// Subscript index + /// The float at the given index + public float this[uint index] + { + get + { + return ValueOfIndex(index); + } + } + + /// + /// + internal static RelativeVector2 GetRelativeVector2FromPtr(global::System.IntPtr cPtr) + { + RelativeVector2 ret = new RelativeVector2(cPtr, false); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; + } + + + /// + /// Constructor + /// + public RelativeVector2() : this(NDalicPINVOKE.new_Vector2__SWIG_0(), true) + { + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + + /// + /// Constructor + /// + /// x component + /// y component + public RelativeVector2(float x, float y) : this(NDalicPINVOKE.new_Vector2__SWIG_1(x, y), true) + { + ValueCheck(x); + ValueCheck(y); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + + /// + /// Constructor + /// + /// RelativeVector3 to create this vector from + public RelativeVector2(RelativeVector3 relativeVector3) : this(NDalicPINVOKE.new_Vector2__SWIG_3(RelativeVector3.getCPtr(relativeVector3)), true) + { + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + + /// + /// Constructor + /// + /// RelativeVector4 to create this vector from + public RelativeVector2(RelativeVector4 relativeVector4) : this(NDalicPINVOKE.new_Vector2__SWIG_4(RelativeVector4.getCPtr(relativeVector4)), true) + { + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + + + private RelativeVector2 Add(RelativeVector2 rhs) + { + RelativeVector2 ret = new RelativeVector2(NDalicPINVOKE.Vector2_Add(swigCPtr, RelativeVector2.getCPtr(rhs)), true); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; + } + + private RelativeVector2 Subtract(RelativeVector2 rhs) + { + RelativeVector2 ret = new RelativeVector2(NDalicPINVOKE.Vector2_Subtract__SWIG_0(swigCPtr, RelativeVector2.getCPtr(rhs)), true); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; + } + + private RelativeVector2 Multiply(RelativeVector2 rhs) + { + RelativeVector2 ret = new RelativeVector2(NDalicPINVOKE.Vector2_Multiply__SWIG_0(swigCPtr, RelativeVector2.getCPtr(rhs)), true); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; + } + + private RelativeVector2 Multiply(float rhs) + { + RelativeVector2 ret = new RelativeVector2(NDalicPINVOKE.Vector2_Multiply__SWIG_1(swigCPtr, rhs), true); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; + } + + private RelativeVector2 Divide(RelativeVector2 rhs) + { + RelativeVector2 ret = new RelativeVector2(NDalicPINVOKE.Vector2_Divide__SWIG_0(swigCPtr, RelativeVector2.getCPtr(rhs)), true); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; + } + + private RelativeVector2 Divide(float rhs) + { + RelativeVector2 ret = new RelativeVector2(NDalicPINVOKE.Vector2_Divide__SWIG_1(swigCPtr, rhs), true); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; + } + + private float ValueOfIndex(uint index) + { + float ret = NDalicPINVOKE.Vector2_ValueOfIndex__SWIG_0(swigCPtr, index); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; + } + + /// + /// Compare if rhs is equal to + /// + /// The vector to compare + /// Returns true if the two vectors are equal, otherwise false + public bool EqualTo(RelativeVector2 rhs) + { + bool ret = NDalicPINVOKE.Vector2_EqualTo(swigCPtr, RelativeVector2.getCPtr(rhs)); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; + } + + /// + /// Compare if rhs is not equal to + /// + /// The vector to compare + /// Returns true if the two vectors are not equal, otherwise false + public bool NotEqualTo(RelativeVector2 rhs) + { + bool ret = NDalicPINVOKE.Vector2_NotEqualTo(swigCPtr, RelativeVector2.getCPtr(rhs)); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; + } + + + /// + /// x component + /// + public float X + { + set + { + ValueCheck(value); + NDalicPINVOKE.Vector2_X_set(swigCPtr, value); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + get + { + float ret = NDalicPINVOKE.Vector2_X_get(swigCPtr); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; + } + } + + /// + /// y component + /// + public float Y + { + set + { + ValueCheck(value); + NDalicPINVOKE.Vector2_Y_set(swigCPtr, value); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + get + { + float ret = NDalicPINVOKE.Vector2_Y_get(swigCPtr); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; + } + } + + /// + /// + public static implicit operator Vector2(RelativeVector2 relativeVector2) + { + return new Vector2(relativeVector2.X, relativeVector2.Y); + } + + /// + /// + public static implicit operator RelativeVector2(Vector2 vec) + { + ValueCheck(vec.X); + ValueCheck(vec.Y); + return new RelativeVector2(vec.X, vec.Y); + } + + internal static void ValueCheck(RelativeVector2 relativeVector2) + { + if(relativeVector2.X < 0.0f) + { + relativeVector2.X = 0.0f; + Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1]."); + } + else if(relativeVector2.X > 1.0f) + { + relativeVector2.X = 1.0f; + Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1]."); + } + if(relativeVector2.Y < 0.0f) + { + relativeVector2.Y = 0.0f; + Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1]."); + } + else if(relativeVector2.Y > 1.0f) + { + relativeVector2.Y = 1.0f; + Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1]."); + } + } + + internal static void ValueCheck(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]."); + } + } + } + +} + + diff --git a/src/Tizen.NUI/src/public/RelativeVector3.cs b/src/Tizen.NUI/src/public/RelativeVector3.cs new file mode 100755 index 0000000..7116b85 --- /dev/null +++ b/src/Tizen.NUI/src/public/RelativeVector3.cs @@ -0,0 +1,413 @@ +/* + * 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; +namespace Tizen.NUI +{ + + /// + /// RelativeVector3 is a three dimensional vector. + /// All values(x, y, z and w) should be between [0, 1]. + /// + public class RelativeVector3 : global::System.IDisposable + { + private global::System.Runtime.InteropServices.HandleRef swigCPtr; + protected bool swigCMemOwn; + + internal RelativeVector3(global::System.IntPtr cPtr, bool cMemoryOwn) + { + swigCMemOwn = cMemoryOwn; + swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr); + } + + internal static global::System.Runtime.InteropServices.HandleRef getCPtr(RelativeVector3 obj) + { + return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr; + } + + ~RelativeVector3() + { + DisposeQueue.Instance.Add(this); + } + + public virtual void Dispose() + { + if (!Stage.IsInstalled()) + { + DisposeQueue.Instance.Add(this); + return; + } + + lock (this) + { + if (swigCPtr.Handle != global::System.IntPtr.Zero) + { + if (swigCMemOwn) + { + swigCMemOwn = false; + NDalicPINVOKE.delete_Vector3(swigCPtr); + } + swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero); + } + global::System.GC.SuppressFinalize(this); + } + } + + + /// + /// Addition operator. + /// + /// Vector to add + /// Vector to add + /// A vector containing the result of the addition + public static RelativeVector3 operator +(RelativeVector3 arg1, RelativeVector3 arg2) + { + RelativeVector3 result = arg1.Add(arg2); + ValueCheck(result); + return result; + } + + /// + /// Subtraction operator. + /// + /// Vector to subtract + /// Vector to subtract + /// A vector containing the result of the subtraction + public static RelativeVector3 operator -(RelativeVector3 arg1, RelativeVector3 arg2) + { + RelativeVector3 result = arg1.Subtract(arg2); + ValueCheck(result); + return result; + } + + /// + /// Multiplication operator. + /// + /// The vector to multiply + /// The vector to multiply + /// A vector containing the result of the multiplication + public static RelativeVector3 operator *(RelativeVector3 arg1, RelativeVector3 arg2) + { + RelativeVector3 result = arg1.Multiply(arg2); + ValueCheck(result); + return result; + } + + /// + /// Multiplication operator. + /// + /// The vector to multiply + /// The float value to scale the vector + /// A vector containing the result of the scaling + public static RelativeVector3 operator *(RelativeVector3 arg1, float arg2) + { + RelativeVector3 result = arg1.Multiply(arg2); + ValueCheck(result); + return result; + } + + /// + /// Division operator. + /// + /// The vector to divide + /// The vector to divide + /// A vector containing the result of the division + public static RelativeVector3 operator /(RelativeVector3 arg1, RelativeVector3 arg2) + { + RelativeVector3 result = arg1.Divide(arg2); + ValueCheck(result); + return result; + } + + /// + /// Division operator. + /// + /// The vector to divide + /// The float value to scale the vector by + /// A vector containing the result of the scaling + public static RelativeVector3 operator /(RelativeVector3 arg1, float arg2) + { + RelativeVector3 result = arg1.Divide(arg2); + ValueCheck(result); + return result; + } + + + /// + /// Const array subscript operator overload. Should be 0, 1 or 2. + /// + /// Subscript index + /// The float at the given index + public float this[uint index] + { + get + { + return ValueOfIndex(index); + } + } + + /// + /// + internal static RelativeVector3 GetRelativeVector3FromPtr(global::System.IntPtr cPtr) + { + RelativeVector3 ret = new RelativeVector3(cPtr, false); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; + } + + + /// + /// Constructor + /// + public RelativeVector3() : this(NDalicPINVOKE.new_Vector3__SWIG_0(), true) + { + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + + /// + /// Constructor + /// + /// x component + /// y component + /// z component + public RelativeVector3(float x, float y, float z) : this(NDalicPINVOKE.new_Vector3__SWIG_1(x, y, z), true) + { + ValueCheck(x); + ValueCheck(y); + ValueCheck(z); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + + /// + /// Constructor + /// + /// RelativeVector2 to create this vector from + public RelativeVector3(RelativeVector2 relativeVector2) : this(NDalicPINVOKE.new_Vector3__SWIG_3(RelativeVector2.getCPtr(relativeVector2)), true) + { + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + + /// + /// Constructor + /// + /// RelativeVector4 to create this vector from + public RelativeVector3(RelativeVector4 relativeVector4) : this(NDalicPINVOKE.new_Vector3__SWIG_4(RelativeVector4.getCPtr(relativeVector4)), true) + { + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + + + private RelativeVector3 Add(RelativeVector3 rhs) + { + RelativeVector3 ret = new RelativeVector3(NDalicPINVOKE.Vector3_Add(swigCPtr, RelativeVector3.getCPtr(rhs)), true); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; + } + + private RelativeVector3 Subtract(RelativeVector3 rhs) + { + RelativeVector3 ret = new RelativeVector3(NDalicPINVOKE.Vector3_Subtract__SWIG_0(swigCPtr, RelativeVector3.getCPtr(rhs)), true); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; + } + + private RelativeVector3 Multiply(RelativeVector3 rhs) + { + RelativeVector3 ret = new RelativeVector3(NDalicPINVOKE.Vector3_Multiply__SWIG_0(swigCPtr, RelativeVector3.getCPtr(rhs)), true); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; + } + + private RelativeVector3 Multiply(float rhs) + { + RelativeVector3 ret = new RelativeVector3(NDalicPINVOKE.Vector3_Multiply__SWIG_1(swigCPtr, rhs), true); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; + } + + private RelativeVector3 Divide(RelativeVector3 rhs) + { + RelativeVector3 ret = new RelativeVector3(NDalicPINVOKE.Vector3_Divide__SWIG_0(swigCPtr, RelativeVector3.getCPtr(rhs)), true); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; + } + + private RelativeVector3 Divide(float rhs) + { + RelativeVector3 ret = new RelativeVector3(NDalicPINVOKE.Vector3_Divide__SWIG_1(swigCPtr, rhs), true); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; + } + + private float ValueOfIndex(uint index) + { + float ret = NDalicPINVOKE.Vector3_ValueOfIndex__SWIG_0(swigCPtr, index); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; + } + + /// + /// Compare if rhs is equal to + /// + /// The vector to compare + /// Returns true if the two vectors are equal, otherwise false + public bool EqualTo(RelativeVector3 rhs) + { + bool ret = NDalicPINVOKE.Vector3_EqualTo(swigCPtr, RelativeVector3.getCPtr(rhs)); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; + } + + /// + /// Compare if rhs is not equal to + /// + /// The vector to compare + /// Returns true if the two vectors are not equal, otherwise false + public bool NotEqualTo(RelativeVector3 rhs) + { + bool ret = NDalicPINVOKE.Vector3_NotEqualTo(swigCPtr, RelativeVector3.getCPtr(rhs)); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; + } + + + /// + /// x component + /// + public float X + { + set + { + ValueCheck(value); + NDalicPINVOKE.Vector3_X_set(swigCPtr, value); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + get + { + float ret = NDalicPINVOKE.Vector3_X_get(swigCPtr); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; + } + } + + /// + /// y component + /// + public float Y + { + set + { + ValueCheck(value); + NDalicPINVOKE.Vector3_Y_set(swigCPtr, value); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + get + { + float ret = NDalicPINVOKE.Vector3_Y_get(swigCPtr); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; + } + } + + /// + /// z component + /// + public float Z + { + set + { + ValueCheck(value); + NDalicPINVOKE.Vector3_Z_set(swigCPtr, value); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + get + { + float ret = NDalicPINVOKE.Vector3_Z_get(swigCPtr); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; + } + } + + /// + /// + public static implicit operator Vector3(RelativeVector3 relativeVector3) + { + return new Vector3(relativeVector3.X, relativeVector3.Y, relativeVector3.Z); + } + + /// + /// + public static implicit operator RelativeVector3(Vector3 vec) + { + ValueCheck(vec.X); + ValueCheck(vec.Y); + ValueCheck(vec.Z); + return new RelativeVector3(vec.X, vec.Y, vec.Z); + } + + internal static void ValueCheck(RelativeVector3 relativeVector3) + { + if(relativeVector3.X < 0.0f) + { + relativeVector3.X = 0.0f; + Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1]."); + } + else if(relativeVector3.X > 1.0f) + { + relativeVector3.X = 1.0f; + Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1]."); + } + if(relativeVector3.Y < 0.0f) + { + relativeVector3.Y = 0.0f; + Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1]."); + } + else if(relativeVector3.Y > 1.0f) + { + relativeVector3.Y = 1.0f; + Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1]."); + } + if(relativeVector3.Z < 0.0f) + { + relativeVector3.Z = 0.0f; + Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1]."); + } + else if(relativeVector3.Z > 1.0f) + { + relativeVector3.Z = 1.0f; + Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1]."); + } + } + + internal static void ValueCheck(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]."); + } + } + } + +} + + diff --git a/src/Tizen.NUI/src/public/RelativeVector4.cs b/src/Tizen.NUI/src/public/RelativeVector4.cs new file mode 100755 index 0000000..82038bf --- /dev/null +++ b/src/Tizen.NUI/src/public/RelativeVector4.cs @@ -0,0 +1,445 @@ +/* + * 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; + +namespace Tizen.NUI +{ + + /// + /// RelativeVector4 is a four dimensional vector. + /// All values(x, y, and z) should be between [0, 1]. + /// + public class RelativeVector4 : global::System.IDisposable + { + private global::System.Runtime.InteropServices.HandleRef swigCPtr; + protected bool swigCMemOwn; + + internal RelativeVector4(global::System.IntPtr cPtr, bool cMemoryOwn) + { + swigCMemOwn = cMemoryOwn; + swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr); + } + + internal static global::System.Runtime.InteropServices.HandleRef getCPtr(RelativeVector4 obj) + { + return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr; + } + + ~RelativeVector4() + { + DisposeQueue.Instance.Add(this); + } + + public virtual void Dispose() + { + if (!Stage.IsInstalled()) + { + DisposeQueue.Instance.Add(this); + return; + } + + lock (this) + { + 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); + } + global::System.GC.SuppressFinalize(this); + } + } + + + /// + /// Addition operator. + /// + /// Vector to add + /// Vector to add + /// A vector containing the result of the addition + public static RelativeVector4 operator +(RelativeVector4 arg1, RelativeVector4 arg2) + { + RelativeVector4 result = arg1.Add(arg2); + ValueCheck(result); + return result; + } + + /// + /// Subtraction operator. + /// + /// Vector to subtract + /// Vector to subtract + /// A vector containing the result of the subtraction + public static RelativeVector4 operator -(RelativeVector4 arg1, RelativeVector4 arg2) + { + RelativeVector4 result = arg1.Subtract(arg2); + ValueCheck(result); + return result; + } + + /// + /// Multiplication operator. + /// + /// The vector to multiply + /// The vector to multiply + /// A vector containing the result of the multiplication + public static RelativeVector4 operator *(RelativeVector4 arg1, RelativeVector4 arg2) + { + RelativeVector4 result = arg1.Multiply(arg2); + ValueCheck(result); + return result; + } + + /// + /// Multiplication operator. + /// + /// The vector to multiply + /// The float value to scale the vector + /// A vector containing the result of the scaling + public static RelativeVector4 operator *(RelativeVector4 arg1, float arg2) + { + RelativeVector4 result = arg1.Multiply(arg2); + ValueCheck(result); + return result; + } + + /// + /// Division operator. + /// + /// The vector to divide + /// The vector to divide + /// A vector containing the result of the division + public static RelativeVector4 operator /(RelativeVector4 arg1, RelativeVector4 arg2) + { + RelativeVector4 result = arg1.Divide(arg2); + ValueCheck(result); + return result; + } + + /// + /// Division operator. + /// + /// The vector to divide + /// The float value to scale the vector by + /// A vector containing the result of the scaling + public static RelativeVector4 operator /(RelativeVector4 arg1, float arg2) + { + RelativeVector4 result = arg1.Divide(arg2); + ValueCheck(result); + return result; + } + + + /// + /// Const array subscript operator overload. Should be 0, 1 3 or 3. + /// + /// Subscript index + /// The float at the given index + public float this[uint index] + { + get + { + return ValueOfIndex(index); + } + } + + /// + /// + internal static RelativeVector4 GetRelativeVector4FromPtr(global::System.IntPtr cPtr) + { + RelativeVector4 ret = new RelativeVector4(cPtr, false); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; + } + + + /// + /// Constructor + /// + public RelativeVector4() : this(NDalicPINVOKE.new_Vector4__SWIG_0(), true) + { + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + + /// + /// Constructor + /// + /// x component + /// y component + /// z component + /// w component + public RelativeVector4(float x, float y, float z, float w) : this(NDalicPINVOKE.new_Vector4__SWIG_1(x, y, z, w), true) + { + ValueCheck(x); + ValueCheck(y); + ValueCheck(z); + ValueCheck(W); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + + /// + /// Constructor + /// + /// RelativeVector2 to create this vector from + public RelativeVector4(RelativeVector2 relativeVector2) : this(NDalicPINVOKE.new_Vector4__SWIG_3(RelativeVector2.getCPtr(relativeVector2)), true) + { + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + + /// + /// Constructor + /// + /// RelativeVector3 to create this vector from + public RelativeVector4(RelativeVector3 relativeVector3) : this(NDalicPINVOKE.new_Vector4__SWIG_4(RelativeVector3.getCPtr(relativeVector3)), true) + { + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + + private RelativeVector4 Add(RelativeVector4 rhs) + { + RelativeVector4 ret = new RelativeVector4(NDalicPINVOKE.Vector4_Add(swigCPtr, RelativeVector4.getCPtr(rhs)), true); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; + } + + private RelativeVector4 Subtract(RelativeVector4 rhs) + { + RelativeVector4 ret = new RelativeVector4(NDalicPINVOKE.Vector4_Subtract__SWIG_0(swigCPtr, RelativeVector4.getCPtr(rhs)), true); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; + } + + private RelativeVector4 Multiply(RelativeVector4 rhs) + { + RelativeVector4 ret = new RelativeVector4(NDalicPINVOKE.Vector4_Multiply__SWIG_0(swigCPtr, RelativeVector4.getCPtr(rhs)), true); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; + } + + private RelativeVector4 Multiply(float rhs) + { + RelativeVector4 ret = new RelativeVector4(NDalicPINVOKE.Vector4_Multiply__SWIG_1(swigCPtr, rhs), true); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; + } + + private RelativeVector4 Divide(RelativeVector4 rhs) + { + RelativeVector4 ret = new RelativeVector4(NDalicPINVOKE.Vector4_Divide__SWIG_0(swigCPtr, RelativeVector4.getCPtr(rhs)), true); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; + } + + private RelativeVector4 Divide(float rhs) + { + RelativeVector4 ret = new RelativeVector4(NDalicPINVOKE.Vector4_Divide__SWIG_1(swigCPtr, rhs), true); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; + } + + private float ValueOfIndex(uint index) + { + float ret = NDalicPINVOKE.Vector4_ValueOfIndex__SWIG_0(swigCPtr, index); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; + } + + /// + /// Compare if rhs is equal to + /// + /// The vector to compare + /// Returns true if the two vectors are equal, otherwise false + public bool EqualTo(RelativeVector4 rhs) + { + bool ret = NDalicPINVOKE.Vector4_EqualTo(swigCPtr, RelativeVector4.getCPtr(rhs)); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; + } + + /// + /// Compare if rhs is not equal to + /// + /// The vector to compare + /// Returns true if the two vectors are not equal, otherwise false + public bool NotEqualTo(RelativeVector4 rhs) + { + bool ret = NDalicPINVOKE.Vector4_NotEqualTo(swigCPtr, RelativeVector4.getCPtr(rhs)); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; + } + + + /// + /// x component + /// + public float X + { + set + { + ValueCheck(value); + NDalicPINVOKE.Vector4_X_set(swigCPtr, value); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + get + { + float ret = NDalicPINVOKE.Vector4_X_get(swigCPtr); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; + } + } + + /// + /// y component + /// + public float Y + { + set + { + ValueCheck(value); + NDalicPINVOKE.Vector4_Y_set(swigCPtr, value); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + get + { + float ret = NDalicPINVOKE.Vector4_Y_get(swigCPtr); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; + } + } + + /// + /// z component + /// + public float Z + { + set + { + ValueCheck(value); + NDalicPINVOKE.Vector4_Z_set(swigCPtr, value); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + get + { + float ret = NDalicPINVOKE.Vector4_Z_get(swigCPtr); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; + } + } + + /// + /// w component + /// + public float W + { + set + { + ValueCheck(value); + NDalicPINVOKE.Vector4_W_set(swigCPtr, value); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + get + { + float ret = NDalicPINVOKE.Vector4_W_get(swigCPtr); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; + } + } + + /// + /// + public static implicit operator Vector4(RelativeVector4 relativeVector4) + { + return new Vector4(relativeVector4.X, relativeVector4.Y, relativeVector4.Z, relativeVector4.W); + } + + /// + /// + public static implicit operator RelativeVector4(Vector4 vec) + { + ValueCheck(vec.X); + ValueCheck(vec.Y); + ValueCheck(vec.Z); + ValueCheck(vec.W); + return new RelativeVector4(vec.X, vec.Y, vec.Z, vec.W); + } + + internal static void ValueCheck(RelativeVector4 relativeVector4) + { + if(relativeVector4.X < 0.0f) + { + relativeVector4.X = 0.0f; + Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1]."); + } + else if(relativeVector4.X > 1.0f) + { + relativeVector4.X = 1.0f; + Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1]."); + } + if(relativeVector4.Y < 0.0f) + { + relativeVector4.Y = 0.0f; + Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1]."); + } + else if(relativeVector4.Y > 1.0f) + { + relativeVector4.Y = 1.0f; + Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1]."); + } + if(relativeVector4.Z < 0.0f) + { + relativeVector4.Z = 0.0f; + Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1]."); + } + else if(relativeVector4.Z > 1.0f) + { + relativeVector4.Z = 1.0f; + Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1]."); + } + if(relativeVector4.W < 0.0f) + { + relativeVector4.W = 0.0f; + Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1]."); + } + else if(relativeVector4.W > 1.0f) + { + relativeVector4.W = 1.0f; + Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1]."); + } + } + + internal static void ValueCheck(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]."); + } + } + + } + +} + +