diff options
| author | Akshay Nair <phenax5@gmail.com> | 2024-12-14 11:23:35 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2024-12-14 11:23:35 +0530 |
| commit | 80add34b15855932e9201d7426d9df01aa82c845 (patch) | |
| tree | 1a5ce02bf169da0dd49c3bf907da129d5c5f4118 /src/Chelleport/Draw.hs | |
| parent | 8fb21cb43b610c5a04268637155d3efb07217040 (diff) | |
| download | chelleport-80add34b15855932e9201d7426d9df01aa82c845.tar.gz chelleport-80add34b15855932e9201d7426d9df01aa82c845.zip | |
Add key sequence filtering and rendering matched keys
Diffstat (limited to 'src/Chelleport/Draw.hs')
| -rw-r--r-- | src/Chelleport/Draw.hs | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/src/Chelleport/Draw.hs b/src/Chelleport/Draw.hs index c042e32..8401966 100644 --- a/src/Chelleport/Draw.hs +++ b/src/Chelleport/Draw.hs @@ -2,24 +2,31 @@ module Chelleport.Draw where import Chelleport.AppShell (DrawContext (ctxFont, ctxRenderer)) import Data.Text (Text) +import Data.Word (Word8) +import Foreign.C (CInt) import qualified SDL import qualified SDL.Font as TTF --- Render text to the screen -renderText :: DrawContext -> Text -> IO () -renderText ctx text = do - -- Render text in white - surface <- TTF.blended (ctxFont ctx) (SDL.V4 255 255 255 255) text +colorWhite :: SDL.V4 Word8 +colorWhite = SDL.V4 255 255 255 255 + +colorLightGray :: SDL.V4 Word8 +colorLightGray = SDL.V4 100 100 100 255 + +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 texture <- SDL.createTextureFromSurface (ctxRenderer ctx) surface SDL.freeSurface surface -- Get text dimensions textureInfo <- SDL.queryTexture texture let textWidth = SDL.textureWidth textureInfo - textHeight = SDL.textureHeight textureInfo - position = - SDL.P (SDL.V2 ((640 - textWidth) `div` 2) ((480 - textHeight) `div` 2)) + let textHeight = SDL.textureHeight textureInfo -- Render the texture - SDL.copy (ctxRenderer ctx) texture Nothing $ Just (SDL.Rectangle position (SDL.V2 textWidth textHeight)) + SDL.copy (ctxRenderer ctx) texture Nothing $ + Just (SDL.Rectangle (SDL.P position) (SDL.V2 textWidth textHeight)) SDL.destroyTexture texture + + pure (textWidth, textHeight) |
