File tree Expand file tree Collapse file tree 3 files changed +24
-0
lines changed Expand file tree Collapse file tree 3 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -65,6 +65,12 @@ Opaque object describing a gradient.
65
65
canvasElementToImageSource :: CanvasElement -> CanvasImageSource
66
66
```
67
67
68
+ #### ` withImage `
69
+
70
+ ``` purescript
71
+ withImage :: forall eff a. String -> (CanvasImageSource -> Eff eff Unit) -> Eff eff Unit
72
+ ```
73
+
68
74
#### ` getCanvasElementById `
69
75
70
76
``` purescript
Original file line number Diff line number Diff line change @@ -7,6 +7,20 @@ exports.canvasElementToImageSource = function(e) {
7
7
return e ;
8
8
} ;
9
9
10
+ exports . withImage = function ( src ) {
11
+ return function ( f ) {
12
+ return function ( ) {
13
+ var img = new Image ( ) ;
14
+ img . src = src ;
15
+ img . addEventListener ( "load" , function ( ) {
16
+ f ( img ) ( ) ;
17
+ } , false ) ;
18
+
19
+ return { } ;
20
+ }
21
+ } ;
22
+ } ;
23
+
10
24
exports . getCanvasElementByIdImpl = function ( id , Just , Nothing ) {
11
25
return function ( ) {
12
26
var el = document . getElementById ( id ) ;
Original file line number Diff line number Diff line change @@ -80,6 +80,7 @@ module Graphics.Canvas
80
80
, restore
81
81
, withContext
82
82
83
+ , withImage
83
84
, getImageData
84
85
, getImageDataWidth
85
86
, getImageDataHeight
@@ -132,6 +133,9 @@ foreign import data CanvasGradient :: *
132
133
133
134
foreign import canvasElementToImageSource :: CanvasElement -> CanvasImageSource
134
135
136
+ -- | Wrapper for asynchronously loading a image file by path and use it in callback, e.g. drawImage
137
+ foreign import withImage :: forall eff a . String -> (CanvasImageSource -> Eff eff Unit ) -> Eff eff Unit
138
+
135
139
foreign import getCanvasElementByIdImpl ::
136
140
forall r eff . Fn3 String
137
141
(CanvasElement -> r )
You can’t perform that action at this time.
0 commit comments