From 728cb2f448155a2984e2efccbcb251790153dccc Mon Sep 17 00:00:00 2001 From: SebastianCrow Date: Thu, 5 Mar 2015 00:17:29 +0100 Subject: [PATCH] Custom bg and fg highlight MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It’s possible now to create custom bg and fg highlight. No highlight is achievable as well. --- js/verlet-1.0.0.js | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/js/verlet-1.0.0.js b/js/verlet-1.0.0.js index bdf342e..64701c8 100644 --- a/js/verlet-1.0.0.js +++ b/js/verlet-1.0.0.js @@ -604,6 +604,13 @@ VerletJS.prototype.draw = function() { this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height); + // nearest / dragged entity + var nearest = this.draggedEntity || this.nearestEntity(); + // draw highlight in background (if defined) + if (nearest && nearest.drawBgHighlight) { + nearest.drawBgHighlight(this.ctx); + } + for (c in this.composites) { // draw constraints if (this.composites[c].drawConstraints) { @@ -624,13 +631,16 @@ VerletJS.prototype.draw = function() { } } - // highlight nearest / dragged entity - var nearest = this.draggedEntity || this.nearestEntity(); if (nearest) { - this.ctx.beginPath(); - this.ctx.arc(nearest.pos.x, nearest.pos.y, 8, 0, 2*Math.PI); - this.ctx.strokeStyle = this.highlightColor; - this.ctx.stroke(); + if (nearest.drawFgHighlight) { // draw highlight in foreground (if defined) + nearest.drawFgHighlight(this.ctx); + } + else { // default highlight + this.ctx.beginPath(); + this.ctx.arc(nearest.pos.x, nearest.pos.y, 8, 0, 2*Math.PI); + this.ctx.strokeStyle = this.highlightColor; + this.ctx.stroke(); + } } }