Skip to content

Commit f8d1fa2

Browse files
committed
Merge pull request #32 from igagen/patterns
Add Blend Modes and Canonical Show instances for Enumerations
2 parents 637ed3a + e2b19f8 commit f8d1fa2

File tree

2 files changed

+121
-27
lines changed

2 files changed

+121
-27
lines changed

docs/Graphics/Canvas.md

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,24 @@ data Composite
243243
| Lighter
244244
| Copy
245245
| Xor
246-
```
247-
248-
Enumerates the different types of alpha composite operations.
246+
| Multiply
247+
| Screen
248+
| Overlay
249+
| Darken
250+
| Lighten
251+
| ColorDodge
252+
| ColorBurn
253+
| HardLight
254+
| SoftLight
255+
| Difference
256+
| Exclusion
257+
| Hue
258+
| Saturation
259+
| Color
260+
| Luminosity
261+
```
262+
263+
Enumerates the different types of composite operations and blend modes.
249264

250265
##### Instances
251266
``` purescript
@@ -669,6 +684,11 @@ data PatternRepeat
669684

670685
Enumerates the different types of pattern repetitions.
671686

687+
##### Instances
688+
``` purescript
689+
Show PatternRepeat
690+
```
691+
672692
#### `createPattern`
673693

674694
``` purescript
@@ -680,7 +700,7 @@ Create a new canvas pattern (repeatable image).
680700
#### `setPatternFillStyle`
681701

682702
``` purescript
683-
setPatternFillStyle :: forall eff. CanvasGradient -> Context2D -> Eff (canvas :: Canvas | eff) Context2D
703+
setPatternFillStyle :: forall eff. CanvasPattern -> Context2D -> Eff (canvas :: Canvas | eff) Context2D
684704
```
685705

686706
Set the Context2D fillstyle to the CanvasPattern.

src/Graphics/Canvas.purs

Lines changed: 97 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,9 @@ setLineCap Round = setLineCapImpl "round"
213213
setLineCap Square = setLineCapImpl "square"
214214
setLineCap Butt = setLineCapImpl "butt"
215215

216-
-- | Enumerates the different types of alpha composite operations.
216+
-- | Enumerates the different types of composite operations and blend modes.
217217
data Composite
218+
-- Composite Operations
218219
= SourceOver
219220
| SourceIn
220221
| SourceOut
@@ -227,24 +228,83 @@ data Composite
227228
| Copy
228229
| Xor
229230

231+
-- Blend Modes
232+
| Multiply
233+
| Screen
234+
| Overlay
235+
| Darken
236+
| Lighten
237+
| ColorDodge
238+
| ColorBurn
239+
| HardLight
240+
| SoftLight
241+
| Difference
242+
| Exclusion
243+
| Hue
244+
| Saturation
245+
| Color
246+
| Luminosity
247+
230248
instance showComposite :: Show Composite where
231-
show SourceOver = "source-over"
232-
show SourceIn = "source-in"
233-
show SourceOut = "source-out"
234-
show SourceAtop = "source-atop"
235-
show DestinationOver = "destination-over"
236-
show DestinationIn = "destination-in"
237-
show DestinationOut = "destination-out"
238-
show DestinationAtop = "destination-atop"
239-
show Lighter = "lighter"
240-
show Copy = "copy"
241-
show Xor = "xor"
249+
show SourceOver = "SourceOver"
250+
show SourceIn = "SourceIn"
251+
show SourceOut = "SourceOut"
252+
show SourceAtop = "SourceAtop"
253+
show DestinationOver = "DestinationOver"
254+
show DestinationIn = "DestinationIn"
255+
show DestinationOut = "DestinationOut"
256+
show DestinationAtop = "DestinationAtop"
257+
show Lighter = "Lighter"
258+
show Copy = "Copy"
259+
show Xor = "Xor"
260+
show Multiply = "Multiply"
261+
show Screen = "Screen"
262+
show Overlay = "Overlay"
263+
show Darken = "Darken"
264+
show Lighten = "Lighten"
265+
show ColorDodge = "ColorDodge"
266+
show ColorBurn = "ColorBurn"
267+
show HardLight = "HardLight"
268+
show SoftLight = "SoftLight"
269+
show Difference = "Difference"
270+
show Exclusion = "Exclusion"
271+
show Hue = "Hue"
272+
show Saturation = "Saturation"
273+
show Color = "Color"
274+
show Luminosity = "Luminosity"
242275

243276
foreign import setGlobalCompositeOperationImpl :: forall eff. Context2D -> String -> Eff (canvas :: Canvas | eff) Context2D
244277

