@@ -22,6 +22,51 @@ foreign import getContext2D
2222 \ };\
2323 \}" :: forall eff . CanvasElement -> Eff (canvas :: Canvas | eff ) Context2D
2424
25+ foreign import getCanvasWidth
26+ " function getCanvasWidth(canvas){\
27+ \ return function(){\
28+ \ return canvas.width;\
29+ \ };\
30+ \};" :: forall eff . CanvasElement -> Eff (canvas :: Canvas | eff ) Number
31+
32+ foreign import getCanvasHeight
33+ " function getCanvasHeight(canvas){\
34+ \ return function(){\
35+ \ return canvas.height;\
36+ \ };\
37+ \};" :: forall eff . CanvasElement -> Eff (canvas :: Canvas | eff ) Number
38+
39+ foreign import setCanvasWidth
40+ " function setCanvasWidth(width){\
41+ \ return function(canvas){\
42+ \ return function(){\
43+ \ canvas.width = width;\
44+ \ return canvas;\
45+ \ };\
46+ \ };\
47+ \};" :: forall eff . Number -> CanvasElement -> Eff (canvas :: Canvas | eff ) CanvasElement
48+
49+ foreign import setCanvasHeight
50+ " function setCanvasHeight(height){\
51+ \ return function(canvas){\
52+ \ return function(){\
53+ \ canvas.height = height;\
54+ \ return canvas; \
55+ \ };\
56+ \ };\
57+ \};" :: forall eff . Number -> CanvasElement -> Eff (canvas :: Canvas | eff ) CanvasElement
58+
59+ type Dimensions = { width :: Number , height :: Number }
60+
61+ getCanvasDimensions :: forall eff . CanvasElement -> Eff (canvas :: Canvas | eff ) Dimensions
62+ getCanvasDimensions ce = do
63+ w <- getCanvasWidth ce
64+ h <- getCanvasHeight ce
65+ return {width : w, height : h}
66+
67+ setCanvasDimensions :: forall eff . Dimensions -> CanvasElement -> Eff (canvas :: Canvas | eff ) CanvasElement
68+ setCanvasDimensions d ce = setCanvasHeight d.height ce >>= setCanvasWidth d.width
69+
2570-- |
2671-- Context Properties
2772--
@@ -96,6 +141,23 @@ foreign import setShadowOffsetY
96141 \ };\
97142 \}" :: forall eff . Number -> Context2D -> Eff (canvas :: Canvas | eff ) Context2D
98143
144+ data LineCap = Round | Square | Butt
145+
146+ foreign import setLineCapImpl
147+ " function setLineCapImpl(cap){\
148+ \ return function(ctx) {\
149+ \ return function() {\
150+ \ ctx.lineCap = cap;\
151+ \ return ctx;\
152+ \ };\
153+ \ };\
154+ \}" :: forall eff . String -> Context2D -> Eff (canvas :: Canvas | eff ) Context2D
155+
156+ setLineCap :: forall eff . LineCap -> Context2D -> Eff (canvas :: Canvas | eff ) Context2D
157+ setLineCap Round = setLineCapImpl " round"
158+ setLineCap Square = setLineCapImpl " square"
159+ setLineCap Butt = setLineCapImpl " butt"
160+
99161-- |
100162-- Paths
101163--
0 commit comments