aboutsummaryrefslogtreecommitdiff
path: root/src/Game/BitmapFont.hs
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2023-04-15 22:59:15 +0100
committerJuan J. Martinez <jjm@usebox.net>2023-04-15 22:59:15 +0100
commit7b3aa61462dc5a1135e01beedcbc98efe47ffb13 (patch)
tree7969d4f80f2640f9b51690eb853993131ad48454 /src/Game/BitmapFont.hs
parent631c611d929ea8fb633fdaa285485b6dbd5db702 (diff)
downloadspace-plat-hs-7b3aa61462dc5a1135e01beedcbc98efe47ffb13.tar.gz
space-plat-hs-7b3aa61462dc5a1135e01beedcbc98efe47ffb13.zip
"Toaster" notifications
To provide feedback to the user when a controller is plugged/unplugged.
Diffstat (limited to 'src/Game/BitmapFont.hs')
-rw-r--r--src/Game/BitmapFont.hs11
1 files changed, 9 insertions, 2 deletions
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