Browse Source

Fixed CTRLPainter scaling artifacts. Now renders grid.

dev-tmpl
Bryan Miller 5 years ago
parent
commit
329ff03e61
1 changed files with 34 additions and 16 deletions
  1. +34
    -16
      app/js/ctrls/CTRLPainter.js

+ 34
- 16
app/js/ctrls/CTRLPainter.js View File

if (ctximg === null) if (ctximg === null)
return; return;


i = Math.round(i);
j = Math.round(j);
size = Math.ceil(size); size = Math.ceil(size);
if (size <= 0){return;} if (size <= 0){return;}


this.__brushColor = 0; this.__brushColor = 0;
this.__brushPalette = 0; this.__brushPalette = 0;


this.__gridEnabled = false;
this.__gridEnabled = true; //false;
this.__gridSize = 1; this.__gridSize = 1;


this.__surface = null; this.__surface = null;
if (context === null || this.__surface === null) if (context === null || this.__surface === null)
return; return;


// Get the contexts initial fillStyle. Don't want the render operation to override it.
var fillStyle = context.fillStyle;

var scalemult = 1.0/this.__scale;
context.save();


// Clearing the context surface... // Clearing the context surface...
context.fillStyle = NESPalette.Default[4]; context.fillStyle = NESPalette.Default[4];


OpenCanvasPixels(); 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 = (j*this.__scale) + 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 = (i*this.__scale) + 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 = NESPalette.Default[4]; var color = NESPalette.Default[4];
color = this.__surface.getColor(i, j); color = this.__surface.getColor(i, j);
} }


PutCanvasPixel(x,y, scalemult, color);
//context.fillStyle = color;
//context.fillRect(
// x,y,
// Math.ceil(scalemult), Math.ceil(scalemult)
//);
PutCanvasPixel(x,y, this.__scale, color);
} }
} }
} }
CloseCanvasPixels(); CloseCanvasPixels();


if (this.__gridEnabled && this.__scale > 0.5){ if (this.__gridEnabled && this.__scale > 0.5){
// TODO: render the grid!
context.strokeStyle = "#00FF00";

var w = this.__surface.width * this.__scale;
var h = this.__surface.height * this.__scale;

var length = Math.max(this.__surface.width, this.__surface.height);
for (var i=0; i < length; i += 8){
var x = (i*this.__scale) + this.__offset[0];
var y = (i*this.__scale) + this.__offset[1];

if (i < this.__surface.width){
context.beginPath();
context.moveTo(x, this.__offset[1]);
context.lineTo(x, this.__offset[1] + h);
context.stroke();
context.closePath();
}

if (i < this.__surface.height){
context.beginPath();
context.moveTo(this.__offset[0], y);
context.lineTo(this.__offset[0] + w, y);
context.stroke();
context.closePath();
}
}
} }


// Return to the context's initial fillStyle.
context.fillStyle = fillStyle;
context.restore();


return this; return this;
} }

Loading…
Cancel
Save