{-# LINE 1 "src/NanoVG/Internal/Paint.chs" #-}
{-# LANGUAGE RecordWildCards #-}
module NanoVG.Internal.Paint where
import qualified Foreign.C.Types as C2HSImp
import qualified Foreign.Ptr as C2HSImp
import qualified Foreign.Storable as C2HSImp
import Control.Applicative (pure)
import Foreign.C.Types
import Foreign.Marshal.Alloc
import Foreign.Marshal.Utils
import Foreign.Ptr
import Foreign.Storable
import NanoVG.Internal.Color
import NanoVG.Internal.Context
import NanoVG.Internal.FixedVector
import NanoVG.Internal.Transformation
import NanoVG.Internal.Types
{-# LINE 19 "src/NanoVG/Internal/Paint.chs" #-}
{-# LINE 20 "src/NanoVG/Internal/Paint.chs" #-}
type PaintPtr = C2HSImp.Ptr (Paint)
{-# LINE 21 "src/NanoVG/Internal/Paint.chs" #-}
newtype Extent = Extent (V2 CFloat) deriving (Show,Read,Eq,Ord)
instance Storable Extent where
sizeOf _ = sizeOf (0 :: CFloat) * 2
alignment _ = alignment (0 :: CFloat)
peek p =
do let p' = castPtr p :: Ptr CFloat
a <- peekElemOff p' 0
b <- peekElemOff p' 1
pure (Extent (V2 a b))
poke p (Extent (V2 a b)) =
do let p' = castPtr p :: Ptr CFloat
pokeElemOff p' 0 a
pokeElemOff p' 1 b
data Paint =
Paint {Paint -> Transformation
xform :: Transformation
,Paint -> Extent
extent :: Extent
,Paint -> CFloat
radius :: !CFloat
,Paint -> CFloat
feather :: !CFloat
,Paint -> Color
innerColor :: !Color
,Paint -> Color
outerColor :: !Color
,Paint -> Image
image :: !Image} deriving (Int -> Paint -> ShowS
[Paint] -> ShowS
Paint -> String
(Int -> Paint -> ShowS)
-> (Paint -> String) -> ([Paint] -> ShowS) -> Show Paint
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Paint] -> ShowS
$cshowList :: [Paint] -> ShowS
show :: Paint -> String
$cshow :: Paint -> String
showsPrec :: Int -> Paint -> ShowS
$cshowsPrec :: Int -> Paint -> ShowS
Show,ReadPrec [Paint]
ReadPrec Paint
Int -> ReadS Paint
ReadS [Paint]
(Int -> ReadS Paint)
-> ReadS [Paint]
-> ReadPrec Paint
-> ReadPrec [Paint]
-> Read Paint
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Paint]
$creadListPrec :: ReadPrec [Paint]
readPrec :: ReadPrec Paint
$creadPrec :: ReadPrec Paint
readList :: ReadS [Paint]
$creadList :: ReadS [Paint]
readsPrec :: Int -> ReadS Paint
$creadsPrec :: Int -> ReadS Paint
Read,Paint -> Paint -> Bool
(Paint -> Paint -> Bool) -> (Paint -> Paint -> Bool) -> Eq Paint
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Paint -> Paint -> Bool
$c/= :: Paint -> Paint -> Bool
== :: Paint -> Paint -> Bool
$c== :: Paint -> Paint -> Bool
Eq,Eq Paint
Eq Paint
-> (Paint -> Paint -> Ordering)
-> (Paint -> Paint -> Bool)
-> (Paint -> Paint -> Bool)
-> (Paint -> Paint -> Bool)
-> (Paint -> Paint -> Bool)
-> (Paint -> Paint -> Paint)
-> (Paint -> Paint -> Paint)
-> Ord Paint
Paint -> Paint -> Bool
Paint -> Paint -> Ordering
Paint -> Paint -> Paint
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
min :: Paint -> Paint -> Paint
$cmin :: Paint -> Paint -> Paint
max :: Paint -> Paint -> Paint
$cmax :: Paint -> Paint -> Paint
>= :: Paint -> Paint -> Bool
$c>= :: Paint -> Paint -> Bool
> :: Paint -> Paint -> Bool
$c> :: Paint -> Paint -> Bool
<= :: Paint -> Paint -> Bool
$c<= :: Paint -> Paint -> Bool
< :: Paint -> Paint -> Bool
$c< :: Paint -> Paint -> Bool
compare :: Paint -> Paint -> Ordering
$ccompare :: Paint -> Paint -> Ordering
$cp1Ord :: Eq Paint
Ord)
instance Storable Paint where
sizeOf :: Paint -> Int
sizeOf Paint
_ = Int
76
alignment :: Paint -> Int
alignment Paint
_ = Int
4
peek :: Ptr Paint -> IO Paint
peek Ptr Paint
p =
do Transformation
xform <- Ptr Transformation -> IO Transformation
forall a. Storable a => Ptr a -> IO a
peek (Ptr Any -> Ptr Transformation
forall a b. Ptr a -> Ptr b
castPtr (Ptr Paint
p Ptr Paint -> Int -> Ptr Any
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` (Int
0)))
Extent
extent <- Ptr Extent -> IO Extent
forall a. Storable a => Ptr a -> IO a
peek (Ptr Any -> Ptr Extent
forall a b. Ptr a -> Ptr b
castPtr (Ptr Paint
p Ptr Paint -> Int -> Ptr Any
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` (Int
24)))
CFloat
radius <- (\Ptr Paint
ptr -> do {Ptr Paint -> Int -> IO CFloat
forall a b. Storable a => Ptr b -> Int -> IO a
C2HSImp.peekByteOff Ptr Paint
ptr Int
32 :: IO C2HSImp.CFloat}) Ptr Paint
p
CFloat
feather <- (\Ptr Paint
ptr -> do {Ptr Paint -> Int -> IO CFloat
forall a b. Storable a => Ptr b -> Int -> IO a
C2HSImp.peekByteOff Ptr Paint
ptr Int
36 :: IO C2HSImp.CFloat}) Ptr Paint
p
Color
innerColor <- Ptr Color -> IO Color
forall a. Storable a => Ptr a -> IO a
peek (Ptr Any -> Ptr Color
forall a b. Ptr a -> Ptr b
castPtr (Ptr Paint
p Ptr Paint -> Int -> Ptr Any
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
40))
Color
outerColor <- Ptr Color -> IO Color
forall a. Storable a => Ptr a -> IO a
peek (Ptr Any -> Ptr Color
forall a b. Ptr a -> Ptr b
castPtr (Ptr Paint
p Ptr Paint -> Int -> Ptr Any
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
56))
CInt
image <- Ptr CInt -> IO CInt
forall a. Storable a => Ptr a -> IO a
peek (Ptr Any -> Ptr CInt
forall a b. Ptr a -> Ptr b
castPtr (Ptr Paint
p Ptr Paint -> Int -> Ptr Any
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
72))
Paint -> IO Paint
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Transformation
-> Extent -> CFloat -> CFloat -> Color -> Color -> Image -> Paint
Paint Transformation
xform Extent
extent CFloat
radius CFloat
feather Color
innerColor Color
outerColor (CInt -> Image
Image CInt
image))
poke :: Ptr Paint -> Paint -> IO ()
poke Ptr Paint
p (Paint{CFloat
Color
Transformation
Image
Extent
image :: Image
outerColor :: Color
innerColor :: Color
feather :: CFloat
radius :: CFloat
extent :: Extent
xform :: Transformation
image :: Paint -> Image
outerColor :: Paint -> Color
innerColor :: Paint -> Color
feather :: Paint -> CFloat
radius :: Paint -> CFloat
extent :: Paint -> Extent
xform :: Paint -> Transformation
..}) =
do Ptr Transformation -> Transformation -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke (Ptr Any -> Ptr Transformation
forall a b. Ptr a -> Ptr b
castPtr (Ptr Paint
p Ptr Paint -> Int -> Ptr Any
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` (Int
0))) Transformation
xform
Ptr Extent -> Extent -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke (Ptr Any -> Ptr Extent
forall a b. Ptr a -> Ptr b
castPtr (Ptr Paint
p Ptr Paint -> Int -> Ptr Any
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` (Int
24))) Extent
extent
(\Ptr Paint
ptr CFloat
val -> do {Ptr Paint -> Int -> CFloat -> IO ()
forall a b. Storable a => Ptr b -> Int -> a -> IO ()
C2HSImp.pokeByteOff Ptr Paint
ptr Int
32 (CFloat
val :: C2HSImp.CFloat)}) Ptr Paint
p CFloat
radius
(\Ptr Paint
ptr CFloat
val -> do {Ptr Paint -> Int -> CFloat -> IO ()
forall a b. Storable a => Ptr b -> Int -> a -> IO ()
C2HSImp.pokeByteOff Ptr Paint
ptr Int
36 (CFloat
val :: C2HSImp.CFloat)}) Ptr Paint
p CFloat
feather
Ptr Color -> Color -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke (Ptr Any -> Ptr Color
forall a b. Ptr a -> Ptr b
castPtr (Ptr Paint
p Ptr Paint -> Int -> Ptr Any
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
40)) Color
innerColor
Ptr Color -> Color -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke (Ptr Any -> Ptr Color
forall a b. Ptr a -> Ptr b
castPtr (Ptr Paint
p Ptr Paint -> Int -> Ptr Any
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
56)) Color
outerColor
Ptr CInt -> CInt -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke (Ptr Any -> Ptr CInt
forall a b. Ptr a -> Ptr b
castPtr (Ptr Paint
p Ptr Paint -> Int -> Ptr Any
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
72)) (Image -> CInt
imageHandle Image
image)
linearGradient :: (Context) -> (CFloat) -> (CFloat) -> (CFloat) -> (CFloat) -> (Color) -> (Color) -> IO ((Paint))
linearGradient :: Context
-> CFloat
-> CFloat
-> CFloat
-> CFloat
-> Color
-> Color
-> IO Paint
linearGradient Context
a1 CFloat
a2 CFloat
a3 CFloat
a4 CFloat
a5 Color
a6 Color
a7 =
let {a1' :: Context
a1' = Context -> Context
forall a. a -> a
id Context
a1} in
let {a2' :: CFloat
a2' = CFloat -> CFloat
forall a b. (Real a, Fractional b) => a -> b
realToFrac CFloat
a2} in
let {a3' :: CFloat
a3' = CFloat -> CFloat
forall a b. (Real a, Fractional b) => a -> b
realToFrac CFloat
a3} in
let {a4' :: CFloat
a4' = CFloat -> CFloat
forall a b. (Real a, Fractional b) => a -> b
realToFrac CFloat
a4} in
let {a5' :: CFloat
a5' = CFloat -> CFloat
forall a b. (Real a, Fractional b) => a -> b
realToFrac CFloat
a5} in
Color -> (Ptr Color -> IO Paint) -> IO Paint
forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
with Color
a6 ((Ptr Color -> IO Paint) -> IO Paint)
-> (Ptr Color -> IO Paint) -> IO Paint
forall a b. (a -> b) -> a -> b
$ \Ptr Color
a6' ->
Color -> (Ptr Color -> IO Paint) -> IO Paint
forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
with Color
a7 ((Ptr Color -> IO Paint) -> IO Paint)
-> (Ptr Color -> IO Paint) -> IO Paint
forall a b. (a -> b) -> a -> b
$ \Ptr Color
a7' ->
(Ptr Paint -> IO Paint) -> IO Paint
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr Paint -> IO Paint) -> IO Paint)
-> (Ptr Paint -> IO Paint) -> IO Paint
forall a b. (a -> b) -> a -> b
$ \Ptr Paint
a8' ->
Context
-> CFloat
-> CFloat
-> CFloat
-> CFloat
-> Ptr Color
-> Ptr Color
-> Ptr Paint
-> IO ()
linearGradient'_ Context
a1' CFloat
a2' CFloat
a3' CFloat
a4' CFloat
a5' Ptr Color
a6' Ptr Color
a7' Ptr Paint
a8' IO () -> IO Paint -> IO Paint
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
Ptr Paint -> IO Paint
forall a. Storable a => Ptr a -> IO a
peek Ptr Paint
a8'IO Paint -> (Paint -> IO Paint) -> IO Paint
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Paint
a8'' ->
Paint -> IO Paint
forall (m :: * -> *) a. Monad m => a -> m a
return (Paint
a8'')
{-# LINE 72 "src/NanoVG/Internal/Paint.chs" #-}
boxGradient :: (Context) -> (CFloat) -> (CFloat) -> (CFloat) -> (CFloat) -> (CFloat) -> (CFloat) -> (Color) -> (Color) -> IO ((Paint))
boxGradient a1 a2 a3 a4 a5 a6 a7 a8 a9 =
let {a1' = id a1} in
let {a2' = realToFrac a2} in
let {a3' = realToFrac a3} in
let {a4' = realToFrac a4} in
let {a5' = realToFrac a5} in
let {a6' = realToFrac a6} in
let {a7' = realToFrac a7} in
with a8 $ \a8' ->
with a9 $ \a9' ->
alloca $ \a10' ->
boxGradient'_ a1' a2' a3' a4' a5' a6' a7' a8' a9' a10' >>
peek a10'>>= \a10'' ->
return (a10'')
{-# LINE 80 "src/NanoVG/Internal/Paint.chs" #-}
radialGradient :: (Context) -> (CFloat) -> (CFloat) -> (CFloat) -> (CFloat) -> (Color) -> (Color) -> IO ((Paint))
radialGradient a1 a2 a3 a4 a5 a6 a7 =
let {a1' = id a1} in
let {a2' = realToFrac a2} in
let {a3' = realToFrac a3} in
let {a4' = realToFrac a4} in
let {a5' = realToFrac a5} in
with a6 $ \a6' ->
with a7 $ \a7' ->
alloca $ \a8' ->
radialGradient'_ a1' a2' a3' a4' a5' a6' a7' a8' >>
peek a8'>>= \a8'' ->
return (a8'')
{-# LINE 86 "src/NanoVG/Internal/Paint.chs" #-}
imagePattern :: (Context) -> (CFloat) -> (CFloat) -> (CFloat) -> (CFloat) -> (CFloat) -> (Image) -> (CFloat) -> IO ((Paint))
imagePattern a1 a2 a3 a4 a5 a6 a7 a8 =
let {a1' = id a1} in
let {a2' = realToFrac a2} in
let {a3' = realToFrac a3} in
let {a4' = realToFrac a4} in
let {a5' = realToFrac a5} in
let {a6' = realToFrac a6} in
let {a7' = imageHandle a7} in
let {a8' = realToFrac a8} in
alloca $ \a9' ->
imagePattern'_ a1' a2' a3' a4' a5' a6' a7' a8' a9' >>
peek a9'>>= \a9'' ->
return (a9'')
{-# LINE 92 "src/NanoVG/Internal/Paint.chs" #-}
foreign import ccall unsafe "NanoVG/Internal/Paint.chs.h nvgLinearGradient_"
linearGradient'_ :: ((Context) -> (C2HSImp.CFloat -> (C2HSImp.CFloat -> (C2HSImp.CFloat -> (C2HSImp.CFloat -> ((ColorPtr) -> ((ColorPtr) -> ((PaintPtr) -> (IO ())))))))))
foreign import ccall unsafe "NanoVG/Internal/Paint.chs.h nvgBoxGradient_"
boxGradient'_ :: ((Context) -> (C2HSImp.CFloat -> (C2HSImp.CFloat -> (C2HSImp.CFloat -> (C2HSImp.CFloat -> (C2HSImp.CFloat -> (C2HSImp.CFloat -> ((ColorPtr) -> ((ColorPtr) -> ((PaintPtr) -> (IO ())))))))))))
foreign import ccall unsafe "NanoVG/Internal/Paint.chs.h nvgRadialGradient_"
radialGradient'_ :: ((Context) -> (C2HSImp.CFloat -> (C2HSImp.CFloat -> (C2HSImp.CFloat -> (C2HSImp.CFloat -> ((ColorPtr) -> ((ColorPtr) -> ((PaintPtr) -> (IO ())))))))))
foreign import ccall unsafe "NanoVG/Internal/Paint.chs.h nvgImagePattern_"
imagePattern'_ :: ((Context) -> (C2HSImp.CFloat -> (C2HSImp.CFloat -> (C2HSImp.CFloat -> (C2HSImp.CFloat -> (C2HSImp.CFloat -> (C2HSImp.CInt -> (C2HSImp.CFloat -> ((PaintPtr) -> (IO ()))))))))))