changeset 605:510c651cb27d

add: window-resize check
author Sam <sam@basx.dev>
date Tue, 25 Apr 2023 18:32:23 +0700
parents fdd80220b5ff
children f41c1b78cf5b
files src/semicongine/engine.nim
diffstat 1 files changed, 7 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/semicongine/engine.nim	Tue Apr 25 18:24:18 2023 +0700
+++ b/src/semicongine/engine.nim	Tue Apr 25 18:32:23 2023 +0700
@@ -25,6 +25,7 @@
     mouseWasReleased: set[MouseButton]
     mousePosition: Vec2f
     eventsProcessed: uint64
+    windowWasResized: bool
   Engine* = object
     running*: bool
     device: Device
@@ -106,9 +107,9 @@
   engine.input.keyWasReleased = {}
   engine.input.mouseWasPressed = {}
   engine.input.mouseWasReleased = {}
-  var
-    killed = false
-    resized = false
+  engine.input.windowWasResized = false
+
+  var killed = false
   for event in engine.window.pendingEvents():
     inc engine.input.eventsProcessed
     if engine.eventHandler != nil:
@@ -117,7 +118,7 @@
       of Quit:
         killed = true
       of ResizedWindow:
-        resized = true
+        engine.input.windowWasResized = true
       of KeyPressed:
         engine.input.keyWasPressed.incl event.key
         engine.input.keyIsDown.incl event.key
@@ -136,7 +137,7 @@
     engine.running = false
     if engine.exitHandler != nil:
       engine.exitHandler(engine)
-  if resized and engine.resizeHandler != nil:
+  if engine.input.windowWasResized and engine.resizeHandler != nil:
     engine.resizeHandler(engine)
 
 func keyIsDown*(engine: Engine, key: Key): auto = key in engine.input.keyIsDown
@@ -150,3 +151,4 @@
 func framesRendered*(engine: Engine): auto = engine.renderer.framesRendered
 func gpuDevice*(engine: Engine): Device = engine.device
 func getWindow*(engine: Engine): auto = engine.window
+func windowWasResized*(engine: Engine): auto = engine.input.windowWasResized