245278
-- | Set the current composite operation.
246279
setGlobalCompositeOperation :: forall eff. Context2D -> Composite -> Eff (canvas :: Canvas | eff) Context2D
247-
setGlobalCompositeOperation ctx composite = setGlobalCompositeOperationImpl ctx (show composite)
280+
setGlobalCompositeOperation ctx composite = setGlobalCompositeOperationImpl ctx (toString composite)
281+
where
282+
toString SourceOver = "source-over"
283+
toString SourceIn = "source-in"
284+
toString SourceOut = "source-out"
285+
toString SourceAtop = "source-atop"
286+
toString DestinationOver = "destination-over"
287+
toString DestinationIn = "destination-in"
288+
toString DestinationOut = "destination-out"
289+
toString DestinationAtop = "destination-atop"
290+
toString Lighter = "lighter"
291+
toString Copy = "copy"
292+
toString Xor = "xor"
293+
toString Multiply = "multiply"
294+
toString Screen = "screen"
295+
toString Overlay = "overlay"
296+
toString Darken = "darken"
297+
toString Lighten = "lighten"
298+
toString ColorDodge = "color-dodge"
299+
toString ColorBurn = "color-burn"
300+
toString HardLight = "hard-light"
301+
toString SoftLight = "soft-light"
302+
toString Difference = "difference"
303+
toString Exclusion = "exclusion"
304+
toString Hue = "hue"
305+
toString Saturation = "saturation"
306+
toString Color = "color"
307+
toString Luminosity = "luminosity"
248308

249309
-- | Set the current global alpha level.
250310
foreign import setGlobalAlpha :: forall eff. Context2D -> Number -> Eff (canvas :: Canvas | eff) Context2D
@@ -388,11 +448,11 @@ data TextAlign
388448
= AlignLeft | AlignRight | AlignCenter | AlignStart | AlignEnd
389449

390450
instance showTextAlign :: Show TextAlign where
391-
show AlignLeft = "left"
392-
show AlignRight = "right"
393-
show AlignCenter = "center"
394-
show AlignStart = "start"
395-
show AlignEnd = "end"
451+
show AlignLeft = "AlignLeft"
452+
show AlignRight = "AlignRight"
453+
show AlignCenter = "AlignCenter"
454+
show AlignStart = "AlignStart"
455+
show AlignEnd = "AlignEnd"
396456

397457
foreign import textAlignImpl :: forall eff. Context2D -> Eff (canvas :: Canvas | eff) String
398458

@@ -414,7 +474,13 @@ foreign import setTextAlignImpl :: forall eff. Context2D -> String -> (Eff (canv
414474
-- | Set the current text alignment.
415475
setTextAlign :: forall eff. Context2D -> TextAlign -> Eff (canvas :: Canvas | eff) Context2D
416476
setTextAlign ctx textalign =
417-
setTextAlignImpl ctx (show textalign)
477+
setTextAlignImpl ctx (toString textalign)
478+
where
479+
toString AlignLeft = "left"
480+
toString AlignRight = "right"
481+
toString AlignCenter = "center"
482+
toString AlignStart = "start"
483+
toString AlignEnd = "end"
418484

419485
-- | Text metrics:
420486
-- |
@@ -482,14 +548,22 @@ foreign import drawImageFull :: forall eff. Context2D -> CanvasImageSource -> Nu
482548
-- | Enumerates the different types of pattern repetitions.
483549
data PatternRepeat = Repeat | RepeatX | RepeatY | NoRepeat
484550

551+
instance showPatternRepeat :: Show PatternRepeat where
552+
show Repeat = "Repeat"
553+
show RepeatX = "RepeatX"
554+
show RepeatY = "RepeatY"
555+
show NoRepeat = "NoRepeat"
556+
485557
foreign import createPatternImpl :: forall eff. CanvasImageSource -> String -> Context2D -> Eff (canvas :: Canvas | eff) CanvasPattern
486558

487559
-- | Create a new canvas pattern (repeatable image).
488560
createPattern :: forall eff. CanvasImageSource -> PatternRepeat -> Context2D -> Eff (canvas :: Canvas | eff) CanvasPattern
489-
createPattern img Repeat = createPatternImpl img "repeat"
490-
createPattern img RepeatX = createPatternImpl img "repeat-x"
491-
createPattern img RepeatY = createPatternImpl img "repeat-y"
492-
createPattern img NoRepeat = createPatternImpl img "no-repeat"
561+
createPattern img repeat = createPatternImpl img (toString repeat)
562+
where
563+
toString Repeat = "repeat"
564+
toString RepeatX = "repeat-x"
565+
toString RepeatY = "repeat-y"
566+
toString NoRepeat = "no-repeat"
493567

494568
-- | Set the Context2D fillstyle to the CanvasPattern.
495569
foreign import setPatternFillStyle :: forall eff. CanvasPattern -> Context2D -> Eff (canvas :: Canvas | eff) Context2D

0 commit comments

Comments
 (0)