From 57b57c3a9172489664400754fa2c001e670bb42b Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Sun, 13 Nov 2016 08:55:22 -0800 Subject: [PATCH] Images can now be positioned with negative units. --- scripts/guide.js | 1 - scripts/ronin.js | 15 ++++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/scripts/guide.js b/scripts/guide.js index 77eb033..598b0d4 100644 --- a/scripts/guide.js +++ b/scripts/guide.js @@ -11,7 +11,6 @@ function Guide(position = new Position(),rect = new Rect(),color = new Color()) 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); diff --git a/scripts/ronin.js b/scripts/ronin.js index 7d86028..79fde40 100644 --- a/scripts/ronin.js +++ b/scripts/ronin.js @@ -7,7 +7,16 @@ function Ronin() base_image = new Image(); base_image.src = p[0]; // media/logo.png base_image.onload = function(){ - context.drawImage(base_image, parseFloat(p[1]), parseFloat(p[2]), parseFloat(p[3]), parseFloat(p[4])); + + var rec_w = parseFloat(p[3]); + var rec_h = parseFloat(p[4]); + var pos_x = parseFloat(p[1]); + var pos_y = parseFloat(p[2]); + + pos_x = pos_x < 0 ? canvas.width - Math.abs(pos_x) - rec_w : pos_x; + pos_y = pos_y < 0 ? canvas.height - Math.abs(pos_y) - rec_h : pos_y; + + context.drawImage(base_image, pos_x, pos_y, rec_w, rec_h); } this.draw_guides(); } @@ -75,18 +84,18 @@ function Ronin() else{ var g = new Guide(new Position(x,y), new Rect(w,h), new Color('ff0000')); g.draw(this.guides_context); + return g; } - } this.add_guide = function(p) { + if(p[0] == "?"){ this.guides = []; this.draw_guides(); return; } 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 ; - if(x < -10 && w === 0 && h === 0){ x = Math.abs(x); for (i = 0; i < canvas.width/x; i++) {