From ee50719de81145b5859d957da722cf183e0c8c60 Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Thu, 9 Mar 2023 12:20:46 +0000 Subject: Use ALT + Enter to toggle fullscreen --- src/Game.hs | 7 +++++-- src/Game/Controller.hs | 11 ++++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/Game.hs b/src/Game.hs index 2f9988d..52ba6a7 100644 --- a/src/Game.hs +++ b/src/Game.hs @@ -134,8 +134,11 @@ gameLoop :: Env -> IO () gameLoop e = do events <- map SDL.eventPayload <$> SDL.pollEvents - -- F11 for fullscreen / windowed - env <- if fromMaybe False $ C.isPressed SDL.KeycodeF11 events then toggleFullscreen e else pure e + -- ALT + Enter for fullscreen / windowed + env <- + if fromMaybe False (C.isPressed SDL.KeycodeReturn events) && C.isModKey C.altMod events + then toggleFullscreen e + else pure e let renderer = env.renderer canvas = env.canvas diff --git a/src/Game/Controller.hs b/src/Game/Controller.hs index 01dfd1b..d47963e 100644 --- a/src/Game/Controller.hs +++ b/src/Game/Controller.hs @@ -1,4 +1,4 @@ -module Game.Controller (Controls (..), init, update, isPressed) where +module Game.Controller (Controls (..), init, update, isPressed, isModKey, altMod) where import Control.Monad import Data.Int (Int32) @@ -48,6 +48,9 @@ processControllerEvents controls [] = pure controls init :: Controls init = Controls False False False False False False False Nothing Nothing +altMod :: SDL.KeyModifier +altMod = SDL.KeyModifier False False False False True False False False False False False + updateGamepad :: Controls -> [SDL.EventPayload] -> Controls updateGamepad controls events = case controls.joyId of @@ -92,6 +95,12 @@ isPressed code events isEventKey expected keycode (SDL.KeyboardEvent (SDL.KeyboardEventData _ motion False ksym)) = expected == motion && SDL.keysymKeycode ksym == keycode isEventKey _ _ _ = False +isModKey :: SDL.KeyModifier -> [SDL.EventPayload] -> Bool +isModKey kmod = any (isModKeyOne kmod) + where + isModKeyOne m (SDL.KeyboardEvent (SDL.KeyboardEventData _ _ _ ksym)) = SDL.keysymModifier ksym == m + isModKeyOne _ _ = False + isPressedGamepad :: Int32 -> SDL.ControllerButton -> [SDL.EventPayload] -> Maybe Bool isPressedGamepad joyId button events | any (isEventButton SDL.ControllerButtonPressed button) events = Just True -- cgit v1.2.3