Skip to content

Commit

Permalink
Merge pull request #21 from puffnfresh/feature/drawimage
Browse files Browse the repository at this point in the history
Add full drawImage API
  • Loading branch information
paf31 committed Aug 14, 2015
2 parents 140ae85 + 2ce6f95 commit 45b77b9
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
59 changes: 59 additions & 0 deletions src/Graphics/Canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
};
};
};
};
};
};
};
};
};
};
};
16 changes: 16 additions & 0 deletions src/Graphics/Canvas.purs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module Graphics.Canvas
, Context2D()
, ImageData()
, CanvasPixelArray()
, CanvasImageSource()
, Arc()
, Composite(..)
, Dimensions()
Expand Down Expand Up @@ -82,6 +83,11 @@ module Graphics.Canvas
, putImageDataFull
, createImageData
, createImageDataCopy

, canvasElementToImageSource
, drawImage
, drawImageScale
, drawImageFull
) where

import Prelude
Expand All @@ -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)
Expand Down Expand Up @@ -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

0 comments on commit 45b77b9

Please sign in to comment.