From 2ce6f956639b33d5a06be01ac3651b31801557c9 Mon Sep 17 00:00:00 2001 From: Brian McKenna Date: Thu, 13 Aug 2015 21:04:04 +1000 Subject: [PATCH] Add full drawImage API --- src/Graphics/Canvas.js | 59 ++++++++++++++++++++++++++++++++++++++++ src/Graphics/Canvas.purs | 16 +++++++++++ 2 files changed, 75 insertions(+) diff --git a/src/Graphics/Canvas.js b/src/Graphics/Canvas.js index 09aafc1..f45036a 100644 --- a/src/Graphics/Canvas.js +++ b/src/Graphics/Canvas.js @@ -3,6 +3,10 @@ // module Graphics.Canvas +exports.canvasElementToImageSource = function(e) { + return e; +}; + exports.getCanvasElementByIdImpl = function(id, Just, Nothing) { return function() { var el = document.getElementById(id); @@ -445,3 +449,58 @@ exports.getImageDataPixelArray = function(image_data) { return image_data.data; }; }; + +exports.drawImage = function(ctx) { + return function(image_source) { + return function(dx) { + return function(dy) { + return function() { + ctx.drawImage(image_source, dx, dy); + return ctx; + }; + }; + }; + }; +}; + +exports.drawImageScale = function(ctx) { + return function(image_source) { + return function(dx) { + return function(dy) { + return function(dWidth) { + return function(dHeight) { + return function() { + ctx.drawImage(image_source, dx, dy, dWidth, dHeight); + return ctx; + }; + }; + }; + }; + }; + }; +}; + +exports.drawImageFull = function(ctx) { + return function(image_source) { + return function(sx) { + return function(sy) { + return function(sWidth) { + return function(sHeight) { + return function(dx) { + return function(dy) { + return function(dWidth) { + return function(dHeight) { + return function() { + ctx.drawImage(image_source, sx, sy, sWidth, sHeight, dx, dy, dWidth, dHeight); + return ctx; + }; + }; + }; + }; + }; + }; + }; + }; + }; + }; +}; diff --git a/src/Graphics/Canvas.purs b/src/Graphics/Canvas.purs index bea9e11..840800c 100644 --- a/src/Graphics/Canvas.purs +++ b/src/Graphics/Canvas.purs @@ -7,6 +7,7 @@ module Graphics.Canvas , Context2D() , ImageData() , CanvasPixelArray() + , CanvasImageSource() , Arc() , Composite(..) , Dimensions() @@ -82,6 +83,11 @@ module Graphics.Canvas , putImageDataFull , createImageData , createImageDataCopy + + , canvasElementToImageSource + , drawImage + , drawImageScale + , drawImageFull ) where import Prelude @@ -105,6 +111,11 @@ foreign import data ImageData :: * -- | An array of pixel data. foreign import data CanvasPixelArray :: * +-- | Opaque object for drawing elements and things to the canvas. +foreign import data CanvasImageSource :: * + +foreign import canvasElementToImageSource :: CanvasElement -> CanvasImageSource + foreign import getCanvasElementByIdImpl :: forall r eff. Fn3 String (CanvasElement -> r) @@ -446,3 +457,8 @@ foreign import getImageDataHeight :: forall eff. ImageData -> Eff (canvas :: Can -- | Get the pixel data array from an image data object. foreign import getImageDataPixelArray :: forall eff. ImageData -> Eff (canvas :: Canvas | eff) CanvasPixelArray +foreign import drawImage :: forall eff. Context2D -> CanvasImageSource -> Number -> Number -> Eff (canvas :: Canvas | eff) Context2D + +foreign import drawImageScale :: forall eff. Context2D -> CanvasImageSource -> Number -> Number -> Number -> Number -> Eff (canvas :: Canvas | eff) Context2D + +foreign import drawImageFull :: forall eff. Context2D -> CanvasImageSource -> Number -> Number -> Number -> Number -> Number -> Number -> Number -> Number -> Eff (canvas :: Canvas | eff) Context2D