module Graphics.UI.SDL.Utilities where
import Foreign (Bits((.|.), (.&.)))
import Foreign.C (CInt)
import Prelude hiding (Enum(..))
class Enum a b | a -> b where
succ :: a -> a
pred :: a -> a
toEnum :: b -> a
:: a -> b
enumFromTo :: a -> a -> [a]
intToBool :: Int -> IO Int -> IO Bool
intToBool :: Int -> IO Int -> IO Bool
intToBool err :: Int
err action :: IO Int
action
= (Int -> Bool) -> IO Int -> IO Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Int
errInt -> Int -> Bool
forall a. Eq a => a -> a -> Bool
/=) IO Int
action
toBitmask :: (Enum a b,Bits b,Num b) => [a] -> b
toBitmask :: [a] -> b
toBitmask = (b -> b -> b) -> b -> [b] -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr b -> b -> b
forall a. Bits a => a -> a -> a
(.|.) 0 ([b] -> b) -> ([a] -> [b]) -> [a] -> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> b) -> [a] -> [b]
forall a b. (a -> b) -> [a] -> [b]
map a -> b
forall a b. Enum a b => a -> b
fromEnum
fromBitmask :: (Bounded a,Enum a b,Bits b,Num b) => b -> [a]
fromBitmask :: b -> [a]
fromBitmask mask :: b
mask = (a -> [a] -> [a]) -> [a] -> [a] -> [a]
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr a -> [a] -> [a]
forall a. Enum a b => a -> [a] -> [a]
worker [] [a]
lst
where lst :: [a]
lst = a -> a -> [a]
forall a b. Enum a b => a -> a -> [a]
enumFromTo a
forall a. Bounded a => a
minBound a
forall a. Bounded a => a
maxBound
worker :: a -> [a] -> [a]
worker v :: a
v
= if (b
mask b -> b -> b
forall a. Bits a => a -> a -> a
.&. a -> b
forall a b. Enum a b => a -> b
fromEnum a
v) b -> b -> Bool
forall a. Eq a => a -> a -> Bool
/= 0
then (:) a
v
else [a] -> [a]
forall a. a -> a
id
fromCInt :: Num a => CInt -> a
fromCInt :: CInt -> a
fromCInt = CInt -> a
forall a b. (Integral a, Num b) => a -> b
fromIntegral
toCInt :: Int -> CInt
toCInt :: Int -> CInt
toCInt = Int -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral