{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE CPP #-}
module Miso.Canvas
(
Canvas
, CanvasContext2D
, Pattern (..)
, Gradient (..)
, ImageData (..)
, LineCapType (..)
, PatternType (..)
, LineJoinType (..)
, DirectionType (..)
, TextAlignType (..)
, TextBaselineType (..)
, CompositeOperation (..)
, StyleArg (..)
, Coord
, canvas
, canvas_
, set
, globalCompositeOperation
, clearRect
, fillRect
, strokeRect
, beginPath
, closePath
, moveTo
, lineTo
, fill
, rect
, stroke
, bezierCurveTo
, arc
, arcTo
, quadraticCurveTo
, direction
, fillText
, font
, strokeText
, textAlign
, textBaseline
, addColorStop
, createLinearGradient
, createPattern
, createRadialGradient
, fillStyle
, lineCap
, lineJoin
, lineWidth
, miterLimit
, shadowBlur
, shadowColor
, shadowOffsetX
, shadowOffsetY
, strokeStyle
, scale
, rotate
, translate
, transform
, setTransform
, drawImage
, drawImage'
, createImageData
, getImageData
, setImageData
, height
, width
, putImageData
, globalAlpha
, clip
, save
, restore
, gradient
, pattern_
, color
) where
import Control.Monad.IO.Class (liftIO)
import Control.Monad.Reader (ReaderT, runReaderT, ask)
import Miso.DSL hiding (call)
import qualified Miso.FFI as FFI
import Miso.FFI (Image)
import Miso.Types
import Miso.CSS (Color, renderColor)
canvas_
:: forall model action canvasState
. (FromJSVal canvasState, ToJSVal canvasState)
=> [ Attribute action ]
-> (DOMRef -> IO canvasState)
-> (canvasState -> IO ())
-> View model action
canvas_ :: forall model action canvasState.
(FromJSVal canvasState, ToJSVal canvasState) =>
[Attribute action]
-> (CanvasContext2D -> IO canvasState)
-> (canvasState -> IO ())
-> View model action
canvas_ [Attribute action]
attributes CanvasContext2D -> IO canvasState
initialize_ canvasState -> IO ()
draw_ = NS
-> MisoString
-> [Attribute action]
-> [View model action]
-> View model action
forall action model.
NS
-> MisoString
-> [Attribute action]
-> [View model action]
-> View model action
node NS
HTML MisoString
"canvas" [Attribute action]
attrs []
where
attrs :: [ Attribute action ]
attrs :: [Attribute action]
attrs = Attribute action
initCallback Attribute action -> [Attribute action] -> [Attribute action]
forall a. a -> [a] -> [a]
: Attribute action
drawCallack Attribute action -> [Attribute action] -> [Attribute action]
forall a. a -> [a] -> [a]
: [Attribute action]
attributes
initCallback :: Attribute action
initCallback :: Attribute action
initCallback = (Sink action -> VTree -> LogLevel -> Events -> IO ())
-> Attribute action
forall action.
(Sink action -> VTree -> LogLevel -> Events -> IO ())
-> Attribute action
On ((Sink action -> VTree -> LogLevel -> Events -> IO ())
-> Attribute action)
-> (Sink action -> VTree -> LogLevel -> Events -> IO ())
-> Attribute action
forall a b. (a -> b) -> a -> b
$ \Sink action
_ (VTree Object
vtree) LogLevel
_ Events
_ -> do
(CanvasContext2D -> Object -> IO ())
-> Object -> CanvasContext2D -> IO ()
forall a b c. (a -> b -> c) -> b -> a -> c
flip (MisoString -> CanvasContext2D -> Object -> IO ()
forall v. ToJSVal v => MisoString -> v -> Object -> IO ()
FFI.set MisoString
"onCreated") Object
vtree (CanvasContext2D -> IO ()) -> IO CanvasContext2D -> IO ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< do
(CanvasContext2D -> IO ()) -> IO CanvasContext2D
FFI.syncCallback1 ((CanvasContext2D -> IO ()) -> IO CanvasContext2D)
-> (CanvasContext2D -> IO ()) -> IO CanvasContext2D
forall a b. (a -> b) -> a -> b
$ \CanvasContext2D
domRef -> do
initialState <- CanvasContext2D -> IO canvasState
initialize_ CanvasContext2D
domRef
FFI.set "state" initialState (Object domRef)
drawCallack :: Attribute action
drawCallack :: Attribute action
drawCallack = (Sink action -> VTree -> LogLevel -> Events -> IO ())
-> Attribute action
forall action.
(Sink action -> VTree -> LogLevel -> Events -> IO ())
-> Attribute action
On ((Sink action -> VTree -> LogLevel -> Events -> IO ())
-> Attribute action)
-> (Sink action -> VTree -> LogLevel -> Events -> IO ())
-> Attribute action
forall a b. (a -> b) -> a -> b
$ \Sink action
_ (VTree Object
vtree) LogLevel
_ Events
_ -> do
(CanvasContext2D -> Object -> IO ())
-> Object -> CanvasContext2D -> IO ()
forall a b c. (a -> b -> c) -> b -> a -> c
flip (MisoString -> CanvasContext2D -> Object -> IO ()
forall v. ToJSVal v => MisoString -> v -> Object -> IO ()
FFI.set MisoString
"draw") Object
vtree (CanvasContext2D -> IO ()) -> IO CanvasContext2D -> IO ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< do
(CanvasContext2D -> IO ()) -> IO CanvasContext2D
FFI.syncCallback1 ((CanvasContext2D -> IO ()) -> IO CanvasContext2D)
-> (CanvasContext2D -> IO ()) -> IO CanvasContext2D
forall a b. (a -> b) -> a -> b
$ \CanvasContext2D
domRef -> do
state <- CanvasContext2D -> IO canvasState
forall a. FromJSVal a => CanvasContext2D -> IO a
fromJSValUnchecked (CanvasContext2D -> IO canvasState)
-> IO CanvasContext2D -> IO canvasState
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< CanvasContext2D
domRef CanvasContext2D -> MisoString -> IO CanvasContext2D
forall o. ToObject o => o -> MisoString -> IO CanvasContext2D
! (MisoString
"state" :: MisoString)
draw_ state
canvas
:: forall model action canvasState
. (FromJSVal canvasState, ToJSVal canvasState)
=> [ Attribute action ]
-> (DOMRef -> Canvas canvasState)
-> (canvasState -> Canvas ())
-> View model action
canvas :: forall model action canvasState.
(FromJSVal canvasState, ToJSVal canvasState) =>
[Attribute action]
-> (CanvasContext2D -> Canvas canvasState)
-> (canvasState -> Canvas ())
-> View model action
canvas [Attribute action]
attributes CanvasContext2D -> Canvas canvasState
initialize canvasState -> Canvas ()
draw = NS
-> MisoString
-> [Attribute action]
-> [View model action]
-> View model action
forall action model.
NS
-> MisoString
-> [Attribute action]
-> [View model action]
-> View model action
node NS
HTML MisoString
"canvas" [Attribute action]
attrs []
where
attrs :: [ Attribute action ]
attrs :: [Attribute action]
attrs = Attribute action
initCallback Attribute action -> [Attribute action] -> [Attribute action]
forall a. a -> [a] -> [a]
: Attribute action
drawCallack Attribute action -> [Attribute action] -> [Attribute action]
forall a. a -> [a] -> [a]
: [Attribute action]
attributes
initCallback :: Attribute action
initCallback :: Attribute action
initCallback = (Sink action -> VTree -> LogLevel -> Events -> IO ())
-> Attribute action
forall action.
(Sink action -> VTree -> LogLevel -> Events -> IO ())
-> Attribute action
On ((Sink action -> VTree -> LogLevel -> Events -> IO ())
-> Attribute action)
-> (Sink action -> VTree -> LogLevel -> Events -> IO ())
-> Attribute action
forall a b. (a -> b) -> a -> b
$ \Sink action
_ (VTree Object
vtree) LogLevel
_ Events
_ -> do
(CanvasContext2D -> Object -> IO ())
-> Object -> CanvasContext2D -> IO ()
forall a b c. (a -> b -> c) -> b -> a -> c
flip (MisoString -> CanvasContext2D -> Object -> IO ()
forall v. ToJSVal v => MisoString -> v -> Object -> IO ()
FFI.set MisoString
"onCreated") Object
vtree (CanvasContext2D -> IO ()) -> IO CanvasContext2D -> IO ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< do
(CanvasContext2D -> IO ()) -> IO CanvasContext2D
FFI.syncCallback1 ((CanvasContext2D -> IO ()) -> IO CanvasContext2D)
-> (CanvasContext2D -> IO ()) -> IO CanvasContext2D
forall a b. (a -> b) -> a -> b
$ \CanvasContext2D
domRef -> do
ctx <- CanvasContext2D
domRef CanvasContext2D -> MisoString -> [MisoString] -> IO CanvasContext2D
forall object args.
(ToObject object, ToArgs args) =>
object -> MisoString -> args -> IO CanvasContext2D
# (MisoString
"getContext" :: MisoString) ([MisoString] -> IO CanvasContext2D)
-> [MisoString] -> IO CanvasContext2D
forall a b. (a -> b) -> a -> b
$ [MisoString
"2d" :: MisoString]
initialState <- runReaderT (initialize domRef) ctx
FFI.set "state" initialState (Object domRef)
drawCallack :: Attribute action
drawCallack :: Attribute action
drawCallack = (Sink action -> VTree -> LogLevel -> Events -> IO ())
-> Attribute action
forall action.
(Sink action -> VTree -> LogLevel -> Events -> IO ())
-> Attribute action
On ((Sink action -> VTree -> LogLevel -> Events -> IO ())
-> Attribute action)
-> (Sink action -> VTree -> LogLevel -> Events -> IO ())
-> Attribute action
forall a b. (a -> b) -> a -> b
$ \Sink action
_ (VTree Object
vtree) LogLevel
_ Events
_ -> do
(CanvasContext2D -> Object -> IO ())
-> Object -> CanvasContext2D -> IO ()
forall a b c. (a -> b -> c) -> b -> a -> c
flip (MisoString -> CanvasContext2D -> Object -> IO ()
forall v. ToJSVal v => MisoString -> v -> Object -> IO ()
FFI.set MisoString
"draw") Object
vtree (CanvasContext2D -> IO ()) -> IO CanvasContext2D -> IO ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< do
(CanvasContext2D -> IO ()) -> IO CanvasContext2D
FFI.syncCallback1 ((CanvasContext2D -> IO ()) -> IO CanvasContext2D)
-> (CanvasContext2D -> IO ()) -> IO CanvasContext2D
forall a b. (a -> b) -> a -> b
$ \CanvasContext2D
domRef -> do
jval <- CanvasContext2D
domRef CanvasContext2D -> MisoString -> IO CanvasContext2D
forall o. ToObject o => o -> MisoString -> IO CanvasContext2D
! (MisoString
"state" :: MisoString)
initialState <- fromJSValUnchecked jval
ctx <- domRef # ("getContext" :: MisoString) $ ["2d" :: MisoString]
runReaderT (draw initialState) ctx
data PatternType = Repeat | RepeatX | RepeatY | NoRepeat
instance ToJSVal PatternType where
toJSVal :: PatternType -> IO CanvasContext2D
toJSVal = MisoString -> IO CanvasContext2D
forall a. ToJSVal a => a -> IO CanvasContext2D
toJSVal (MisoString -> IO CanvasContext2D)
-> (PatternType -> MisoString) -> PatternType -> IO CanvasContext2D
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PatternType -> MisoString
renderPattern
instance FromJSVal PatternType where
fromJSVal :: CanvasContext2D -> IO (Maybe PatternType)
fromJSVal CanvasContext2D
pat =
forall a. FromJSVal a => CanvasContext2D -> IO a
fromJSValUnchecked @MisoString CanvasContext2D
pat IO MisoString
-> (MisoString -> IO (Maybe PatternType)) -> IO (Maybe PatternType)
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
MisoString
"repeat" -> Maybe PatternType -> IO (Maybe PatternType)
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (PatternType -> Maybe PatternType
forall a. a -> Maybe a
Just PatternType
Repeat)
MisoString
"repeat-x" -> Maybe PatternType -> IO (Maybe PatternType)
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (PatternType -> Maybe PatternType
forall a. a -> Maybe a
Just PatternType
RepeatX)
MisoString
"repeat-y" -> Maybe PatternType -> IO (Maybe PatternType)
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (PatternType -> Maybe PatternType
forall a. a -> Maybe a
Just PatternType
RepeatY)
MisoString
"no-repeat" -> Maybe PatternType -> IO (Maybe PatternType)
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (PatternType -> Maybe PatternType
forall a. a -> Maybe a
Just PatternType
NoRepeat)
MisoString
_ -> Maybe PatternType -> IO (Maybe PatternType)
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe PatternType
forall a. Maybe a
Nothing
data StyleArg
= ColorArg Color
| GradientArg Gradient
| PatternArg Pattern
color :: Color -> StyleArg
color :: Color -> StyleArg
color = Color -> StyleArg
ColorArg
gradient :: Gradient -> StyleArg
gradient :: Gradient -> StyleArg
gradient = Gradient -> StyleArg
GradientArg
pattern_ :: Pattern -> StyleArg
pattern_ :: Pattern -> StyleArg
pattern_ = Pattern -> StyleArg
PatternArg
renderStyleArg :: StyleArg -> IO JSVal
renderStyleArg :: StyleArg -> IO CanvasContext2D
renderStyleArg = \case
ColorArg Color
c -> MisoString -> IO CanvasContext2D
forall a. ToJSVal a => a -> IO CanvasContext2D
toJSVal (Color -> MisoString
renderColor Color
c)
GradientArg Gradient
g -> Gradient -> IO CanvasContext2D
forall a. ToJSVal a => a -> IO CanvasContext2D
toJSVal Gradient
g
PatternArg Pattern
p -> Pattern -> IO CanvasContext2D
forall a. ToJSVal a => a -> IO CanvasContext2D
toJSVal Pattern
p
instance ToArgs StyleArg where
toArgs :: StyleArg -> IO [CanvasContext2D]
toArgs StyleArg
arg = (CanvasContext2D -> [CanvasContext2D] -> [CanvasContext2D]
forall a. a -> [a] -> [a]
:[]) (CanvasContext2D -> [CanvasContext2D])
-> IO CanvasContext2D -> IO [CanvasContext2D]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> StyleArg -> IO CanvasContext2D
forall a. ToJSVal a => a -> IO CanvasContext2D
toJSVal StyleArg
arg
instance ToJSVal StyleArg where
toJSVal :: StyleArg -> IO CanvasContext2D
toJSVal = StyleArg -> IO CanvasContext2D
renderStyleArg
renderPattern :: PatternType -> MisoString
renderPattern :: PatternType -> MisoString
renderPattern = \case
PatternType
Repeat -> MisoString
"repeat"
PatternType
RepeatX -> MisoString
"repeat-x"
PatternType
RepeatY -> MisoString
"repeat-y"
PatternType
NoRepeat -> MisoString
"no-repeat"
data LineCapType
= LineCapButt
| LineCapRound
| LineCapSquare
deriving (Int -> LineCapType -> ShowS
[LineCapType] -> ShowS
LineCapType -> String
(Int -> LineCapType -> ShowS)
-> (LineCapType -> String)
-> ([LineCapType] -> ShowS)
-> Show LineCapType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> LineCapType -> ShowS
showsPrec :: Int -> LineCapType -> ShowS
$cshow :: LineCapType -> String
show :: LineCapType -> String
$cshowList :: [LineCapType] -> ShowS
showList :: [LineCapType] -> ShowS
Show, LineCapType -> LineCapType -> Bool
(LineCapType -> LineCapType -> Bool)
-> (LineCapType -> LineCapType -> Bool) -> Eq LineCapType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: LineCapType -> LineCapType -> Bool
== :: LineCapType -> LineCapType -> Bool
$c/= :: LineCapType -> LineCapType -> Bool
/= :: LineCapType -> LineCapType -> Bool
Eq)
instance ToArgs LineCapType where
toArgs :: LineCapType -> IO [CanvasContext2D]
toArgs LineCapType
arg = (CanvasContext2D -> [CanvasContext2D] -> [CanvasContext2D]
forall a. a -> [a] -> [a]
:[]) (CanvasContext2D -> [CanvasContext2D])
-> IO CanvasContext2D -> IO [CanvasContext2D]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> LineCapType -> IO CanvasContext2D
forall a. ToJSVal a => a -> IO CanvasContext2D
toJSVal LineCapType
arg
instance ToJSVal LineCapType where
toJSVal :: LineCapType -> IO CanvasContext2D
toJSVal = MisoString -> IO CanvasContext2D
forall a. ToJSVal a => a -> IO CanvasContext2D
toJSVal (MisoString -> IO CanvasContext2D)
-> (LineCapType -> MisoString) -> LineCapType -> IO CanvasContext2D
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LineCapType -> MisoString
renderLineCapType
renderLineCapType :: LineCapType -> MisoString
renderLineCapType :: LineCapType -> MisoString
renderLineCapType = \case
LineCapType
LineCapButt -> MisoString
"butt"
LineCapType
LineCapRound -> MisoString
"round"
LineCapType
LineCapSquare -> MisoString
"square"
data LineJoinType
= LineJoinBevel
| LineJoinRound
| LineJoinMiter
deriving (Int -> LineJoinType -> ShowS
[LineJoinType] -> ShowS
LineJoinType -> String
(Int -> LineJoinType -> ShowS)
-> (LineJoinType -> String)
-> ([LineJoinType] -> ShowS)
-> Show LineJoinType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> LineJoinType -> ShowS
showsPrec :: Int -> LineJoinType -> ShowS
$cshow :: LineJoinType -> String
show :: LineJoinType -> String
$cshowList :: [LineJoinType] -> ShowS
showList :: [LineJoinType] -> ShowS
Show, LineJoinType -> LineJoinType -> Bool
(LineJoinType -> LineJoinType -> Bool)
-> (LineJoinType -> LineJoinType -> Bool) -> Eq LineJoinType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: LineJoinType -> LineJoinType -> Bool
== :: LineJoinType -> LineJoinType -> Bool
$c/= :: LineJoinType -> LineJoinType -> Bool
/= :: LineJoinType -> LineJoinType -> Bool
Eq)
instance ToArgs LineJoinType where
toArgs :: LineJoinType -> IO [CanvasContext2D]
toArgs LineJoinType
arg = (CanvasContext2D -> [CanvasContext2D] -> [CanvasContext2D]
forall a. a -> [a] -> [a]
:[]) (CanvasContext2D -> [CanvasContext2D])
-> IO CanvasContext2D -> IO [CanvasContext2D]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> LineJoinType -> IO CanvasContext2D
forall a. ToJSVal a => a -> IO CanvasContext2D
toJSVal LineJoinType
arg
instance ToJSVal LineJoinType where
toJSVal :: LineJoinType -> IO CanvasContext2D
toJSVal = MisoString -> IO CanvasContext2D
forall a. ToJSVal a => a -> IO CanvasContext2D
toJSVal (MisoString -> IO CanvasContext2D)
-> (LineJoinType -> MisoString)
-> LineJoinType
-> IO CanvasContext2D
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LineJoinType -> MisoString
renderLineJoinType
renderLineJoinType :: LineJoinType -> MisoString
renderLineJoinType :: LineJoinType -> MisoString
renderLineJoinType = \case
LineJoinType
LineJoinBevel -> MisoString
"bevel"
LineJoinType
LineJoinRound -> MisoString
"round"
LineJoinType
LineJoinMiter -> MisoString
"miter"
data DirectionType
= LTR
| RTL
| Inherit
deriving (Int -> DirectionType -> ShowS
[DirectionType] -> ShowS
DirectionType -> String
(Int -> DirectionType -> ShowS)
-> (DirectionType -> String)
-> ([DirectionType] -> ShowS)
-> Show DirectionType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> DirectionType -> ShowS
showsPrec :: Int -> DirectionType -> ShowS
$cshow :: DirectionType -> String
show :: DirectionType -> String
$cshowList :: [DirectionType] -> ShowS
showList :: [DirectionType] -> ShowS
Show, DirectionType -> DirectionType -> Bool
(DirectionType -> DirectionType -> Bool)
-> (DirectionType -> DirectionType -> Bool) -> Eq DirectionType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: DirectionType -> DirectionType -> Bool
== :: DirectionType -> DirectionType -> Bool
$c/= :: DirectionType -> DirectionType -> Bool
/= :: DirectionType -> DirectionType -> Bool
Eq)
instance ToArgs DirectionType where
toArgs :: DirectionType -> IO [CanvasContext2D]
toArgs DirectionType
arg = (CanvasContext2D -> [CanvasContext2D] -> [CanvasContext2D]
forall a. a -> [a] -> [a]
:[]) (CanvasContext2D -> [CanvasContext2D])
-> IO CanvasContext2D -> IO [CanvasContext2D]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> DirectionType -> IO CanvasContext2D
forall a. ToJSVal a => a -> IO CanvasContext2D
toJSVal DirectionType
arg
instance ToJSVal DirectionType where
toJSVal :: DirectionType -> IO CanvasContext2D
toJSVal = MisoString -> IO CanvasContext2D
forall a. ToJSVal a => a -> IO CanvasContext2D
toJSVal (MisoString -> IO CanvasContext2D)
-> (DirectionType -> MisoString)
-> DirectionType
-> IO CanvasContext2D
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DirectionType -> MisoString
renderDirectionType
renderDirectionType :: DirectionType -> MisoString
renderDirectionType :: DirectionType -> MisoString
renderDirectionType = \case
DirectionType
LTR -> MisoString
"ltr"
DirectionType
RTL -> MisoString
"rtl"
DirectionType
Inherit -> MisoString
"inherit"
data TextAlignType
= TextAlignCenter
| TextAlignEnd
| TextAlignLeft
| TextAlignRight
| TextAlignStart
deriving (Int -> TextAlignType -> ShowS
[TextAlignType] -> ShowS
TextAlignType -> String
(Int -> TextAlignType -> ShowS)
-> (TextAlignType -> String)
-> ([TextAlignType] -> ShowS)
-> Show TextAlignType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TextAlignType -> ShowS
showsPrec :: Int -> TextAlignType -> ShowS
$cshow :: TextAlignType -> String
show :: TextAlignType -> String
$cshowList :: [TextAlignType] -> ShowS
showList :: [TextAlignType] -> ShowS
Show, TextAlignType -> TextAlignType -> Bool
(TextAlignType -> TextAlignType -> Bool)
-> (TextAlignType -> TextAlignType -> Bool) -> Eq TextAlignType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: TextAlignType -> TextAlignType -> Bool
== :: TextAlignType -> TextAlignType -> Bool
$c/= :: TextAlignType -> TextAlignType -> Bool
/= :: TextAlignType -> TextAlignType -> Bool
Eq)
instance ToArgs TextAlignType where
toArgs :: TextAlignType -> IO [CanvasContext2D]
toArgs TextAlignType
arg = (CanvasContext2D -> [CanvasContext2D] -> [CanvasContext2D]
forall a. a -> [a] -> [a]
:[]) (CanvasContext2D -> [CanvasContext2D])
-> IO CanvasContext2D -> IO [CanvasContext2D]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TextAlignType -> IO CanvasContext2D
forall a. ToJSVal a => a -> IO CanvasContext2D
toJSVal TextAlignType
arg
instance ToJSVal TextAlignType where
toJSVal :: TextAlignType -> IO CanvasContext2D
toJSVal = MisoString -> IO CanvasContext2D
forall a. ToJSVal a => a -> IO CanvasContext2D
toJSVal (MisoString -> IO CanvasContext2D)
-> (TextAlignType -> MisoString)
-> TextAlignType
-> IO CanvasContext2D
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TextAlignType -> MisoString
renderTextAlignType
renderTextAlignType :: TextAlignType -> MisoString
renderTextAlignType :: TextAlignType -> MisoString
renderTextAlignType = \case
TextAlignType
TextAlignCenter -> MisoString
"center"
TextAlignType
TextAlignEnd -> MisoString
"end"
TextAlignType
TextAlignLeft -> MisoString
"left"
TextAlignType
TextAlignRight -> MisoString
"right"
TextAlignType
TextAlignStart -> MisoString
"start"
data TextBaselineType
= TextBaselineAlphabetic
| TextBaselineTop
| TextBaselineHanging
| TextBaselineMiddle
| TextBaselineIdeographic
| TextBaselineBottom
deriving (Int -> TextBaselineType -> ShowS
[TextBaselineType] -> ShowS
TextBaselineType -> String
(Int -> TextBaselineType -> ShowS)
-> (TextBaselineType -> String)
-> ([TextBaselineType] -> ShowS)
-> Show TextBaselineType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TextBaselineType -> ShowS
showsPrec :: Int -> TextBaselineType -> ShowS
$cshow :: TextBaselineType -> String
show :: TextBaselineType -> String
$cshowList :: [TextBaselineType] -> ShowS
showList :: [TextBaselineType] -> ShowS
Show, TextBaselineType -> TextBaselineType -> Bool
(TextBaselineType -> TextBaselineType -> Bool)
-> (TextBaselineType -> TextBaselineType -> Bool)
-> Eq TextBaselineType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: TextBaselineType -> TextBaselineType -> Bool
== :: TextBaselineType -> TextBaselineType -> Bool
$c/= :: TextBaselineType -> TextBaselineType -> Bool
/= :: TextBaselineType -> TextBaselineType -> Bool
Eq)
instance ToArgs TextBaselineType where
toArgs :: TextBaselineType -> IO [CanvasContext2D]
toArgs TextBaselineType
arg = (CanvasContext2D -> [CanvasContext2D] -> [CanvasContext2D]
forall a. a -> [a] -> [a]
:[]) (CanvasContext2D -> [CanvasContext2D])
-> IO CanvasContext2D -> IO [CanvasContext2D]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TextBaselineType -> IO CanvasContext2D
forall a. ToJSVal a => a -> IO CanvasContext2D
toJSVal TextBaselineType
arg
instance ToJSVal TextBaselineType where
toJSVal :: TextBaselineType -> IO CanvasContext2D
toJSVal = MisoString -> IO CanvasContext2D
forall a. ToJSVal a => a -> IO CanvasContext2D
toJSVal (MisoString -> IO CanvasContext2D)
-> (TextBaselineType -> MisoString)
-> TextBaselineType
-> IO CanvasContext2D
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TextBaselineType -> MisoString
renderTextBaselineType
renderTextBaselineType :: TextBaselineType -> MisoString
renderTextBaselineType :: TextBaselineType -> MisoString
renderTextBaselineType = \case
TextBaselineType
TextBaselineAlphabetic -> MisoString
"alphabetic"
TextBaselineType
TextBaselineTop -> MisoString
"top"
TextBaselineType
TextBaselineHanging -> MisoString
"hanging"
TextBaselineType
TextBaselineMiddle -> MisoString
"middle"
TextBaselineType
TextBaselineIdeographic -> MisoString
"ideographic"
TextBaselineType
TextBaselineBottom -> MisoString
"bottom"
data CompositeOperation
= SourceOver
| SourceAtop
| SourceIn
| SourceOut
| DestinationOver
| DestinationAtop
| DestinationIn
| DestinationOut
| Lighter
| Copy
| Xor
deriving (Int -> CompositeOperation -> ShowS
[CompositeOperation] -> ShowS
CompositeOperation -> String
(Int -> CompositeOperation -> ShowS)
-> (CompositeOperation -> String)
-> ([CompositeOperation] -> ShowS)
-> Show CompositeOperation
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CompositeOperation -> ShowS
showsPrec :: Int -> CompositeOperation -> ShowS
$cshow :: CompositeOperation -> String
show :: CompositeOperation -> String
$cshowList :: [CompositeOperation] -> ShowS
showList :: [CompositeOperation] -> ShowS
Show, CompositeOperation -> CompositeOperation -> Bool
(CompositeOperation -> CompositeOperation -> Bool)
-> (CompositeOperation -> CompositeOperation -> Bool)
-> Eq CompositeOperation
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: CompositeOperation -> CompositeOperation -> Bool
== :: CompositeOperation -> CompositeOperation -> Bool
$c/= :: CompositeOperation -> CompositeOperation -> Bool
/= :: CompositeOperation -> CompositeOperation -> Bool
Eq)
instance ToArgs CompositeOperation where
toArgs :: CompositeOperation -> IO [CanvasContext2D]
toArgs CompositeOperation
arg = (CanvasContext2D -> [CanvasContext2D] -> [CanvasContext2D]
forall a. a -> [a] -> [a]
:[]) (CanvasContext2D -> [CanvasContext2D])
-> IO CanvasContext2D -> IO [CanvasContext2D]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> CompositeOperation -> IO CanvasContext2D
forall a. ToJSVal a => a -> IO CanvasContext2D
toJSVal CompositeOperation
arg
instance ToJSVal CompositeOperation where
toJSVal :: CompositeOperation -> IO CanvasContext2D
toJSVal = MisoString -> IO CanvasContext2D
forall a. ToJSVal a => a -> IO CanvasContext2D
toJSVal (MisoString -> IO CanvasContext2D)
-> (CompositeOperation -> MisoString)
-> CompositeOperation
-> IO CanvasContext2D
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CompositeOperation -> MisoString
renderCompositeOperation
renderCompositeOperation :: CompositeOperation -> MisoString
renderCompositeOperation :: CompositeOperation -> MisoString
renderCompositeOperation = \case
CompositeOperation
SourceOver -> MisoString
"source-over"
CompositeOperation
SourceAtop -> MisoString
"source-atop"
CompositeOperation
SourceIn -> MisoString
"source-in"
CompositeOperation
SourceOut -> MisoString
"source-out"
CompositeOperation
DestinationOver -> MisoString
"destination-over"
CompositeOperation
DestinationAtop -> MisoString
"destination-atop"
CompositeOperation
DestinationIn -> MisoString
"destination-in"
CompositeOperation
DestinationOut -> MisoString
"destination-out"
CompositeOperation
Lighter -> MisoString
"lighter"
CompositeOperation
Copy -> MisoString
"copy"
CompositeOperation
Xor -> MisoString
"xor"
newtype Pattern = Pattern JSVal deriving (Pattern -> IO CanvasContext2D
(Pattern -> IO CanvasContext2D) -> ToJSVal Pattern
forall a. (a -> IO CanvasContext2D) -> ToJSVal a
$ctoJSVal :: Pattern -> IO CanvasContext2D
toJSVal :: Pattern -> IO CanvasContext2D
ToJSVal)
instance FromJSVal Pattern where
fromJSVal :: CanvasContext2D -> IO (Maybe Pattern)
fromJSVal = Maybe Pattern -> IO (Maybe Pattern)
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe Pattern -> IO (Maybe Pattern))
-> (CanvasContext2D -> Maybe Pattern)
-> CanvasContext2D
-> IO (Maybe Pattern)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Pattern -> Maybe Pattern
forall a. a -> Maybe a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Pattern -> Maybe Pattern)
-> (CanvasContext2D -> Pattern) -> CanvasContext2D -> Maybe Pattern
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CanvasContext2D -> Pattern
Pattern
newtype Gradient = Gradient JSVal deriving (Gradient -> IO CanvasContext2D
(Gradient -> IO CanvasContext2D) -> ToJSVal Gradient
forall a. (a -> IO CanvasContext2D) -> ToJSVal a
$ctoJSVal :: Gradient -> IO CanvasContext2D
toJSVal :: Gradient -> IO CanvasContext2D
ToJSVal, Gradient -> IO [CanvasContext2D]
(Gradient -> IO [CanvasContext2D]) -> ToArgs Gradient
forall args. (args -> IO [CanvasContext2D]) -> ToArgs args
$ctoArgs :: Gradient -> IO [CanvasContext2D]
toArgs :: Gradient -> IO [CanvasContext2D]
ToArgs)
instance FromJSVal Gradient where
fromJSVal :: CanvasContext2D -> IO (Maybe Gradient)
fromJSVal = Maybe Gradient -> IO (Maybe Gradient)
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe Gradient -> IO (Maybe Gradient))
-> (CanvasContext2D -> Maybe Gradient)
-> CanvasContext2D
-> IO (Maybe Gradient)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Gradient -> Maybe Gradient
forall a. a -> Maybe a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Gradient -> Maybe Gradient)
-> (CanvasContext2D -> Gradient)
-> CanvasContext2D
-> Maybe Gradient
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CanvasContext2D -> Gradient
Gradient
newtype ImageData = ImageData JSVal deriving (ImageData -> IO CanvasContext2D
(ImageData -> IO CanvasContext2D) -> ToJSVal ImageData
forall a. (a -> IO CanvasContext2D) -> ToJSVal a
$ctoJSVal :: ImageData -> IO CanvasContext2D
toJSVal :: ImageData -> IO CanvasContext2D
ToJSVal, ImageData -> IO Object
(ImageData -> IO Object) -> ToObject ImageData
forall a. (a -> IO Object) -> ToObject a
$ctoObject :: ImageData -> IO Object
toObject :: ImageData -> IO Object
ToObject)
instance ToArgs ImageData where
toArgs :: ImageData -> IO [CanvasContext2D]
toArgs ImageData
args = (CanvasContext2D -> [CanvasContext2D] -> [CanvasContext2D]
forall a. a -> [a] -> [a]
:[]) (CanvasContext2D -> [CanvasContext2D])
-> IO CanvasContext2D -> IO [CanvasContext2D]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ImageData -> IO CanvasContext2D
forall a. ToJSVal a => a -> IO CanvasContext2D
toJSVal ImageData
args
instance FromJSVal ImageData where
fromJSVal :: CanvasContext2D -> IO (Maybe ImageData)
fromJSVal = Maybe ImageData -> IO (Maybe ImageData)
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe ImageData -> IO (Maybe ImageData))
-> (CanvasContext2D -> Maybe ImageData)
-> CanvasContext2D
-> IO (Maybe ImageData)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ImageData -> Maybe ImageData
forall a. a -> Maybe a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ImageData -> Maybe ImageData)
-> (CanvasContext2D -> ImageData)
-> CanvasContext2D
-> Maybe ImageData
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CanvasContext2D -> ImageData
ImageData
type Coord = (Double, Double)
type CanvasContext2D = JSVal
call :: (FromJSVal a, ToArgs args) => MisoString -> args -> Canvas a
call :: forall a args.
(FromJSVal a, ToArgs args) =>
MisoString -> args -> Canvas a
call MisoString
name args
arg = do
ctx <- ReaderT CanvasContext2D IO CanvasContext2D
forall r (m :: * -> *). MonadReader r m => m r
ask
liftIO $ fromJSValUnchecked =<< do
ctx # name $ arg
set :: ToArgs args => MisoString -> args -> Canvas ()
set :: forall args. ToArgs args => MisoString -> args -> Canvas ()
set MisoString
name args
args = do
ctx <- ReaderT CanvasContext2D IO CanvasContext2D
forall r (m :: * -> *). MonadReader r m => m r
ask
liftIO $ setField ctx name (toArgs args)
type Canvas a = ReaderT CanvasContext2D IO a
globalCompositeOperation :: CompositeOperation -> Canvas ()
globalCompositeOperation :: CompositeOperation -> Canvas ()
globalCompositeOperation = MisoString -> CompositeOperation -> Canvas ()
forall args. ToArgs args => MisoString -> args -> Canvas ()
set MisoString
"globalCompositeOperation"
clearRect :: (Double, Double, Double, Double) -> Canvas ()
clearRect :: (Double, Double, Double, Double) -> Canvas ()
clearRect = MisoString -> (Double, Double, Double, Double) -> Canvas ()
forall a args.
(FromJSVal a, ToArgs args) =>
MisoString -> args -> Canvas a
call MisoString
"clearRect"
fillRect :: (Double, Double, Double, Double) -> Canvas ()
fillRect :: (Double, Double, Double, Double) -> Canvas ()
fillRect = MisoString -> (Double, Double, Double, Double) -> Canvas ()
forall a args.
(FromJSVal a, ToArgs args) =>
MisoString -> args -> Canvas a
call MisoString
"fillRect"
strokeRect :: (Double, Double, Double, Double) -> Canvas ()
strokeRect :: (Double, Double, Double, Double) -> Canvas ()
strokeRect = MisoString -> (Double, Double, Double, Double) -> Canvas ()
forall a args.
(FromJSVal a, ToArgs args) =>
MisoString -> args -> Canvas a
call MisoString
"strokeRect"
beginPath :: () -> Canvas ()
beginPath :: () -> Canvas ()
beginPath = MisoString -> () -> Canvas ()
forall a args.
(FromJSVal a, ToArgs args) =>
MisoString -> args -> Canvas a
call MisoString
"beginPath"
closePath :: () -> Canvas ()
closePath :: () -> Canvas ()
closePath = MisoString -> () -> Canvas ()
forall a args.
(FromJSVal a, ToArgs args) =>
MisoString -> args -> Canvas a
call MisoString
"closePath"
moveTo :: Coord -> Canvas ()
moveTo :: Coord -> Canvas ()
moveTo = MisoString -> Coord -> Canvas ()
forall a args.
(FromJSVal a, ToArgs args) =>
MisoString -> args -> Canvas a
call MisoString
"moveTo"
lineTo :: Coord -> Canvas ()
lineTo :: Coord -> Canvas ()
lineTo = MisoString -> Coord -> Canvas ()
forall a args.
(FromJSVal a, ToArgs args) =>
MisoString -> args -> Canvas a
call MisoString
"lineTo"
fill :: () -> Canvas ()
fill :: () -> Canvas ()
fill = MisoString -> () -> Canvas ()
forall a args.
(FromJSVal a, ToArgs args) =>
MisoString -> args -> Canvas a
call MisoString
"fill"
rect :: (Double, Double, Double, Double) -> Canvas ()
rect :: (Double, Double, Double, Double) -> Canvas ()
rect = MisoString -> (Double, Double, Double, Double) -> Canvas ()
forall a args.
(FromJSVal a, ToArgs args) =>
MisoString -> args -> Canvas a
call MisoString
"rect"
stroke :: () -> Canvas ()
stroke :: () -> Canvas ()
stroke = MisoString -> () -> Canvas ()
forall a args.
(FromJSVal a, ToArgs args) =>
MisoString -> args -> Canvas a
call MisoString
"stroke"
bezierCurveTo :: (Double, Double, Double, Double, Double, Double) -> Canvas ()
bezierCurveTo :: (Double, Double, Double, Double, Double, Double) -> Canvas ()
bezierCurveTo = MisoString
-> (Double, Double, Double, Double, Double, Double) -> Canvas ()
forall a args.
(FromJSVal a, ToArgs args) =>
MisoString -> args -> Canvas a
call MisoString
"bezierCurveTo"
arc :: (Double, Double, Double, Double, Double) -> Canvas ()
arc :: (Double, Double, Double, Double, Double) -> Canvas ()
arc = MisoString -> (Double, Double, Double, Double, Double) -> Canvas ()
forall a args.
(FromJSVal a, ToArgs args) =>
MisoString -> args -> Canvas a
call MisoString
"arc"
arcTo :: (Double, Double, Double, Double, Double) -> Canvas ()
arcTo :: (Double, Double, Double, Double, Double) -> Canvas ()
arcTo = MisoString -> (Double, Double, Double, Double, Double) -> Canvas ()
forall a args.
(FromJSVal a, ToArgs args) =>
MisoString -> args -> Canvas a
call MisoString
"arcTo"
quadraticCurveTo :: (Double, Double, Double, Double) -> Canvas ()
quadraticCurveTo :: (Double, Double, Double, Double) -> Canvas ()
quadraticCurveTo = MisoString -> (Double, Double, Double, Double) -> Canvas ()
forall a args.
(FromJSVal a, ToArgs args) =>
MisoString -> args -> Canvas a
call MisoString
"quadraticCurveTo"
direction :: DirectionType -> Canvas ()
direction :: DirectionType -> Canvas ()
direction = MisoString -> DirectionType -> Canvas ()
forall args. ToArgs args => MisoString -> args -> Canvas ()
set MisoString
"direction"
fillText :: (MisoString, Double, Double) -> Canvas ()
fillText :: (MisoString, Double, Double) -> Canvas ()
fillText = MisoString -> (MisoString, Double, Double) -> Canvas ()
forall a args.
(FromJSVal a, ToArgs args) =>
MisoString -> args -> Canvas a
call MisoString
"fillText"
font :: MisoString -> Canvas ()
font :: MisoString -> Canvas ()
font = MisoString -> MisoString -> Canvas ()
forall args. ToArgs args => MisoString -> args -> Canvas ()
set MisoString
"font"
strokeText :: (MisoString, Double, Double) -> Canvas ()
strokeText :: (MisoString, Double, Double) -> Canvas ()
strokeText = MisoString -> (MisoString, Double, Double) -> Canvas ()
forall a args.
(FromJSVal a, ToArgs args) =>
MisoString -> args -> Canvas a
call MisoString
"strokeText"
textAlign :: TextAlignType -> Canvas ()
textAlign :: TextAlignType -> Canvas ()
textAlign = MisoString -> TextAlignType -> Canvas ()
forall args. ToArgs args => MisoString -> args -> Canvas ()
set MisoString
"textAlign"
textBaseline :: TextBaselineType -> Canvas ()
textBaseline :: TextBaselineType -> Canvas ()
textBaseline = MisoString -> TextBaselineType -> Canvas ()
forall args. ToArgs args => MisoString -> args -> Canvas ()
set MisoString
"textBaseline"
addColorStop :: (Double, Color) -> Gradient -> Canvas ()
addColorStop :: (Double, Color) -> Gradient -> Canvas ()
addColorStop (Double, Color)
args (Gradient CanvasContext2D
g) = do
_ <- IO CanvasContext2D -> ReaderT CanvasContext2D IO CanvasContext2D
forall a. IO a -> ReaderT CanvasContext2D IO a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO CanvasContext2D -> ReaderT CanvasContext2D IO CanvasContext2D)
-> IO CanvasContext2D -> ReaderT CanvasContext2D IO CanvasContext2D
forall a b. (a -> b) -> a -> b
$ CanvasContext2D
g CanvasContext2D
-> MisoString -> (Double, Color) -> IO CanvasContext2D
forall object args.
(ToObject object, ToArgs args) =>
object -> MisoString -> args -> IO CanvasContext2D
# (MisoString
"addColorStop" :: MisoString) ((Double, Color) -> IO CanvasContext2D)
-> (Double, Color) -> IO CanvasContext2D
forall a b. (a -> b) -> a -> b
$ (Double, Color)
args
pure ()
createLinearGradient :: (Double, Double, Double, Double) -> Canvas Gradient
createLinearGradient :: (Double, Double, Double, Double) -> Canvas Gradient
createLinearGradient = MisoString -> (Double, Double, Double, Double) -> Canvas Gradient
forall a args.
(FromJSVal a, ToArgs args) =>
MisoString -> args -> Canvas a
call MisoString
"createLinearGradient"
createPattern :: (Image, PatternType) -> Canvas Pattern
createPattern :: (Image, PatternType) -> Canvas Pattern
createPattern = MisoString -> (Image, PatternType) -> Canvas Pattern
forall a args.
(FromJSVal a, ToArgs args) =>
MisoString -> args -> Canvas a
call MisoString
"createPattern"
createRadialGradient :: (Double,Double,Double,Double,Double,Double) -> Canvas Gradient
createRadialGradient :: (Double, Double, Double, Double, Double, Double) -> Canvas Gradient
createRadialGradient = MisoString
-> (Double, Double, Double, Double, Double, Double)
-> Canvas Gradient
forall a args.
(FromJSVal a, ToArgs args) =>
MisoString -> args -> Canvas a
call MisoString
"createRadialGradient"
fillStyle :: StyleArg -> Canvas ()
fillStyle :: StyleArg -> Canvas ()
fillStyle = MisoString -> StyleArg -> Canvas ()
forall args. ToArgs args => MisoString -> args -> Canvas ()
set MisoString
"fillStyle"
lineCap :: LineCapType -> Canvas ()
lineCap :: LineCapType -> Canvas ()
lineCap = MisoString -> LineCapType -> Canvas ()
forall args. ToArgs args => MisoString -> args -> Canvas ()
set MisoString
"lineCap"
lineJoin :: LineJoinType -> Canvas ()
lineJoin :: LineJoinType -> Canvas ()
lineJoin = MisoString -> LineJoinType -> Canvas ()
forall args. ToArgs args => MisoString -> args -> Canvas ()
set MisoString
"lineJoin"
lineWidth :: Double -> Canvas ()
lineWidth :: Double -> Canvas ()
lineWidth = MisoString -> Double -> Canvas ()
forall args. ToArgs args => MisoString -> args -> Canvas ()
set MisoString
"lineWidth"
miterLimit :: Double -> Canvas ()
miterLimit :: Double -> Canvas ()
miterLimit = MisoString -> Double -> Canvas ()
forall args. ToArgs args => MisoString -> args -> Canvas ()
set MisoString
"miterLimit"
shadowBlur :: Double -> Canvas ()
shadowBlur :: Double -> Canvas ()
shadowBlur = MisoString -> Double -> Canvas ()
forall args. ToArgs args => MisoString -> args -> Canvas ()
set MisoString
"shadowBlur"
shadowColor :: Color -> Canvas ()
shadowColor :: Color -> Canvas ()
shadowColor = MisoString -> Color -> Canvas ()
forall args. ToArgs args => MisoString -> args -> Canvas ()
set MisoString
"shadowColor"
shadowOffsetX :: Double -> Canvas ()
shadowOffsetX :: Double -> Canvas ()
shadowOffsetX = MisoString -> Double -> Canvas ()
forall args. ToArgs args => MisoString -> args -> Canvas ()
set MisoString
"shadowOffsetX"
shadowOffsetY :: Double -> Canvas ()
shadowOffsetY :: Double -> Canvas ()
shadowOffsetY = MisoString -> Double -> Canvas ()
forall args. ToArgs args => MisoString -> args -> Canvas ()
set MisoString
"shadowOffsetY"
strokeStyle :: StyleArg -> Canvas ()
strokeStyle :: StyleArg -> Canvas ()
strokeStyle = MisoString -> StyleArg -> Canvas ()
forall args. ToArgs args => MisoString -> args -> Canvas ()
set MisoString
"strokeStyle"
scale :: (Double, Double) -> Canvas ()
scale :: Coord -> Canvas ()
scale = MisoString -> Coord -> Canvas ()
forall a args.
(FromJSVal a, ToArgs args) =>
MisoString -> args -> Canvas a
call MisoString
"scale"
rotate :: Double -> Canvas ()
rotate :: Double -> Canvas ()
rotate = MisoString -> Double -> Canvas ()
forall a args.
(FromJSVal a, ToArgs args) =>
MisoString -> args -> Canvas a
call MisoString
"rotate"
translate :: Coord -> Canvas ()
translate :: Coord -> Canvas ()
translate = MisoString -> Coord -> Canvas ()
forall a args.
(FromJSVal a, ToArgs args) =>
MisoString -> args -> Canvas a
call MisoString
"translate"
transform :: (Double, Double, Double, Double, Double, Double) -> Canvas ()
transform :: (Double, Double, Double, Double, Double, Double) -> Canvas ()
transform = MisoString
-> (Double, Double, Double, Double, Double, Double) -> Canvas ()
forall a args.
(FromJSVal a, ToArgs args) =>
MisoString -> args -> Canvas a
call MisoString
"transform"
setTransform :: (Double, Double, Double, Double, Double, Double) -> Canvas ()
setTransform :: (Double, Double, Double, Double, Double, Double) -> Canvas ()
setTransform = MisoString
-> (Double, Double, Double, Double, Double, Double) -> Canvas ()
forall a args.
(FromJSVal a, ToArgs args) =>
MisoString -> args -> Canvas a
call MisoString
"setTransform"
drawImage :: (Image, Double, Double) -> Canvas ()
drawImage :: (Image, Double, Double) -> Canvas ()
drawImage = MisoString -> (Image, Double, Double) -> Canvas ()
forall a args.
(FromJSVal a, ToArgs args) =>
MisoString -> args -> Canvas a
call MisoString
"drawImage"
drawImage' :: (Image, Double, Double, Double, Double) -> Canvas ()
drawImage' :: (Image, Double, Double, Double, Double) -> Canvas ()
drawImage' = MisoString -> (Image, Double, Double, Double, Double) -> Canvas ()
forall a args.
(FromJSVal a, ToArgs args) =>
MisoString -> args -> Canvas a
call MisoString
"drawImage"
createImageData :: (Double, Double) -> Canvas ImageData
createImageData :: Coord -> Canvas ImageData
createImageData = MisoString -> Coord -> Canvas ImageData
forall a args.
(FromJSVal a, ToArgs args) =>
MisoString -> args -> Canvas a
call MisoString
"createImageData"
getImageData :: (Double, Double, Double, Double) -> Canvas ImageData
getImageData :: (Double, Double, Double, Double) -> Canvas ImageData
getImageData = MisoString -> (Double, Double, Double, Double) -> Canvas ImageData
forall a args.
(FromJSVal a, ToArgs args) =>
MisoString -> args -> Canvas a
call MisoString
"getImageData"
setImageData :: (ImageData, Int, Double) -> Canvas ()
setImageData :: (ImageData, Int, Double) -> Canvas ()
setImageData (ImageData
imgData, Int
index, Double
value) = IO () -> Canvas ()
forall a. IO a -> ReaderT CanvasContext2D IO a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> Canvas ()) -> IO () -> Canvas ()
forall a b. (a -> b) -> a -> b
$ do
o <- ImageData
imgData ImageData -> MisoString -> IO CanvasContext2D
forall o. ToObject o => o -> MisoString -> IO CanvasContext2D
! (MisoString
"data" :: MisoString)
(o <## index) value
height :: ImageData -> Canvas Double
height :: ImageData -> Canvas Double
height (ImageData CanvasContext2D
imgData) = IO Double -> Canvas Double
forall a. IO a -> ReaderT CanvasContext2D IO a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Double -> Canvas Double) -> IO Double -> Canvas Double
forall a b. (a -> b) -> a -> b
$ do
CanvasContext2D -> IO Double
forall a. FromJSVal a => CanvasContext2D -> IO a
fromJSValUnchecked (CanvasContext2D -> IO Double) -> IO CanvasContext2D -> IO Double
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< CanvasContext2D
imgData CanvasContext2D -> MisoString -> IO CanvasContext2D
forall o. ToObject o => o -> MisoString -> IO CanvasContext2D
! (MisoString
"height" :: MisoString)
width :: ImageData -> Canvas Double
width :: ImageData -> Canvas Double
width (ImageData CanvasContext2D
imgData) = IO Double -> Canvas Double
forall a. IO a -> ReaderT CanvasContext2D IO a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Double -> Canvas Double) -> IO Double -> Canvas Double
forall a b. (a -> b) -> a -> b
$
CanvasContext2D -> IO Double
forall a. FromJSVal a => CanvasContext2D -> IO a
fromJSValUnchecked (CanvasContext2D -> IO Double) -> IO CanvasContext2D -> IO Double
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< CanvasContext2D
imgData CanvasContext2D -> MisoString -> IO CanvasContext2D
forall o. ToObject o => o -> MisoString -> IO CanvasContext2D
! (MisoString
"width" :: MisoString)
putImageData :: (ImageData, Double, Double) -> Canvas ()
putImageData :: (ImageData, Double, Double) -> Canvas ()
putImageData = MisoString -> (ImageData, Double, Double) -> Canvas ()
forall a args.
(FromJSVal a, ToArgs args) =>
MisoString -> args -> Canvas a
call MisoString
"putImageData"
globalAlpha :: Double -> Canvas ()
globalAlpha :: Double -> Canvas ()
globalAlpha = MisoString -> Double -> Canvas ()
forall args. ToArgs args => MisoString -> args -> Canvas ()
set MisoString
"globalAlpha"
clip :: () -> Canvas ()
clip :: () -> Canvas ()
clip = MisoString -> () -> Canvas ()
forall a args.
(FromJSVal a, ToArgs args) =>
MisoString -> args -> Canvas a
call MisoString
"clip"
save :: () -> Canvas ()
save :: () -> Canvas ()
save = MisoString -> () -> Canvas ()
forall a args.
(FromJSVal a, ToArgs args) =>
MisoString -> args -> Canvas a
call MisoString
"save"
restore :: () -> Canvas ()
restore :: () -> Canvas ()
restore = MisoString -> () -> Canvas ()
forall a args.
(FromJSVal a, ToArgs args) =>
MisoString -> args -> Canvas a
call MisoString
"restore"