{-# LINE 1 "Graphics/UI/SDL/Rect.hsc" #-}


{-# LINE 5 "Graphics/UI/SDL/Rect.hsc" #-}
-----------------------------------------------------------------------------
-- |
-- 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
    { Rect -> Int
rectX, Rect -> Int
rectY :: Int,  -- Actually Int16
      Rect -> Int
rectW, Rect -> Int
rectH :: Int } -- Actually Word16
    deriving (Int -> Rect -> ShowS
[Rect] -> ShowS
Rect -> String
(Int -> Rect -> ShowS)
-> (Rect -> String) -> ([Rect] -> ShowS) -> Show Rect
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Rect -> ShowS
showsPrec :: Int -> Rect -> ShowS
$cshow :: Rect -> String
show :: Rect -> String
$cshowList :: [Rect] -> ShowS
showList :: [Rect] -> ShowS
Show,Rect -> Rect -> Bool
(Rect -> Rect -> Bool) -> (Rect -> Rect -> Bool) -> Eq Rect
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Rect -> Rect -> Bool
== :: Rect -> Rect -> Bool
$c/= :: Rect -> Rect -> Bool
/= :: Rect -> Rect -> Bool
Eq,Eq Rect
Eq Rect
-> (Rect -> Rect -> Ordering)
-> (Rect -> Rect -> Bool)
-> (Rect -> Rect -> Bool)
-> (Rect -> Rect -> Bool)
-> (Rect -> Rect -> Bool)
-> (Rect -> Rect -> Rect)
-> (Rect -> Rect -> Rect)
-> Ord Rect
Rect -> Rect -> Bool
Rect -> Rect -> Ordering
Rect -> Rect -> Rect
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: Rect -> Rect -> Ordering
compare :: Rect -> Rect -> Ordering
$c< :: Rect -> Rect -> Bool
< :: Rect -> Rect -> Bool
$c<= :: Rect -> Rect -> Bool
<= :: Rect -> Rect -> Bool
$c> :: Rect -> Rect -> Bool
> :: Rect -> Rect -> Bool
$c>= :: Rect -> Rect -> Bool
>= :: Rect -> Rect -> Bool
$cmax :: Rect -> Rect -> Rect
max :: Rect -> Rect -> Rect
$cmin :: Rect -> Rect -> Rect
min :: Rect -> Rect -> Rect
Ord)

instance Storable Rect where
    sizeOf :: Rect -> Int
sizeOf = Int -> Rect -> Int
forall a b. a -> b -> a
const (Int
8)
{-# LINE 31 "Graphics/UI/SDL/Rect.hsc" #-}
    alignment = const 2
    peek :: Ptr Rect -> IO Rect
peek Ptr Rect
ptr
        = do Int16
x <- (\Ptr Rect
hsc_ptr -> Ptr Rect -> Int -> IO Int16
forall b. Ptr b -> Int -> IO Int16
forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff Ptr Rect
hsc_ptr Int
0) Ptr Rect
ptr :: IO Int16
{-# LINE 34 "Graphics/UI/SDL/Rect.hsc" #-}
             Int16
y <- (\Ptr Rect
hsc_ptr -> Ptr Rect -> Int -> IO Int16
forall b. Ptr b -> Int -> IO Int16
forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff Ptr Rect
hsc_ptr Int
2) Ptr Rect
ptr :: IO Int16
{-# LINE 35 "Graphics/UI/SDL/Rect.hsc" #-}
             Word16
w <- (\Ptr Rect
hsc_ptr -> Ptr Rect -> Int -> IO Word16
forall b. Ptr b -> Int -> IO Word16
forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff Ptr Rect
hsc_ptr Int
4) Ptr Rect
ptr :: IO Word16
{-# LINE 36 "Graphics/UI/SDL/Rect.hsc" #-}
             Word16
h <- (\Ptr Rect
hsc_ptr -> Ptr Rect -> Int -> IO Word16
forall b. Ptr b -> Int -> IO Word16
forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff Ptr Rect
hsc_ptr Int
6) Ptr Rect
ptr :: IO Word16
{-# LINE 37 "Graphics/UI/SDL/Rect.hsc" #-}
             Rect -> IO Rect
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Rect -> IO Rect) -> Rect -> IO Rect
forall a b. (a -> b) -> a -> b
$! Int -> Int -> Int -> Int -> Rect
Rect (Int16 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int16
x) (Int16 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int16
y) (Word16 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word16
w) (Word16 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word16
h)
    poke :: Ptr Rect -> Rect -> IO ()
poke Ptr Rect
ptr (Rect Int
x Int
y Int
w Int
h)
        = do (\Ptr Rect
hsc_ptr -> Ptr Rect -> Int -> Int16 -> IO ()
forall b. Ptr b -> Int -> Int16 -> IO ()
forall a b. Storable a => Ptr b -> Int -> a -> IO ()
pokeByteOff Ptr Rect
hsc_ptr Int
0) Ptr Rect
ptr (Int -> Int16
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
x :: Int16)
{-# LINE 40 "Graphics/UI/SDL/Rect.hsc" #-}
             (\Ptr Rect
hsc_ptr -> Ptr Rect -> Int -> Int16 -> IO ()
forall b. Ptr b -> Int -> Int16 -> IO ()
forall a b. Storable a => Ptr b -> Int -> a -> IO ()
pokeByteOff Ptr Rect
hsc_ptr Int
2) Ptr Rect
ptr (Int -> Int16
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
y :: Int16)
{-# LINE 41 "Graphics/UI/SDL/Rect.hsc" #-}
             (\Ptr Rect
hsc_ptr -> Ptr Rect -> Int -> Word16 -> IO ()
forall b. Ptr b -> Int -> Word16 -> IO ()
forall a b. Storable a => Ptr b -> Int -> a -> IO ()
pokeByteOff Ptr Rect
hsc_ptr Int
4) Ptr Rect
ptr (Int -> Word16
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
w :: Word16)
{-# LINE 42 "Graphics/UI/SDL/Rect.hsc" #-}
             (\Ptr Rect
hsc_ptr -> Ptr Rect -> Int -> Word16 -> IO ()
forall b. Ptr b -> Int -> Word16 -> IO ()
forall a b. Storable a => Ptr b -> Int -> a -> IO ()
pokeByteOff Ptr Rect
hsc_ptr Int
6) Ptr Rect
ptr (Int -> Word16
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
h :: Word16)
{-# LINE 43 "Graphics/UI/SDL/Rect.hsc" #-}