From 9ac5ca2ad326667a182686aa48c4a4da45f4f5ce Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Sat, 15 Apr 2023 23:11:17 +0100 Subject: Make the solid frame partially transparent --- src/Game/BitmapFont.hs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/Game/BitmapFont.hs') diff --git a/src/Game/BitmapFont.hs b/src/Game/BitmapFont.hs index e68ee26..66b9b5d 100644 --- a/src/Game/BitmapFont.hs +++ b/src/Game/BitmapFont.hs @@ -6,6 +6,7 @@ import qualified Data.Map as Map import Data.Maybe (fromMaybe) import Foreign.C.Types (CInt) import qualified Game.Utils as U +import SDL (($=)) import qualified SDL import Text.JSON @@ -51,6 +52,11 @@ renderText renderer (BitmapFont (FontDesc w h m) tex) x y text = mapM_ renderOne -- | 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 + oldBlend <- SDL.get $ SDL.rendererDrawBlendMode renderer + SDL.rendererDrawBlendMode renderer $= SDL.BlendAlphaBlend + oldColor <- SDL.get $ SDL.rendererDrawColor renderer + SDL.rendererDrawColor renderer $= SDL.V4 32 32 32 192 _ <- SDL.fillRect renderer (Just (U.rect (x - 5) (y - 5) (length text * w + 10) (h + 10))) + SDL.rendererDrawColor renderer $= oldColor + SDL.rendererDrawBlendMode renderer $= oldBlend renderText renderer font x y text -- cgit v1.2.3