Add option to use existing canvas for rendering

This commit is contained in:
MoyuScript
2014-09-28 22:51:11 +03:00
parent c083985f93
commit 418492074f
5 changed files with 66 additions and 10 deletions

View File

@@ -1,8 +1,10 @@
function CanvasRenderer(width, height) {
Renderer.apply(this, arguments);
this.canvas = this.document.createElement("canvas");
this.canvas.width = width;
this.canvas.height = height;
this.canvas = this.options.canvas || this.document.createElement("canvas");
if (!this.options.canvas) {
this.canvas.width = width;
this.canvas.height = height;
}
this.ctx = this.canvas.getContext("2d");
this.taintCtx = this.document.createElement("canvas").getContext("2d");
this.ctx.textBaseline = "bottom";