File: Rect.hsc

package info (click to toggle)
haskell-sdl 0.6.4-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 376 kB
  • ctags: 3
  • sloc: haskell: 200; ansic: 18; makefile: 13
file content (43 lines) | stat: -rw-r--r-- 1,454 bytes parent folder | download | duplicates (3)
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
37
38
39
40
41
42
43
#include "SDL.h"
#ifdef main
#undef main
#endif
-----------------------------------------------------------------------------
-- |
-- Module      :  Graphics.UI.SDL.Video
-- Copyright   :  (c) David Himmelstrup 2005
-- License     :  BSD-like
--
-- Maintainer  :  lemmih@gmail.com
-- Stability   :  provisional
-- Portability :  portable
--
-----------------------------------------------------------------------------
module Graphics.UI.SDL.Rect where

import Foreign (Storable(poke, sizeOf, alignment, peekByteOff, pokeByteOff,
                         peek))
import Data.Word (Word16)
import Data.Int (Int16)

data Rect
    = Rect
    { rectX, rectY :: Int,  -- Actually Int16
      rectW, rectH :: Int } -- Actually Word16
    deriving (Show,Eq,Ord)

instance Storable Rect where
    sizeOf = const #{size SDL_Rect}
    alignment = const 2
    peek ptr
        = do x <- #{peek SDL_Rect, x} ptr :: IO Int16
             y <- #{peek SDL_Rect, y} ptr :: IO Int16
             w <- #{peek SDL_Rect, w} ptr :: IO Word16
             h <- #{peek SDL_Rect, h} ptr :: IO Word16
             return $! Rect (fromIntegral x) (fromIntegral y) (fromIntegral w) (fromIntegral h)
    poke ptr (Rect x y w h)
        = do #{poke SDL_Rect, x} ptr (fromIntegral x :: Int16)
             #{poke SDL_Rect, y} ptr (fromIntegral y :: Int16)
             #{poke SDL_Rect, w} ptr (fromIntegral w :: Word16)
             #{poke SDL_Rect, h} ptr (fromIntegral h :: Word16)