2019-01-31 15:01:01 +00:00
|
|
|
module Events where
|
|
|
|
|
|
|
|
import qualified SDL
|
|
|
|
|
2019-02-04 19:33:45 +00:00
|
|
|
import qualified Data.Text as T
|
|
|
|
|
2019-01-31 15:01:01 +00:00
|
|
|
import Linear
|
|
|
|
|
2019-01-31 15:09:01 +00:00
|
|
|
import Control.Concurrent.MVar
|
|
|
|
|
2019-01-31 15:01:01 +00:00
|
|
|
-- internal impomrts
|
|
|
|
|
|
|
|
import Util
|
|
|
|
|
2019-02-03 01:08:37 +00:00
|
|
|
import Types
|
2019-01-31 15:09:01 +00:00
|
|
|
|
2019-02-03 01:08:37 +00:00
|
|
|
eventHandler :: MVar Bool -> MVar State -> SDL.Event -> IO ()
|
|
|
|
eventHandler run state (SDL.Event _ payload) =
|
|
|
|
handlePayload run state payload
|
2019-01-31 15:01:01 +00:00
|
|
|
|
2019-02-03 01:08:37 +00:00
|
|
|
handlePayload :: MVar Bool -> MVar State -> SDL.EventPayload -> IO ()
|
|
|
|
|
|
|
|
handlePayload _ _ (SDL.WindowResizedEvent (SDL.WindowResizedEventData _ dim)) =
|
2019-01-31 15:01:01 +00:00
|
|
|
fitViewport (800 / 600) dim
|
2019-01-31 15:09:01 +00:00
|
|
|
|
2019-02-03 01:08:37 +00:00
|
|
|
handlePayload run _ (SDL.WindowClosedEvent _) = do
|
2019-01-31 15:09:01 +00:00
|
|
|
_ <- swapMVar run False
|
|
|
|
return ()
|
|
|
|
|
2019-02-03 01:08:37 +00:00
|
|
|
handlePayload run state (SDL.KeyboardEvent (SDL.KeyboardEventData _ SDL.Pressed False sym))
|
|
|
|
| SDL.keysymKeycode sym == SDL.KeycodeEscape = do
|
|
|
|
_ <- swapMVar run False
|
|
|
|
return ()
|
|
|
|
| SDL.keysymKeycode sym == SDL.KeycodeF12 || SDL.keysymKeycode sym == SDL.KeycodeF =
|
|
|
|
modifyMVar_ state $ \st -> do
|
2019-02-04 19:33:45 +00:00
|
|
|
let st2 = st
|
|
|
|
{ stPresentationWindow =
|
|
|
|
if length (stWindows st) > 1 && stPresentationWindow st == 0
|
|
|
|
then 1
|
|
|
|
else 0
|
|
|
|
}
|
|
|
|
mapM_ (\(ident, win) -> do
|
|
|
|
let title = "Ibis - " `T.append` stFilename st2
|
|
|
|
if ident == stPresentationWindow st2
|
|
|
|
then SDL.windowTitle win SDL.$= title
|
|
|
|
else SDL.windowTitle win SDL.$= title `T.append` " - Notes"
|
|
|
|
)
|
|
|
|
(stWindows st2)
|
|
|
|
return st2
|
2019-02-03 01:08:37 +00:00
|
|
|
|
2019-01-31 15:09:01 +00:00
|
|
|
-- catch all other events
|
2019-02-03 01:08:37 +00:00
|
|
|
handlePayload _ _ _ = return ()
|