-- GENERATED by C->Haskell Compiler, version 0.28.3 Switcheroo, 25 November 2017 (Haskell)
-- Edit the ORIGNAL .chs file instead!


{-# LINE 1 "src/NanoVG/Internal/GlobalComposite.chs" #-}
module NanoVG.Internal.GlobalComposite where
import qualified Foreign.C.Types as C2HSImp
import qualified Foreign.Ptr as C2HSImp



import NanoVG.Internal.Context




{-# LINE 7 "src/NanoVG/Internal/GlobalComposite.chs" #-}


data BlendFactor = Zero
                 | One
                 | SrcColor
                 | OneMinusSrcColor
                 | DstColor
                 | OneMinusDstColor
                 | SrcAlpha
                 | OneMinusSrcAlpha
                 | DstAlpha
                 | OneMinusDstAlpha
                 | SrcAlphaSaturate
  deriving (Show,Read,Eq,Ord)
instance Enum BlendFactor where
  succ :: BlendFactor -> BlendFactor
succ BlendFactor
Zero = BlendFactor
One
  succ BlendFactor
One = BlendFactor
SrcColor
  succ BlendFactor
SrcColor = BlendFactor
OneMinusSrcColor
  succ OneMinusSrcColor = DstColor
  succ DstColor = OneMinusDstColor
  succ OneMinusDstColor = SrcAlpha
  succ SrcAlpha = OneMinusSrcAlpha
  succ OneMinusSrcAlpha = DstAlpha
  succ DstAlpha = OneMinusDstAlpha
  succ BlendFactor
OneMinusDstAlpha = SrcAlphaSaturate
  succ BlendFactor
SrcAlphaSaturate = String -> BlendFactor
forall a. HasCallStack => String -> a
error String
"BlendFactor.succ: SrcAlphaSaturate has no successor"

  pred One = Zero
  pred SrcColor = One
  pred OneMinusSrcColor = SrcColor
  pred DstColor = OneMinusSrcColor
  pred OneMinusDstColor = DstColor
  pred SrcAlpha = OneMinusDstColor
  pred OneMinusSrcAlpha = SrcAlpha
  pred DstAlpha = OneMinusSrcAlpha
  pred OneMinusDstAlpha = DstAlpha
  pred SrcAlphaSaturate = OneMinusDstAlpha
  pred Zero = error "BlendFactor.pred: Zero has no predecessor"

  enumFromTo :: BlendFactor -> BlendFactor -> [BlendFactor]
enumFromTo BlendFactor
from BlendFactor
to = BlendFactor -> [BlendFactor]
forall t. Enum t => t -> [t]
go BlendFactor
from
    where
      end :: Int
end = BlendFactor -> Int
forall a. Enum a => a -> Int
fromEnum BlendFactor
to
      go :: t -> [t]
go t
v = case Int -> Int -> Ordering
forall a. Ord a => a -> a -> Ordering
compare (t -> Int
forall a. Enum a => a -> Int
fromEnum t
v) Int
end of
                 Ordering
LT -> t
v t -> [t] -> [t]
forall a. a -> [a] -> [a]
: t -> [t]
go (t -> t
forall a. Enum a => a -> a
succ t
v)
                 Ordering
EQ -> [t
v]
                 Ordering
GT -> []

  enumFrom :: BlendFactor -> [BlendFactor]
enumFrom BlendFactor
from = BlendFactor -> BlendFactor -> [BlendFactor]
forall a. Enum a => a -> a -> [a]
enumFromTo BlendFactor
from BlendFactor
SrcAlphaSaturate

  fromEnum :: BlendFactor -> Int
fromEnum BlendFactor
Zero = Int
1
  fromEnum BlendFactor
One = Int
2
  fromEnum BlendFactor
SrcColor = Int
4
  fromEnum BlendFactor
OneMinusSrcColor = Int
8
  fromEnum BlendFactor
DstColor = Int
16
  fromEnum BlendFactor
OneMinusDstColor = Int
32
  fromEnum BlendFactor
SrcAlpha = Int
64
  fromEnum BlendFactor
OneMinusSrcAlpha = Int
128
  fromEnum BlendFactor
DstAlpha = Int
256
  fromEnum BlendFactor
OneMinusDstAlpha = Int
512
  fromEnum BlendFactor
SrcAlphaSaturate = Int
1024

  toEnum :: Int -> BlendFactor
toEnum Int
1 = BlendFactor
Zero
  toEnum Int
2 = BlendFactor
One
  toEnum Int
4 = BlendFactor
SrcColor
  toEnum Int
8 = BlendFactor
OneMinusSrcColor
  toEnum Int
16 = BlendFactor
DstColor
  toEnum Int
32 = BlendFactor
OneMinusDstColor
  toEnum Int
64 = BlendFactor
SrcAlpha
  toEnum Int
128 = BlendFactor
OneMinusSrcAlpha
  toEnum Int
256 = BlendFactor
DstAlpha
  toEnum Int
512 = BlendFactor
OneMinusDstAlpha
  toEnum Int
1024 = BlendFactor
SrcAlphaSaturate
  toEnum Int
unmatched = String -> BlendFactor
forall a. HasCallStack => String -> a
error (String
"BlendFactor.toEnum: Cannot match " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show Int
unmatched)

{-# LINE 11 "src/NanoVG/Internal/GlobalComposite.chs" #-}


data CompositeOperation = SourceOver
                        | SourceIn
                        | SourceOut
                        | Atop
                        | DestinationOver
                        | DestinationIn
                        | DestinationOut
                        | DestinationAtop
                        | Lighter
                        | Copy
                        | Xor
  deriving (Enum,Show,Read,Eq,Ord)

{-# LINE 15 "src/NanoVG/Internal/GlobalComposite.chs" #-}


-- | Composite operation
--
-- The composite operations in NanoVG are modeled after HTML Canvas API, and
-- the blend func is based on OpenGL (see corresponding manuals for more info).
-- The colors in the blending state have premultiplied alpha.

-- | Sets the composite operation. The op parameter should be one of
-- NVGcompositeOperation.
globalCompositeOperation :: (Context) -> (CompositeOperation) -> IO ()
globalCompositeOperation a1 a2 =
  let {a1' = id a1} in 
  let {a2' = (fromIntegral . fromEnum) a2} in 
  globalCompositeOperation'_ a1' a2' >>
  return ()

{-# LINE 26 "src/NanoVG/Internal/GlobalComposite.chs" #-}


-- | Sets the composite operation with custom pixel arithmetic. The parameters
-- should be one of NVGblendFactor.
globalCompositeBlendFunc :: (Context) -> (BlendFactor) -> (BlendFactor) -> IO ()
globalCompositeBlendFunc a1 a2 a3 =
  let {a1' = id a1} in 
  let {a2' = (fromIntegral . fromEnum) a2} in 
  let {a3' = (fromIntegral . fromEnum) a3} in 
  globalCompositeBlendFunc'_ a1' a2' a3' >>
  return ()

{-# LINE 31 "src/NanoVG/Internal/GlobalComposite.chs" #-}


-- | Sets the composite operation with custom pixel arithmetic for RGB and alpha
-- components separately. The parameters should be one of NVGblendFactor.
globalCompositeBlendFuncSeparate :: (Context) -> (BlendFactor) -> (BlendFactor) -> (BlendFactor) -> (BlendFactor) -> IO ()
globalCompositeBlendFuncSeparate a1 a2 a3 a4 a5 =
  let {a1' = id a1} in 
  let {a2' = (fromIntegral . fromEnum) a2} in 
  let {a3' = (fromIntegral . fromEnum) a3} in 
  let {a4' = (fromIntegral . fromEnum) a4} in 
  let {a5' = (fromIntegral . fromEnum) a5} in 
  globalCompositeBlendFuncSeparate'_ a1' a2' a3' a4' a5' >>
  return ()

{-# LINE 36 "src/NanoVG/Internal/GlobalComposite.chs" #-}


foreign import ccall unsafe "NanoVG/Internal/GlobalComposite.chs.h nvgGlobalCompositeOperation"
  globalCompositeOperation'_ :: ((Context) -> (C2HSImp.CInt -> (IO ())))

foreign import ccall unsafe "NanoVG/Internal/GlobalComposite.chs.h nvgGlobalCompositeBlendFunc"
  globalCompositeBlendFunc'_ :: ((Context) -> (C2HSImp.CInt -> (C2HSImp.CInt -> (IO ()))))

foreign import ccall unsafe "NanoVG/Internal/GlobalComposite.chs.h nvgGlobalCompositeBlendFuncSeparate"
  globalCompositeBlendFuncSeparate'_ :: ((Context) -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> (IO ()))))))