Fix some bugs in PlayfieldCanvasView.
Cat's Eye Technologies
11 years ago
39 | 39 | * Return the requested bounds of the occupied portion of the playfield. |
40 | 40 | * "Occupation" in this sense includes all cursors. |
41 | 41 | * |
42 | * These may return 'undefined' if there is nothing in the playfield. | |
43 | * | |
42 | 44 | * Override these if you want to draw some portion of the |
43 | 45 | * playfield which is not the whole playfield. |
44 | 46 | * (Not yet implemented) |
46 | 48 | this.getLowerX = function() { |
47 | 49 | var minX = this.pf.getMinX(); |
48 | 50 | for (var i = 0; i < this.cursors.length; i++) { |
49 | if (this.cursors[i].x < minX) minX = this.cursors[i].x; | |
51 | if (minX === undefined || this.cursors[i].x < minX) { | |
52 | minX = this.cursors[i].x; | |
53 | } | |
50 | 54 | } |
51 | 55 | return minX; |
52 | 56 | }; |
53 | 57 | this.getUpperX = function() { |
54 | 58 | var maxX = this.pf.getMaxX(); |
55 | 59 | for (var i = 0; i < this.cursors.length; i++) { |
56 | if (this.cursors[i].x > maxX) maxX = this.cursors[i].x; | |
60 | if (maxX === undefined || this.cursors[i].x > maxX) { | |
61 | maxX = this.cursors[i].x; | |
62 | } | |
57 | 63 | } |
58 | 64 | return maxX; |
59 | 65 | }; |
60 | 66 | this.getLowerY = function() { |
61 | 67 | var minY = this.pf.getMinY(); |
62 | 68 | for (var i = 0; i < this.cursors.length; i++) { |
63 | if (this.cursors[i].y < minY) minY = this.cursors[i].y; | |
69 | if (minY === undefined || this.cursors[i].y < minY) { | |
70 | minY = this.cursors[i].y; | |
71 | } | |
64 | 72 | } |
65 | 73 | return minY; |
66 | 74 | }; |
67 | 75 | this.getUpperY = function() { |
68 | 76 | var maxY = this.pf.getMaxY(); |
69 | 77 | for (var i = 0; i < this.cursors.length; i++) { |
70 | if (this.cursors[i].y > maxY) maxY = this.cursors[i].y; | |
78 | if (maxY === undefined || this.cursors[i].y > maxY) { | |
79 | maxY = this.cursors[i].y; | |
80 | } | |
71 | 81 | } |
72 | 82 | return maxY; |
73 | 83 | }; |
158 | 168 | ctx.textBaseline = "top"; |
159 | 169 | ctx.font = cellHeight + "px monospace"; |
160 | 170 | |
161 | var offsetX = this.pf.getMinX() * cellWidth * -1; | |
162 | var offsetY = this.pf.getMinY() * cellHeight * -1; | |
171 | var offsetX = (this.getLowerX() || 0) * cellWidth * -1; | |
172 | var offsetY = (this.getLowerY() || 0) * cellHeight * -1; | |
163 | 173 | |
164 | 174 | if (this.fixedPosition) { |
165 | 175 | offsetX = 0; |