From 72bddc748ea026a7028fbc68a0ae1cecd5d95bf8 Mon Sep 17 00:00:00 2001 From: InHong Han Date: Fri, 9 Jul 2021 12:53:45 +0900 Subject: [PATCH] Supports dim and popup windows Change-Id: I2b4ee3fccec955a1a54906560dabe87e0b72f5e1 --- ISEDefaultNUI/DimView.cs | 57 +++++++++++ ISEDefaultNUI/Interop/Interop.SclNui.cs | 8 +- ISEDefaultNUI/MagnifierWindow.cs | 22 +---- ISEDefaultNUI/PopupWindow.cs | 82 +++++++++++++++ ISEDefaultNUI/SCLNUI.cs | 170 ++++++++++++++++++++++++++------ ISEDefaultNUI/WindowAttribute.cs | 43 ++++++++ 6 files changed, 333 insertions(+), 49 deletions(-) create mode 100644 ISEDefaultNUI/DimView.cs create mode 100644 ISEDefaultNUI/PopupWindow.cs create mode 100644 ISEDefaultNUI/WindowAttribute.cs diff --git a/ISEDefaultNUI/DimView.cs b/ISEDefaultNUI/DimView.cs new file mode 100644 index 0000000..96e97cc --- /dev/null +++ b/ISEDefaultNUI/DimView.cs @@ -0,0 +1,57 @@ +using Tizen.NUI; +using Tizen.NUI.BaseComponents; + +namespace ISEDefaultNUI +{ + public class DimView + { + private static DimView instance; + private View dimView; + + private DimView() + { + dimView = new View(); + } + + public static DimView Instance + { + get + { + if (instance == null) + instance = new DimView(); + + return instance; + } + } + + public void Show(View parent) + { + parent.Add(dimView); + } + + public void Hide() + { + dimView.Unparent(); + } + + public void SetWindowColor(WindowAttribute.BackgroundColor color) + { + dimView.BackgroundColor = new Color((float)(color.Red / 255.0), (float)(color.Green / 255.0), (float)(color.Blue / 255.0), (float)(color.Alpha / 255.0)); + } + + public void SetPosition(int x, int y) + { + dimView.Position = new Position(x, y); + } + + public void SetSize(float width, float height) + { + dimView.Size = new Size(width, height); + } + + public View GetDimView() + { + return dimView; + } + } +} diff --git a/ISEDefaultNUI/Interop/Interop.SclNui.cs b/ISEDefaultNUI/Interop/Interop.SclNui.cs index 4cfca8b..b06f93f 100644 --- a/ISEDefaultNUI/Interop/Interop.SclNui.cs +++ b/ISEDefaultNUI/Interop/Interop.SclNui.cs @@ -169,7 +169,7 @@ internal static partial class Interop [UnmanagedFunctionPointer(CallingConvention.Cdecl)] internal delegate void DrawRectangleCallback(int pos_x, int pos_y, int width, int height, - bool fill, int fill_color_r, int fill_color_g, int fill_color_b, int fill_color_a, IntPtr user_data); + bool fill, int fill_color_r, int fill_color_g, int fill_color_b, int fill_color_a, int type, IntPtr user_data); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] internal delegate void UpdateWindowCallback(int x, int y, int width, int height, IntPtr user_data); @@ -181,6 +181,9 @@ internal static partial class Interop internal delegate int DragStateChangedCallback(IntPtr eventDesc); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate int EventNotificationCallback(int notiType, IntPtr notiDesc); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] internal delegate void UpdateWindowPositionCallback(int type, int x, int y, int rotationX, int rotationY, IntPtr user_data); [DllImport(Libraries.SclNui, EntryPoint = "scl_nui_init")] @@ -234,6 +237,9 @@ internal static partial class Interop [DllImport(Libraries.SclNui, EntryPoint = "scl_nui_set_drag_state_changed_cb")] internal static extern int SclNuiDragStateChangedCb(DragStateChangedCallback callbackFunction); + [DllImport(Libraries.SclNui, EntryPoint = "scl_nui_set_event_notification_cb")] + internal static extern int SclNuiEventNotificationCb(EventNotificationCallback callbackFunction); + [DllImport(Libraries.SclNui, EntryPoint = "scl_nui_set_update_window_position_cb")] internal static extern int SclNuiUpdateWindowPositionCb(UpdateWindowPositionCallback callbackFunction, IntPtr userData); diff --git a/ISEDefaultNUI/MagnifierWindow.cs b/ISEDefaultNUI/MagnifierWindow.cs index 8bf28c4..e8a0c07 100644 --- a/ISEDefaultNUI/MagnifierWindow.cs +++ b/ISEDefaultNUI/MagnifierWindow.cs @@ -5,29 +5,13 @@ using Tizen; namespace ISEDefaultNUI { - public class MagnifierPosition - { - public int X; - public int Y; - public int rotationX; - public int rotationY; - - public MagnifierPosition(int X, int Y, int rotationX, int rotationY) - { - this.X = X; - this.Y = Y; - this.rotationX = rotationX; - this.rotationY = rotationY; - } - } - public class MagnifierWindow { private static MagnifierWindow instance; private Timer timer; private List imageList; private List labelList; - private MagnifierPosition position; + private WindowAttribute.Position position; private MagnifierWindow() { @@ -83,12 +67,12 @@ namespace ISEDefaultNUI imageList.Clear(); } - public void SetPosition(MagnifierPosition newPosition) + public void SetPosition(WindowAttribute.Position newPosition) { position = newPosition; } - public MagnifierPosition GetPosition() + public WindowAttribute.Position GetPosition() { return position; } diff --git a/ISEDefaultNUI/PopupWindow.cs b/ISEDefaultNUI/PopupWindow.cs new file mode 100644 index 0000000..4d56995 --- /dev/null +++ b/ISEDefaultNUI/PopupWindow.cs @@ -0,0 +1,82 @@ +using System.Collections.Generic; +using Tizen.NUI; +using Tizen.NUI.BaseComponents; +using Tizen; + +namespace ISEDefaultNUI +{ + public class PopupWindow + { + private static PopupWindow instance; + private List imageList; + private List labelList; + private bool isShowing; + + private PopupWindow() + { + imageList = new List(); + labelList = new List(); + isShowing = false; + } + + public static PopupWindow Instance + { + get + { + if (instance == null) + instance = new PopupWindow(); + + return instance; + } + } + + public void Show(View parent) + { + isShowing = true; + imageList.ForEach(image => parent.Add(image)); + labelList.ForEach(label => parent.Add(label)); + } + + public void Hide() + { + isShowing = false; + labelList.ForEach(label => + { + label.Unparent(); + label.Dispose(); + }); + + imageList.ForEach(image => + { + image.Unparent(); + image.Dispose(); + }); + + labelList.Clear(); + imageList.Clear(); + } + + public void AddImage(ImageView imageView) + { + imageList.Add(imageView); + } + + public void AddLabel(TextLabel textLabel) + { + labelList.Add(textLabel); + } + + public bool IsExists() + { + if (imageList.Count != 0 || labelList.Count != 0) + return true; + + return false; + } + + public bool IsShowing() + { + return isShowing; + } + } +} diff --git a/ISEDefaultNUI/SCLNUI.cs b/ISEDefaultNUI/SCLNUI.cs index 44145b3..47e8053 100644 --- a/ISEDefaultNUI/SCLNUI.cs +++ b/ISEDefaultNUI/SCLNUI.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Runtime.InteropServices; using Tizen; using Tizen.Applications; @@ -18,6 +19,7 @@ namespace ISEDefaultNUI private UpdateWindowCallback _update_window_cb = null; private KeyClickEventCallback _onKeyClickEvent = null; private DragStateChangedCallback _onDragStateChangedEvent = null; + private EventNotificationCallback _onEventNotification = null; private UpdateWindowPositionCallback _updateWindowPositionChangedEvent = null; private List image_list; @@ -32,6 +34,8 @@ namespace ISEDefaultNUI private int afterPositionX = 0; private MagnifierWindow magnifier = MagnifierWindow.Instance; + private DimView dim = DimView.Instance; + private PopupWindow popup = PopupWindow.Instance; enum LabelAlignment { @@ -55,6 +59,19 @@ namespace ISEDefaultNUI Popup, } + enum NotificationType + { + PopupOpening = 0, + PopupOpened, + PopupClosing, + PopupClosed, + GestureFlick, + ShiftStateChange, + InputModeChange, + HighlightNavigate, + Max, + } + struct SclPoint { public int x, y; @@ -86,21 +103,36 @@ namespace ISEDefaultNUI string keystr = Marshal.PtrToStringAnsi(str); WindowType windowType = (WindowType)type; - if (windowType == WindowType.Magnifier) + switch (windowType) { - MagnifierPosition magnifierPosition = magnifier.GetPosition(); - TextLabel magnifierText = draw_text(FontName, font_size, is_italic, is_bold, r, g, b, a, - keystr, magnifierPosition.X, magnifierPosition.Y, width, height, - align, padding_x, padding_y, inner_width, inner_height); - magnifier.AddLabel(magnifierText); - } - else - { - keyText = draw_text(FontName, font_size, is_italic, is_bold, r, g, b, a, + case WindowType.Keypad: + { + keyText = draw_text(FontName, font_size, is_italic, is_bold, r, g, b, a, keystr, pos_x, pos_y, width, height, align, padding_x, padding_y, inner_width, inner_height); - Add(keyText); - label_list.Add(keyText); + Add(keyText); + label_list.Add(keyText); + break; + } + case WindowType.Magnifier: + { + WindowAttribute.Position magnifierPosition = magnifier.GetPosition(); + TextLabel magnifierText = draw_text(FontName, font_size, is_italic, is_bold, r, g, b, a, + keystr, magnifierPosition.X, magnifierPosition.Y, width, height, + align, padding_x, padding_y, inner_width, inner_height); + magnifier.AddLabel(magnifierText); + break; + } + case WindowType.Popup: + { + TextLabel popupText = draw_text(FontName, font_size, is_italic, is_bold, r, g, b, a, + keystr, pos_x, pos_y, width, height, + align, padding_x, padding_y, inner_width, inner_height); + popup.AddLabel(popupText); + break; + } + default: + break; } }; SclNuiSetDrawTextCb(_draw_text_cb, (IntPtr)null); @@ -114,29 +146,78 @@ namespace ISEDefaultNUI if (image_path_str.EndsWith("/")) return; - if (windowType == WindowType.Magnifier) + switch (windowType) { - MagnifierPosition magnifierPosition = magnifier.GetPosition(); - ImageView magnifierImageView = draw_image(image_path_str, magnifierPosition.X, magnifierPosition.Y, dest_weight, dest_height, src_x, src_y, src_width, src_height); - magnifier.AddImage(magnifierImageView); - } - else - { - imageView = draw_image(image_path_str, dest_x, dest_y, dest_weight, dest_height, src_x, src_y, src_width, src_height); - Add(imageView); - image_list.Add(imageView); + case WindowType.Keypad: + { + if (popup.IsShowing()) + { + ImageView imageView = image_list.Find(image => image.Position.X == dest_x && image.Position.Y == dest_y && + image.Size.Width == dest_weight && image.Size.Height == dest_height); + + if (imageView != null) + { + imageView.ResourceUrl = image_path_str; + int dimOrder = DimView.Instance.GetDimView().SiblingOrder; + imageView.SiblingOrder = dimOrder - 1; + } + } + else + { + imageView = draw_image(image_path_str, dest_x, dest_y, dest_weight, dest_height, src_x, src_y, src_width, src_height); + Add(imageView); + image_list.Add(imageView); + } + break; + } + case WindowType.Magnifier: + { + WindowAttribute.Position magnifierPosition = magnifier.GetPosition(); + ImageView magnifierImageView = draw_image(image_path_str, magnifierPosition.X, magnifierPosition.Y, dest_weight, dest_height, src_x, src_y, src_width, src_height); + magnifier.AddImage(magnifierImageView); + break; + } + case WindowType.Popup: + { + ImageView popupImageView = draw_image(image_path_str, dest_x, dest_y, dest_weight, dest_height, src_x, src_y, src_width, src_height); + popup.AddImage(popupImageView); + break; + } + default: + break; } }; SclNuiSetDrawImageCb(_draw_image_cb, (IntPtr)null); /* Draw rectangle */ - _draw_rectangle_cb = (int pos_x, int pos_y, int width, int height, bool fill, int fill_color_r, int fill_color_g, int fill_color_b, int fill_color_a, IntPtr user_data) => + _draw_rectangle_cb = (int pos_x, int pos_y, int width, int height, bool fill, int fill_color_r, int fill_color_g, int fill_color_b, int fill_color_a, int type, IntPtr user_data) => { Log.Info("NUIIME", "rectangle: x=" + pos_x + ", y=" + pos_y + ", w=" + width + ", h=" + height); Log.Info("NUIIME", "fill: " + fill + ", r=" + fill_color_r + ", g=" + fill_color_g + ", b=" + fill_color_b + ", a=" + fill_color_a); - rectView = draw_rectangle(pos_x, pos_y, width, height, fill, fill_color_r, fill_color_g, fill_color_b, fill_color_a); - Add(rectView); + WindowType windowType = (WindowType)type; + switch (windowType) + { + case WindowType.Keypad: + { + rectView = draw_rectangle(pos_x, pos_y, width, height, fill, fill_color_r, fill_color_g, fill_color_b, fill_color_a); + Add(rectView); + break; + } + case WindowType.Dim: + { + dim.SetWindowColor(new WindowAttribute.BackgroundColor(fill_color_r, fill_color_g, fill_color_b, fill_color_a)); + dim.SetPosition(pos_x, pos_y); + dim.SetSize(720, 442); + break; + } + case WindowType.Popup: + { + break; + } + default: + break; + } }; SclNuiSetDrawRectangleCb(_draw_rectangle_cb, (IntPtr)null); @@ -144,7 +225,8 @@ namespace ISEDefaultNUI { Log.Info("NUIIME", "update_window"); - UpdateArea(x, y, width, height); + if (!popup.IsShowing()) + UpdateArea(x, y, width, height); if (magnifier.IsExists() && !magnifier.IsRunning()) magnifier.Show(this); @@ -209,12 +291,42 @@ namespace ISEDefaultNUI }; SclNuiDragStateChangedCb(_onDragStateChangedEvent); + _onEventNotification = (int notificationType, IntPtr eventDesc) => + { + NotificationType type = (NotificationType)notificationType; + + if (type == NotificationType.PopupOpened) + { + if (popup.IsExists() && !popup.IsShowing()) + { + dim.Show(this); + popup.Show(this); + } + } + else if (type == NotificationType.PopupClosing) + { + popup.Hide(); + dim.Hide(); + } + + return (int)SclNuiEventReturnType.PassOn; + }; + SclNuiEventNotificationCb(_onEventNotification); + Window.Instance.TouchEvent += OnWindowTouched; Window.Instance.Resized += OnResized; BackKeyPressed += (object source, EventArgs args) => { - NUIApplication.Current.Exit(); + if (popup.IsShowing()) + { + popup.Hide(); + dim.Hide(); + } + else + { + NUIApplication.Current.Exit(); + } }; Preference.EventContext context = null; @@ -227,9 +339,10 @@ namespace ISEDefaultNUI _updateWindowPositionChangedEvent = (int type, int x, int y, int rotationX, int rotationY, IntPtr user_data) => { WindowType windowType = (WindowType)type; + if (windowType == WindowType.Magnifier) { - magnifier.SetPosition(new MagnifierPosition(x, y, rotationX, rotationY)); + magnifier.SetPosition(new WindowAttribute.Position(x, y, rotationX, rotationY)); } }; SclNuiUpdateWindowPositionCb(_updateWindowPositionChangedEvent, (IntPtr)null); @@ -393,7 +506,6 @@ namespace ISEDefaultNUI { Log.Info("NUIIME", "### start draw image"); - ImageView imageView = new ImageView(image_path_str); imageView.Position = new Position(dest_x, dest_y); imageView.Size = new Size(dest_weight, dest_height); diff --git a/ISEDefaultNUI/WindowAttribute.cs b/ISEDefaultNUI/WindowAttribute.cs new file mode 100644 index 0000000..ee1cc1b --- /dev/null +++ b/ISEDefaultNUI/WindowAttribute.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ISEDefaultNUI +{ + public class WindowAttribute + { + public class BackgroundColor + { + public int Red; + public int Green; + public int Blue; + public int Alpha; + + public BackgroundColor(int r, int g, int b, int a) + { + Red = r; + Green = g; + Blue = b; + Alpha = a; + } + } + + public class Position + { + public int X; + public int Y; + public int rotationX; + public int rotationY; + + public Position(int X, int Y, int rotationX, int rotationY) + { + this.X = X; + this.Y = Y; + this.rotationX = rotationX; + this.rotationY = rotationY; + } + } + } +} -- 2.7.4