Skip to content

Commit

Permalink
Fixed deletion error
Browse files Browse the repository at this point in the history
  • Loading branch information
AntixK committed Apr 28, 2019
1 parent 0f1273b commit 69fc659
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 7 deletions.
3 changes: 2 additions & 1 deletion public/mouse_events.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ function create_point()

function delete_point()
{
k = text_field_array.length-1;
let k = text_field_array.length-1;
text_field_array[k].remove_field();
text_field_array.pop();

Expand All @@ -92,6 +92,7 @@ function delete_point()
point_num[N-1].html('');
point_num.pop();
control_points.pop();

N -= 1;
if(N >1)
{
Expand Down
55 changes: 49 additions & 6 deletions public/sketch.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ function setup() {
x_mark.mouseClicked(delete_point);


reset_canvas();
reset_canvas(false);

rectMode(RADIUS);
noStroke();
Expand Down Expand Up @@ -228,26 +228,68 @@ function import_json()
reader.onload = function(){
in_json_file = JSON.parse(reader.result);
let pts = in_json_file.control_points;

zoom = 1.0;
zoom_slider.value(zoom*100);
for(let i =0; i < N;++i)
{
delete_point();
}

control_points = []
text_field_array = []
N = pts.length;

let k = 0;
for(let i = 0;i<pts.length;++i)
{
control_points.push(new Marker());
control_points[i].x = pts[i][0];
control_points[i].y = pts[i][1];

point_num.push(createElement('p'));
point_num[i].style('font-size', '18px');
point_num[i].style('font-family', font.font.names.postScriptName["en"]);
point_num[i].style('color', 'white');
point_num[i].html(i+1);
point_num[i].style('text-align', 'left');
point_num[i].position(NUM_X - 20,(NUM_Y - 15)+i*40);

for(let j = 0; j < 2; ++j)
{
text_field_array.push(new TextField(NUM_X + j*80, NUM_Y+i*40));
text_field_array[k].set_id_coord(i,j);
if(j==0)
{
text_field_array[k].set_val(control_points[i].x.toFixed(2));
}
else
{
text_field_array[k].set_val(control_points[i].y.toFixed(2));
}

k++;
}

}
x_mark.position(NUM_X + 160,(NUM_Y - 12)+(N-1)*40);
x_mark.html('\u2718');


}
reader.readAsText(file_handle.files[0]);
}, false);

}

function reset_canvas()
function reset_canvas(flag = true)
{
zoom = 1.0;
zoom_slider.value(zoom*100);
if(N > 4)
zoom_slider.value(zoom*100);

if(flag)
{
for(let i =0; i < N;++i)
while(N > 0)
{
delete_point();
}
Expand Down Expand Up @@ -287,6 +329,7 @@ function reset_canvas()
}
}
x_mark.position(NUM_X + 160,(NUM_Y - 12)+(N-1)*40);
x_mark.html('\u2718');

noStroke();
}
Expand Down

0 comments on commit 69fc659

Please sign in to comment.