From 0b2ed36f5882d3ae9ef079529c7529ea1d264892 Mon Sep 17 00:00:00 2001 From: Wonsik Jung Date: Tue, 4 Oct 2022 10:18:14 +0900 Subject: [PATCH] [NUI] Supports new native window position data type. Previous native window data type can not support negative window coordinates. New native window position data type support that. --- .../src/internal/Interop/Interop.WindowIntPair.cs | 45 +++++++++ src/Tizen.NUI/src/internal/Window/WindowIntPair.cs | 102 +++++++++++++++++++++ .../src/internal/Window/WindowMovedSignal.cs | 4 +- src/Tizen.NUI/src/public/Window/Window.cs | 8 +- .../Tizen.NUI.Samples/Samples/BorderWindowTest.cs | 54 +++++++++++ 5 files changed, 207 insertions(+), 6 deletions(-) create mode 100644 src/Tizen.NUI/src/internal/Interop/Interop.WindowIntPair.cs create mode 100644 src/Tizen.NUI/src/internal/Window/WindowIntPair.cs diff --git a/src/Tizen.NUI/src/internal/Interop/Interop.WindowIntPair.cs b/src/Tizen.NUI/src/internal/Interop/Interop.WindowIntPair.cs new file mode 100644 index 0000000..2937a58 --- /dev/null +++ b/src/Tizen.NUI/src/internal/Interop/Interop.WindowIntPair.cs @@ -0,0 +1,45 @@ +/* + * Copyright(c) 2021 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. + * + */ +namespace Tizen.NUI +{ + internal static partial class Interop + { + internal static partial class IntPair + { + [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_new_IntPair__SWIG_0")] + public static extern global::System.IntPtr NewIntPair(); + + [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_new_IntPair__SWIG_1")] + public static extern global::System.IntPtr NewIntPair(int x, int y); + + [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_IntPair_SetX")] + public static extern void SetX(global::System.Runtime.InteropServices.HandleRef handle, int x); + + [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_IntPair_GetX")] + public static extern int GetX(global::System.Runtime.InteropServices.HandleRef handle); + + [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_IntPair_SetY")] + public static extern void SetY(global::System.Runtime.InteropServices.HandleRef handle, int y); + + [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_IntPair_GetY")] + public static extern int GetY(global::System.Runtime.InteropServices.HandleRef handle); + + [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_delete_IntPair")] + public static extern void DeleteIntPair(global::System.Runtime.InteropServices.HandleRef handle); + } + } +} diff --git a/src/Tizen.NUI/src/internal/Window/WindowIntPair.cs b/src/Tizen.NUI/src/internal/Window/WindowIntPair.cs new file mode 100644 index 0000000..74dcd02 --- /dev/null +++ b/src/Tizen.NUI/src/internal/Window/WindowIntPair.cs @@ -0,0 +1,102 @@ +/* + * Copyright(c) 2021 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.ComponentModel; + +namespace Tizen.NUI +{ + /// + /// Simple class for window position pairs of integers. + /// Use this for integer position with window coordinates. + /// + internal class IntPair : Disposable + { + internal IntPair(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn) + { + } + + protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr) + { + Interop.IntPair.DeleteIntPair(swigCPtr); + } + + /// + /// Default constructor for the(0, 0) tuple. + /// + public IntPair() : this(Interop.IntPair.NewIntPair(), true) + { + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + + /// + /// Default constructor for the(0, 0) tuple. + /// + /// The X dimension of the tuple. + /// The Y dimension of the tuple. + public IntPair(int x, int y) : this(Interop.IntPair.NewIntPair(x, y), true) + { + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + + /// + /// Sets the x dimension. + /// + /// The x dimension to be stored in this 2-tuple. + public void SetX(int x) + { + Interop.IntPair.SetX(SwigCPtr, x); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + + /// + /// Get the x dimension. + /// + /// + /// The x dimension stored in this 2-tuple. + /// + public int GetX() + { + int ret = Interop.IntPair.GetX(SwigCPtr); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; + } + + /// + /// Sets the y dimension. + /// + /// The y dimension to be stored in this 2-tuple. + public void SetY(int y) + { + Interop.IntPair.SetY(SwigCPtr, y); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + + /// + /// Get the y dimension. + /// + /// + /// The y dimension stored in this 2-tuple. + /// + public int GetY() + { + int ret = Interop.IntPair.GetY(SwigCPtr); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; + } + } +} diff --git a/src/Tizen.NUI/src/internal/Window/WindowMovedSignal.cs b/src/Tizen.NUI/src/internal/Window/WindowMovedSignal.cs index a6bf9ad..e74202b 100644 --- a/src/Tizen.NUI/src/internal/Window/WindowMovedSignal.cs +++ b/src/Tizen.NUI/src/internal/Window/WindowMovedSignal.cs @@ -62,9 +62,9 @@ namespace Tizen.NUI } } - public bool Emit(Window window, Rectangle positionSize) + public bool Emit(Window window, Position2D position) { - bool ret = Interop.WindowMovedSignal.Emit(SwigCPtr, Window.getCPtr(window), Rectangle.getCPtr(positionSize)); + bool ret = Interop.WindowMovedSignal.Emit(SwigCPtr, Window.getCPtr(window), Position2D.getCPtr(position)); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } diff --git a/src/Tizen.NUI/src/public/Window/Window.cs b/src/Tizen.NUI/src/public/Window/Window.cs index 448cceb..f0e9568 100755 --- a/src/Tizen.NUI/src/public/Window/Window.cs +++ b/src/Tizen.NUI/src/public/Window/Window.cs @@ -1569,8 +1569,8 @@ private void TestWindowKeyEventHandler(object o, Window.KeyEventArgs e) { throw new ArgumentNullException(nameof(position)); } - var val = new Uint16Pair((uint)position.X, (uint)position.Y); - Interop.Window.SetPosition(SwigCPtr, Uint16Pair.getCPtr(val)); + var val = new IntPair(position.X, position.Y); + Interop.Window.SetPosition(SwigCPtr, IntPair.getCPtr(val)); val.Dispose(); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); // Setting Position of the window should request a relayout of the tree. @@ -1578,8 +1578,8 @@ private void TestWindowKeyEventHandler(object o, Window.KeyEventArgs e) internal Position2D GetPosition() { - var val = new Uint16Pair(Interop.Window.GetPosition(SwigCPtr), true); - Position2D ret = new Position2D(val.GetX(), val.GetY()); + var val = new IntPair(Interop.Window.GetPosition(SwigCPtr), true); + Position2D ret = new Position2D((int)val.GetX(), (int)val.GetY()); val.Dispose(); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; diff --git a/test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/BorderWindowTest.cs b/test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/BorderWindowTest.cs index 1196587..d26eaa1 100755 --- a/test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/BorderWindowTest.cs +++ b/test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/BorderWindowTest.cs @@ -12,6 +12,16 @@ namespace Tizen.NUI.Samples public class BorderWindowTest : IExample { string tag = "NUITEST"; + private const string KEY_BACK = "XF86Back"; + private const string KEY_ESCAPE = "Escape"; + private const string KEY_NUM_1 = "1"; + private const string KEY_NUM_2 = "2"; + private const string KEY_NUM_3 = "3"; + private const string KEY_NUM_4 = "4"; + private const string KEY_NUM_5 = "5"; + private const string KEY_PARENT_ABOVE = "6"; + private const string KEY_PARENT_BELOW = "7"; + private Window win; private Window subWindowOne = null; private Window subWindowTwo = null; @@ -269,6 +279,49 @@ namespace Tizen.NUI.Samples } + private void OnKeyEvent(object sender, Window.KeyEventArgs e) + { + if (e.Key.State == Key.StateType.Down) + { + log.Debug(tag, $"key down! key={e.Key.KeyPressedName}"); + + switch (e.Key.KeyPressedName) + { + case KEY_BACK: + case KEY_ESCAPE: + break; + + case KEY_NUM_1: + subWindowOne.WindowPosition = new Position2D(10, 20); + break; + + case KEY_NUM_2: + subWindowOne.WindowPosition = new Position2D(-10, 20); + break; + + case KEY_NUM_3: + + break; + + case KEY_NUM_4: + break; + + case KEY_NUM_5: + break; + + case KEY_PARENT_ABOVE: + break; + + case KEY_PARENT_BELOW: + break; + + default: + log.Debug(tag, $"no test!"); + break; + } + } + } + private void OnWindowMoved(object sender, WindowMovedEventArgs e) { Position2D position = e.WindowPosition; @@ -305,6 +358,7 @@ namespace Tizen.NUI.Samples animation.Looping = true; animation.Play(); + subWindowOne.KeyEvent += OnKeyEvent; subWindowOne.Moved += OnWindowMoved; } else -- 2.7.4