function Vector(rune) { Module.call(this,rune); this.parameters = [Any]; this.variables = {"fill_color" : null,"stroke_width" : 5,"stroke_color" : "#ffffff", "line_cap" : "square"}; this.coordinates = []; this.last_pos = null; this.paths = []; // Module this.passive = function(cmd) { if(!ronin.vector.layer){ ronin.vector.create_layer(); } this.layer.clear(); this.layer.context().lineCap = cmd.variable("line_cap") ? cmd.variable("line_cap").value : "square"; this.layer.context().lineWidth = cmd.variable("stroke_width") ? cmd.variable("stroke_width").value : 10; this.layer.context().strokeStyle = cmd.variable("stroke_color") ? cmd.variable("stroke_color").value : "#ffffff"; this.layer.context().fillStyle = cmd.variable("fill_color") ? cmd.variable("fill_color").value : "#ffffff"; if(cmd.variable("fill_color")){ronin.vector.layer.context().fill(new Path2D(cmd.content.join(" ")));} ronin.vector.layer.context().stroke(new Path2D(cmd.content.join(" "))); } this.active = function(cmd) { this.paths.push(this.create_path()); this.coordinates = []; if(this.layer){ this.layer.remove(this); } ronin.surface.active_layer.context().lineCap = cmd.variable("line_cap") ? cmd.variable("line_cap").value : "square"; ronin.surface.active_layer.context().lineWidth = cmd.variable("stroke_width") ? cmd.variable("stroke_width").value : 10; ronin.surface.active_layer.context().strokeStyle = cmd.variable("stroke_color") ? cmd.variable("stroke_color").value : "#ffffff"; ronin.surface.active_layer.context().fillStyle = cmd.variable("fill_color") ? cmd.variable("fill_color").value : "#ffffff"; if(cmd.variable("fill_color")){ronin.surface.active_layer.context().fill(new Path2D(cmd.content.join(" ")));} ronin.surface.active_layer.context().stroke(new Path2D(cmd.content.join(" "))); } // Tools this.create_path = function() { var command = ""; for (var i = 0; i < this.coordinates.length; i++) { command += this.coordinates[i]+" "; } return command; } this.create_svg = function() { var s = ""; s += ""; for (var i = 0; i < this.paths.length; i++) { s += ""; } s += ""; console.log(s); return s; } // Mouse this.click = null; this.mouse_mode = function() { if(keyboard.shift_held == true && keyboard.alt_held == true){ return "Vector(Origin)"; } else if(keyboard.shift_held == true){ return "Vector(Counterclock Arc)"; } else if(keyboard.alt_held == true){ return "Vector(Clockwise Arc)"; } else{ return "Vector(Line)"; } } this.mouse_down = function(position) { this.click = true; ronin.terminal.input_element.value = "+ "+this.create_path(); this.passive(ronin.terminal.cmd()); ronin.terminal.update_hint(); } this.mouse_move = function(position) { if(!this.click){ return; } ronin.terminal.input_element.value = "+ "+this.create_path(); ronin.terminal.input_element.value += "L"+position.render(); this.passive(ronin.terminal.cmd()); ronin.terminal.update_hint(); } this.mouse_up = function(position) { this.click = null; if(this.coordinates.length == 0){ this.coordinates.push("M"+position.render()); } else{ var offset = this.last_pos ? position.offset(this.last_pos) : position; if(keyboard.shift_held == true && keyboard.alt_held == true){ this.coordinates.push("M"+position.render()); } else if(keyboard.shift_held == true){ this.coordinates.push("a"+offset.render()+" 0 0,1 "+offset.render()); } else if(keyboard.alt_held == true){ this.coordinates.push("a"+offset.render()+" 0 0,0 "+offset.render()); } else{ this.coordinates.push("l"+offset.render()); } } ronin.terminal.input_element.value = "+ "+this.create_path(); this.passive(ronin.terminal.cmd()); this.last_pos = position; ronin.terminal.update_hint(); } this.key_escape = function() { if(this.layer){ this.layer.remove(this); } this.coordinates = []; this.last_pos = null; } }