From 7b3aa61462dc5a1135e01beedcbc98efe47ffb13 Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Sat, 15 Apr 2023 22:59:15 +0100 Subject: "Toaster" notifications To provide feedback to the user when a controller is plugged/unplugged. --- src/Game/BitmapFont.hs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src/Game/BitmapFont.hs') diff --git a/src/Game/BitmapFont.hs b/src/Game/BitmapFont.hs index d42f293..e68ee26 100644 --- a/src/Game/BitmapFont.hs +++ b/src/Game/BitmapFont.hs @@ -1,4 +1,4 @@ -module Game.BitmapFont (BitmapFont, load, renderText) where +module Game.BitmapFont (BitmapFont, load, renderText, renderTextSolid) where import Control.Monad import Data.Map (Map) @@ -36,7 +36,7 @@ load filename tex = do Ok desc -> pure $ BitmapFont desc tex Error e -> error e --- | Render a string at position x, y using the prodided bitmap font. +-- | Render a string at position x, y using the provided bitmap font. renderText :: SDL.Renderer -> BitmapFont -> Int -> Int -> String -> IO () renderText renderer (BitmapFont (FontDesc w h m) tex) x y text = mapM_ renderOne (zip [0 ..] text) where @@ -47,3 +47,10 @@ renderText renderer (BitmapFont (FontDesc w h m) tex) x y text = mapM_ renderOne -- find the glyph or render the special one as error src = fromMaybe (U.rect (length m * w) 0 w h) (Map.lookup c m) dst = U.rect (x + i * w) y w h + +-- | Render a string like renderText but with a translucid background. +renderTextSolid :: SDL.Renderer -> BitmapFont -> Int -> Int -> String -> IO () +renderTextSolid renderer font@(BitmapFont (FontDesc w h _) _) x y text = do + -- TODO: make the rect transparent + _ <- SDL.fillRect renderer (Just (U.rect (x - 5) (y - 5) (length text * w + 10) (h + 10))) + renderText renderer font x y text -- cgit v1.2.3