From 75bc5bb7ea7cd04601c3d662d445f7575b14a546 Mon Sep 17 00:00:00 2001 From: WonYoung Choi Date: Fri, 21 Sep 2018 18:37:16 +0900 Subject: [PATCH] [Tizen] Close window when the TERM event is received (#3) --- src/OpenTK/Platform/Tizen/TizenGameApplication.cs | 32 +++++++++++++---------- src/OpenTK/Platform/Tizen/TizenGameCoreBackend.cs | 27 ++++++++++++++++--- 2 files changed, 42 insertions(+), 17 deletions(-) mode change 100755 => 100644 src/OpenTK/Platform/Tizen/TizenGameApplication.cs diff --git a/src/OpenTK/Platform/Tizen/TizenGameApplication.cs b/src/OpenTK/Platform/Tizen/TizenGameApplication.cs old mode 100755 new mode 100644 index d6e2454..f5aaabb --- a/src/OpenTK/Platform/Tizen/TizenGameApplication.cs +++ b/src/OpenTK/Platform/Tizen/TizenGameApplication.cs @@ -30,7 +30,6 @@ namespace OpenTK.Platform.Tizen /// /// Represents an application that have a GameWindow of OpenTK. /// - /// 5 public class TizenGameApplication : CoreUIApplication { private TizenGameWindow window; @@ -38,13 +37,11 @@ namespace OpenTK.Platform.Tizen /// /// Gets the GameWindow instance that created in OnCreate() method. /// - /// 5 public IGameWindow Window => window; /// /// Gets the Window Attributes instance that include the window attributes could be changed by the user. /// - /// 5 public ITizenWindowAttributes WindowAttributes => window; /// @@ -65,7 +62,6 @@ namespace OpenTK.Platform.Tizen /// /// Initializes the TizenGameApplication class. /// - /// 5 public TizenGameApplication() : base(new TizenGameCoreBackend()) { } @@ -74,10 +70,8 @@ namespace OpenTK.Platform.Tizen /// Overrides this method if you want to handle the behavior when the application is resumed. /// If base.OnResume() is not called, the event 'Resumed' will not be emitted. /// - /// 3 protected override void OnResume() { - window.Paused = false; base.OnResume(); } @@ -85,10 +79,8 @@ namespace OpenTK.Platform.Tizen /// Overrides this method if you want to handle the behavior when the application is paused. /// If base.OnPause() is not called, the event 'Paused' will not be emitted. /// - /// 3 protected override void OnPause() { - window.Paused = true; base.OnPause(); } @@ -96,7 +88,6 @@ namespace OpenTK.Platform.Tizen /// Runs the UI application's main loop. The GameWindow uses the maximum update rate. /// /// Arguments from the commandline. - /// 3 public override void Run(string[] args) { Run(args, 0.0, 0.0); @@ -107,7 +98,6 @@ namespace OpenTK.Platform.Tizen /// /// Arguments from the commandline. /// The frequency of UpdateFrame events. - /// 5 public void Run(string[] args, double updatesPerSecond) { Run(args, updatesPerSecond, 0.0); @@ -119,7 +109,6 @@ namespace OpenTK.Platform.Tizen /// Arguments from the commandline. /// The frequency of UpdateFrame events. /// The frequency of RenderFrame events. - /// 5 public void Run(string[] args, double updatesPerSecond, double framesPerSecond) { // Initialize SDL2 @@ -127,12 +116,28 @@ namespace OpenTK.Platform.Tizen SDL2.SDL.SetMainReady(); Toolkit.Init(); - // Set Create Window - Backend.AddEventHandler(TizenGameCoreBackend.WindowCreationEventType, () => + // Set Internal Event Handlers + Backend.AddEventHandler(TizenGameCoreBackend.InternalCreateEventType, () => { window = new TizenGameWindow(GraphicsMode, DisplayDevice.Default, GLMajor, GLMinor); }); + Backend.AddEventHandler(TizenGameCoreBackend.InternalTerminateEventType, () => + { + window.Exit(); + }); + + Backend.AddEventHandler(TizenGameCoreBackend.InternalResumeEventType, () => + { + window.Paused = false; + }); + + Backend.AddEventHandler(TizenGameCoreBackend.InternalPauseEventType, () => + { + window.Paused = true; + }); + + // Configure callbacks for application events base.Run(args); @@ -143,7 +148,6 @@ namespace OpenTK.Platform.Tizen /// /// Exits the main loop of the application. /// - /// 3 public override void Exit() { window.Exit(); diff --git a/src/OpenTK/Platform/Tizen/TizenGameCoreBackend.cs b/src/OpenTK/Platform/Tizen/TizenGameCoreBackend.cs index 9c72c75..5b2bca0 100644 --- a/src/OpenTK/Platform/Tizen/TizenGameCoreBackend.cs +++ b/src/OpenTK/Platform/Tizen/TizenGameCoreBackend.cs @@ -32,7 +32,10 @@ namespace OpenTK.Platform.Tizen { internal class TizenGameCoreBackend : DefaultCoreBackend { - internal readonly static string WindowCreationEventType = "WindowCreation"; + internal static readonly string InternalCreateEventType = "_TGCB_CREATE_EVENT_TYPE_"; + internal static readonly string InternalTerminateEventType = "_TGCB_TERMINATE_EVENT_TYPE_"; + internal static readonly string InternalResumeEventType = "_TGCB_RESUME_EVENT_TYPE_"; + internal static readonly string InternalPauseEventType = "_TGCB_PAUSE_EVENT_TYPE_"; private readonly SDL2.EventFilter EventFilterDelegate_GCUnsafe; private readonly IntPtr EventFilterDelegate; @@ -82,9 +85,9 @@ namespace OpenTK.Platform.Tizen handler?.Invoke(); } - if (Handlers.ContainsKey(WindowCreationEventType)) + if (Handlers.ContainsKey(InternalCreateEventType)) { - var handler = Handlers[WindowCreationEventType] as Action; + var handler = Handlers[InternalCreateEventType] as Action; handler?.Invoke(); } @@ -147,6 +150,12 @@ namespace OpenTK.Platform.Tizen var handler = Handlers[EventType.Terminated] as Action; handler?.Invoke(); } + + if (Handlers.ContainsKey(InternalTerminateEventType)) + { + var handler = Handlers[InternalTerminateEventType] as Action; + handler?.Invoke(); + } } private void OnAppControlNative(IntPtr appControlHandle) @@ -164,6 +173,12 @@ namespace OpenTK.Platform.Tizen private void OnResumeNative() { + if (Handlers.ContainsKey(InternalResumeEventType)) + { + var handler = Handlers[InternalResumeEventType] as Action; + handler?.Invoke(); + } + if (Handlers.ContainsKey(EventType.Resumed)) { var handler = Handlers[EventType.Resumed] as Action; @@ -173,6 +188,12 @@ namespace OpenTK.Platform.Tizen private void OnPauseNative() { + if (Handlers.ContainsKey(InternalPauseEventType)) + { + var handler = Handlers[InternalPauseEventType] as Action; + handler?.Invoke(); + } + if (Handlers.ContainsKey(EventType.Paused)) { var handler = Handlers[EventType.Paused] as Action; -- 2.7.4