From a6022005fe050ed1614f9023c31e0031e1a56a7a Mon Sep 17 00:00:00 2001 From: Wonsik Jung Date: Wed, 28 Aug 2024 17:40:08 +0900 Subject: [PATCH] [NUI] Supports window background blur. Supports window background blur. This new APIs is to request window blur to window manager. Next time, behind blur will be added. --- .../src/internal/Interop/Interop.Window.cs | 6 ++ .../Interop/Interop.WindowBlurInfo.cs | 61 ++++++++++++++ .../src/public/Common/NUIConstants.cs | 21 ++++- src/Tizen.NUI/src/public/Window/Window.cs | 40 ++++++++++ .../src/public/Window/WindowBlurInfo.cs | 80 +++++++++++++++++++ .../Tizen.NUI.Samples/Samples/WindowTest1.cs | 17 +++- 6 files changed, 223 insertions(+), 2 deletions(-) create mode 100644 src/Tizen.NUI/src/internal/Interop/Interop.WindowBlurInfo.cs create mode 100644 src/Tizen.NUI/src/public/Window/WindowBlurInfo.cs diff --git a/src/Tizen.NUI/src/internal/Interop/Interop.Window.cs b/src/Tizen.NUI/src/internal/Interop/Interop.Window.cs index ffd7ce6f8..19d41f90a 100755 --- a/src/Tizen.NUI/src/internal/Interop/Interop.Window.cs +++ b/src/Tizen.NUI/src/internal/Interop/Interop.Window.cs @@ -392,6 +392,12 @@ namespace Tizen.NUI [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_Window_RelativeMotionUnGrab")] [return: global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.U1)] public static extern bool RelativeMotionUnGrab(global::System.Runtime.InteropServices.HandleRef window); + + [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_Window_SetBlur")] + public static extern void SetBlur(global::System.Runtime.InteropServices.HandleRef window, global::System.IntPtr blurInfo); + + [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_Window_GetBlur")] + public static extern global::System.IntPtr GetBlur(global::System.Runtime.InteropServices.HandleRef window); } } } diff --git a/src/Tizen.NUI/src/internal/Interop/Interop.WindowBlurInfo.cs b/src/Tizen.NUI/src/internal/Interop/Interop.WindowBlurInfo.cs new file mode 100644 index 000000000..6114c1216 --- /dev/null +++ b/src/Tizen.NUI/src/internal/Interop/Interop.WindowBlurInfo.cs @@ -0,0 +1,61 @@ +/* + * Copyright(c) 2024 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.Runtime.InteropServices; + +namespace Tizen.NUI +{ + internal static partial class Interop + { + internal static partial class WindowBlurInfo + { + [DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_new_WindowBlurInfo")] + public static extern global::System.IntPtr New(); + + [DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_new_WindowBlurInfo_SWIG_0")] + public static extern global::System.IntPtr New(int nuiBlurType, int nuiBlurRadius, int nuiCornerRadius); + + [DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_new_WindowBlurInfo_SWIG_1")] + public static extern global::System.IntPtr New(int nuiBlurType, int nuiBlurRadius); + + [DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_delete_WindowBlurInfo")] + public static extern void DeleteWindowBlurInfo(global::System.IntPtr nuiWindowBlurInfo); + + [DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_WindowBlurInfo_EqualTo")] + [return: global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.U1)] + public static extern bool EqualTo(global::System.IntPtr nuiWindowBlurInfo1, global::System.IntPtr nuiWindowBlurInfo2); + + [DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_WindowBlurInfo_SetBlurType")] + public static extern void SetBlurType(global::System.IntPtr nuiWindowBlurInfo, int nuiWindowBlurType); + + [DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_WindowBlurInfo_GetBlurType")] + public static extern int GetBlurType(global::System.IntPtr nuiWindowBlurInfo); + + [DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_WindowBlurInfo_SetBlurRadius")] + public static extern void SetBlurRadius(global::System.IntPtr nuiWindowBlurInfo, int nuiWindowBlurRadius); + + [DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_WindowBlurInfo_GetBlurRadius")] + public static extern int GetBlurRadius(global::System.IntPtr nuiWindowBlurInfo); + + [DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_WindowBlurInfo_SetBackgroundCornerRadius")] + public static extern void SetBackgroundCornerRadius(global::System.IntPtr nuiWindowBlurInfo, int nuiCornerRadius); + + [DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_WindowBlurInfo_GetBackgroundCornerRadius")] + public static extern int GetBackgroundCornerRadius(global::System.IntPtr nuiWindowBlurInfo); + } + } +} diff --git a/src/Tizen.NUI/src/public/Common/NUIConstants.cs b/src/Tizen.NUI/src/public/Common/NUIConstants.cs index 65523d4d7..afbae4b27 100755 --- a/src/Tizen.NUI/src/public/Common/NUIConstants.cs +++ b/src/Tizen.NUI/src/public/Common/NUIConstants.cs @@ -783,7 +783,7 @@ namespace Tizen.NUI /// This is a desktop type. No other windows can be placed below this type of window. /// [EditorBrowsable(EditorBrowsableState.Never)] - Desktop + Desktop } /// @@ -2294,4 +2294,23 @@ namespace Tizen.NUI } } } + + /// + /// Enumeration of window blur type. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public enum WindowBlurType + { + /// + /// None type. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + None = 0, + /// + /// background blur for the window. + /// It has a blur effect ot th background area of the window, making it appear blurred. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + Background = 1, + } } diff --git a/src/Tizen.NUI/src/public/Window/Window.cs b/src/Tizen.NUI/src/public/Window/Window.cs index 1567a5ccc..020608939 100755 --- a/src/Tizen.NUI/src/public/Window/Window.cs +++ b/src/Tizen.NUI/src/public/Window/Window.cs @@ -2611,6 +2611,46 @@ namespace Tizen.NUI return ret; } + /// + /// Sets or gets the window blur using window blur information. + /// + /// It is designed to apply a blur effect to a window based on specified parameters. + /// This supports different types of blurring effects, including blurring the window's background only. + /// Or blurring the area surrounding the window while keeping the window itself clear. + /// The more information is written WindowBlurInfo struct. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public WindowBlurInfo BlurInfo + { + get + { + IntPtr internalBlurInfo = Interop.Window.GetBlur(SwigCPtr); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + + WindowBlurInfo blurInfo = new WindowBlurInfo(); + blurInfo.BlurType = (WindowBlurType)Interop.WindowBlurInfo.GetBlurType(internalBlurInfo); + blurInfo.BlurRadius = Interop.WindowBlurInfo.GetBlurRadius(internalBlurInfo); + blurInfo.BackgroundCornerRadius = Interop.WindowBlurInfo.GetBackgroundCornerRadius(internalBlurInfo); + + Interop.WindowBlurInfo.DeleteWindowBlurInfo(internalBlurInfo); + + return blurInfo; + } + set + { + IntPtr internalBlurInfo = Interop.WindowBlurInfo.New((int)value.BlurType, value.BlurRadius, value.BackgroundCornerRadius); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + + try { + Interop.Window.SetBlur(SwigCPtr, internalBlurInfo); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + finally { + Interop.WindowBlurInfo.DeleteWindowBlurInfo(internalBlurInfo); + } + } + } + IntPtr IWindowProvider.WindowHandle => GetNativeWindowHandler(); float IWindowProvider.X => WindowPosition.X; float IWindowProvider.Y => WindowPosition.Y; diff --git a/src/Tizen.NUI/src/public/Window/WindowBlurInfo.cs b/src/Tizen.NUI/src/public/Window/WindowBlurInfo.cs new file mode 100644 index 000000000..206bd7cae --- /dev/null +++ b/src/Tizen.NUI/src/public/Window/WindowBlurInfo.cs @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2023 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; +using Tizen.NUI.Binding; + +namespace Tizen.NUI +{ + /// + /// WindowBlurInfo is a struct designed to encapsulate the information required to apply a blur effect to a window. + /// It contains three properties that define how the blur effect is applied to the window, + /// including the type of blur, its intensity, and the corner rounding for the background blur. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public struct WindowBlurInfo + { + /// + /// The construct with blur type, radius and corner radius for background type. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public WindowBlurInfo(WindowBlurType blurType, int blurRadius, int cornerRadius) + { + BlurType = blurType; + BlurRadius = blurRadius; + BackgroundCornerRadius = cornerRadius; + } + + /// + /// The construct with blur type and radius. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public WindowBlurInfo(WindowBlurType blurType, int blurRadius) + { + BlurType = blurType; + BlurRadius = blurRadius; + BackgroundCornerRadius = 0; + } + + /// + /// Gets or sets the blur type of the window. + /// + /// The window blur type of the window. + [EditorBrowsable(EditorBrowsableState.Never)] + public WindowBlurType BlurType {get; set;} + + /// + /// Gets or sets the blur radius of the window. + /// + /// The blur radius of the window. + [EditorBrowsable(EditorBrowsableState.Never)] + public int BlurRadius {get; set;} + + /// + /// Gets or sets the corner radius of the window. + /// It is only useful when window blur type is background. + /// + /// When applying the background corner radius, ensure that the window's own corner radius is applied first. + /// The blur effect will respect the window's pre-defined corner radius settings + /// before applying the specified background corner radius. + /// + /// The corner radius of the window. + [EditorBrowsable(EditorBrowsableState.Never)] + public int BackgroundCornerRadius {get; set;} + } +} diff --git a/test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/WindowTest1.cs b/test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/WindowTest1.cs index bc61186a1..1da43a490 100644 --- a/test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/WindowTest1.cs +++ b/test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/WindowTest1.cs @@ -291,6 +291,9 @@ namespace Tizen.NUI.Samples mainWin.TouchEvent += WinTouchEvent; mainWin.BackgroundColor = Color.Cyan; + Rectangle rec = new Rectangle(20, 10, 400, 300); + mainWin.WindowPositionSize = rec; + Information.TryGetValue("http://tizen.org/feature/screen.width", out screenWidth); Information.TryGetValue("http://tizen.org/feature/screen.height", out screenHeight); log.Fatal(tag, $"Initialize= screenWidth {screenWidth}, screenHeight {screenHeight} "); @@ -416,6 +419,9 @@ namespace Tizen.NUI.Samples return false; }; + subWindow.SetTransparency(true); + subWindow.BackgroundColor = new Color(0.0f, 0.0f, 0.0f, 0.0f); + var root = new View() { Layout = new LinearLayout() @@ -424,7 +430,6 @@ namespace Tizen.NUI.Samples }, WidthResizePolicy = ResizePolicyType.FillToParent, HeightResizePolicy = ResizePolicyType.FillToParent, - BackgroundColor = Color.Brown, }; var image = new ImageView() @@ -451,6 +456,8 @@ namespace Tizen.NUI.Samples subWindow.KeyEvent += OnSubWindowKeyEvent; subWindow.MoveCompleted += OnSubWindowMoveCompleted; subWindow.ResizeCompleted += OnSubWindowResizeCompleted; + + subWindow.BlurInfo = new WindowBlurInfo(WindowBlurType.Background, 10, 50); } else { @@ -569,6 +576,14 @@ namespace Tizen.NUI.Samples break; case KEY_NUM_8: + WindowBlurInfo blurInfo = subWindow.BlurInfo; + log.Fatal(tag, $"blur type={blurInfo.BlurType}"); + log.Fatal(tag, $"blur radius={blurInfo.BlurRadius}"); + log.Fatal(tag, $"background Corner Radius={blurInfo.BackgroundCornerRadius}"); + blurInfo.BlurType = WindowBlurType.Background; + blurInfo.BlurRadius += 10; + blurInfo.BackgroundCornerRadius += 10; + subWindow.BlurInfo = blurInfo; break; case KEY_NUM_9: -- 2.34.1