[NUI] Supports window background blur.
authorWonsik Jung <sidein@samsung.com>
Wed, 28 Aug 2024 08:40:08 +0000 (17:40 +0900)
committerSangHyeon Jade Lee <dltkdgus1764@gmail.com>
Wed, 4 Sep 2024 09:37:54 +0000 (18:37 +0900)
Supports window background blur.
This new APIs is to request window blur to window manager.
Next time, behind blur will be added.

src/Tizen.NUI/src/internal/Interop/Interop.Window.cs
src/Tizen.NUI/src/internal/Interop/Interop.WindowBlurInfo.cs [new file with mode: 0644]
src/Tizen.NUI/src/public/Common/NUIConstants.cs
src/Tizen.NUI/src/public/Window/Window.cs
src/Tizen.NUI/src/public/Window/WindowBlurInfo.cs [new file with mode: 0644]
test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/WindowTest1.cs

index ffd7ce6f88f91b283e142cbc2389ae0c3b7e8e8e..19d41f90abdaa95970f95b4f39bbee1d72b6d56d 100755 (executable)
@@ -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 (file)
index 0000000..6114c12
--- /dev/null
@@ -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);
+        }
+    }
+}
index 65523d4d70a455471b44082db50110fa3ed69228..afbae4b2723a3712949e394c36a35d83e00302c7 100755 (executable)
@@ -783,7 +783,7 @@ namespace Tizen.NUI
         /// This is a desktop type. No other windows can be placed below this type of window.
         /// </summary>
         [EditorBrowsable(EditorBrowsableState.Never)]
-        Desktop        
+        Desktop
     }
 
     /// <summary>
@@ -2294,4 +2294,23 @@ namespace Tizen.NUI
             }
         }
     }
+
+    /// <summary>
+    /// Enumeration of window blur type.
+    /// </summary>
+    [EditorBrowsable(EditorBrowsableState.Never)]
+    public enum WindowBlurType
+    {
+        /// <summary>
+        /// None type.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        None = 0,
+        /// <summary>
+        /// background blur for the window.
+        /// It has a blur effect ot th background area of the window, making it appear blurred.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        Background = 1,
+    }
 }
index 1567a5ccc7472009e63986e22f066329a4a998a3..0206089390640f4e9579f59a2f7c382db7b97a6a 100755 (executable)
@@ -2611,6 +2611,46 @@ namespace Tizen.NUI
             return ret;
         }
 
+        /// <summary>
+        /// 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.
+        /// </summary>
+        [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 (file)
index 0000000..206bd7c
--- /dev/null
@@ -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
+{
+    /// <summary>
+    /// 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.
+    /// </summary>
+    [EditorBrowsable(EditorBrowsableState.Never)]
+    public struct WindowBlurInfo
+    {
+        /// <summary>
+        /// The construct with blur type, radius and corner radius for background type.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public WindowBlurInfo(WindowBlurType blurType, int blurRadius, int cornerRadius)
+        {
+            BlurType = blurType;
+            BlurRadius = blurRadius;
+            BackgroundCornerRadius = cornerRadius;
+        }
+
+        /// <summary>
+        /// The construct with blur type and radius.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public WindowBlurInfo(WindowBlurType blurType, int blurRadius)
+        {
+            BlurType = blurType;
+            BlurRadius = blurRadius;
+            BackgroundCornerRadius = 0;            
+        }
+
+        /// <summary>
+        /// Gets or sets the blur type of the window.
+        /// </summary>
+        /// <value>The window blur type of the window.</value>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public WindowBlurType BlurType {get; set;}
+
+        /// <summary>
+        /// Gets or sets the blur radius of the window.
+        /// </summary>
+        /// <value>The blur radius of the window.</value>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public int BlurRadius {get; set;}
+
+        /// <summary>
+        /// 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.
+        /// </summary>
+        /// <value>The corner radius of the window.</value>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public int BackgroundCornerRadius {get; set;}
+    }
+}
index bc61186a13c441d8a47b174a9ee9e1609aba6852..1da43a490b95bfa6f83878741b7731499c4d4b67 100644 (file)
@@ -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<int>("http://tizen.org/feature/screen.width", out screenWidth);
       Information.TryGetValue<int>("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: