From 73564537897f7573690955596097085b711c92e5 Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Sat, 14 Dec 2024 19:01:02 +0530 Subject: Grid ui cleanup --- src/Chelleport/AppShell.hs | 3 ++- src/Chelleport/Draw.hs | 21 ++++++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) (limited to 'src/Chelleport') diff --git a/src/Chelleport/AppShell.hs b/src/Chelleport/AppShell.hs index 6a0195d..0a65ce2 100644 --- a/src/Chelleport/AppShell.hs +++ b/src/Chelleport/AppShell.hs @@ -1,6 +1,7 @@ module Chelleport.AppShell where import Chelleport.Context (DrawContext (ctxRenderer, ctxWindow, ctxX11Display), createContext) +import Chelleport.Draw (colorBackground) import Control.Monad (foldM, unless) import qualified Graphics.X11 as X11 import SDL (($=)) @@ -32,7 +33,7 @@ setupAppShell initState update eventHandler draw = do appLoop drawCtx (state, sysState) = do events <- SDL.pollEvents - SDL.rendererDrawColor (ctxRenderer drawCtx) $= SDL.V4 0 0 0 0 + SDL.rendererDrawColor (ctxRenderer drawCtx) $= colorBackground SDL.clear $ ctxRenderer drawCtx draw state drawCtx SDL.present $ ctxRenderer drawCtx diff --git a/src/Chelleport/Draw.hs b/src/Chelleport/Draw.hs index 3c2e2a8..6375997 100644 --- a/src/Chelleport/Draw.hs +++ b/src/Chelleport/Draw.hs @@ -1,6 +1,6 @@ module Chelleport.Draw where -import Chelleport.Context (DrawContext (ctxFont, ctxRenderer)) +import Chelleport.Context (DrawContext (ctxFont, ctxRenderer, ctxWindow)) import Data.Text (Text) import Data.Word (Word8) import Foreign.C (CInt) @@ -13,6 +13,15 @@ colorWhite = SDL.V4 255 255 255 255 colorLightGray :: SDL.V4 Word8 colorLightGray = SDL.V4 100 100 100 255 +colorGridLines :: SDL.V4 Word8 +colorGridLines = SDL.V4 127 29 29 150 + +colorAxisLines :: SDL.V4 Word8 +colorAxisLines = SDL.V4 239 68 68 255 + +colorBackground :: SDL.V4 Word8 +colorBackground = SDL.V4 15 12 25 0 + renderText :: DrawContext -> SDL.V2 CInt -> SDL.V4 Word8 -> Text -> IO (CInt, CInt) renderText ctx position color text = do surface <- TTF.blended (ctxFont ctx) color text @@ -30,3 +39,13 @@ renderText ctx position color text = do SDL.destroyTexture texture pure (textWidth, textHeight) + +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) + +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) -- cgit v1.3.1