[Tizen] Close window when the TERM event is received (#3) accepted/tizen/unified/20180921.143133 submit/tizen/20180921.093921
authorWonYoung Choi <wy80.choi@samsung.com>
Fri, 21 Sep 2018 09:37:16 +0000 (18:37 +0900)
committerGitHub <noreply@github.com>
Fri, 21 Sep 2018 09:37:16 +0000 (18:37 +0900)
src/OpenTK/Platform/Tizen/TizenGameApplication.cs [changed mode: 0755->0644]
src/OpenTK/Platform/Tizen/TizenGameCoreBackend.cs

old mode 100755 (executable)
new mode 100644 (file)
index d6e2454..f5aaabb
@@ -30,7 +30,6 @@ namespace OpenTK.Platform.Tizen
     /// <summary>
     /// Represents an application that have a GameWindow of OpenTK.
     /// </summary>
-    /// <since_tizen> 5 </since_tizen>
     public class TizenGameApplication : CoreUIApplication
     {
         private TizenGameWindow window;
@@ -38,13 +37,11 @@ namespace OpenTK.Platform.Tizen
         /// <summary>
         /// Gets the GameWindow instance that created in OnCreate() method.
         /// </summary>
-        /// <since_tizen> 5 </since_tizen>
         public IGameWindow Window => window;
 
         /// <summary>
         /// Gets the Window Attributes instance that include the window attributes could be changed by the user.
         /// </summary>
-        /// <since_tizen> 5 </since_tizen>
         public ITizenWindowAttributes WindowAttributes => window;
 
         /// <summary>
@@ -65,7 +62,6 @@ namespace OpenTK.Platform.Tizen
         /// <summary>
         /// Initializes the TizenGameApplication class.
         /// </summary>
-        /// <since_tizen> 5 </since_tizen>
         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.
         /// </summary>
-        /// <since_tizen> 3 </since_tizen>
         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.
         /// </summary>
-        /// <since_tizen> 3 </since_tizen>
         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.
         /// </summary>
         /// <param name="args">Arguments from the commandline.</param>
-        /// <since_tizen> 3 </since_tizen>
         public override void Run(string[] args)
         {
             Run(args, 0.0, 0.0);
@@ -107,7 +98,6 @@ namespace OpenTK.Platform.Tizen
         /// </summary>
         /// <param name="args">Arguments from the commandline.</param>
         /// <param name="updatesPerSecond">The frequency of UpdateFrame events.</param>
-        /// <since_tizen> 5 </since_tizen>
         public void Run(string[] args, double updatesPerSecond)
         {
             Run(args, updatesPerSecond, 0.0);
@@ -119,7 +109,6 @@ namespace OpenTK.Platform.Tizen
         /// <param name="args">Arguments from the commandline.</param>
         /// <param name="updatesPerSecond">The frequency of UpdateFrame events.</param>
         /// <param name="framesPerSecond">The frequency of RenderFrame events.</param>
-        /// <since_tizen> 5 </since_tizen>
         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
         /// <summary>
         /// Exits the main loop of the application.
         /// </summary>
-        /// <since_tizen> 3 </since_tizen>
         public override void Exit()
         {
             window.Exit();
index 9c72c75..5b2bca0 100644 (file)
@@ -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;