diff --git a/scripts/color.js b/scripts/color.js index 0b25a2c..75ee3c2 100644 --- a/scripts/color.js +++ b/scripts/color.js @@ -11,4 +11,9 @@ function Color(val = '000000') b: parseInt(result[3], 16) } : null; } + + this.rgba = function() + { + return "rgba("+this.rgb().r+","+this.rgb().g+","+this.rgb().b+",1)"; + } } \ No newline at end of file diff --git a/scripts/guide.js b/scripts/guide.js index 2a3e138..32dc7b3 100644 --- a/scripts/guide.js +++ b/scripts/guide.js @@ -1,13 +1,27 @@ -function Guide(position,rect) +function Guide(position = new Position(),rect = new Rect(),color = new Color()) { this.position = position; this.rect = rect; + this.color = color; this.draw = function(context) { context.beginPath(); - if(this.position.x > 0 && this.position.y === 0){ + if(this.position.x > 0 && this.position.y > 0 && (this.rect.w > 0 || this.rect.h > 0)){ + context.moveTo(this.position.x,this.position.y); + context.lineTo(this.position.x + this.rect.w,this.position.y); + context.lineTo(this.position.x + this.rect.w,this.position.y + this.rect.h); + context.lineTo(this.position.x,this.position.y + this.rect.h); + context.lineTo(this.position.x,this.position.y); + } + else if(this.position.x > 0 && this.position.y > 0){ + context.moveTo(this.position.x,this.position.y); + context.lineTo(this.position.x + 10,this.position.y); + context.lineTo(this.position.x,this.position.y + 10); + context.lineTo(this.position.x,this.position.y); + } + else if(this.position.x > 0 && this.position.y === 0){ context.moveTo(this.position.x,0); context.lineTo(this.position.x,canvas.height); } @@ -15,21 +29,10 @@ function Guide(position,rect) context.moveTo(0,this.position.y); context.lineTo(canvas.width,this.position.y); } - else if(this.position.x > 0 && this.position.y > 0 && this.rect.w > 0 && this.rect.h > 0){ - context.moveTo(this.position.x,0); - context.lineTo(this.position.x,200); - context.lineTo(x + w,y); - context.lineTo(x + w,y + h); - context.lineTo(x,y + h); - context.lineTo(x,y); - } - else{ - console.log(this.position); - } context.lineCap="round"; context.lineWidth = 1; - context.strokeStyle = "rgba(255,0,0,1)"; + context.strokeStyle = this.color.rgba(); context.stroke(); context.closePath(); } diff --git a/scripts/keyboard.js b/scripts/keyboard.js index 72e2710..4adc6f3 100644 --- a/scripts/keyboard.js +++ b/scripts/keyboard.js @@ -73,5 +73,6 @@ function Keyboard() this.key_escape = function() { commander.hide(); + ronin.draw_guides(); } } \ No newline at end of file diff --git a/scripts/ronin.js b/scripts/ronin.js index 689dbae..ab93990 100644 --- a/scripts/ronin.js +++ b/scripts/ronin.js @@ -16,19 +16,16 @@ function Ronin() this.guide = function(p) { - return ; - - // guides_context = document.getElementById('guides').getContext('2d'); - // guides_context.clearRect(0, 0, canvas.width, canvas.height); + this.guides_context.clearRect(0, 0, canvas.width, canvas.height); var x = p[0] ? p[0] : 0 ; var y = p[1] ? p[1] : 0 ; var w = p[2] ? p[2] : 0 ; var h = p[3] ? p[3] : 0 ; - var g = new Guide(new Position(x,y), new Rect(w,h)); + var g = new Guide(new Position(x,y), new Rect(w,h), new Color('000000')); - g.draw(guides_context); + g.draw(this.guides_context); } this.add_guide = function(p) @@ -38,7 +35,7 @@ function Ronin() var w = p[2] ? p[2] : 0 ; var h = p[3] ? p[3] : 0 ; - var g = new Guide(new Position(x,y), new Rect(w,h)); + var g = new Guide(new Position(x,y), new Rect(w,h), new Color('ff0000')); this.guides.push(g); this.draw_guides();