Interop.Window.delete_Window(swigCPtr);
}
+ private static Dictionary<int, internalHookCallbackType> frameCallbackList = new Dictionary<int, internalHookCallbackType>();
+
+ private static readonly object locker = new object();
+
+ private static int key = 0;
+
+ private static FrameCallbackType internalHookFrameCallback = OnInternalHookFrameCallback;
+
+ private struct internalHookCallbackType
+ {
+ public FrameCallbackType userCallback;
+ public int frameId;
+ }
+
+ private static void OnInternalHookFrameCallback(int id)
+ {
+ lock (locker)
+ {
+ if (frameCallbackList.ContainsKey(id))
+ {
+ if (frameCallbackList[id].userCallback != null)
+ {
+ frameCallbackList[id].userCallback.Invoke(frameCallbackList[id].frameId);
+ frameCallbackList.Remove(id);
+ }
+ else
+ {
+ NUILog.Error($"found userCallback is NULL");
+ frameCallbackList.Remove(id);
+ }
+ }
+ }
+ }
+
+ private int AddInterHookCallback(FrameCallbackType callback, int frameId)
+ {
+ if (null == callback)
+ {
+ throw new ArgumentNullException(nameof(callback), "FrameCallbackType should not be null");
+ }
+ var assignedKey = 0;
+ lock (locker)
+ {
+ key++;
+ assignedKey = key;
+ frameCallbackList.Add(assignedKey, new internalHookCallbackType()
+ {
+ userCallback = callback,
+ frameId = frameId,
+ });
+ }
+ return assignedKey;
+ }
+
/// <summary>
/// Type of callback which is called when the frame rendering is done by graphics driver or when the frame is displayed on display.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public void AddFrameRenderedCallback(FrameCallbackType callback, int frameId)
{
- IntPtr ip = Marshal.GetFunctionPointerForDelegate<Delegate>(callback);
-
- if (IntPtr.Zero == ip)
- {
- throw new ArgumentNullException(nameof(callback), "FrameCallbackType should not be null");
- }
-
- Interop.WindowInternal.AddFrameRenderedCallback(swigCPtr, new HandleRef(this, ip), frameId);
+ var assignedKey = AddInterHookCallback(callback, frameId);
+ Interop.WindowInternal.AddFrameRenderedCallback(swigCPtr, new HandleRef(this, Marshal.GetFunctionPointerForDelegate<Delegate>(internalHookFrameCallback)), assignedKey);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
[EditorBrowsable(EditorBrowsableState.Never)]
public void AddFramePresentedCallback(FrameCallbackType callback, int frameId)
{
- IntPtr ip = Marshal.GetFunctionPointerForDelegate<Delegate>(callback);
-
- if (IntPtr.Zero == ip)
- {
- throw new ArgumentNullException(nameof(callback), "FrameCallbackType should not be null");
- }
-
- Interop.WindowInternal.AddFramePresentedCallback(swigCPtr, new HandleRef(this, ip), frameId);
+ var assignedKey = AddInterHookCallback(callback, frameId);
+ Interop.WindowInternal.AddFramePresentedCallback(swigCPtr, new HandleRef(this, Marshal.GetFunctionPointerForDelegate<Delegate>(internalHookFrameCallback)), assignedKey);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
Window win;
Window.FrameCallbackType cb;
+ TextLabel tl;
+ View view;
void test()
{
+ tlog.Fatal(tag, $"test start");
win = NUIApplication.GetDefaultWindow();
win.TouchEvent += WinTouchEvent;
- View view = new View();
+ view = new View();
view.Size = new Size(100, 100);
view.BackgroundColor = Color.Blue;
+ view.Focusable = true;
+ view.KeyEvent += View_KeyEvent;
win.Add(view);
cb = testCallback;
Timer timer = new Timer(5000);
timer.Tick += testOnTick;
timer.Start();
+
+ tl = new TextLabel("frameId");
+ tl.Size = new Size(500, 200);
+ tl.Position = new Position(10, 200);
+ tl.BackgroundColor = Color.White;
+ win.Add(tl);
+
+ FocusManager.Instance.SetCurrentFocusView(view);
}
private void WinTouchEvent(object sender, Window.TouchEventArgs e)
void testCallback(int id)
{
- Console.WriteLine($"testCallback() id={id}");
+ tlog.Fatal(tag, $"testCallback() id={id}");
+ tl.Text = $"frameId={id}";
+ }
+
+ private bool View_KeyEvent(object source, View.KeyEventArgs e)
+ {
+ if (e.Key.State == Key.StateType.Down)
+ {
+ if (e.Key.KeyPressedName == "1")
+ {
+ cb = testCallback;
+ win.AddFrameRenderedCallback(cb, cnt++);
+ tlog.Fatal(tag, $"1) testOnTick() AddFrameRenderedCallback() send id={cnt}");
+ }
+ else if (e.Key.KeyPressedName == "2")
+ {
+ cb = testCallback;
+ win.AddFramePresentedCallback(cb, cnt++);
+ tlog.Fatal(tag, $"2) testOnTick() AddFramePresentedCallback() send id={cnt}");
+ }
+ else if (e.Key.KeyPressedName == "3")
+ {
+ cb = testCallback;
+ win.AddFramePresentedCallback(cb, cnt++);
+ cb = null;
+ tlog.Fatal(tag, $"3) testOnTick() AddFramePresentedCallback() send id={cnt}");
+ }
+ else if (e.Key.KeyPressedName == "4")
+ {
+ win.AddFrameRenderedCallback((int id) =>
+ {
+ tlog.Fatal(tag, $"testCallback() id={id}");
+ tl.Text = $"frameId={id}";
+ }, cnt++);
+ tlog.Fatal(tag, $"4) testOnTick() AddFrameRenderedCallback() send id={cnt}");
+ }
+ else if (e.Key.KeyPressedName == "Return")
+ {
+ Random rand = new Random();
+ view.BackgroundColor = new Color((float)rand.NextDouble(), (float)rand.NextDouble(), (float)rand.NextDouble(), 1);
+ }
+ }
+ return true;
}