From: Umar Date: Mon, 4 Sep 2017 20:01:04 +0000 (+0100) Subject: [Tizen] Scene Graph support in NUI X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F08%2F153508%2F1;p=platform%2Fcore%2Fcsapi%2Fnui.git [Tizen] Scene Graph support in NUI The RSS was increased 0.3% from 519254 to 521274 for 50,000 views. Change-Id: Ib739b406af034e14d8193785b52a5d17f570e4c7 --- diff --git a/Tizen.NUI/src/public/BaseComponents/View.cs b/Tizen.NUI/src/public/BaseComponents/View.cs index 1002e87..286bcf9 100755 --- a/Tizen.NUI/src/public/BaseComponents/View.cs +++ b/Tizen.NUI/src/public/BaseComponents/View.cs @@ -27,6 +27,7 @@ namespace Tizen.NUI.BaseComponents { private global::System.Runtime.InteropServices.HandleRef swigCPtr; + internal View(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicPINVOKE.View_SWIGUpcast(cPtr), cMemoryOwn) { swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr); @@ -50,6 +51,8 @@ namespace Tizen.NUI.BaseComponents NDalicPINVOKE.Actor_Add(swigCPtr, View.getCPtr(child)); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + + Children.Add(child); } /// @@ -62,6 +65,8 @@ namespace Tizen.NUI.BaseComponents NDalicPINVOKE.Actor_Remove(swigCPtr, View.getCPtr(child)); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + + Children.Remove(child); } /// @@ -71,13 +76,14 @@ namespace Tizen.NUI.BaseComponents /// public override View GetChildAt(uint index) { - IntPtr cPtr = NDalicPINVOKE.Actor_GetChildAt(swigCPtr, index); - - View ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as View; - - if (NDalicPINVOKE.SWIGPendingException.Pending) - throw NDalicPINVOKE.SWIGPendingException.Retrieve(); - return ret ?? null; + if (index < Children.Count) + { + return Children[Convert.ToInt32(index)]; + } + else + { + return null; + } } /// @@ -87,10 +93,7 @@ namespace Tizen.NUI.BaseComponents /// protected override uint GetChildCount() { - uint ret = NDalicPINVOKE.Actor_GetChildCount(swigCPtr); - if (NDalicPINVOKE.SWIGPendingException.Pending) - throw NDalicPINVOKE.SWIGPendingException.Retrieve(); - return ret; + return Convert.ToUInt32(Children.Count); } /// @@ -99,23 +102,14 @@ namespace Tizen.NUI.BaseComponents /// protected override Container GetParent() { - Container ret; IntPtr cPtr = NDalicPINVOKE.Actor_GetParent(swigCPtr); BaseHandle basehandle = Registry.GetManagedBaseHandleFromNativePtr(cPtr); - if(basehandle is Layer) - { - ret = basehandle as Layer; - } - else - { - ret = basehandle as View; - } - if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); - return ret; + + return basehandle as Container; } [Obsolete("This is temporal API. Currently Parent returns View but Container class has been introduced so 'View Parent' will be changed 'Container Parent' later soon, then this will be removed")] @@ -2198,6 +2192,21 @@ namespace Tizen.NUI.BaseComponents internal void Raise() { + var parentChildren = Parent?.Children; + + if (parentChildren != null) + { + int currentIndex = parentChildren.IndexOf(this); + + // If the view is not already the last item in the list. + if (currentIndex != parentChildren.Count -1) + { + View temp = parentChildren[currentIndex + 1]; + parentChildren[currentIndex + 1] = this; + parentChildren[currentIndex] = temp; + } + } + NDalicPINVOKE.Raise(swigCPtr); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); @@ -2205,6 +2214,21 @@ namespace Tizen.NUI.BaseComponents internal void Lower() { + var parentChildren = Parent?.Children; + + if (parentChildren != null) + { + int currentIndex = parentChildren.IndexOf(this); + + // If the view is not already the first item in the list. + if (currentIndex > 0) + { + View temp = parentChildren[currentIndex - 1]; + parentChildren[currentIndex - 1] = this; + parentChildren[currentIndex] = temp; + } + } + NDalicPINVOKE.Lower(swigCPtr); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); @@ -2219,6 +2243,14 @@ namespace Tizen.NUI.BaseComponents /// public void RaiseToTop() { + var parentChildren = Parent?.Children; + + if (parentChildren != null) + { + parentChildren.Remove(this); + parentChildren.Add(this); + } + NDalicPINVOKE.RaiseToTop(swigCPtr); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); @@ -2233,6 +2265,14 @@ namespace Tizen.NUI.BaseComponents /// public void LowerToBottom() { + var parentChildren = Parent?.Children; + + if (parentChildren != null) + { + parentChildren.Remove(this); + parentChildren.Insert(0, this); + } + NDalicPINVOKE.LowerToBottom(swigCPtr); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); @@ -2261,6 +2301,21 @@ namespace Tizen.NUI.BaseComponents /// Will be raised above this view. internal void RaiseAbove(View target) { + var parentChildren = Parent?.Children; + + if (parentChildren != null) + { + int currentIndex = parentChildren.IndexOf(this); + int targetIndex = parentChildren.IndexOf(target); + + // If the currentIndex is less than the target index and the target has the same parent. + if (currentIndex < targetIndex) + { + parentChildren.Remove(this); + parentChildren.Insert(targetIndex, this); + } + } + NDalicPINVOKE.RaiseAbove(swigCPtr, View.getCPtr(target)); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); @@ -2276,7 +2331,23 @@ namespace Tizen.NUI.BaseComponents /// Will be lowered below this view. internal void LowerBelow(View target) { - NDalicPINVOKE.RaiseAbove(swigCPtr, View.getCPtr(target)); + var parentChildren = Parent?.Children; + + if (parentChildren != null) + { + int currentIndex = parentChildren.IndexOf(this); + int targetIndex = parentChildren.IndexOf(target); + + // If the currentIndex is not already the 0th index and the target has the same parent. + if ((currentIndex != 0) && (targetIndex != -1) && + (currentIndex > targetIndex)) + { + parentChildren.Remove(this); + parentChildren.Insert(targetIndex, this); + } + } + + NDalicPINVOKE.LowerBelow(swigCPtr, View.getCPtr(target)); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } @@ -2335,9 +2406,7 @@ namespace Tizen.NUI.BaseComponents ///
The (child) view has been initialized. 
public void Unparent() { - NDalicPINVOKE.Actor_Unparent(swigCPtr); - if (NDalicPINVOKE.SWIGPendingException.Pending) - throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + GetParent()?.Remove(this); } /// diff --git a/Tizen.NUI/src/public/Container.cs b/Tizen.NUI/src/public/Container.cs index 1078d6a..a83f187 100755 --- a/Tizen.NUI/src/public/Container.cs +++ b/Tizen.NUI/src/public/Container.cs @@ -1,114 +1,125 @@ -/** 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.BaseComponents; - -namespace Tizen.NUI -{ - /// - /// - /// The Container is an abstract class to be inherited from by classes that desire to have views - /// added to them. - /// - /// - - public abstract class Container : Animatable - { - - internal Container(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn) - { - // No un-managed data hence no need to store a native ptr - } - - protected override void Dispose(DisposeTypes type) - { - if (disposed) - { - return; - } - - base.Dispose(type); - } - - - /// - /// Adds a child view to this Container. - /// - ///
This Container (the parent) has been initialized. The child view has been initialized. The child view is not the same as the parent view.
- /// The child will be referenced by its parent. This means that the child will be kept alive, even if the handle passed into this method is reset or destroyed. - /// If the child already has a parent, it will be removed from the old parent and reparented to this view. This may change child's position, color, scale, etc. as it now inherits them from this view. - /// The child view to add. - public abstract void Add( View view ); - - /// - /// Removes a child view from this view. If the view was not a child of this view, this is a no-op. - /// - ///
This view (the parent) has been initialized. The child view is not the same as the parent view.
- /// The child. - public abstract void Remove( View view ); - - /// - /// Retrieves the child view by the index. - /// - ///
The view has been initialized.
- /// The index of the child to retrieve. - /// The view for the given index or empty handle if children are not initialized. - public abstract View GetChildAt( uint index ); - - /// - /// Gets the parent of this container. - /// - ///
The child container has been initialized.
- /// The parent container. - protected abstract Container GetParent(); - - /// - /// Gets the number of children for this container. - /// - ///
The container has been initialized.
- /// The number of children. - protected abstract UInt32 GetChildCount(); - - /// - /// Gets the parent container. - /// Read only - /// - ///
The child container has been initialized.
- /// The parent container. - public Container Parent - { - get - { - return GetParent(); - } - } - - /// - /// Gets the number of children for this container. - /// Read only - /// - ///
The container has been initialized.
- /// The number of children. - public uint ChildCount - { - get - { - return GetChildCount(); - } - } - } +/** 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 System.Collections.Generic; +using Tizen.NUI.BaseComponents; + +namespace Tizen.NUI +{ + /// + /// + /// Container is an abstract class to be inherited from by classes that desire to have Views + /// added to them. + /// + /// + + public abstract class Container : Animatable + { + + private List _childViews = new List(); + + public List Children + { + get + { + return _childViews; + } + } + + internal Container(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn) + { + // No un-managed data hence no need to store a native ptr + } + + protected override void Dispose(DisposeTypes type) + { + if (disposed) + { + return; + } + + base.Dispose(type); + } + + + /// + /// Adds a child view to this Container. + /// + ///
This Container(the parent) has been initialized. The child view has been initialized. The child view is not the same as the parent view.
+ /// The child will be referenced by its parent. This means that the child will be kept alive, even if the handle passed into this method is reset or destroyed. + /// If the child already has a parent, it will be removed from old parent and reparented to this view. This may change child's position, color, scale etc as it now inherits them from this view. + /// The child view to add + public abstract void Add( View view ); + + /// + /// Removes a child View from this View. If the view was not a child of this view, this is a no-op. + /// + ///
This View(the parent) has been initialized. The child view is not the same as the parent view.
+ /// The child + public abstract void Remove( View view ); + + /// + /// Retrieves child view by index. + /// + ///
The View has been initialized.
+ /// The index of the child to retrieve + /// The view for the given index or empty handle if children not initialized + public abstract View GetChildAt( uint index ); + + /// + /// Get the parent of this container + /// + ///
The child container has been initialized.
+ /// The parent container + protected abstract Container GetParent(); + + /// + /// Get the number of children for this container + /// + ///
The container has been initialized.
+ /// number of children + protected abstract UInt32 GetChildCount(); + + /// + /// Get the parent Container + /// Read only + /// + ///
The child container has been initialized.
+ /// The parent container + public Container Parent + { + get + { + return GetParent(); + } + } + + /// + /// Get the number of children for this container + /// Read only + /// + ///
The container has been initialized.
+ /// number of children + public uint ChildCount + { + get + { + return GetChildCount(); + } + } + } } // namespace Tizen.NUI \ No newline at end of file diff --git a/Tizen.NUI/src/public/Layer.cs b/Tizen.NUI/src/public/Layer.cs index cc9dd25..e62d647 100755 --- a/Tizen.NUI/src/public/Layer.cs +++ b/Tizen.NUI/src/public/Layer.cs @@ -48,6 +48,8 @@ namespace Tizen.NUI NDalicPINVOKE.Actor_Add(swigCPtr, View.getCPtr(child)); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + + Children.Add(child); } /// @@ -60,6 +62,8 @@ namespace Tizen.NUI NDalicPINVOKE.Actor_Remove(swigCPtr, View.getCPtr(child)); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + + Children.Remove(child); } /// @@ -70,14 +74,14 @@ namespace Tizen.NUI /// The view for the given index or empty handle if children not initialized. public override View GetChildAt(uint index) { - System.IntPtr cPtr = NDalicPINVOKE.Actor_GetChildAt(swigCPtr, index); - - View ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as View; - - if (NDalicPINVOKE.SWIGPendingException.Pending) - throw NDalicPINVOKE.SWIGPendingException.Retrieve(); - - return ret ?? null; + if (index < Children.Count) + { + return Children[Convert.ToInt32(index)]; + } + else + { + return null; + } } @@ -88,10 +92,7 @@ namespace Tizen.NUI protected override uint GetChildCount() { - uint ret = NDalicPINVOKE.Actor_GetChildCount(swigCPtr); - if (NDalicPINVOKE.SWIGPendingException.Pending) - throw NDalicPINVOKE.SWIGPendingException.Retrieve(); - return ret; + return Convert.ToUInt32(Children.Count); } protected override void Dispose(DisposeTypes type) diff --git a/Tizen.NUI/src/public/Window.cs b/Tizen.NUI/src/public/Window.cs index 220424e..5c39f3f 100755 --- a/Tizen.NUI/src/public/Window.cs +++ b/Tizen.NUI/src/public/Window.cs @@ -600,14 +600,12 @@ namespace Tizen.NUI public void Add(View view) { - NDalicPINVOKE.Stage_Add(stageCPtr, View.getCPtr(view)); - if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + GetRootLayer()?.Add(view); } public void Remove(View view) { - NDalicPINVOKE.Stage_Remove(stageCPtr, View.getCPtr(view)); - if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + GetRootLayer()?.Remove(view); } internal Vector2 GetSize() @@ -647,11 +645,13 @@ namespace Tizen.NUI internal Layer GetRootLayer() { - if (_rootLayer == null) + // Window.IsInstalled() is actually true only when called from event thread and + // Core has been initialized, not when Stage is ready. + if (_rootLayer == null && Window.IsInstalled()) + { _rootLayer = new Layer(NDalicPINVOKE.Stage_GetRootLayer(stageCPtr), true); - - - if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } return _rootLayer; }