| 1 | // Wrapper for some canvas drawing functions |
| 2 | |
| 3 | var Canvas = |
| 4 | { |
| 5 | get canvas() |
| 6 | { |
| 7 | return GameWindow.canvas; |
| 8 | }, |
| 9 | |
| 10 | get context() |
| 11 | { |
| 12 | GameWindow.canvasContext.webkitImageSmoothingEnabled = false; |
| 13 | GameWindow.canvasContext.mozImageSmoothingEnabled = false; |
| 14 | GameWindow.canvasContext.imageSmoothingEnabled = false; |
| 15 | return GameWindow.canvasContext; |
| 16 | }, |
| 17 | |
| 18 | drawText: function(text, x, y, size, font, color) |
| 19 | { |
| 20 | this.context.font = font? size + 'px ' + font : size + 'px Arial'; |
| 21 | |
| 22 | this.context.fillStyle = color; |
| 23 | this.context.strokeStyle = color; |
| 24 | this.context.textAlign = "center"; |
| 25 | this.context.textBaseline="middle"; |
| 26 | |
| 27 | this.context.fillText(text, x, y); |
| 28 | }, |
| 29 | |
| 30 | drawLine(xStart, yStart, xEnd, yEnd, color) |
| 31 | { |
| 32 | this.context.fillStyle = color; |
| 33 | this.context.strokeStyle = color; |
| 34 | |
| 35 | this.context.beginPath(); |
| 36 | this.context.moveTo(xStart, yStart); |
| 37 | this.context.lineTo(xEnd, yEnd); |
| 38 | |
| 39 | this.context.stroke(); |
| 40 | }, |
| 41 | |
| 42 | drawRect(xStart, yStart, xEnd, yEnd, color) |
| 43 | { |
| 44 | this.context.fillStyle = color; |
| 45 | this.context.strokeStyle = color; |
| 46 | |
| 47 | this.context.beginPath(); |
| 48 | this.context.fillRect(xStart, yStart, xEnd, yEnd); |
| 49 | }, |
| 50 | |
| 51 | drawImage(img, x, y, w, h) |
| 52 | { |
| 53 | this.context.drawImage(img, x, y, w, h); |
| 54 | } |
| 55 | } |