Improved guide

This commit is contained in:
Devine Lu Linvega 2017-09-28 09:19:34 +13:00
parent f568911e8c
commit a8f1c92906
4 changed files with 31 additions and 14 deletions

View File

@ -55,9 +55,9 @@ function Commander()
return this.query().module;
}
this.inject = function(str,entry_code = "$")
this.inject = function(str)
{
ronin.commander.input_el.value = ronin.commander.input_el.value.replace(entry_code,str);
ronin.commander.input_el.value = str;
ronin.guide.update();
}

View File

@ -3,12 +3,17 @@ function Cursor(rune)
this.line = {origin:null,from:null,to:null,destination:null};
this.is_down = false;
this.query = null;
this.mouse_down = function(e)
{
e.preventDefault();
ronin.cursor.line.origin = {x:e.clientX,y:e.clientY};
ronin.cursor.line.from = {x:e.clientX,y:e.clientY};
// Save original query
ronin.cursor.query = ronin.commander.input_el.value;
}
this.mouse_move = function(e)
@ -28,6 +33,8 @@ function Cursor(rune)
else{
ronin.brush.stroke(ronin.cursor.line);
}
ronin.cursor.inject_query();
ronin.cursor.line.from = {x:e.clientX,y:e.clientY};
}
@ -38,19 +45,30 @@ function Cursor(rune)
ronin.cursor.line.destination = {x:e.clientX,y:e.clientY};
if(distance_between(ronin.cursor.line.origin,ronin.cursor.line.destination) > 10){
var offset = ronin.cursor.line.origin.x+","+ronin.cursor.line.origin.y;
var rect = (ronin.cursor.line.destination.x - ronin.cursor.line.origin.x)+"x"+(ronin.cursor.line.destination.y - ronin.cursor.line.origin.y);
ronin.commander.inject(offset+"|"+rect);
}
else{
ronin.commander.inject(e.clientX+","+e.clientY);
}
ronin.cursor.inject_query();
ronin.cursor.is_down = false;
ronin.cursor.line = {};
}
this.inject_query = function()
{
if(ronin.cursor.query.indexOf("$") < 0){ return; }
var a = ronin.cursor.line.origin;
var b = ronin.cursor.line.destination ? ronin.cursor.line.destination : ronin.cursor.line.from;
if(distance_between(a,b) > 10){
var offset = a.x+","+a.y;
var rect = (b.x - a.x)+"x"+(b.y - a.y);
var str = offset+"|"+rect;
}
else{
var str = a.x+","+a.y;
}
ronin.commander.inject(ronin.cursor.query.replace("$",str));
}
function distance_between(a,b)
{
return Math.sqrt( (a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y) );

View File

@ -12,7 +12,6 @@ function Guide()
this.el.style.height = (window.innerHeight)+"px";
var u = this.find_unit();
console.log("found:",u)
if(!u){ return; }
this.clear();
@ -26,6 +25,7 @@ function Guide()
}
if(u.width && u.height){
this.draw_rect(u);
this.draw_pos({x:u.x + (u.width/2),y:u.y + (u.height/2)});
}
}
@ -39,6 +39,8 @@ function Guide()
var offset = {x:u.x * 2, y:u.y * 2};
var rect = {width:u.width * 2,height:u.height * 2};
// Outline
ctx.beginPath();
ctx.globalCompositeOperation="source-over";
ctx.moveTo(offset.x,offset.y);
@ -83,7 +85,6 @@ function Guide()
{
if(q.settings.anchor){ return q.settings.anchor; }
console.log("-----",q.settings)
for(method_id in q.methods){
var params = q.methods[method_id];
if(!params){ return null; }

View File

@ -50,8 +50,6 @@ function IO()
var files = e.dataTransfer.files;
var file = files[0];
console.log(file);
if (!file.type.match(/image.*/)) { console.log("Not image"); return false; }
var reader = new FileReader();