Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions src/Graphics/Canvas.purs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,55 @@ setLineCap Round = setLineCapImpl "round"
setLineCap Square = setLineCapImpl "square"
setLineCap Butt = setLineCapImpl "butt"

data Composite
= SourceOver
| SourceIn
| SourceOut
| SourceAtop
| DestinationOver
| DestinationIn
| DestinationOut
| DestinationAtop
| Lighter
| Copy
| Xor

instance showComposite :: Show Composite where
show SourceOver = "source-over"
show SourceIn = "source-in"
show SourceOut = "source-out"
show SourceAtop = "source-atop"
show DestinationOver = "destination-over"
show DestinationIn = "destination-in"
show DestinationOut = "destination-out"
show DestinationAtop = "destination-atop"
show Lighter = "lighter"
show Copy = "copy"
show Xor = "xor"

foreign import setGlobalCompositeOperationImpl
"function setGlobalCompositeOperationImpl(ctx) {\
\ return function(op) {\
\ return function() {\
\ ctx.globalCompositeOperation = op;\
\ return ctx;\
\ };\
\ };\
\}" :: forall eff. Context2D -> String -> Eff (canvas :: Canvas | eff) Context2D

setGlobalCompositeOperation :: forall eff. Context2D -> Composite -> Eff (canvas :: Canvas | eff) Context2D
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be a little simpler to implement Composite -> String and then define setGlobalCompositeOperation by composition.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added an instance for Show Composite originally this was a new class ToJS (essentially identical to Show here) but I had removed it when I saw the existing pattern for setLineCap above.

setGlobalCompositeOperation ctx composite = setGlobalCompositeOperationImpl ctx (show composite)

foreign import setGlobalAlpha
"function setGlobalAlpha(ctx) {\
\ return function(alpha) {\
\ return function() {\
\ ctx.setGlobalAlpha = alpha;\
\ return ctx;\
\ };\
\ };\
\}" :: forall eff. Context2D -> Number -> Eff (canvas :: Canvas | eff) Context2D

-- |
-- Paths
--
Expand Down