3 import Prelude
hiding (init, flip)
15 loadImage
:: String -> IO Image
,
16 setClip
:: Maybe (Coord
, Coord
) -> IO (),
20 setupSDL
:: Int -> Int -> IO Surface
23 setVideoMode w h
32 []
25 setupGL
:: Int -> Int -> IO ()
27 error "OpenGL backend non-existent"
29 setVideoMode w h
32 [OpenGL
]
30 -- opengl boilerplate here
36 sdlLoadImage
:: Surface
-> String -> IO Image
37 sdlLoadImage screen path
= do
39 surf
<- displayFormat raw
40 setColorKey surf
[SrcColorKey
] (Pixel
0)
41 return (sdlImage screen surf
)
43 glLoadImage
:: String -> IO Image
44 glLoadImage path
= undefined
46 sdlSetClip
:: Surface
-> Maybe (Coord
,Coord
) -> IO ()
47 sdlSetClip screen Nothing
= setClipRect screen Nothing
48 sdlSetClip screen
(Just
(xy
,wh
)) = setClipRect screen r
where
49 r
= Just
(Rect
(floor x
) (floor y
) (floor w
) (floor h
))
52 glSetClip
:: Maybe (Coord
,Coord
) -> IO ()
55 sdlClear
:: Surface
-> IO ()
56 sdlClear screen
= fillRect screen Nothing
(Pixel
0) >> return ()
58 glClear
= error "glClear ?"
60 sdlFinalize
:: Surface
-> IO ()
61 sdlFinalize screen
= flip screen
63 glFinalize
= error "glFinalize ?"
65 loadAllImages
:: Video
-> IO (IntMap Image
)
66 loadAllImages vid
= return empty
73 sdlBlit
:: Surface
-> Surface
-> Complex Double -> IO ()
74 sdlBlit dst src xy
= blitSurface src Nothing dst loc
>> return () where
76 (w
,h
) = (surfaceGetWidth src
, surfaceGetHeight src
)
77 loc
= Just
(Rect
(floor x
) (floor y
) w h
)
79 loadSurface
:: String -> IO Surface
80 loadSurface filename
= loadBMP filename
83 loadAllImages :: Video -> IO Video
84 loadAllImages video = do
85 (numbers, files) <- return ([],[])
86 images <- forM files (loadImage video)
87 let table = fromList (zip numbers images)
88 return (video { vidImages = table })
92 surfWH
:: Surface
-> Complex Double
93 surfWH surf
= fromIntegral (surfaceGetWidth surf
) :+ fromIntegral (surfaceGetHeight surf
)
95 sdlImage
:: Surface
-> Surface
-> Image
96 sdlImage screen surf
= Image
{
98 imgApply
= \xy
-> sdlBlit screen surf xy
101 glImage
:: Int -> Rect
-> Surface
-> Image
102 glImage n rect surf
= Image
{
104 imgApply
= \xy
-> glQuad n rect xy