From 26972ebce51e5c710bf8a0c9d35f265c506ae4b8 Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Sun, 13 Nov 2016 08:44:57 -0800 Subject: [PATCH] Guides now tile, and can be positioned at the bottom. --- links/main.css | 2 +- scripts/guide.js | 12 +++++++++++- scripts/ronin.js | 16 +++++++++------- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/links/main.css b/links/main.css index 582c38e..e35516c 100644 --- a/links/main.css +++ b/links/main.css @@ -4,7 +4,7 @@ canvas:hover { cursor: crosshair;} #guides { position:fixed; z-index:1000;} -#commander { display:none; } +#commander { display:none; z-index: 2000; } #commander.visible { display:block; } #commander.hidden { display:none; } #commander input { background:black; padding:15px; position:fixed; bottom:0; color:white; left:0; border:0; width:calc(100vw); font-family:courier; cursor:pointer; display:block;} \ No newline at end of file diff --git a/scripts/guide.js b/scripts/guide.js index 32dc7b3..77eb033 100644 --- a/scripts/guide.js +++ b/scripts/guide.js @@ -8,7 +8,17 @@ function Guide(position = new Position(),rect = new Rect(),color = new Color()) { context.beginPath(); - if(this.position.x > 0 && this.position.y > 0 && (this.rect.w > 0 || this.rect.h > 0)){ + if((this.position.x < 0 || this.position.y < 0) && (this.rect.w > 0 || this.rect.h > 0)){ + var new_x = this.position.x < 0 ? canvas.width - Math.abs(this.position.x) - this.rect.w : this.position.x; + var new_y = this.position.y < 0 ? canvas.height - Math.abs(this.position.y) - this.rect.h : this.position.y; + console.log(new_y); + context.moveTo(new_x,new_y); + context.lineTo(new_x + this.rect.w,new_y); + context.lineTo(new_x + this.rect.w,new_y + this.rect.h); + context.lineTo(new_x,new_y + this.rect.h); + context.lineTo(new_x,new_y); + } + else 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); diff --git a/scripts/ronin.js b/scripts/ronin.js index ccf1903..7d86028 100644 --- a/scripts/ronin.js +++ b/scripts/ronin.js @@ -58,24 +58,25 @@ function Ronin() var w = p[2] ? p[2] : 0 ; var h = p[3] ? p[3] : 0 ; - if(x < -10){ + if(x < -10 && w === 0 && h === 0){ x = Math.abs(x); for (i = 0; i < canvas.width/x; i++) { - var g = new Guide(new Position(x * i,y), new Rect(w,h), new Color('000000')); + var g = new Guide(new Position(x * i,y), new Rect(w,h), new Color('ff0000')); g.draw(this.guides_context); } } - else if(y < -10){ + else if(y < -10 && w === 0 && h === 0){ y = Math.abs(y); for (i = 0; i < canvas.width/y; i++) { - var g = new Guide(new Position(x,y* i), new Rect(w,h), new Color('000000')); + var g = new Guide(new Position(x,y* i), new Rect(w,h), new Color('ff0000')); g.draw(this.guides_context); } } else{ - var g = new Guide(new Position(x,y), new Rect(w,h), new Color('000000')); + var g = new Guide(new Position(x,y), new Rect(w,h), new Color('ff0000')); g.draw(this.guides_context); } + } this.add_guide = function(p) @@ -85,14 +86,15 @@ function Ronin() var w = p[2] ? p[2] : 0 ; var h = p[3] ? p[3] : 0 ; - if(x < -10){ + + if(x < -10 && w === 0 && h === 0){ x = Math.abs(x); for (i = 0; i < canvas.width/x; i++) { var g = new Guide(new Position(x * i,y), new Rect(w,h), new Color('000000')); this.guides.push(g); } } - else if(y < -10){ + else if(y < -10 && w === 0 && h === 0){ y = Math.abs(y); for (i = 0; i < canvas.width/y; i++) { var g = new Guide(new Position(x,y* i), new Rect(w,h), new Color('000000'));