diff options
author | David Winter <david.winter@analog.com> | 2021-07-07 14:19:19 +0200 |
---|---|---|
committer | mormj <34754695+mormj@users.noreply.github.com> | 2021-07-09 11:43:26 -0400 |
commit | b6f2120e84b3b541a636420ac2af8d2d86f091ac (patch) | |
tree | a33838574c43af645856e376861de4831d3ac06e /grc/gui | |
parent | 7b21032dea9d4d8ead09178fa2fa99fb37d7f9a2 (diff) |
grc: Fix desync when dragging block
This commit fixes what's basically a broken numerical integration in
the block dragging code, leading to a position desynchronization between
mouse pointer and block.
Signed-off-by: David Winter <david.winter@analog.com>
Diffstat (limited to 'grc/gui')
-rw-r--r-- | grc/gui/canvas/flowgraph.py | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/grc/gui/canvas/flowgraph.py b/grc/gui/canvas/flowgraph.py index 61bf96378c..cb63f578ac 100644 --- a/grc/gui/canvas/flowgraph.py +++ b/grc/gui/canvas/flowgraph.py @@ -803,11 +803,17 @@ class FlowGraph(CoreFlowgraph, Drawable): x, y = coordinate if not self.drawing_area.ctrl_mask: X, Y = self.coordinate - dX, dY = int(x - X), int(y - Y) - active = Actions.TOGGLE_SNAP_TO_GRID.get_active() or self.drawing_area.mod1_mask - if not active or abs(dX) >= Constants.CANVAS_GRID_SIZE or abs(dY) >= Constants.CANVAS_GRID_SIZE: + dX, dY = x - X, y - Y + + if Actions.TOGGLE_SNAP_TO_GRID.get_active() or self.drawing_area.mod1_mask: + dX, dY = int(round(dX / Constants.CANVAS_GRID_SIZE)), int(round(dY / Constants.CANVAS_GRID_SIZE)) + dX, dY = dX * Constants.CANVAS_GRID_SIZE, dY * Constants.CANVAS_GRID_SIZE + else: + dX, dY = int(round(dX)), int(round(dY)) + + if dX != 0 or dY != 0: self.move_selected((dX, dY)) - self.coordinate = (x, y) + self.coordinate = (X+dX, Y+dY) redraw = True return redraw |