class CGRDrawn implements ColorGridRenderer { private boolean border, selection; private int srow, scol; private float x, y, dim; private ColorGrid cg; private color bcolor, bcolor_fade; CGRDrawn(ColorGrid grid, float x, float y, float dim, color borderColor) { cg = grid; this.x = x; this.y = y; this.dim = dim; selection = false; border = true; srow = scol = 0; bcolor = borderColor; bcolor_fade = color(red(borderColor), green(borderColor), blue(borderColor), 160); } void showBorder(boolean show) { border = show; } void showSelection(boolean show) { selection = show; } void setSelection(int row, int col) { srow = row; scol = col; } ColorGrid getColorGrid() { return cg; } void setColorGrid(ColorGrid grid) { cg = grid; } void draw() { stroke(0); strokeWeight(1); for(int i = 0; i < cg.rows(); i++) { for(int j = 0; j < cg.cols(); j++) { fill( cg.get(i,j) ); rect(x + j*dim, y + i*dim, dim, dim); } } noFill(); if ( border ) { if ( selection ) { stroke(bcolor); } else { stroke(bcolor_fade); } strokeWeight(3); rect(x - 2, y - 2, cg.cols() * dim + 4, cg.rows() * dim + 4); } strokeWeight(1); if ( selection ) { // TODO: animate stroke(255); } else { // solid stroke(255); } rect(x + scol*dim, y + srow*dim, dim, dim); } }