diff --git a/index.html b/index.html index ab39a75..865b589 100644 --- a/index.html +++ b/index.html @@ -10,6 +10,7 @@ + diff --git a/scripts/commander.js b/scripts/commander.js index ff404cc..7904cf6 100644 --- a/scripts/commander.js +++ b/scripts/commander.js @@ -29,16 +29,13 @@ function Commander(element,element_input) ronin.history.active(cmd); break; case "$": - ronin.save.active(cmd); + ronin.file.save(cmd); break; case "/": - ronin.load.active(cmd); - break; - case "&": - ronin.brush.active(cmd); + ronin.file.active(cmd); break; case ">": - ronin.pointer.active(cmd); + ronin.brush.active(cmd); break; case "|": ronin.overlay.active(cmd); @@ -116,13 +113,10 @@ function Commander(element,element_input) ronin.history.passive(cmd); break; case "/": - ronin.load.passive(cmd); - break; - case "&": - ronin.brush.passive(cmd); + ronin.file.passive(cmd); break; case ">": - ronin.pointer.passive(cmd); + ronin.brush.passive(cmd); break; case "|": ronin.overlay.passive(cmd); @@ -142,11 +136,6 @@ function Commander(element,element_input) } /* - // Guides - if(parts[0] == "|"){ - parts.shift(); - ronin.guide(parts); - } // Draw if(parts[0] == "/"){ diff --git a/scripts/keyboard.js b/scripts/keyboard.js index b71a063..7ce08ff 100644 --- a/scripts/keyboard.js +++ b/scripts/keyboard.js @@ -114,6 +114,6 @@ function Keyboard() this.key_escape = function() { commander.hide(); - ronin.draw_guides(); + ronin.overlay.clear(); } } \ No newline at end of file diff --git a/scripts/ronin.brush.js b/scripts/ronin.brush.js index b3958d7..4eed28c 100644 --- a/scripts/ronin.brush.js +++ b/scripts/ronin.brush.js @@ -6,6 +6,7 @@ function Brush() this.is_drawing = false; this.size = 1; this.opacity = 1; + this.color = new Color(); // Module @@ -15,6 +16,9 @@ function Brush() var pointer = new Pointer(cmd.position()); this.add_pointer(pointer); } + if(cmd.color()){ + this.color = cmd.color(); + } } this.passive = function(cmd) diff --git a/scripts/ronin.brush.pointer.js b/scripts/ronin.brush.pointer.js index 933a6c0..9b4802a 100644 --- a/scripts/ronin.brush.pointer.js +++ b/scripts/ronin.brush.pointer.js @@ -14,7 +14,7 @@ function Pointer(offset = new Position(), color = new Color('000000')) context.lineTo(this.position().x,this.position().y); context.lineCap="round"; context.lineWidth = this.thickness(); - context.strokeStyle = "rgba("+this.color.rgb().r+","+this.color.rgb().g+","+this.color.rgb().b+","+1+")"; + context.strokeStyle = ronin.brush.color.rgba(); context.stroke(); context.closePath(); diff --git a/scripts/ronin.file.js b/scripts/ronin.file.js new file mode 100644 index 0000000..bc173b5 --- /dev/null +++ b/scripts/ronin.file.js @@ -0,0 +1,24 @@ +function File() +{ + Module.call(this); + + this.active = function() + { + console.log("Nothing to do."); + ronin.overlay.clear(); + } + + this.passive = function(cmd) + { + if(!cmd.path()){ return; } + + var position = cmd.position() ? cmd.position() : new Position(); + + if(position && cmd.rect()){ + ronin.overlay.draw(position,cmd.rect()); + } + else if(position){ + ronin.overlay.draw(position); + } + } +} \ No newline at end of file diff --git a/scripts/ronin.js b/scripts/ronin.js index 37a162f..8754f24 100644 --- a/scripts/ronin.js +++ b/scripts/ronin.js @@ -4,6 +4,7 @@ function Ronin() this.canvas = new Canvas(); this.overlay = new Overlay(); this.brush = new Brush(); + this.file = new File(); this.load_image = function(p) { @@ -38,86 +39,4 @@ function Ronin() context.drawImage(imgObj,0,0); } - - // Guides - - this.guides_element = null; - this.guides_context = null; - this.guides = []; - - this.clear_guides = function() - { - this.guides = []; - this.draw_guides(); - } - - this.draw_guides = function() - { - this.guides_context.clearRect(0, 0, canvas.width, canvas.height); - - for (i = 0; i < this.guides.length; i++) { - this.guides[i].draw(this.guides_context); - } - } - - this.guide = function(p) - { - this.guides_context.clearRect(0, 0, canvas.width, canvas.height); - this.draw_guides(); - - 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 ; - - if(x < -10 && w === 0 && h === 0){ - x = Math.abs(x); - for (i = 0; i < canvas.width/x; i++) { - var g = new Guide(new Position(x * i,y), new Rect(w,h), new Color('ff0000')); - g.draw(this.guides_context); - } - } - else if(y < -10 && w === 0 && h === 0){ - y = Math.abs(y); - for (i = 0; i < canvas.width/y; i++) { - var g = new Guide(new Position(x,y* i), new Rect(w,h), new Color('ff0000')); - g.draw(this.guides_context); - } - } - else{ - var g = new Guide(new Position(x,y), new Rect(w,h), new Color('ff0000')); - g.draw(this.guides_context); - return g; - } - } - - this.add_guide = function(p) - { - if(p[0] == "?"){ this.guides = []; this.draw_guides(); return; } - 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 ; - - if(x < -10 && w === 0 && h === 0){ - x = Math.abs(x); - for (i = 0; i < canvas.width/x; i++) { - var g = new Guide(new Position(x * i,y), new Rect(w,h), new Color('000000')); - this.guides.push(g); - } - } - else if(y < -10 && w === 0 && h === 0){ - y = Math.abs(y); - for (i = 0; i < canvas.width/y; i++) { - var g = new Guide(new Position(x,y* i), new Rect(w,h), new Color('000000')); - this.guides.push(g); - } - } - else{ - var g = new Guide(new Position(x,y), new Rect(w,h), new Color('000000')); - this.guides.push(g); - } - - this.draw_guides(); - } } \ No newline at end of file diff --git a/scripts/ronin.overlay.js b/scripts/ronin.overlay.js index fd02b48..f0d4a54 100644 --- a/scripts/ronin.overlay.js +++ b/scripts/ronin.overlay.js @@ -8,22 +8,7 @@ function Overlay(element) this.passive = function(cmd) { - this.clear(); - - if(!cmd.position()){ return; } - - if(cmd.rect()){ - this.draw_rect(cmd.position(),cmd.rect()); - } - else if(cmd.position().x > 0 && cmd.position().y > 0){ - this.draw_pointer(cmd.position()); - } - else if(cmd.position().x > 0 ){ - this.draw_vertical_line(cmd.position()); - } - else if(cmd.position().y > 0 ){ - this.draw_horizontal_line(cmd.position()); - } + this.draw(cmd.position(),cmd.rect()); } this.active = function(cmd) @@ -31,6 +16,28 @@ function Overlay(element) } + // draw + + this.draw = function(position,rect) + { + this.clear(); + + if(!position){ return; } + + if(rect){ + this.draw_rect(position,rect); + } + else if(position.x > 0 && position.y > 0){ + this.draw_pointer(position); + } + else if(position.x > 0 ){ + this.draw_vertical_line(position); + } + else if(position.y > 0 ){ + this.draw_horizontal_line(position); + } + } + this.draw_rect = function(position,rect) { this.context().beginPath(); diff --git a/scripts/unit.command.js b/scripts/unit.command.js index 8f582cf..4352dd4 100644 --- a/scripts/unit.command.js +++ b/scripts/unit.command.js @@ -25,4 +25,12 @@ function Command(cmd_array) } return null; } + + this.path = function() + { + for (i = 0; i < this.cmd_array.length; i++) { + if(this.cmd_array[i].indexOf("/") >= 0){ return this.cmd_array[i]; } + } + return null; + } } \ No newline at end of file