Skip to content

Commit db52e14

Browse files
author
jdeseno
committed
Add global composite and alpha functions
1 parent 4de1b8b commit db52e14

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

src/Graphics/Canvas.purs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,55 @@ setLineCap Round = setLineCapImpl "round"
167167
setLineCap Square = setLineCapImpl "square"
168168
setLineCap Butt = setLineCapImpl "butt"
169169

170+
data Composite
171+
= SourceOver
172+
| SourceIn
173+
| SourceOut
174+
| SourceAtop
175+
| DestinationOver
176+
| DestinationIn
177+
| DestinationOut
178+
| DestinationAtop
179+
| Lighter
180+
| Copy
181+
| Xor
182+
183+
instance showComposite :: Show Composite where
184+
show SourceOver = "source-over"
185+
show SourceIn = "source-in"
186+
show SourceOut = "source-out"
187+
show SourceAtop = "source-atop"
188+
show DestinationOver = "destination-over"
189+
show DestinationIn = "destination-in"
190+
show DestinationOut = "destination-out"
191+
show DestinationAtop = "destination-atop"
192+
show Lighter = "lighter"
193+
show Copy = "copy"
194+
show Xor = "xor"
195+
196+
foreign import setGlobalCompositeOperationImpl
197+
"function setGlobalCompositeOperationImpl(ctx) {\
198+
\ return function(op) {\
199+
\ return function() {\
200+
\ ctx.globalCompositeOperation = op;\
201+
\ return ctx;\
202+
\ };\
203+
\ };\
204+
\}" :: forall eff. Context2D -> String -> Eff (canvas :: Canvas | eff) Context2D
205+
206+
setGlobalCompositeOperation :: forall eff. Context2D -> Composite -> Eff (canvas :: Canvas | eff) Context2D
207+
setGlobalCompositeOperation ctx composite = setGlobalCompositeOperationImpl ctx (show composite)
208+
209+
foreign import setGlobalAlpha
210+
"function setGlobalAlpha(ctx) {\
211+
\ return function(alpha) {\
212+
\ return function() {\
213+
\ ctx.setGlobalAlpha = alpha;\
214+
\ return ctx;\
215+
\ };\
216+
\ };\
217+
\}" :: forall eff. Context2D -> Number -> Eff (canvas :: Canvas | eff) Context2D
218+
170219
-- |
171220
-- Paths
172221
--

0 commit comments

Comments
 (0)