From ac6646cc4310501a822d48a5c74ec009dcf2b49a Mon Sep 17 00:00:00 2001 From: Ingmar Gagen Date: Wed, 9 Mar 2016 22:39:44 -0800 Subject: [PATCH 1/2] Implement appropriate Show instances for TextAlign, Composite and PatternRepeat --- docs/Graphics/Canvas.md | 7 +++- src/Graphics/Canvas.purs | 70 +++++++++++++++++++++++++++------------- 2 files changed, 54 insertions(+), 23 deletions(-) diff --git a/docs/Graphics/Canvas.md b/docs/Graphics/Canvas.md index 831ad92..417182d 100644 --- a/docs/Graphics/Canvas.md +++ b/docs/Graphics/Canvas.md @@ -669,6 +669,11 @@ data PatternRepeat Enumerates the different types of pattern repetitions. +##### Instances +``` purescript +Show PatternRepeat +``` + #### `createPattern` ``` purescript @@ -680,7 +685,7 @@ Create a new canvas pattern (repeatable image). #### `setPatternFillStyle` ``` purescript -setPatternFillStyle :: forall eff. CanvasGradient -> Context2D -> Eff (canvas :: Canvas | eff) Context2D +setPatternFillStyle :: forall eff. CanvasPattern -> Context2D -> Eff (canvas :: Canvas | eff) Context2D ``` Set the Context2D fillstyle to the CanvasPattern. diff --git a/src/Graphics/Canvas.purs b/src/Graphics/Canvas.purs index b7d4a01..e8b0aff 100644 --- a/src/Graphics/Canvas.purs +++ b/src/Graphics/Canvas.purs @@ -228,23 +228,35 @@ data Composite | 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" + show SourceOver = "SourceOver" + show SourceIn = "SourceIn" + show SourceOut = "SourceOut" + show SourceAtop = "SourceAtop" + show DestinationOver = "DestinationOver" + show DestinationIn = "DestinationIn" + show DestinationOut = "DestinationOut" + show DestinationAtop = "DestinationAtop" + show Lighter = "Lighter" + show Copy = "Copy" + show Xor = "Xor" foreign import setGlobalCompositeOperationImpl :: forall eff. Context2D -> String -> Eff (canvas :: Canvas | eff) Context2D -- | Set the current composite operation. setGlobalCompositeOperation :: forall eff. Context2D -> Composite -> Eff (canvas :: Canvas | eff) Context2D -setGlobalCompositeOperation ctx composite = setGlobalCompositeOperationImpl ctx (show composite) +setGlobalCompositeOperation ctx composite = setGlobalCompositeOperationImpl ctx (toString composite) + where + toString SourceOver = "source-over" + toString SourceIn = "source-in" + toString SourceOut = "source-out" + toString SourceAtop = "source-atop" + toString DestinationOver = "destination-over" + toString DestinationIn = "destination-in" + toString DestinationOut = "destination-out" + toString DestinationAtop = "destination-atop" + toString Lighter = "lighter" + toString Copy = "copy" + toString Xor = "xor" -- | Set the current global alpha level. foreign import setGlobalAlpha :: forall eff. Context2D -> Number -> Eff (canvas :: Canvas | eff) Context2D @@ -388,11 +400,11 @@ data TextAlign = AlignLeft | AlignRight | AlignCenter | AlignStart | AlignEnd instance showTextAlign :: Show TextAlign where - show AlignLeft = "left" - show AlignRight = "right" - show AlignCenter = "center" - show AlignStart = "start" - show AlignEnd = "end" + show AlignLeft = "AlignLeft" + show AlignRight = "AlignRight" + show AlignCenter = "AlignCenter" + show AlignStart = "AlignStart" + show AlignEnd = "AlignEnd" foreign import textAlignImpl :: forall eff. Context2D -> Eff (canvas :: Canvas | eff) String @@ -414,7 +426,13 @@ foreign import setTextAlignImpl :: forall eff. Context2D -> String -> (Eff (canv -- | Set the current text alignment. setTextAlign :: forall eff. Context2D -> TextAlign -> Eff (canvas :: Canvas | eff) Context2D setTextAlign ctx textalign = - setTextAlignImpl ctx (show textalign) + setTextAlignImpl ctx (toString textalign) + where + toString AlignLeft = "left" + toString AlignRight = "right" + toString AlignCenter = "center" + toString AlignStart = "start" + toString AlignEnd = "end" -- | Text metrics: -- | @@ -482,14 +500,22 @@ foreign import drawImageFull :: forall eff. Context2D -> CanvasImageSource -> Nu -- | Enumerates the different types of pattern repetitions. data PatternRepeat = Repeat | RepeatX | RepeatY | NoRepeat +instance showPatternRepeat :: Show PatternRepeat where + show Repeat = "Repeat" + show RepeatX = "RepeatX" + show RepeatY = "RepeatY" + show NoRepeat = "NoRepeat" + foreign import createPatternImpl :: forall eff. CanvasImageSource -> String -> Context2D -> Eff (canvas :: Canvas | eff) CanvasPattern -- | Create a new canvas pattern (repeatable image). createPattern :: forall eff. CanvasImageSource -> PatternRepeat -> Context2D -> Eff (canvas :: Canvas | eff) CanvasPattern -createPattern img Repeat = createPatternImpl img "repeat" -createPattern img RepeatX = createPatternImpl img "repeat-x" -createPattern img RepeatY = createPatternImpl img "repeat-y" -createPattern img NoRepeat = createPatternImpl img "no-repeat" +createPattern img repeat = createPatternImpl img (toString repeat) + where + toString Repeat = "repeat" + toString RepeatX = "repeat-x" + toString RepeatY = "repeat-y" + toString NoRepeat = "no-repeat" -- | Set the Context2D fillstyle to the CanvasPattern. foreign import setPatternFillStyle :: forall eff. CanvasPattern -> Context2D -> Eff (canvas :: Canvas | eff) Context2D From e2b19f8a6d98610f91a228e2bed933c107a6467c Mon Sep 17 00:00:00 2001 From: Ingmar Gagen Date: Thu, 10 Mar 2016 22:18:29 -0800 Subject: [PATCH 2/2] Add support for new canvas blend modes --- docs/Graphics/Canvas.md | 21 ++++++++++++++--- src/Graphics/Canvas.purs | 50 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 67 insertions(+), 4 deletions(-) diff --git a/docs/Graphics/Canvas.md b/docs/Graphics/Canvas.md index 417182d..d0be550 100644 --- a/docs/Graphics/Canvas.md +++ b/docs/Graphics/Canvas.md @@ -243,9 +243,24 @@ data Composite | Lighter | Copy | Xor -``` - -Enumerates the different types of alpha composite operations. + | Multiply + | Screen + | Overlay + | Darken + | Lighten + | ColorDodge + | ColorBurn + | HardLight + | SoftLight + | Difference + | Exclusion + | Hue + | Saturation + | Color + | Luminosity +``` + +Enumerates the different types of composite operations and blend modes. ##### Instances ``` purescript diff --git a/src/Graphics/Canvas.purs b/src/Graphics/Canvas.purs index e8b0aff..0029ec3 100644 --- a/src/Graphics/Canvas.purs +++ b/src/Graphics/Canvas.purs @@ -213,8 +213,9 @@ setLineCap Round = setLineCapImpl "round" setLineCap Square = setLineCapImpl "square" setLineCap Butt = setLineCapImpl "butt" --- | Enumerates the different types of alpha composite operations. +-- | Enumerates the different types of composite operations and blend modes. data Composite + -- Composite Operations = SourceOver | SourceIn | SourceOut @@ -227,6 +228,23 @@ data Composite | Copy | Xor + -- Blend Modes + | Multiply + | Screen + | Overlay + | Darken + | Lighten + | ColorDodge + | ColorBurn + | HardLight + | SoftLight + | Difference + | Exclusion + | Hue + | Saturation + | Color + | Luminosity + instance showComposite :: Show Composite where show SourceOver = "SourceOver" show SourceIn = "SourceIn" @@ -239,6 +257,21 @@ instance showComposite :: Show Composite where show Lighter = "Lighter" show Copy = "Copy" show Xor = "Xor" + show Multiply = "Multiply" + show Screen = "Screen" + show Overlay = "Overlay" + show Darken = "Darken" + show Lighten = "Lighten" + show ColorDodge = "ColorDodge" + show ColorBurn = "ColorBurn" + show HardLight = "HardLight" + show SoftLight = "SoftLight" + show Difference = "Difference" + show Exclusion = "Exclusion" + show Hue = "Hue" + show Saturation = "Saturation" + show Color = "Color" + show Luminosity = "Luminosity" foreign import setGlobalCompositeOperationImpl :: forall eff. Context2D -> String -> Eff (canvas :: Canvas | eff) Context2D @@ -257,6 +290,21 @@ setGlobalCompositeOperation ctx composite = setGlobalCompositeOperationImpl ctx toString Lighter = "lighter" toString Copy = "copy" toString Xor = "xor" + toString Multiply = "multiply" + toString Screen = "screen" + toString Overlay = "overlay" + toString Darken = "darken" + toString Lighten = "lighten" + toString ColorDodge = "color-dodge" + toString ColorBurn = "color-burn" + toString HardLight = "hard-light" + toString SoftLight = "soft-light" + toString Difference = "difference" + toString Exclusion = "exclusion" + toString Hue = "hue" + toString Saturation = "saturation" + toString Color = "color" + toString Luminosity = "luminosity" -- | Set the current global alpha level. foreign import setGlobalAlpha :: forall eff. Context2D -> Number -> Eff (canvas :: Canvas | eff) Context2D