handle closing windows
This commit is contained in:
parent
756d63a2d6
commit
9f6c292406
2 changed files with 16 additions and 7 deletions
|
@ -4,15 +4,24 @@ import qualified SDL
|
|||
|
||||
import Linear
|
||||
|
||||
import Control.Concurrent.MVar
|
||||
|
||||
-- internal impomrts
|
||||
|
||||
import Util
|
||||
|
||||
eventHandler :: SDL.Event -> IO ()
|
||||
eventHandler (SDL.Event _ payload) =
|
||||
handlePayload payload
|
||||
eventHandler :: MVar Bool -> SDL.Event -> IO ()
|
||||
eventHandler run (SDL.Event _ payload) =
|
||||
handlePayload run payload
|
||||
|
||||
handlePayload :: SDL.EventPayload -> IO ()
|
||||
handlePayload (SDL.WindowResizedEvent (SDL.WindowResizedEventData _ dim)) =
|
||||
handlePayload :: MVar Bool -> SDL.EventPayload -> IO ()
|
||||
|
||||
handlePayload _ (SDL.WindowResizedEvent (SDL.WindowResizedEventData _ dim)) =
|
||||
fitViewport (800 / 600) dim
|
||||
handlePayload _ = return ()
|
||||
|
||||
handlePayload run (SDL.WindowClosedEvent _) = do
|
||||
_ <- swapMVar run False
|
||||
return ()
|
||||
|
||||
-- catch all other events
|
||||
handlePayload _ _ = return ()
|
||||
|
|
|
@ -101,7 +101,7 @@ main = do
|
|||
mapM_ (\(ident, context) -> do
|
||||
let win = fromJust (lookup ident wins)
|
||||
SDL.glMakeCurrent win context
|
||||
mapM_ eventHandler =<< SDL.pollEvents
|
||||
mapM_ (eventHandler run) =<< SDL.pollEvents
|
||||
GL.clear [GL.ColorBuffer, GL.DepthBuffer, GL.StencilBuffer]
|
||||
GL.flush
|
||||
SDL.glSwapWindow win
|
||||
|
|
Loading…
Reference in a new issue