0 | 0 |
/*
|
1 | |
* This file is part of yoob.js version 0.11
|
|
1 |
* This file is part of yoob.js version 0.12-PRE
|
2 | 2 |
* Available from https://github.com/catseye/yoob.js/
|
3 | 3 |
* This file is in the public domain. See http://unlicense.org/ for details.
|
4 | 4 |
*/
|
|
14 | 14 |
* If the cell values are solid and fill the entire cell, drawCursorsFirst: false
|
15 | 15 |
* may be in order.
|
16 | 16 |
*
|
17 | |
* TODO: don't necesarily resize canvas each time?
|
|
17 |
* resizeCanvas defaults to true. If set to false, the canvas element will
|
|
18 |
* not be resized before each draw. You may wish to do this yourself in your
|
|
19 |
* code which calls playfieldCanvasView.draw().
|
|
20 |
*
|
18 | 21 |
*/
|
19 | 22 |
yoob.PlayfieldCanvasView = function() {
|
20 | 23 |
this.init = function(cfg) {
|
|
25 | 28 |
this.fixedSizeCanvas = !!cfg.fixedSizeCanvas;
|
26 | 29 |
this.drawCursorsFirst = (cfg.drawCursorsFirst === undefined) ? true : !!cfg.drawCursorsFirst;
|
27 | 30 |
this.setCellDimensions(cfg.cellWidth || 8, cfg.cellHeight || 8);
|
|
31 |
this.resizeCanvas = cfg.resizeCanvas === false ? false : true;
|
28 | 32 |
return this;
|
29 | 33 |
};
|
30 | 34 |
|
|
115 | 119 |
|
116 | 120 |
/*
|
117 | 121 |
* Draw the Playfield, and its set of Cursors, on the canvas element.
|
118 | |
* Resizes the canvas to the needed dimensions first.
|
|
122 |
* Optionally resizes the canvas to the needed dimensions first.
|
119 | 123 |
*/
|
120 | 124 |
this.draw = function() {
|
121 | 125 |
var canvas = this.canvas;
|
|
125 | 129 |
var width = this.pf.getCursoredExtentX();
|
126 | 130 |
var height = this.pf.getCursoredExtentY();
|
127 | 131 |
|
128 | |
canvas.width = width * cellWidth;
|
129 | |
canvas.height = height * cellHeight;
|
|
132 |
if (this.resizeCanvas) {
|
|
133 |
canvas.width = width * cellWidth;
|
|
134 |
canvas.height = height * cellHeight;
|
|
135 |
}
|
130 | 136 |
var ctx = this.ctx;
|
131 | 137 |
|
132 | 138 |
ctx.textBaseline = "top";
|