From f1f44b1f4b8215b6c1cc2f5992d128cb50f2415b Mon Sep 17 00:00:00 2001 From: Patrick Simianer Date: Sat, 19 Sep 2015 14:42:48 +0200 Subject: more glitches --- edit.js | 42 +++++++++++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/edit.js b/edit.js index af1611d..0cf7c67 100644 --- a/edit.js +++ b/edit.js @@ -10,6 +10,7 @@ var r, texts = [], connections = {}, id = 0, + next_grid = 0, // layout margin = 30, padding = margin/3, @@ -193,14 +194,18 @@ var collide = function collide (obj) debug = function () { var s = ""; for (var i=0; i del_grid) { + target_shapes[i]["grid_"] -= 1; + } + if (g > max) + max = g; + } + next_grid = g; + if (!next_grid) // empty + next_grid = 0; snap_to_grid(true); return; @@ -252,8 +269,8 @@ snap_to_grid = function (anim=false) // left -> right for (var i=0; i < target_shapes.length; i++) { pos = target_shapes[i]["grid_"]; - id = target_shapes[i]["id_"]; - if (id == cur_id) + id_ = target_shapes[i]["id_"]; + if (id_ == cur_id) continue; if (pos >= old_pos && pos <= new_pos) { target_shapes[i]["grid_"] -= 1; @@ -265,8 +282,8 @@ snap_to_grid = function (anim=false) // right -> left for (var i=0; i < target_shapes.length; i++) { pos = target_shapes[i]["grid_"]; - id = target_shapes[i]["id_"]; - if (id == cur_id) + id_ = target_shapes[i]["id_"]; + if (id_ == cur_id) continue; if (pos >= new_pos && pos <= old_pos) { target_shapes[i]["grid_"] += 1; @@ -341,8 +358,8 @@ var make_obj = function(x, text, type) sh.drag(move, dragger, up).onDragOver( function(obj) { collide(obj); }) sh.attr({ cursor: "move" }); tx.drag(move, dragger, up); - sh["grid_"] = id; - sh["grid_tmp_"] = id; + sh["grid_"] = next_grid; + sh["grid_tmp_"] = next_grid; sh.click(function() { if (connect_mode) { if (connections[conn_str(connect_mode_shape,this)]) { @@ -416,6 +433,8 @@ var make_obj = function(x, text, type) }); } id++; + if (type == "target") + next_grid++; }, add_obj = function() { @@ -427,15 +446,15 @@ add_obj = function() } } if (!shapes[max_idx]) { - make_obj(xbegin+padding, "X", "target", 0); + make_obj(xbegin+padding, "X", "target"); } else { make_obj(shapes[max_idx].getBBox().x2+(margin-padding), "X", - "target", - max+1); + "target"); } r.setSize(r.width+target_shapes[target_shapes.length-1].getBBox().width+margin, r.height); + cur_drag = null; snap_to_grid(true); }, make_objs = function (a, type) @@ -516,7 +535,7 @@ var init = function () rm_shape = r.rect(5, line_margin+ybegin, 50, box_height).attr({"fill":"#fff","stroke":0}).animate({"fill":"red"}, 2000); rm_shape.toBack(); rm_shape["rm_shape_"] = true; - rm_shape["id_"] = -1; + rm_shape["id_"] = -1; // source objs make_objs(source, "source"); // target objs @@ -532,6 +551,7 @@ reset = function() texts = []; connections = {}; id = 0; + next_grid = 0; cur_drag = null; edit_mode = false; cur_ed = null; -- cgit v1.2.3