From 6b3d31b4ca3f4d2960dd92c633fd18b85d6948e9 Mon Sep 17 00:00:00 2001 From: nek0 Date: Fri, 29 Dec 2017 17:21:47 +0100 Subject: [PATCH] clean and proper screen resize --- haskelloids.cabal | 1 - src/Main.hs | 16 ++++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/haskelloids.cabal b/haskelloids.cabal index db074a7..5caffb9 100644 --- a/haskelloids.cabal +++ b/haskelloids.cabal @@ -70,7 +70,6 @@ executable haskelloids , affection <= 0.0.0.8 , sdl2 >= 2.1.3.1 , OpenGL - , containers , random , linear diff --git a/src/Main.hs b/src/Main.hs index 0a5b3ae..c8a3001 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -30,6 +30,7 @@ main = do { SDL.glProfile = SDL.Core SDL.Normal 3 2 , SDL.glColorPrecision = V4 8 8 8 1 } + , SDL.windowResizable = True } , initScreenMode = SDL.Windowed , canvasSize = Nothing @@ -48,9 +49,15 @@ pre = do _ <- partSubscribe (subWindow subs) $ \msg -> case msg of MsgWindowResize _ _ (V2 w h) -> do liftIO $ logIO A.Debug "Window has been resized" - let nw = floor (fromIntegral h * (800/600) :: Double) - dw = floor ((fromIntegral w - fromIntegral nw) / 2 :: Double) - GL.viewport $= (GL.Position dw 0, GL.Size nw h) + if (fromIntegral w / fromIntegral h) > (800/600) + then do + let nw = floor (fromIntegral h * (800/600) :: Double) + dw = floor ((fromIntegral w - fromIntegral nw) / 2 :: Double) + GL.viewport $= (GL.Position dw 0, GL.Size nw h) + else do + let nh = floor (fromIntegral w / (800/600) :: Double) + dh = floor ((fromIntegral h - fromIntegral nh) / 2 :: Double) + GL.viewport $= (GL.Position 0 dh, GL.Size w nh) _ -> return () _ <- partSubscribe (subKeyboard subs) $ \kbdev -> when (msgKbdKeyMotion kbdev == SDL.Pressed) $ @@ -76,9 +83,6 @@ handle e = do draw :: Affection UserData () draw = do ud <- getAffection - -- window <- drawWindow <$> get - -- pf <- liftIO $ SDL.getWindowPixelFormat window - -- liftIO $ logIO A.Debug $ "Window pixel format: " ++ show pf liftIO $ beginFrame (nano ud) 800 600 1 smDraw (state ud) drawVignette