From a8f1c92906bcf63789fd38c71f4efaa2814d52ab Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Thu, 28 Sep 2017 09:19:34 +1300 Subject: [PATCH] Improved guide --- sources/scripts/commander.js | 4 ++-- sources/scripts/cursor.js | 34 +++++++++++++++++++++++++-------- sources/scripts/layers/guide.js | 5 +++-- sources/scripts/modules/io.js | 2 -- 4 files changed, 31 insertions(+), 14 deletions(-) diff --git a/sources/scripts/commander.js b/sources/scripts/commander.js index d790c43..299fb83 100644 --- a/sources/scripts/commander.js +++ b/sources/scripts/commander.js @@ -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(); } diff --git a/sources/scripts/cursor.js b/sources/scripts/cursor.js index 8106ec2..9b1d76e 100644 --- a/sources/scripts/cursor.js +++ b/sources/scripts/cursor.js @@ -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) ); diff --git a/sources/scripts/layers/guide.js b/sources/scripts/layers/guide.js index e50ef11..8101c29 100644 --- a/sources/scripts/layers/guide.js +++ b/sources/scripts/layers/guide.js @@ -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; } diff --git a/sources/scripts/modules/io.js b/sources/scripts/modules/io.js index 08630f6..156b437 100644 --- a/sources/scripts/modules/io.js +++ b/sources/scripts/modules/io.js @@ -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();