From 7fee4459402b5caea3e6eefffdb333f9bd2cf8e9 Mon Sep 17 00:00:00 2001 From: "Zafar, Adnan F" Date: Wed, 5 Sep 2018 10:52:17 -0500 Subject: [PATCH] Several usability improvements for dotty: 1) Center the node's bounding box on the nodes position (in the global coordinate system) based on it's size while being moved. This solves the issue of being unable to click-and-drag a node after it was initially dragged, since the bounding box erroneously remained at the initial position. 2) Keep the relative position offset between the center of the node and the position of the cursor when clicking-and-dragging. This avoid snapping the center of the node to the current cursor position, but rather allows it to move with the cursor. 3) Redraw the graph on 'leftup' to correct nodes that may have become visually corrupted by edges obscuring their outlines. --- cmd/dotty/dotty_draw.lefty | 7 +++++++ cmd/dotty/dotty_ui.lefty | 19 ++++++++++++++----- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/cmd/dotty/dotty_draw.lefty b/cmd/dotty/dotty_draw.lefty index cd67f3ef2b..2c10f85109 100644 --- a/cmd/dotty/dotty_draw.lefty +++ b/cmd/dotty/dotty_draw.lefty @@ -158,6 +158,13 @@ dotty.protogt.movenode = function (gt, node, pos) { gt.undrawnode (gt, gt.views, node); node.pos.x = pos.x; node.pos.y = pos.y; + + # correct the bounding box when moving + node.rect[0].x = node.pos.x - node.size.x/2; + node.rect[1].x = node.pos.x + node.size.x/2; + node.rect[0].y = node.pos.y - node.size.y/2; + node.rect[1].y = node.pos.y + node.size.y/2; + gt.movenodedraw (node.draws, dp); for (eid in node.edges) { edge = node.edges[eid]; diff --git a/cmd/dotty/dotty_ui.lefty b/cmd/dotty/dotty_ui.lefty index a8c91165dc..6fdec8f8b1 100644 --- a/cmd/dotty/dotty_ui.lefty +++ b/cmd/dotty/dotty_ui.lefty @@ -273,29 +273,38 @@ dotty.protovt.normal.uifuncs = [ dotty.node2move = data.obj; dotty.movewidget = data.widget; dotty.rp2 = data.pos; + # save the previous object pos + dotty.node_ppos = data.obj.pos; } }; 'leftmove' = function (data) { - local gt; + local gt, offset_pos; gt = dotty.graphs[dotty.views[data.widget].gtid]; if (dotty.node2move & ( dotty.rp2.x ~= data.pos.x | dotty.rp2.y ~= data.pos.y )) { - gt.movenode (gt, dotty.node2move, data.pos); + # use an offset from the cursor to the node's pre-move position + offset_pos.x = data.pos.x - (dotty.rp2.x - dotty.node_ppos.x); + offset_pos.y = data.pos.y - (dotty.rp2.y - dotty.node_ppos.y); + gt.movenode (gt, dotty.node2move, offset_pos); dotty.rp2 = data.pos; } }; 'leftup' = function (data) { - local gt; + local gt, offset_pos; gt = dotty.graphs[dotty.views[data.widget].gtid]; if (dotty.node2move) { - if (dotty.movewidget == data.widget) - gt.movenode (gt, dotty.node2move, data.pos); + if (dotty.movewidget == data.widget) { + offset_pos.x = data.pos.x - (dotty.rp2.x - dotty.node_ppos.x); + offset_pos.y = data.pos.y - (dotty.rp2.y - dotty.node_ppos.y); + gt.movenode (gt, dotty.node2move, offset_pos); + } dotty.node2move = 0; } else if (~data.obj) gt.insertnode (gt, data.pos, null, null, null, 1); + gt.redrawgraph(gt, gt.views); }; 'middledown' = function (data) { if (~(data.obj.nid >= 0)) -- GitLab