-
Notifications
You must be signed in to change notification settings - Fork 398
/
Copy pathcanvas-renderer.js
71 lines (57 loc) · 1.45 KB
/
canvas-renderer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/**
* CanvasRenderer
*/
( function( root, factory ) {
// module definition
if ( typeof module == 'object' && module.exports ) {
// CommonJS
module.exports = factory();
} else {
// browser global
root.Zdog.CanvasRenderer = factory();
}
}( this, function factory() {
var CanvasRenderer = { isCanvas: true };
CanvasRenderer.begin = function( ctx ) {
ctx.beginPath();
};
CanvasRenderer.move = function( ctx, elem, point ) {
ctx.moveTo( point.x, point.y );
};
CanvasRenderer.line = function( ctx, elem, point ) {
ctx.lineTo( point.x, point.y );
};
CanvasRenderer.bezier = function( ctx, elem, cp0, cp1, end ) {
ctx.bezierCurveTo( cp0.x, cp0.y, cp1.x, cp1.y, end.x, end.y );
};
CanvasRenderer.closePath = function( ctx ) {
ctx.closePath();
};
CanvasRenderer.setPath = function() {};
CanvasRenderer.renderPath = function( ctx, elem, pathCommands, isClosed ) {
this.begin( ctx, elem );
pathCommands.forEach( function( command ) {
command.render( ctx, elem, CanvasRenderer );
} );
if ( isClosed ) {
this.closePath( ctx, elem );
}
};
CanvasRenderer.stroke = function( ctx, elem, isStroke, color, lineWidth ) {
if ( !isStroke ) {
return;
}
ctx.strokeStyle = color;
ctx.lineWidth = lineWidth;
ctx.stroke();
};
CanvasRenderer.fill = function( ctx, elem, isFill, color ) {
if ( !isFill ) {
return;
}
ctx.fillStyle = color;
ctx.fill();
};
CanvasRenderer.end = function() {};
return CanvasRenderer;
} ) );