{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE CPP #-}
module Miso.Canvas
(
Canvas
, Pattern (..)
, Gradient (..)
, ImageData (..)
, LineCapType (..)
, PatternType (..)
, LineJoinType (..)
, DirectionType (..)
, TextAlignType (..)
, TextBaselineType (..)
, CompositeOperation (..)
, StyleArg (..)
, Coord
, canvas
, canvas_
, 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.Reader (ReaderT, runReaderT, ask)
import Language.Javascript.JSaddle ( JSM, JSVal, (#), fromJSVal, MakeArgs (..)
, (<#), toJSVal, (!), fromJSValUnchecked
, liftJSM, FromJSVal, Object (..)
, ToJSVal, MakeObject, (<##)
)
import qualified Miso.FFI as FFI
import Miso.FFI (Image)
import Miso.Types
import Miso.Style (Color, renderColor)
import Miso.String (MisoString)
canvas_
:: forall action canvasState
. (FromJSVal canvasState, ToJSVal canvasState)
=> [ Attribute action ]
-> (DOMRef -> JSM canvasState)
-> (canvasState -> JSM ())
-> View action
canvas_ :: forall action canvasState.
(FromJSVal canvasState, ToJSVal canvasState) =>
[Attribute action]
-> (Context -> JSM canvasState)
-> (canvasState -> JSM ())
-> View action
canvas_ [Attribute action]
attributes Context -> JSM canvasState
initialize_ canvasState -> JSM ()
draw_ = NS
-> MisoString -> [Attribute action] -> [View action] -> View action
forall action.
NS
-> MisoString -> [Attribute action] -> [View action] -> View 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 -> Object -> LogLevel -> Events -> JSM ())
-> Attribute action
forall action.
(Sink action -> Object -> LogLevel -> Events -> JSM ())
-> Attribute action
Event ((Sink action -> Object -> LogLevel -> Events -> JSM ())
-> Attribute action)
-> (Sink action -> Object -> LogLevel -> Events -> JSM ())
-> Attribute action
forall a b. (a -> b) -> a -> b
$ \Sink action
_ Object
o LogLevel
_ Events
_ -> do
(Function -> Object -> JSM ()) -> Object -> Function -> JSM ()
forall a b c. (a -> b -> c) -> b -> a -> c
flip (MisoString -> Function -> Object -> JSM ()
forall v. ToJSVal v => MisoString -> v -> Object -> JSM ()
FFI.set MisoString
"onCreated") Object
o (Function -> JSM ()) -> JSM Function -> JSM ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< do
(Context -> JSM ()) -> JSM Function
FFI.syncCallback1 ((Context -> JSM ()) -> JSM Function)
-> (Context -> JSM ()) -> JSM Function
forall a b. (a -> b) -> a -> b
$ \Context
domRef -> do
initialState <- Context -> JSM canvasState
initialize_ Context
domRef
FFI.set "state" initialState (Object domRef)
drawCallack :: Attribute action
drawCallack :: Attribute action
drawCallack = (Sink action -> Object -> LogLevel -> Events -> JSM ())
-> Attribute action
forall action.
(Sink action -> Object -> LogLevel -> Events -> JSM ())
-> Attribute action
Event ((Sink action -> Object -> LogLevel -> Events -> JSM ())
-> Attribute action)
-> (Sink action -> Object -> LogLevel -> Events -> JSM ())
-> Attribute action
forall a b. (a -> b) -> a -> b
$ \Sink action
_ Object
o LogLevel
_ Events
_ -> do
(Function -> Object -> JSM ()) -> Object -> Function -> JSM ()
forall a b c. (a -> b -> c) -> b -> a -> c
flip (MisoString -> Function -> Object -> JSM ()
forall v. ToJSVal v => MisoString -> v -> Object -> JSM ()
FFI.set MisoString
"draw") Object
o (Function -> JSM ()) -> JSM Function -> JSM ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< do
(Context -> JSM ()) -> JSM Function
FFI.syncCallback1 ((Context -> JSM ()) -> JSM Function)
-> (Context -> JSM ()) -> JSM Function
forall a b. (a -> b) -> a -> b
$ \Context
domRef -> do
state <- Context -> JSM canvasState
forall a. FromJSVal a => Context -> JSM a
fromJSValUnchecked (Context -> JSM canvasState) -> JSM Context -> JSM canvasState
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Context
domRef Context -> MisoString -> JSM Context
forall this name.
(MakeObject this, ToJSString name) =>
this -> name -> JSM Context
! (MisoString
"state" :: MisoString)
draw_ state
canvas
:: forall action canvasState
. (FromJSVal canvasState, ToJSVal canvasState)
=> [ Attribute action ]
-> (DOMRef -> Canvas canvasState)
-> (canvasState -> Canvas ())
-> View action
canvas :: forall action canvasState.
(FromJSVal canvasState, ToJSVal canvasState) =>
[Attribute action]
-> (Context -> Canvas canvasState)
-> (canvasState -> Canvas ())
-> View action
canvas [Attribute action]
attributes Context -> Canvas canvasState
initialize canvasState -> Canvas ()
draw = NS
-> MisoString -> [Attribute action] -> [View action] -> View action
forall action.
NS
-> MisoString -> [Attribute action] -> [View action] -> View 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 -> Object -> LogLevel -> Events -> JSM ())
-> Attribute action
forall action.
(Sink action -> Object -> LogLevel -> Events -> JSM ())
-> Attribute action
Event ((Sink action -> Object -> LogLevel -> Events -> JSM ())
-> Attribute action)
-> (Sink action -> Object -> LogLevel -> Events -> JSM ())
-> Attribute action
forall a b. (a -> b) -> a -> b
$ \Sink action
_ Object
obj LogLevel
_ Events
_ -> do
(Function -> Object -> JSM ()) -> Object -> Function -> JSM ()
forall a b c. (a -> b -> c) -> b -> a -> c
flip (MisoString -> Function -> Object -> JSM ()
forall v. ToJSVal v => MisoString -> v -> Object -> JSM ()
FFI.set MisoString
"onCreated") Object
obj (Function -> JSM ()) -> JSM Function -> JSM ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< do
(Context -> JSM ()) -> JSM Function
FFI.syncCallback1 ((Context -> JSM ()) -> JSM Function)
-> (Context -> JSM ()) -> JSM Function
forall a b. (a -> b) -> a -> b
$ \Context
domRef -> do
ctx <- Context
domRef Context -> MisoString -> [MisoString] -> JSM Context
forall this name args.
(MakeObject this, ToJSString name, MakeArgs args) =>
this -> name -> args -> JSM Context
# (MisoString
"getContext" :: MisoString) ([MisoString] -> JSM Context) -> [MisoString] -> JSM Context
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 -> Object -> LogLevel -> Events -> JSM ())
-> Attribute action
forall action.
(Sink action -> Object -> LogLevel -> Events -> JSM ())
-> Attribute action
Event ((Sink action -> Object -> LogLevel -> Events -> JSM ())
-> Attribute action)
-> (Sink action -> Object -> LogLevel -> Events -> JSM ())
-> Attribute action
forall a b. (a -> b) -> a -> b
$ \Sink action
_ Object
obj LogLevel
_ Events
_ -> do
(Function -> Object -> JSM ()) -> Object -> Function -> JSM ()
forall a b c. (a -> b -> c) -> b -> a -> c
flip (MisoString -> Function -> Object -> JSM ()
forall v. ToJSVal v => MisoString -> v -> Object -> JSM ()
FFI.set MisoString
"draw") Object
obj (Function -> JSM ()) -> JSM Function -> JSM ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< do
(Context -> JSM ()) -> JSM Function
FFI.syncCallback1 ((Context -> JSM ()) -> JSM Function)
-> (Context -> JSM ()) -> JSM Function
forall a b. (a -> b) -> a -> b
$ \Context
domRef -> do
jval <- Context
domRef Context -> MisoString -> JSM Context
forall this name.
(MakeObject this, ToJSString name) =>
this -> name -> JSM Context
! (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 -> JSM Context
toJSVal = MisoString -> JSM Context
forall a. ToJSVal a => a -> JSM Context
toJSVal (MisoString -> JSM Context)
-> (PatternType -> MisoString) -> PatternType -> JSM Context
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PatternType -> MisoString
renderPattern
instance FromJSVal PatternType where
fromJSVal :: Context -> JSM (Maybe PatternType)
fromJSVal Context
pat =
forall a. FromJSVal a => Context -> JSM a
fromJSValUnchecked @MisoString Context
pat JSM MisoString
-> (MisoString -> JSM (Maybe PatternType))
-> JSM (Maybe PatternType)
forall a b. JSM a -> (a -> JSM b) -> JSM b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
MisoString
"repeat" -> Maybe PatternType -> JSM (Maybe PatternType)
forall a. a -> JSM 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 -> JSM (Maybe PatternType)
forall a. a -> JSM 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 -> JSM (Maybe PatternType)
forall a. a -> JSM 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 -> JSM (Maybe PatternType)
forall a. a -> JSM a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (PatternType -> Maybe PatternType
forall a. a -> Maybe a
Just PatternType
NoRepeat)
MisoString
_ -> Maybe PatternType -> JSM (Maybe PatternType)
forall a. a -> JSM 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 -> JSM JSVal
renderStyleArg :: StyleArg -> JSM Context
renderStyleArg (ColorArg Color
c) = MisoString -> JSM Context
forall a. ToJSVal a => a -> JSM Context
toJSVal (Color -> MisoString
renderColor Color
c)
renderStyleArg (GradientArg Gradient
g) = Gradient -> JSM Context
forall a. ToJSVal a => a -> JSM Context
toJSVal Gradient
g
renderStyleArg (PatternArg Pattern
p) = Pattern -> JSM Context
forall a. ToJSVal a => a -> JSM Context
toJSVal Pattern
p
instance MakeArgs StyleArg where
makeArgs :: StyleArg -> JSM [Context]
makeArgs StyleArg
arg = (Context -> [Context] -> [Context]
forall a. a -> [a] -> [a]
:[]) (Context -> [Context]) -> JSM Context -> JSM [Context]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> StyleArg -> JSM Context
forall a. ToJSVal a => a -> JSM Context
toJSVal StyleArg
arg
instance ToJSVal StyleArg where
toJSVal :: StyleArg -> JSM Context
toJSVal = JSM Context -> JSM Context
forall a. ToJSVal a => a -> JSM Context
toJSVal (JSM Context -> JSM Context)
-> (StyleArg -> JSM Context) -> StyleArg -> JSM Context
forall b c a. (b -> c) -> (a -> b) -> a -> c
. StyleArg -> JSM Context
renderStyleArg
renderPattern :: PatternType -> MisoString
renderPattern :: PatternType -> MisoString
renderPattern PatternType
Repeat = MisoString
"repeat"
renderPattern PatternType
RepeatX = MisoString
"repeat-x"
renderPattern PatternType
RepeatY = MisoString
"repeat-y"
renderPattern 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 MakeArgs LineCapType where
makeArgs :: LineCapType -> JSM [Context]
makeArgs LineCapType
arg = (Context -> [Context] -> [Context]
forall a. a -> [a] -> [a]
:[]) (Context -> [Context]) -> JSM Context -> JSM [Context]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> LineCapType -> JSM Context
forall a. ToJSVal a => a -> JSM Context
toJSVal LineCapType
arg
instance ToJSVal LineCapType where
toJSVal :: LineCapType -> JSM Context
toJSVal = MisoString -> JSM Context
forall a. ToJSVal a => a -> JSM Context
toJSVal (MisoString -> JSM Context)
-> (LineCapType -> MisoString) -> LineCapType -> JSM Context
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LineCapType -> MisoString
renderLineCapType
renderLineCapType :: LineCapType -> MisoString
renderLineCapType :: LineCapType -> MisoString
renderLineCapType LineCapType
LineCapButt = MisoString
"butt"
renderLineCapType LineCapType
LineCapRound = MisoString
"round"
renderLineCapType 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 MakeArgs LineJoinType where
makeArgs :: LineJoinType -> JSM [Context]
makeArgs LineJoinType
arg = (Context -> [Context] -> [Context]
forall a. a -> [a] -> [a]
:[]) (Context -> [Context]) -> JSM Context -> JSM [Context]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> LineJoinType -> JSM Context
forall a. ToJSVal a => a -> JSM Context
toJSVal LineJoinType
arg
instance ToJSVal LineJoinType where
toJSVal :: LineJoinType -> JSM Context
toJSVal = MisoString -> JSM Context
forall a. ToJSVal a => a -> JSM Context
toJSVal (MisoString -> JSM Context)
-> (LineJoinType -> MisoString) -> LineJoinType -> JSM Context
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LineJoinType -> MisoString
renderLineJoinType
renderLineJoinType :: LineJoinType -> MisoString
renderLineJoinType :: LineJoinType -> MisoString
renderLineJoinType LineJoinType
LineJoinBevel = MisoString
"bevel"
renderLineJoinType LineJoinType
LineJoinRound = MisoString
"round"
renderLineJoinType 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 MakeArgs DirectionType where
makeArgs :: DirectionType -> JSM [Context]
makeArgs DirectionType
arg = (Context -> [Context] -> [Context]
forall a. a -> [a] -> [a]
:[]) (Context -> [Context]) -> JSM Context -> JSM [Context]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> DirectionType -> JSM Context
forall a. ToJSVal a => a -> JSM Context
toJSVal DirectionType
arg
instance ToJSVal DirectionType where
toJSVal :: DirectionType -> JSM Context
toJSVal = MisoString -> JSM Context
forall a. ToJSVal a => a -> JSM Context
toJSVal (MisoString -> JSM Context)
-> (DirectionType -> MisoString) -> DirectionType -> JSM Context
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DirectionType -> MisoString
renderDirectionType
renderDirectionType :: DirectionType -> MisoString
renderDirectionType :: DirectionType -> MisoString
renderDirectionType DirectionType
LTR = MisoString
"ltr"
renderDirectionType DirectionType
RTL = MisoString
"rtl"
renderDirectionType 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 MakeArgs TextAlignType where
makeArgs :: TextAlignType -> JSM [Context]
makeArgs TextAlignType
arg = (Context -> [Context] -> [Context]
forall a. a -> [a] -> [a]
:[]) (Context -> [Context]) -> JSM Context -> JSM [Context]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TextAlignType -> JSM Context
forall a. ToJSVal a => a -> JSM Context
toJSVal TextAlignType
arg
instance ToJSVal TextAlignType where
toJSVal :: TextAlignType -> JSM Context
toJSVal = MisoString -> JSM Context
forall a. ToJSVal a => a -> JSM Context
toJSVal (MisoString -> JSM Context)
-> (TextAlignType -> MisoString) -> TextAlignType -> JSM Context
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TextAlignType -> MisoString
renderTextAlignType
renderTextAlignType :: TextAlignType -> MisoString
renderTextAlignType :: TextAlignType -> MisoString
renderTextAlignType TextAlignType
TextAlignCenter = MisoString
"center"
renderTextAlignType TextAlignType
TextAlignEnd = MisoString
"end"
renderTextAlignType TextAlignType
TextAlignLeft = MisoString
"left"
renderTextAlignType TextAlignType
TextAlignRight = MisoString
"right"
renderTextAlignType 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 MakeArgs TextBaselineType where
makeArgs :: TextBaselineType -> JSM [Context]
makeArgs TextBaselineType
arg = (Context -> [Context] -> [Context]
forall a. a -> [a] -> [a]
:[]) (Context -> [Context]) -> JSM Context -> JSM [Context]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TextBaselineType -> JSM Context
forall a. ToJSVal a => a -> JSM Context
toJSVal TextBaselineType
arg
instance ToJSVal TextBaselineType where
toJSVal :: TextBaselineType -> JSM Context
toJSVal = MisoString -> JSM Context
forall a. ToJSVal a => a -> JSM Context
toJSVal (MisoString -> JSM Context)
-> (TextBaselineType -> MisoString)
-> TextBaselineType
-> JSM Context
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TextBaselineType -> MisoString
renderTextBaselineType
renderTextBaselineType :: TextBaselineType -> MisoString
renderTextBaselineType :: TextBaselineType -> MisoString
renderTextBaselineType TextBaselineType
TextBaselineAlphabetic = MisoString
"alphabetic"
renderTextBaselineType TextBaselineType
TextBaselineTop = MisoString
"top"
renderTextBaselineType TextBaselineType
TextBaselineHanging = MisoString
"hanging"
renderTextBaselineType TextBaselineType
TextBaselineMiddle = MisoString
"middle"
renderTextBaselineType TextBaselineType
TextBaselineIdeographic = MisoString
"ideographic"
renderTextBaselineType 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 MakeArgs CompositeOperation where
makeArgs :: CompositeOperation -> JSM [Context]
makeArgs CompositeOperation
arg = (Context -> [Context] -> [Context]
forall a. a -> [a] -> [a]
:[]) (Context -> [Context]) -> JSM Context -> JSM [Context]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> CompositeOperation -> JSM Context
forall a. ToJSVal a => a -> JSM Context
toJSVal CompositeOperation
arg
instance ToJSVal CompositeOperation where
toJSVal :: CompositeOperation -> JSM Context
toJSVal = MisoString -> JSM Context
forall a. ToJSVal a => a -> JSM Context
toJSVal (MisoString -> JSM Context)
-> (CompositeOperation -> MisoString)
-> CompositeOperation
-> JSM Context
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CompositeOperation -> MisoString
renderCompositeOperation
renderCompositeOperation :: CompositeOperation -> MisoString
renderCompositeOperation :: CompositeOperation -> MisoString
renderCompositeOperation CompositeOperation
SourceOver = MisoString
"source-over"
renderCompositeOperation CompositeOperation
SourceAtop = MisoString
"source-atop"
renderCompositeOperation CompositeOperation
SourceIn = MisoString
"source-in"
renderCompositeOperation CompositeOperation
SourceOut = MisoString
"source-out"
renderCompositeOperation CompositeOperation
DestinationOver = MisoString
"destination-over"
renderCompositeOperation CompositeOperation
DestinationAtop = MisoString
"destination-atop"
renderCompositeOperation CompositeOperation
DestinationIn = MisoString
"destination-in"
renderCompositeOperation CompositeOperation
DestinationOut = MisoString
"destination-out"
renderCompositeOperation CompositeOperation
Lighter = MisoString
"lighter"
renderCompositeOperation CompositeOperation
Copy = MisoString
"copy"
renderCompositeOperation CompositeOperation
Xor = MisoString
"xor"
newtype Pattern = Pattern JSVal deriving ([Pattern] -> JSM Context
Pattern -> JSM Context
(Pattern -> JSM Context)
-> ([Pattern] -> JSM Context) -> ToJSVal Pattern
forall a. (a -> JSM Context) -> ([a] -> JSM Context) -> ToJSVal a
$ctoJSVal :: Pattern -> JSM Context
toJSVal :: Pattern -> JSM Context
$ctoJSValListOf :: [Pattern] -> JSM Context
toJSValListOf :: [Pattern] -> JSM Context
ToJSVal)
instance FromJSVal Pattern where
fromJSVal :: Context -> JSM (Maybe Pattern)
fromJSVal = Maybe Pattern -> JSM (Maybe Pattern)
forall a. a -> JSM a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe Pattern -> JSM (Maybe Pattern))
-> (Context -> Maybe Pattern) -> Context -> JSM (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)
-> (Context -> Pattern) -> Context -> Maybe Pattern
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Context -> Pattern
Pattern
newtype Gradient = Gradient JSVal deriving ([Gradient] -> JSM Context
Gradient -> JSM Context
(Gradient -> JSM Context)
-> ([Gradient] -> JSM Context) -> ToJSVal Gradient
forall a. (a -> JSM Context) -> ([a] -> JSM Context) -> ToJSVal a
$ctoJSVal :: Gradient -> JSM Context
toJSVal :: Gradient -> JSM Context
$ctoJSValListOf :: [Gradient] -> JSM Context
toJSValListOf :: [Gradient] -> JSM Context
ToJSVal)
instance FromJSVal Gradient where
fromJSVal :: Context -> JSM (Maybe Gradient)
fromJSVal = Maybe Gradient -> JSM (Maybe Gradient)
forall a. a -> JSM a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe Gradient -> JSM (Maybe Gradient))
-> (Context -> Maybe Gradient) -> Context -> JSM (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)
-> (Context -> Gradient) -> Context -> Maybe Gradient
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Context -> Gradient
Gradient
newtype ImageData = ImageData JSVal deriving ([ImageData] -> JSM Context
ImageData -> JSM Context
(ImageData -> JSM Context)
-> ([ImageData] -> JSM Context) -> ToJSVal ImageData
forall a. (a -> JSM Context) -> ([a] -> JSM Context) -> ToJSVal a
$ctoJSVal :: ImageData -> JSM Context
toJSVal :: ImageData -> JSM Context
$ctoJSValListOf :: [ImageData] -> JSM Context
toJSValListOf :: [ImageData] -> JSM Context
ToJSVal, ImageData -> JSM Object
(ImageData -> JSM Object) -> MakeObject ImageData
forall this. (this -> JSM Object) -> MakeObject this
$cmakeObject :: ImageData -> JSM Object
makeObject :: ImageData -> JSM Object
MakeObject)
instance MakeArgs ImageData where
makeArgs :: ImageData -> JSM [Context]
makeArgs ImageData
args = (Context -> [Context] -> [Context]
forall a. a -> [a] -> [a]
:[]) (Context -> [Context]) -> JSM Context -> JSM [Context]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ImageData -> JSM Context
forall a. ToJSVal a => a -> JSM Context
toJSVal ImageData
args
instance FromJSVal ImageData where
fromJSVal :: Context -> JSM (Maybe ImageData)
fromJSVal = Maybe ImageData -> JSM (Maybe ImageData)
forall a. a -> JSM a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe ImageData -> JSM (Maybe ImageData))
-> (Context -> Maybe ImageData) -> Context -> JSM (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)
-> (Context -> ImageData) -> Context -> Maybe ImageData
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Context -> ImageData
ImageData
type Coord = (Double, Double)
type Context = JSVal
call :: (FromJSVal a, MakeArgs args) => MisoString -> args -> Canvas a
call :: forall a args.
(FromJSVal a, MakeArgs args) =>
MisoString -> args -> Canvas a
call MisoString
name args
arg = do
ctx <- ReaderT Context JSM Context
forall r (m :: * -> *). MonadReader r m => m r
ask
liftJSM $ fromJSValUnchecked =<< do
ctx # name $ arg
set :: MakeArgs args => MisoString -> args -> Canvas ()
set :: forall args. MakeArgs args => MisoString -> args -> Canvas ()
set MisoString
name args
arg = do
ctx <- ReaderT Context JSM Context
forall r (m :: * -> *). MonadReader r m => m r
ask
liftJSM (ctx <# name $ makeArgs arg)
type Canvas a = ReaderT Context JSM a
globalCompositeOperation :: CompositeOperation -> Canvas ()
globalCompositeOperation :: CompositeOperation -> Canvas ()
globalCompositeOperation = MisoString -> CompositeOperation -> Canvas ()
forall args. MakeArgs 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, MakeArgs 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, MakeArgs 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, MakeArgs args) =>
MisoString -> args -> Canvas a
call MisoString
"strokeRect"
beginPath :: () -> Canvas ()
beginPath :: () -> Canvas ()
beginPath = MisoString -> () -> Canvas ()
forall a args.
(FromJSVal a, MakeArgs args) =>
MisoString -> args -> Canvas a
call MisoString
"beginPath"
closePath :: () -> Canvas ()
closePath :: () -> Canvas ()
closePath = MisoString -> () -> Canvas ()
forall a args.
(FromJSVal a, MakeArgs args) =>
MisoString -> args -> Canvas a
call MisoString
"closePath"
moveTo :: Coord -> Canvas ()
moveTo :: Coord -> Canvas ()
moveTo = MisoString -> Coord -> Canvas ()
forall a args.
(FromJSVal a, MakeArgs args) =>
MisoString -> args -> Canvas a
call MisoString
"moveTo"
lineTo :: Coord -> Canvas ()
lineTo :: Coord -> Canvas ()
lineTo = MisoString -> Coord -> Canvas ()
forall a args.
(FromJSVal a, MakeArgs args) =>
MisoString -> args -> Canvas a
call MisoString
"lineTo"
fill :: () -> Canvas ()
fill :: () -> Canvas ()
fill = MisoString -> () -> Canvas ()
forall a args.
(FromJSVal a, MakeArgs 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, MakeArgs args) =>
MisoString -> args -> Canvas a
call MisoString
"rect"
stroke :: () -> Canvas ()
stroke :: () -> Canvas ()
stroke = MisoString -> () -> Canvas ()
forall a args.
(FromJSVal a, MakeArgs 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, MakeArgs 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, MakeArgs 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, MakeArgs 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, MakeArgs args) =>
MisoString -> args -> Canvas a
call MisoString
"quadraticCurveTo"
direction :: DirectionType -> Canvas ()
direction :: DirectionType -> Canvas ()
direction = MisoString -> DirectionType -> Canvas ()
forall args. MakeArgs 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, MakeArgs args) =>
MisoString -> args -> Canvas a
call MisoString
"fillText"
font :: MisoString -> Canvas ()
font :: MisoString -> Canvas ()
font = MisoString -> MisoString -> Canvas ()
forall args. MakeArgs 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, MakeArgs args) =>
MisoString -> args -> Canvas a
call MisoString
"strokeText"
textAlign :: TextAlignType -> Canvas ()
textAlign :: TextAlignType -> Canvas ()
textAlign = MisoString -> TextAlignType -> Canvas ()
forall args. MakeArgs args => MisoString -> args -> Canvas ()
set MisoString
"textAlign"
textBaseline :: TextBaselineType -> Canvas ()
textBaseline :: TextBaselineType -> Canvas ()
textBaseline = MisoString -> TextBaselineType -> Canvas ()
forall args. MakeArgs args => MisoString -> args -> Canvas ()
set MisoString
"textBaseline"
addColorStop :: (Gradient, Double, Color) -> Canvas ()
addColorStop :: (Gradient, Double, Color) -> Canvas ()
addColorStop = MisoString -> (Gradient, Double, Color) -> Canvas ()
forall a args.
(FromJSVal a, MakeArgs args) =>
MisoString -> args -> Canvas a
call MisoString
"addColorStop"
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, MakeArgs 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, MakeArgs 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, MakeArgs args) =>
MisoString -> args -> Canvas a
call MisoString
"createRadialGradient"
fillStyle :: StyleArg -> Canvas ()
fillStyle :: StyleArg -> Canvas ()
fillStyle = MisoString -> StyleArg -> Canvas ()
forall args. MakeArgs args => MisoString -> args -> Canvas ()
set MisoString
"fillStyle"
lineCap :: LineCapType -> Canvas ()
lineCap :: LineCapType -> Canvas ()
lineCap = MisoString -> LineCapType -> Canvas ()
forall args. MakeArgs args => MisoString -> args -> Canvas ()
set MisoString
"lineCap"
lineJoin :: LineJoinType -> Canvas ()
lineJoin :: LineJoinType -> Canvas ()
lineJoin = MisoString -> LineJoinType -> Canvas ()
forall args. MakeArgs args => MisoString -> args -> Canvas ()
set MisoString
"lineJoin"
lineWidth :: Double -> Canvas ()
lineWidth :: Double -> Canvas ()
lineWidth = MisoString -> Double -> Canvas ()
forall args. MakeArgs args => MisoString -> args -> Canvas ()
set MisoString
"lineWidth"
miterLimit :: Double -> Canvas ()
miterLimit :: Double -> Canvas ()
miterLimit = MisoString -> Double -> Canvas ()
forall args. MakeArgs args => MisoString -> args -> Canvas ()
set MisoString
"miterLimit"
shadowBlur :: Double -> Canvas ()
shadowBlur :: Double -> Canvas ()
shadowBlur = MisoString -> Double -> Canvas ()
forall args. MakeArgs args => MisoString -> args -> Canvas ()
set MisoString
"shadowBlur"
shadowColor :: Color -> Canvas ()
shadowColor :: Color -> Canvas ()
shadowColor = MisoString -> Color -> Canvas ()
forall args. MakeArgs args => MisoString -> args -> Canvas ()
set MisoString
"shadowColor"
shadowOffsetX :: Double -> Canvas ()
shadowOffsetX :: Double -> Canvas ()
shadowOffsetX = MisoString -> Double -> Canvas ()
forall args. MakeArgs args => MisoString -> args -> Canvas ()
set MisoString
"shadowOffsetX"
shadowOffsetY :: Double -> Canvas ()
shadowOffsetY :: Double -> Canvas ()
shadowOffsetY = MisoString -> Double -> Canvas ()
forall args. MakeArgs args => MisoString -> args -> Canvas ()
set MisoString
"shadowOffsetY"
strokeStyle :: StyleArg -> Canvas ()
strokeStyle :: StyleArg -> Canvas ()
strokeStyle = MisoString -> StyleArg -> Canvas ()
forall args. MakeArgs args => MisoString -> args -> Canvas ()
set MisoString
"strokeStyle"
scale :: (Double, Double) -> Canvas ()
scale :: Coord -> Canvas ()
scale = MisoString -> Coord -> Canvas ()
forall a args.
(FromJSVal a, MakeArgs args) =>
MisoString -> args -> Canvas a
call MisoString
"scale"
rotate :: Double -> Canvas ()
rotate :: Double -> Canvas ()
rotate = MisoString -> Double -> Canvas ()
forall a args.
(FromJSVal a, MakeArgs args) =>
MisoString -> args -> Canvas a
call MisoString
"rotate"
translate :: Coord -> Canvas ()
translate :: Coord -> Canvas ()
translate = MisoString -> Coord -> Canvas ()
forall a args.
(FromJSVal a, MakeArgs 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, MakeArgs 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, MakeArgs 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, MakeArgs 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, MakeArgs 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, MakeArgs 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, MakeArgs 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) = JSM () -> Canvas ()
forall (m :: * -> *) a. MonadJSM m => JSM a -> m a
liftJSM (JSM () -> Canvas ()) -> JSM () -> Canvas ()
forall a b. (a -> b) -> a -> b
$ do
o <- ImageData
imgData ImageData -> MisoString -> JSM Context
forall this name.
(MakeObject this, ToJSString name) =>
this -> name -> JSM Context
! (MisoString
"data" :: MisoString)
(o <## index) value
height :: ImageData -> Canvas Double
height :: ImageData -> Canvas Double
height (ImageData Context
imgData) = JSM Double -> Canvas Double
forall (m :: * -> *) a. MonadJSM m => JSM a -> m a
liftJSM (JSM Double -> Canvas Double) -> JSM Double -> Canvas Double
forall a b. (a -> b) -> a -> b
$ do
Context -> JSM Double
forall a. FromJSVal a => Context -> JSM a
fromJSValUnchecked (Context -> JSM Double) -> JSM Context -> JSM Double
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Context
imgData Context -> MisoString -> JSM Context
forall this name.
(MakeObject this, ToJSString name) =>
this -> name -> JSM Context
! (MisoString
"height" :: MisoString)
width :: ImageData -> Canvas Double
width :: ImageData -> Canvas Double
width (ImageData Context
imgData) = JSM Double -> Canvas Double
forall (m :: * -> *) a. MonadJSM m => JSM a -> m a
liftJSM (JSM Double -> Canvas Double) -> JSM Double -> Canvas Double
forall a b. (a -> b) -> a -> b
$ do
Context -> JSM Double
forall a. FromJSVal a => Context -> JSM a
fromJSValUnchecked (Context -> JSM Double) -> JSM Context -> JSM Double
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Context
imgData Context -> MisoString -> JSM Context
forall this name.
(MakeObject this, ToJSString name) =>
this -> name -> JSM Context
! (MisoString
"width" :: MisoString)
putImageData :: (ImageData, Double, Double) -> Canvas ()
putImageData :: (ImageData, Double, Double) -> Canvas ()
putImageData = MisoString -> (ImageData, Double, Double) -> Canvas ()
forall a args.
(FromJSVal a, MakeArgs args) =>
MisoString -> args -> Canvas a
call MisoString
"putImageData"
globalAlpha :: Double -> Canvas ()
globalAlpha :: Double -> Canvas ()
globalAlpha = MisoString -> Double -> Canvas ()
forall args. MakeArgs args => MisoString -> args -> Canvas ()
set MisoString
"globalAlpha"
clip :: () -> Canvas ()
clip :: () -> Canvas ()
clip = MisoString -> () -> Canvas ()
forall a args.
(FromJSVal a, MakeArgs args) =>
MisoString -> args -> Canvas a
call MisoString
"clip"
save :: () -> Canvas ()
save :: () -> Canvas ()
save = MisoString -> () -> Canvas ()
forall a args.
(FromJSVal a, MakeArgs args) =>
MisoString -> args -> Canvas a
call MisoString
"save"
restore :: () -> Canvas ()
restore :: () -> Canvas ()
restore = MisoString -> () -> Canvas ()
forall a args.
(FromJSVal a, MakeArgs args) =>
MisoString -> args -> Canvas a
call MisoString
"restore"