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/Draw.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/Draw.hs | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/src/Chelleport/Draw.hs b/src/Chelleport/Draw.hs index fff5d0d..530713a 100644 --- a/src/Chelleport/Draw.hs +++ b/src/Chelleport/Draw.hs @@ -19,6 +19,9 @@ colorGray = SDL.V4 55 52 65 200 colorAccent :: SDL.V4 Word8 colorAccent = SDL.V4 110 112 247 255 +colorHighlight :: SDL.V4 Word8 +colorHighlight = colorAccent + colorGridLines :: SDL.V4 Word8 colorGridLines = SDL.V4 127 29 29 150 @@ -29,9 +32,9 @@ colorBackground :: SDL.V4 Word8 colorBackground = SDL.V4 15 12 25 0 drawText :: DrawContext -> SDL.V2 CInt -> SDL.V4 Word8 -> Text -> IO (CInt, CInt) -drawText ctx position color text = do - surface <- TTF.blended (ctxFont ctx) color text - texture <- SDL.createTextureFromSurface (ctxRenderer ctx) surface +drawText ctx@(DrawContext {ctxRenderer = renderer}) position color text = do + surface <- TTF.solid (ctxFont ctx) color text -- TTF.blended + texture <- SDL.createTextureFromSurface renderer surface SDL.freeSurface surface -- Get text dimensions @@ -40,18 +43,21 @@ drawText ctx position color text = do let textHeight = SDL.textureHeight textureInfo -- Render the texture - SDL.copy (ctxRenderer ctx) texture Nothing $ + SDL.copy renderer texture Nothing $ Just (SDL.Rectangle (SDL.P position) (SDL.V2 textWidth textHeight)) SDL.destroyTexture texture pure (textWidth, textHeight) +windowSize :: DrawContext -> IO (SDL.V2 CInt) +windowSize = SDL.get . SDL.windowSize . ctxWindow + drawHorizontalLine :: DrawContext -> CInt -> IO () -drawHorizontalLine ctx x = do - (SDL.V2 width _height) <- SDL.get $ SDL.windowSize $ ctxWindow ctx - SDL.drawLine (ctxRenderer ctx) (SDL.P $ SDL.V2 0 x) (SDL.P $ SDL.V2 width x) +drawHorizontalLine ctx@(DrawContext {ctxRenderer = renderer}) x = do + (SDL.V2 width _height) <- windowSize ctx + SDL.drawLine renderer (SDL.P $ SDL.V2 0 x) (SDL.P $ SDL.V2 width x) drawVerticalLine :: DrawContext -> CInt -> IO () -drawVerticalLine ctx x = do - (SDL.V2 _width height) <- SDL.get $ SDL.windowSize $ ctxWindow ctx - SDL.drawLine (ctxRenderer ctx) (SDL.P $ SDL.V2 x 0) (SDL.P $ SDL.V2 x height) +drawVerticalLine ctx@(DrawContext {ctxRenderer = renderer}) x = do + (SDL.V2 _width height) <- windowSize ctx + SDL.drawLine renderer (SDL.P $ SDL.V2 x 0) (SDL.P $ SDL.V2 x height) |
