Guides are now working properly.
This commit is contained in:
parent
80465dd71b
commit
b6b63e4e48
@ -11,4 +11,9 @@ function Color(val = '000000')
|
|||||||
b: parseInt(result[3], 16)
|
b: parseInt(result[3], 16)
|
||||||
} : null;
|
} : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.rgba = function()
|
||||||
|
{
|
||||||
|
return "rgba("+this.rgb().r+","+this.rgb().g+","+this.rgb().b+",1)";
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,13 +1,27 @@
|
|||||||
function Guide(position,rect)
|
function Guide(position = new Position(),rect = new Rect(),color = new Color())
|
||||||
{
|
{
|
||||||
this.position = position;
|
this.position = position;
|
||||||
this.rect = rect;
|
this.rect = rect;
|
||||||
|
this.color = color;
|
||||||
|
|
||||||
this.draw = function(context)
|
this.draw = function(context)
|
||||||
{
|
{
|
||||||
context.beginPath();
|
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.moveTo(this.position.x,0);
|
||||||
context.lineTo(this.position.x,canvas.height);
|
context.lineTo(this.position.x,canvas.height);
|
||||||
}
|
}
|
||||||
@ -15,21 +29,10 @@ function Guide(position,rect)
|
|||||||
context.moveTo(0,this.position.y);
|
context.moveTo(0,this.position.y);
|
||||||
context.lineTo(canvas.width,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.lineCap="round";
|
||||||
context.lineWidth = 1;
|
context.lineWidth = 1;
|
||||||
context.strokeStyle = "rgba(255,0,0,1)";
|
context.strokeStyle = this.color.rgba();
|
||||||
context.stroke();
|
context.stroke();
|
||||||
context.closePath();
|
context.closePath();
|
||||||
}
|
}
|
||||||
|
@ -73,5 +73,6 @@ function Keyboard()
|
|||||||
this.key_escape = function()
|
this.key_escape = function()
|
||||||
{
|
{
|
||||||
commander.hide();
|
commander.hide();
|
||||||
|
ronin.draw_guides();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -16,19 +16,16 @@ function Ronin()
|
|||||||
|
|
||||||
this.guide = function(p)
|
this.guide = function(p)
|
||||||
{
|
{
|
||||||
return ;
|
this.guides_context.clearRect(0, 0, canvas.width, canvas.height);
|
||||||
|
|
||||||
// guides_context = document.getElementById('guides').getContext('2d');
|
|
||||||
// guides_context.clearRect(0, 0, canvas.width, canvas.height);
|
|
||||||
|
|
||||||
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 ;
|
||||||
|
|
||||||
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)
|
this.add_guide = function(p)
|
||||||
@ -38,7 +35,7 @@ function Ronin()
|
|||||||
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 ;
|
||||||
|
|
||||||
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.guides.push(g);
|
||||||
this.draw_guides();
|
this.draw_guides();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user