Guides are now working properly.

This commit is contained in:
Devine Lu Linvega 2016-11-12 15:20:27 -08:00
parent 80465dd71b
commit b6b63e4e48
4 changed files with 27 additions and 21 deletions

View File

@ -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)";
}
}

View File

@ -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();
}

View File

@ -73,5 +73,6 @@ function Keyboard()
this.key_escape = function()
{
commander.hide();
ronin.draw_guides();
}
}

View File

@ -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();