update screenmode toggle function
This commit is contained in:
parent
a7eac3e392
commit
d6804f95fb
2 changed files with 30 additions and 18 deletions
|
@ -103,7 +103,7 @@ pre ud = do
|
||||||
|
|
||||||
toggleFullScreen :: KeyboardMessage -> Affection ()
|
toggleFullScreen :: KeyboardMessage -> Affection ()
|
||||||
toggleFullScreen (MsgKeyboardEvent _ _ SDL.Pressed False sym)
|
toggleFullScreen (MsgKeyboardEvent _ _ SDL.Pressed False sym)
|
||||||
| SDL.keysymKeycode sym == SDL.KeycodeF11 = toggleScreen
|
| SDL.keysymKeycode sym == SDL.KeycodeF11 = toggleScreen 0
|
||||||
| otherwise = return ()
|
| otherwise = return ()
|
||||||
toggleFullScreen _ = return ()
|
toggleFullScreen _ = return ()
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@ import qualified Graphics.Rendering.OpenGL as GL
|
||||||
import System.Clock
|
import System.Clock
|
||||||
|
|
||||||
import Data.String (fromString)
|
import Data.String (fromString)
|
||||||
|
import Data.List (find)
|
||||||
|
|
||||||
import Control.Monad.State
|
import Control.Monad.State
|
||||||
|
|
||||||
|
@ -35,24 +36,35 @@ getDelta = gets deltaTime
|
||||||
|
|
||||||
-- | Toggle the Screen mode between 'SDL.Windowed' and 'SDL.FullscreenDesktop'.
|
-- | Toggle the Screen mode between 'SDL.Windowed' and 'SDL.FullscreenDesktop'.
|
||||||
-- Pauses the Engine in the process.
|
-- Pauses the Engine in the process.
|
||||||
toggleScreen :: Affection ()
|
toggleScreen :: Word -> Affection ()
|
||||||
toggleScreen = do
|
toggleScreen windowIdent = do
|
||||||
ad <- get
|
ad <- get
|
||||||
newMode <- case screenMode ad of
|
let mwindow = find (\(ident, _, _) -> ident == windowIdent) (drawWindows ad)
|
||||||
SDL.Windowed -> do
|
case mwindow of
|
||||||
mapM_ (flip SDL.setWindowMode SDL.FullscreenDesktop . (\(_,y,_) -> y)) (drawWindows ad)
|
Just (ident, window, mode) -> do
|
||||||
return SDL.FullscreenDesktop
|
newMode <- case mode of
|
||||||
SDL.FullscreenDesktop -> do
|
SDL.FullscreenDesktop -> do
|
||||||
mapM_ (flip SDL.setWindowMode SDL.Windowed . (\(_,y,_) -> y)) (drawWindows ad)
|
SDL.setWindowMode window SDL.Windowed
|
||||||
return SDL.Windowed
|
return SDL.Windowed
|
||||||
|
SDL.Windowed -> do
|
||||||
|
SDL.setWindowMode window SDL.FullscreenDesktop
|
||||||
|
return SDL.FullscreenDesktop
|
||||||
x -> do
|
x -> do
|
||||||
liftIO $ logIO Warn ("Unexpected Screen mode: " <> fromString (show x))
|
liftIO $ logIO Warn ("Unexpected window mode: " <> fromString (show x))
|
||||||
return x
|
return x
|
||||||
now <- liftIO $ getTime Monotonic
|
now <- liftIO $ getTime Monotonic
|
||||||
put ad
|
put ad
|
||||||
{ sysTime = now
|
{ sysTime = now
|
||||||
, screenMode = newMode
|
, drawWindows = map
|
||||||
|
(\e@(lid, win, mod) ->
|
||||||
|
if lid == ident
|
||||||
|
then (lid, win, newMode)
|
||||||
|
else e
|
||||||
|
)
|
||||||
|
(drawWindows ad)
|
||||||
}
|
}
|
||||||
|
Nothing -> do
|
||||||
|
liftIO $ logIO Warn ("No window found with ident " <> fromString (show windowIdent))
|
||||||
|
|
||||||
-- | Fit the GL Viewport to Window size
|
-- | Fit the GL Viewport to Window size
|
||||||
fitViewport
|
fitViewport
|
||||||
|
|
Loading…
Reference in a new issue