Images can now be positioned with negative units.
This commit is contained in:
parent
26972ebce5
commit
57b57c3a91
@ -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)){
|
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_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;
|
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.moveTo(new_x,new_y);
|
||||||
context.lineTo(new_x + this.rect.w,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 + this.rect.w,new_y + this.rect.h);
|
||||||
|
@ -7,7 +7,16 @@ function Ronin()
|
|||||||
base_image = new Image();
|
base_image = new Image();
|
||||||
base_image.src = p[0]; // media/logo.png
|
base_image.src = p[0]; // media/logo.png
|
||||||
base_image.onload = function(){
|
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();
|
this.draw_guides();
|
||||||
}
|
}
|
||||||
@ -75,18 +84,18 @@ function Ronin()
|
|||||||
else{
|
else{
|
||||||
var g = new Guide(new Position(x,y), new Rect(w,h), new Color('ff0000'));
|
var g = new Guide(new Position(x,y), new Rect(w,h), new Color('ff0000'));
|
||||||
g.draw(this.guides_context);
|
g.draw(this.guides_context);
|
||||||
|
return g;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.add_guide = function(p)
|
this.add_guide = function(p)
|
||||||
{
|
{
|
||||||
|
if(p[0] == "?"){ this.guides = []; this.draw_guides(); return; }
|
||||||
var x = p[0] ? p[0] : 0 ;
|
var x = p[0] ? p[0] : 0 ;
|
||||||
var y = p[1] ? p[1] : 0 ;
|
var y = p[1] ? p[1] : 0 ;
|
||||||
var w = p[2] ? p[2] : 0 ;
|
var w = p[2] ? p[2] : 0 ;
|
||||||
var h = p[3] ? p[3] : 0 ;
|
var h = p[3] ? p[3] : 0 ;
|
||||||
|
|
||||||
|
|
||||||
if(x < -10 && w === 0 && h === 0){
|
if(x < -10 && w === 0 && h === 0){
|
||||||
x = Math.abs(x);
|
x = Math.abs(x);
|
||||||
for (i = 0; i < canvas.width/x; i++) {
|
for (i = 0; i < canvas.width/x; i++) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user