Show
Ignore:
Timestamp:
10/07/08 20:42:00 (3 months ago)
Author:
mokehehe
Message:

ソース整理

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/haskell/nario/Font.hs

    r20670 r20925  
     1-- -*- mode: haskell; Encoding: UTF-8 -*- 
    12-- Bitmap font 
    23module Font ( 
     4        Font(..), 
    35        fontPut, 
    46        fontPutc 
    57) where 
    68 
    7 import Multimedia.SDL 
    8 import Control.Monad 
    9 import Data.Char 
     9import Multimedia.SDL (blitSurface, pt, Rect(..), Surface) 
     10import Control.Monad (zipWithM_) 
     11import Data.Char (ord) 
    1012 
    11 fontWidth = 8 
    12 fontHeight = 8 
    13 fontXN = 16 
     13data Font = Font { 
     14        fontSurface :: Surface, 
     15        fontWidth :: Int, 
     16        fontHeight :: Int, 
     17        fontXN :: Int 
     18        } 
     19 
    1420 
    1521-- 文字列表示 
    16 fontPut sur imgsur x y str = zipWithM_ (\i c -> fontPutc sur imgsur i y c) [x..] str 
     22fontPut font sur x y str = zipWithM_ (\i c -> fontPutc font sur i y c) [x..] str 
    1723 
    1824-- 1文字表示 
    19 fontPutc sur imgsur x y c = do 
    20         blitSurface imgsur (Just rc) sur pos 
     25fontPutc font sur x y c = do 
     26        blitSurface (fontSurface font) (Just rc) sur pos 
    2127        where 
    22                 pos = pt (x * fontWidth) (y * fontHeight) 
     28                pos = pt (x * (fontWidth font)) (y * (fontHeight font)) 
    2329                ic = ord c - ord ' ' 
    24                 u = (ic `mod` fontXN) * fontWidth 
    25                 v = (ic `div` fontXN) * fontHeight 
    26                 rc = Rect u v fontWidth fontHeight 
     30                u = (ic `mod` xn) * w 
     31                v = (ic `div` xn) * h 
     32                rc = Rect u v w h 
     33 
     34                xn = fontXN font 
     35                w = fontWidth font 
     36                h = fontHeight font