-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathFont.hs
36 lines (30 loc) · 781 Bytes
/
Font.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
-- Bitmap font
module Font (
Font(..),
fontPut,
fontPutc
) where
import Graphics.UI.SDL
import Control.Monad (zipWithM_)
import Data.Char (ord)
data Font = Font {
fontSurface :: Surface,
fontWidth :: Int,
fontHeight :: Int,
fontXN :: Int
}
-- Put string
fontPut :: Font -> Surface -> Int -> Int -> String -> IO ()
fontPut font sur x y str = zipWithM_ (\i c -> fontPutc font sur i y c) [x..] str
-- Put char
fontPutc :: Font -> Surface -> Int -> Int -> Char -> IO Bool
fontPutc font sur x y c = do
blitSurface (fontSurface font) (Just rc) sur (Just $ Rect (x * fontWidth font) (y * fontHeight font) w h)
where
ic = ord c - ord ' '
u = (ic `mod` xn) * w
v = (ic `div` xn) * h
rc = Rect u v w h
xn = fontXN font
w = fontWidth font
h = fontHeight font