Skip to content

Add createPattern, setPatternFillStyle to Graphics.Canvas #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 10, 2016

Conversation

igagen
Copy link
Contributor

@igagen igagen commented Mar 10, 2016

This adds the following to the public Graphics.Canvas API:

  • createPattern - bindings to the canvas function for creating repeatable patterns from images.
  • setPatternFillStyle - sets the current fill style to a previously created pattern.
  • PatternRepeat - enumerates the different types of pattern repetition (used in createPattern).
  • CanvasPattern - opaque data type returned by createPattern.


-- | Create a new canvas pattern (repeatable image).
createPattern :: forall eff. CanvasImageSource -> PatternRepeat -> Context2D -> Eff (canvas :: Canvas | eff) CanvasPattern
createPattern img Repeat = createPatternImpl img "repeat"
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should do something consistent with other enum strings like TextAlign. I don't particularly like the TextAlign solution of using Show, so I suggest both data types get changed to have a (valid) Show instance, and a helper function to convert to their string values.

But that can be another commit. This looks good to merge.

Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for merging this. I can add the Show instance for PatternRepeat. For the helper, what would you call that, toString?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good.

Sent from my iPhone

On Mar 9, 2016, at 10:07 PM, Ingmar Gagen [email protected] wrote:

In src/Graphics/Canvas.purs:

@@ -471,6 +479,21 @@ foreign import drawImageScale :: forall eff. Context2D -> CanvasImageSource -> N

foreign import drawImageFull :: forall eff. Context2D -> CanvasImageSource -> Number -> Number -> Number -> Number -> Number -> Number -> Number -> Number -> Eff (canvas :: Canvas | eff) Context2D

+-- | Enumerates the different types of pattern repetitions.
+data PatternRepeat = Repeat | RepeatX | RepeatY | 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"
Thanks for merging this. I can add the Show instance for PatternRepeat. For the helper, what would you call that, toString?


Reply to this email directly or view it on GitHub.

paf31 added a commit that referenced this pull request Mar 10, 2016
Add createPattern, setPatternFillStyle to Graphics.Canvas
@paf31 paf31 merged commit 637ed3a into purescript-web:master Mar 10, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants