| var canvas = null; | var canvas = null; | ||||
| var context = null; | var context = null; | ||||
| var ctximg = null; | |||||
| function OpenCanvasPixels(){ | |||||
| if (context !== null){ | |||||
| if (ctximg === null){ | |||||
| ctximg = context.getImageData(0,0,Math.floor(canvas.clientWidth),Math.floor(canvas.clientHeight)); | |||||
| } | |||||
| return (ctximg !== null) | |||||
| } | |||||
| return false; | |||||
| } | |||||
| function PutCanvasPixel(i,j,size,color){ | |||||
| if (ctximg === null) | |||||
| return; | |||||
| size = Math.ceil(size); | |||||
| if (size <= 0){return;} | |||||
| var cw = Math.floor(canvas.clientWidth); | |||||
| var ch = Math.floor(canvas.clientHeight); | |||||
| var r = parseInt(color.substring(1, 3), 16); | |||||
| var g = parseInt(color.substring(3, 5), 16); | |||||
| var b = parseInt(color.substring(5, 7), 16); | |||||
| var idat = ctximg.data; | |||||
| for (var y=j; y < j+size; y++){ | |||||
| for (var x=i; x < i+size; x++){ | |||||
| if (x >= 0 && x < cw && y >= 0 && y < ch){ | |||||
| var index = (y*cw*4) + (x*4); | |||||
| idat[index] = r; | |||||
| idat[index+1] = g; | |||||
| idat[index+2] = b; | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| function CloseCanvasPixels(){ | |||||
| if (ctximg !== null){ | |||||
| context.putImageData(ctximg, 0, 0); | |||||
| ctximg = null; | |||||
| } | |||||
| } | |||||
| function ResizeCanvasImg(w, h){ | function ResizeCanvasImg(w, h){ | ||||
| if (canvas !== null){ | if (canvas !== null){ | ||||
| var self = this; | var self = this; | ||||
| var RenderD = Utils.throttle((function(){ | |||||
| this.render(); | |||||
| }).bind(this), 20); | |||||
| var handle_resize = (function(w,h){ | var handle_resize = (function(w,h){ | ||||
| this.render(); | this.render(); | ||||
| }).bind(this); | }).bind(this); | ||||
| } | } | ||||
| this.__surface = surf; | this.__surface = surf; | ||||
| this.center_surface(); | this.center_surface(); | ||||
| this.render(); | |||||
| RenderD(); | |||||
| }).bind(this); | }).bind(this); | ||||
| GlobalEvents.listen("change_surface", handle_change_surface); | GlobalEvents.listen("change_surface", handle_change_surface); | ||||
| var handle_offset = (function(e){ | var handle_offset = (function(e){ | ||||
| this.__offset[0] += e.x - e.lastX; | this.__offset[0] += e.x - e.lastX; | ||||
| this.__offset[1] += e.y - e.lastY; | this.__offset[1] += e.y - e.lastY; | ||||
| this.render(); | |||||
| RenderD(); | |||||
| }).bind(this); | }).bind(this); | ||||
| input.listen("shift+mouseleft+mousemove", handle_offset); | input.listen("shift+mouseleft+mousemove", handle_offset); | ||||
| this.scale_up(); | this.scale_up(); | ||||
| } | } | ||||
| if (e.delta !== 0) | if (e.delta !== 0) | ||||
| this.render(); | |||||
| RenderD(); | |||||
| }).bind(this); | }).bind(this); | ||||
| input.listen("wheel", handle_scale); | input.listen("wheel", handle_scale); | ||||
| } | } | ||||
| Math.floor(canvas.clientHeight) | Math.floor(canvas.clientHeight) | ||||
| ); | ); | ||||
| OpenCanvasPixels(); | |||||
| for (var j = 0; j < this.__surface.height; j++){ | for (var j = 0; j < this.__surface.height; j++){ | ||||
| var y = Math.floor((j*scalemult) + this.__offset[1]); | var y = Math.floor((j*scalemult) + this.__offset[1]); | ||||
| for (var i = 0; i < this.__surface.width; i++){ | for (var i = 0; i < this.__surface.width; i++){ | ||||
| var x = Math.floor((i*scalemult) + this.__offset[0]); | var x = Math.floor((i*scalemult) + this.__offset[0]); | ||||
| if (x >= 0 && x < canvas.clientWidth && y >= 0 && y < canvas.clientHeight){ | if (x >= 0 && x < canvas.clientWidth && y >= 0 && y < canvas.clientHeight){ | ||||
| var color = "#666666"; | |||||
| var color = NESPalette.Default[4]; | |||||
| if (this.__onePaletteMode){ | if (this.__onePaletteMode){ | ||||
| var pinfo = this.__surface.getColorIndex(i, j); | var pinfo = this.__surface.getColorIndex(i, j); | ||||
| if (pinfo.ci >= 0) | if (pinfo.ci >= 0) | ||||
| color = this.__surface.getColor(i, j); | color = this.__surface.getColor(i, j); | ||||
| } | } | ||||
| context.fillStyle = color; | |||||
| context.fillRect( | |||||
| x,y, | |||||
| 1, 1 | |||||
| ); | |||||
| PutCanvasPixel(x,y, scalemult, color); | |||||
| //context.fillStyle = color; | |||||
| //context.fillRect( | |||||
| // x,y, | |||||
| // Math.ceil(scalemult), Math.ceil(scalemult) | |||||
| //); | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| CloseCanvasPixels(); | |||||
| if (this.__gridEnabled && this.__scale > 0.5){ | if (this.__gridEnabled && this.__scale > 0.5){ | ||||
| // TODO: render the grid! | // TODO: render the grid! |