Commit 7fee4459 authored by Zafar, Adnan F's avatar Zafar, Adnan F

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.
parent 3a83759e
......@@ -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];
......
......@@ -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))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment