Skip to content

Commit 817e046

Browse files
committed
Merge pull request #6 from jdeseno/global-composite
Add global composite and alpha functions
2 parents bdb3126 + db52e14 commit 817e046

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
@@ -169,6 +169,55 @@ setLineCap Round = setLineCapImpl "round"
169169
setLineCap Square = setLineCapImpl "square"
170170
setLineCap Butt = setLineCapImpl "butt"
171171

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

0 commit comments

Comments
 (0)