First draft for the new vector tool

This commit is contained in:
Devine Lu Linvega 2017-01-23 15:35:50 -07:00
parent decbb6fdf4
commit 4e235bbd36
3 changed files with 90 additions and 11 deletions

View File

@ -7,6 +7,8 @@ function Cursor(rune)
this.mode = null;
this.position = new Position();
this.magnetism = null;
this.grid = new Position(4,4);
this.layer = null;
@ -27,8 +29,20 @@ function Cursor(rune)
this.active = function(cmd)
{
if(!cmd.rect()){ return; }
this.draw(cmd.rect(),cmd.position());
this.layer.clear();
if(cmd.bang()){
this.magnetism = null;
}
if(cmd.position()){
this.grid = cmd.position();
}
if(cmd.rect()){
this.magnetism = cmd.rect();
this.draw(cmd.rect(),this.grid);
}
}
this.draw = function(rect,grid)
@ -59,7 +73,10 @@ function Cursor(rune)
this.update = function(event)
{
if(event.altKey == true){
if(ronin.module){
this.set_mode(ronin.module);
}
else if(event.altKey == true){
this.set_mode(ronin.surface);
}
else{
@ -73,9 +90,25 @@ function Cursor(rune)
this.mode = mode;
document.body.setAttribute("class",this.mode.constructor.name);
}
//
this.magnetic_position = function(position)
{
var x = parseInt(position.x / 20) * 20;
var y = parseInt(position.y / 20) * 20;
return new Position(x,y);
}
//
this.mouse_down = function(position)
{
if(this.magnetism){
position = this.magnetic_position(position);
}
this.position = position;
if(this.mode.constructor.name != Cursor.name){
this.mode.mouse_down(position);
@ -85,6 +118,10 @@ function Cursor(rune)
this.mouse_move = function(position)
{
if(this.magnetism){
position = this.magnetic_position(position);
}
this.position = position;
if(this.mode.constructor.name != Cursor.name){
this.mode.mouse_move(position);
@ -93,6 +130,10 @@ function Cursor(rune)
this.mouse_up = function(position)
{
if(this.magnetism){
position = this.magnetic_position(position);
}
this.position = position;
if(this.mode.constructor.name != Cursor.name){
this.mode.mouse_up(position);

View File

@ -1,12 +1,16 @@
function Keyboard()
{
this.shift_held = false;
this.alt_held = false;
this.listen_onkeydown = function(event)
{
if(event.shiftKey == true){
this.shift_held = true;
}
if(event.altKey == true){
this.alt_held = true;
}
ronin.cursor.update(event);
ronin.widget.update();
}
@ -14,6 +18,7 @@ function Keyboard()
this.listen_onkeyup = function(event)
{
this.shift_held = false;
this.alt_held = false;
switch (event.key) {
case "Enter": this.key_enter(); break;

View File

@ -3,7 +3,7 @@ function Vector(rune)
Module.call(this,rune);
this.parameters = [Any];
this.variables = {"fill_color" : "none","stroke_width" : 2,"stroke_color" : "#ffffff", "line_cap" : "square"};
this.variables = {"fill_color" : "none","stroke_width" : 5,"stroke_color" : "#ffffff", "line_cap" : "square"};
this.layer = null;
@ -20,7 +20,7 @@ function Vector(rune)
{
this.layer.clear();
this.layer.context().lineCap = cmd.variable("line_cap") ? cmd.variable("line_cap").value : "round";
this.layer.context().lineWidth = cmd.variable("stroke_width") ? cmd.variable("stroke_width").value : ronin.brush.size;
this.layer.context().lineWidth = cmd.variable("stroke_width") ? cmd.variable("stroke_width").value : 5;
this.layer.context().strokeStyle = cmd.variable("stroke_color") ? cmd.variable("stroke_color").value : "#ffffff";
this.layer.context().stroke(new Path2D(cmd.content.join(" ")));
}
@ -29,7 +29,7 @@ function Vector(rune)
{
this.layer.clear();
ronin.surface.active_layer.context().lineCap = cmd.variable("line_cap") ? cmd.variable("line_cap").value : "round";
ronin.surface.active_layer.context().lineWidth = cmd.variable("stroke_width") ? cmd.variable("stroke_width").value : ronin.brush.size;
ronin.surface.active_layer.context().lineWidth = cmd.variable("stroke_width") ? cmd.variable("stroke_width").value : 5;
ronin.surface.active_layer.context().strokeStyle = cmd.variable("stroke_color") ? cmd.variable("stroke_color").value : "#ffffff";
ronin.surface.active_layer.context().stroke(new Path2D(cmd.content.join(" ")));
}
@ -40,17 +40,34 @@ function Vector(rune)
this.widget_cursor = function()
{
return "Vector";
if(keyboard.shift_held == true){
return "Vector(Counterclock Arc)";
}
else if(keyboard.alt_held == true){
return "Vector(Clockwise Arc)";
}
else{
return "Vector(Line)";
}
}
this.memory = null;
this.coordinates = [];
this.create_command = function()
{
var command = "+ ";
for (var i = 0; i < this.coordinates.length; i++) {
command += i == 0 ? "M"+this.coordinates[i]+" " : this.coordinates[i]+" ";
}
return command;
}
this.mouse_down = function(position)
{
this.click = true;
this.memory = commander.element_input.value;
commander.element_input.value += "L"+position.render()+" ";
commander.element_input.value = this.create_command();
commander.hint.update();
this.passive(commander.cmd());
}
@ -58,7 +75,8 @@ function Vector(rune)
this.mouse_move = function(position)
{
if(!this.click){ return; }
commander.element_input.value = this.memory+"L"+position.render()+" ";
commander.element_input.value = this.create_command();
commander.element_input.value += "L"+position.render();
commander.hint.update();
this.passive(commander.cmd());
}
@ -66,5 +84,20 @@ function Vector(rune)
this.mouse_up = function(position)
{
this.click = null;
// Add the right thing
if(keyboard.shift_held == true){
this.coordinates.push("A1,1 0 0,1 "+position.render());
}
else if(keyboard.alt_held == true){
this.coordinates.push("A1,1 0 0,0 "+position.render());
}
else{
this.coordinates.push(position.render());
}
commander.element_input.value = this.create_command();
commander.hint.update();
this.passive(commander.cmd());
}
}