diff options
author | Glenn Richardson <glenn.richardson@live.com> | 2015-11-19 20:34:55 -0500 |
---|---|---|
committer | Sebastian Koslowski <koslowski@kit.edu> | 2015-11-24 17:03:24 +0100 |
commit | dcc09deb064453f4add1ece3502ee99f12f3cb25 (patch) | |
tree | 352305829f7fe57ea16c66e5b0254636e787890b /grc/gui/Block.py | |
parent | ba57cd0c5e7352c81e5025760d7aaecde92d083b (diff) |
grc: preserve block spacing when dragging multiple blocks into canvas boundary
Diffstat (limited to 'grc/gui/Block.py')
-rw-r--r-- | grc/gui/Block.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/grc/gui/Block.py b/grc/gui/Block.py index 6a2e496e20..8c74fcb4a5 100644 --- a/grc/gui/Block.py +++ b/grc/gui/Block.py @@ -127,6 +127,40 @@ class Block(Element): ) self.get_param('_coordinate').set_value(str(coor)) + def bound_move_delta(self, delta_coor): + """ + Limit potential moves from exceeding the bounds of the canvas + + Args: + delta_coor: requested delta coordinate (dX, dY) to move + + Returns: + The delta coordinate possible to move while keeping the block on the canvas + or the input (dX, dY) on failure + """ + dX, dY = delta_coor + + try: + fgW, fgH = self.get_parent().get_size() + x, y = map(int, eval(self.get_param("_coordinate").get_value())) + if self.is_horizontal(): + sW, sH = self.W, self.H + else: + sW, sH = self.H, self.W + + if x + dX < 0: + dX = -x + elif dX + x + sW >= fgW: + dX = fgW - x - sW + if y + dY < 0: + dY = -y + elif dY + y + sH >= fgH: + dY = fgH - y - sH + except: + pass + + return ( dX, dY ) + def get_rotation(self): """ Get the rotation from the position param. |