[NUI.Scene3D] Add AddLight API
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI.Scene3D / src / public / Controls / SceneView.cs
index f84af37..61ceb2a 100755 (executable)
@@ -18,6 +18,7 @@
 using System;
 using System.Runtime.InteropServices;
 using System.ComponentModel;
+using System.Diagnostics.CodeAnalysis;
 using Tizen.NUI;
 using Tizen.NUI.Binding;
 using Tizen.NUI.BaseComponents;
@@ -71,7 +72,11 @@ namespace Tizen.NUI.Scene3D
         private Animation cameraTransition;
         private string skyboxUrl;
 
-        internal SceneView(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
+        internal SceneView(global::System.IntPtr cPtr, bool cMemoryOwn) : this(cPtr, cMemoryOwn, cMemoryOwn)
+        {
+        }
+
+        internal SceneView(global::System.IntPtr cPtr, bool cMemoryOwn, bool cRegister) : base(cPtr, cMemoryOwn, true, cRegister)
         {
         }
 
@@ -89,7 +94,7 @@ namespace Tizen.NUI.Scene3D
         /// </summary>
         /// <param name="sceneView">The source object.</param>
         /// <since_tizen> 10 </since_tizen>
-        public SceneView(SceneView sceneView) : this(Interop.SceneView.NewScene(SceneView.getCPtr(sceneView)), true)
+        public SceneView(SceneView sceneView) : this(Interop.SceneView.NewScene(SceneView.getCPtr(sceneView)), true, false)
         {
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
@@ -250,7 +255,7 @@ namespace Tizen.NUI.Scene3D
         /// <since_tizen> 10 </since_tizen>
         public void AddCamera(Camera camera)
         {
-            if(camera != null)
+            if (camera != null)
             {
                 Interop.SceneView.AddCamera(SwigCPtr, camera.SwigCPtr);
                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
@@ -271,7 +276,7 @@ namespace Tizen.NUI.Scene3D
         /// <since_tizen> 10 </since_tizen>
         public void RemoveCamera(Camera camera)
         {
-            if(camera != null)
+            if (camera != null)
             {
                 Interop.SceneView.RemoveCamera(SwigCPtr, camera.SwigCPtr);
                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
@@ -300,7 +305,7 @@ namespace Tizen.NUI.Scene3D
         {
             global::System.IntPtr cPtr = Interop.SceneView.GetCamera(SwigCPtr, index);
             Camera camera = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as Camera;
-            if(camera == null)
+            if (camera == null)
             {
                 // Register new camera into Registry.
                 camera = new Camera(cPtr, true);
@@ -326,7 +331,7 @@ namespace Tizen.NUI.Scene3D
         {
             global::System.IntPtr cPtr = Interop.SceneView.GetCamera(SwigCPtr, name);
             Camera camera = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as Camera;
-            if(camera == null)
+            if (camera == null)
             {
                 // Register new camera into Registry.
                 camera = new Camera(cPtr, true);
@@ -349,10 +354,11 @@ namespace Tizen.NUI.Scene3D
         /// <since_tizen> 10 </since_tizen>
         public void SelectCamera(uint index)
         {
-            if(inCameraTransition)
+            if (inCameraTransition)
             {
                 return;
             }
+            this.GetSelectedCamera()?.Unparent();
             Interop.SceneView.SelectCamera(SwigCPtr, index);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
@@ -364,10 +370,11 @@ namespace Tizen.NUI.Scene3D
         /// <since_tizen> 10 </since_tizen>
         public void SelectCamera(string name)
         {
-            if(inCameraTransition)
+            if (inCameraTransition)
             {
                 return;
             }
+            this.GetSelectedCamera()?.Unparent();
             Interop.SceneView.SelectCamera(SwigCPtr, name);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
@@ -385,9 +392,10 @@ namespace Tizen.NUI.Scene3D
         /// <param name="durationMilliSeconds">The duration in milliseconds.</param>
         /// <param name="alphaFunction">The alpha function to apply.</param>
         /// <since_tizen> 10 </since_tizen>
+        [SuppressMessage("Microsoft.Design", "CA2000: Dispose objects before losing scope", Justification = "The ownership of camera object is not owned by this class.")]
         public void CameraTransition(uint index, int durationMilliSeconds, AlphaFunction alphaFunction = null)
         {
-            if(inCameraTransition || GetSelectedCamera() == GetCamera(index))
+            if (inCameraTransition || GetSelectedCamera() == GetCamera(index))
             {
                 return;
             }
@@ -395,8 +403,6 @@ namespace Tizen.NUI.Scene3D
             SelectCamera(index);
             Camera destination = GetSelectedCamera();
             CameraTransition(source, destination, durationMilliSeconds, alphaFunction);
-            source.Dispose();
-            destination.Dispose();
         }
 
         /// <summary>
@@ -412,9 +418,10 @@ namespace Tizen.NUI.Scene3D
         /// <param name="durationMilliSeconds">The duration in milliseconds.</param>
         /// <param name="alphaFunction">The alpha function to apply.</param>
         /// <since_tizen> 10 </since_tizen>
+        [SuppressMessage("Microsoft.Design", "CA2000: Dispose objects before losing scope", Justification = "The ownership of camera object is not owned by this class.")]
         public void CameraTransition(string name, int durationMilliSeconds, AlphaFunction alphaFunction = null)
         {
-            if(inCameraTransition || GetSelectedCamera() == GetCamera(name))
+            if (inCameraTransition || GetSelectedCamera() == GetCamera(name))
             {
                 return;
             }
@@ -422,8 +429,6 @@ namespace Tizen.NUI.Scene3D
             SelectCamera(name);
             Camera destination = GetSelectedCamera();
             CameraTransition(source, destination, durationMilliSeconds, alphaFunction);
-            source.Dispose();
-            destination.Dispose();
         }
 
         /// <summary>
@@ -435,7 +440,7 @@ namespace Tizen.NUI.Scene3D
         {
             global::System.IntPtr cPtr = Interop.SceneView.GetSelectedCamera(SwigCPtr);
             Camera camera = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as Camera;
-            if(camera == null)
+            if (camera == null)
             {
                 // Register new camera into Registry.
                 camera = new Camera(cPtr, true);
@@ -468,6 +473,90 @@ namespace Tizen.NUI.Scene3D
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
+        /// <summary>
+        /// Add Lights to this SceneView.
+        /// </summary>
+        /// <param name="light">The light what we want to add</param>
+        // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public void AddLight(Light light)
+        {
+            Interop.SceneView.AddLight(SwigCPtr, Light.getCPtr(light));
+            NDalicPINVOKE.ThrowExceptionIfExists();
+        }
+
+        /// <summary>
+        /// Remove Lights from this SceneView.
+        /// </summary>
+        /// <param name="light">The light what we want to remove</param>
+        // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public void RemoveLight(Light light)
+        {
+            Interop.SceneView.RemoveLight(SwigCPtr, Light.getCPtr(light));
+            NDalicPINVOKE.ThrowExceptionIfExists();
+        }
+
+        /// <summary>
+        /// Sets SceneView's resolution manually.
+        /// </summary>
+        /// <param name="width">The input width.</param>
+        /// <param name="height">The input height.</param>
+        /// <remarks>
+        /// This manual resolution is only available when the SceneView uses FBO for rendering by using FBO (UseFrameBuffer is true).
+        /// If the aspect ratio of input width/height is different with SceneView's aspect ratio, the rendered result is stretched to fill SceneView's area.
+        /// </remarks>
+        // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public void SetResolution(uint width, uint height)
+        {
+            Interop.SceneView.SetResolution(SwigCPtr, width, height);
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+        }
+
+        /// <summary>
+        /// Retrieves width of resolution of the SceneView.
+        /// </summary>
+        /// <remarks>
+        ///  If the SceneView not uses FBO, this method returns SceneView's width.
+        /// </remarks>
+        /// <returns> Camera currently used in SceneView as a selected Camera.</returns>
+        // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public uint GetResolutionWidth()
+        {
+            uint result = Interop.SceneView.GetResolutionWidth(SwigCPtr);
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            return result;
+        }
+
+        /// <summary>
+        /// Retrieves height of resolution of the SceneView.
+        /// </summary>
+        /// <remarks>
+        ///  If the SceneView not uses FBO, this method returns SceneView's height.
+        /// </remarks>
+        /// <returns> Camera currently used in SceneView as a selected Camera.</returns>
+        // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public uint GetResolutionHeight()
+        {
+            uint result = Interop.SceneView.GetResolutionHeight(SwigCPtr);
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            return result;
+        }
+
+        /// <summary>
+        /// Resets SceneView's resolution to the current size of SceneView.
+        /// </summary>
+        // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public void ResetResolution()
+        {
+            Interop.SceneView.ResetResolution(SwigCPtr);
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+        }
+
         internal void SetUseFramebuffer(bool useFramebuffer)
         {
             Interop.SceneView.UseFramebuffer(SwigCPtr, useFramebuffer);
@@ -596,7 +685,7 @@ namespace Tizen.NUI.Scene3D
             cameraTransition.AnimateBetween(destinationCamera, "Position", positionKeyFrames, Animation.Interpolation.Linear, alphaFunction);
             cameraTransition.AnimateBetween(destinationCamera, "Orientation", orientationKeyFrames, Animation.Interpolation.Linear, alphaFunction);
 
-            if(destinationCamera.ProjectionMode == Camera.ProjectionModeType.Perspective)
+            if (destinationCamera.ProjectionMode == Camera.ProjectionModeType.Perspective)
             {
                 Radian sourceFieldOfView = sourceCamera.FieldOfView;
                 Radian destinationFieldOfView = destinationCamera.FieldOfView;
@@ -607,11 +696,11 @@ namespace Tizen.NUI.Scene3D
                     float aspect = destinationCamera.AspectRatio;
                     if (destinationCamera.ProjectionDirection == Camera.ProjectionDirectionType.Vertical)
                     {
-                        sourceFieldOfView = Camera.ConvertFovFromHorizontalToVertical(aspect, sourceFieldOfView);
+                        Camera.ConvertFovFromHorizontalToVertical(aspect, ref sourceFieldOfView);
                     }
                     else
                     {
-                        sourceFieldOfView = Camera.ConvertFovFromVerticalToHorizontal(aspect, sourceFieldOfView);
+                        Camera.ConvertFovFromVerticalToHorizontal(aspect, ref sourceFieldOfView);
                     }
                 }