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 Linear
|
||||||
|
|
||||||
|
import Control.Concurrent.MVar
|
||||||
|
|
||||||
-- internal impomrts
|
-- internal impomrts
|
||||||
|
|
||||||
import Util
|
import Util
|
||||||
|
|
||||||
eventHandler :: SDL.Event -> IO ()
|
eventHandler :: MVar Bool -> SDL.Event -> IO ()
|
||||||
eventHandler (SDL.Event _ payload) =
|
eventHandler run (SDL.Event _ payload) =
|
||||||
handlePayload payload
|
handlePayload run payload
|
||||||
|
|
||||||
handlePayload :: SDL.EventPayload -> IO ()
|
handlePayload :: MVar Bool -> SDL.EventPayload -> IO ()
|
||||||
handlePayload (SDL.WindowResizedEvent (SDL.WindowResizedEventData _ dim)) =
|
|
||||||
|
handlePayload _ (SDL.WindowResizedEvent (SDL.WindowResizedEventData _ dim)) =
|
||||||
fitViewport (800 / 600) 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
|
mapM_ (\(ident, context) -> do
|
||||||
let win = fromJust (lookup ident wins)
|
let win = fromJust (lookup ident wins)
|
||||||
SDL.glMakeCurrent win context
|
SDL.glMakeCurrent win context
|
||||||
mapM_ eventHandler =<< SDL.pollEvents
|
mapM_ (eventHandler run) =<< SDL.pollEvents
|
||||||
GL.clear [GL.ColorBuffer, GL.DepthBuffer, GL.StencilBuffer]
|
GL.clear [GL.ColorBuffer, GL.DepthBuffer, GL.StencilBuffer]
|
||||||
GL.flush
|
GL.flush
|
||||||
SDL.glSwapWindow win
|
SDL.glSwapWindow win
|
||||||
|
|
Loading…
Reference in a new issue