diff options
| author | Akshay Nair <phenax5@gmail.com> | 2024-12-15 15:39:02 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2024-12-15 15:45:37 +0530 |
| commit | 1d07e554284593cdca804404d1d9f68a473ee986 (patch) | |
| tree | 6f90288426699384cdb85cfdca4a036c3da1e51c /src/Chelleport/Context.hs | |
| parent | 0c6b8c83e8673b394914e1f824dfb887b762b0ee (diff) | |
| download | chelleport-1d07e554284593cdca804404d1d9f68a473ee986.tar.gz chelleport-1d07e554284593cdca804404d1d9f68a473ee986.zip | |
Refactor a bunch of stuff
Diffstat (limited to '')
| -rw-r--r-- | src/Chelleport/Context.hs | 49 |
1 files changed, 36 insertions, 13 deletions
diff --git a/src/Chelleport/Context.hs b/src/Chelleport/Context.hs index 9b1e13e..b573975 100644 --- a/src/Chelleport/Context.hs +++ b/src/Chelleport/Context.hs @@ -1,26 +1,23 @@ module Chelleport.Context where import Chelleport.Types +import Foreign.C (CFloat) import qualified Graphics.X11 as X11 import SDL (($=)) import qualified SDL import qualified SDL.Font as TTF +windowOpacity :: CFloat +windowOpacity = 0.6 + +fontSize :: Int +fontSize = 24 + initializeContext :: IO DrawContext initializeContext = do - let windowCfg = - SDL.defaultWindow - { SDL.windowMode = SDL.FullscreenDesktop, - SDL.windowPosition = SDL.Absolute $ SDL.P $ SDL.V2 0 0, - SDL.windowInitialSize = SDL.V2 0 0, - SDL.windowBorder = False - } - window <- SDL.createWindow "Chelleport" windowCfg - renderer <- SDL.createRenderer window (-1) SDL.defaultRenderer - font <- TTF.load "Inter-Regular.ttf" 24 - - SDL.windowOpacity window $= 0.6 - SDL.rendererDrawBlendMode renderer $= SDL.BlendAlphaBlend + window <- initializeWindow + renderer <- initializeRenderer window + font <- loadFont display <- X11.openDisplay "" @@ -31,3 +28,29 @@ initializeContext = do ctxFont = font, ctxX11Display = display } + +loadFont :: IO TTF.Font +loadFont = do + font <- TTF.load "Inter-Regular.ttf" fontSize + TTF.setStyle font [TTF.Bold] + pure font + +initializeRenderer :: SDL.Window -> IO SDL.Renderer +initializeRenderer window = do + renderer <- SDL.createRenderer window (-1) SDL.defaultRenderer + SDL.windowOpacity window $= windowOpacity + SDL.rendererDrawBlendMode renderer $= SDL.BlendAlphaBlend + pure renderer + +initializeWindow :: IO SDL.Window +initializeWindow = do + let windowCfg = + SDL.defaultWindow + { SDL.windowMode = SDL.FullscreenDesktop, + SDL.windowPosition = SDL.Absolute $ SDL.P $ SDL.V2 0 0, + SDL.windowInitialSize = SDL.V2 0 0, + SDL.windowBorder = False + } + window <- SDL.createWindow "Chelleport" windowCfg + SDL.showWindow window + pure window |
