Skip to content

Commit

Permalink
Discretize nodes position on the scene
Browse files Browse the repository at this point in the history
  • Loading branch information
don4get committed Nov 1, 2020
1 parent 4d1032a commit 97b85ce
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 22 deletions.
40 changes: 20 additions & 20 deletions examples/calculator/calculator.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
{
"id": 1583748004592,
"title": "Input",
"posX": -346.0,
"posY": -184.0,
"posX": -375.0,
"posY": -330.0,
"inputSockets": [],
"outputSockets": [
{
Expand All @@ -26,8 +26,8 @@
{
"id": 1583747824656,
"title": "Input",
"posX": -347.0,
"posY": -22.0,
"posX": -375.0,
"posY": -225.0,
"inputSockets": [],
"outputSockets": [
{
Expand All @@ -46,8 +46,8 @@
{
"id": 1583747825136,
"title": "Add",
"posX": -49.25,
"posY": -296.75,
"posX": -45.0,
"posY": -330.0,
"inputSockets": [
{
"id": 1583749317968,
Expand Down Expand Up @@ -79,8 +79,8 @@
{
"id": 1583749281056,
"title": "Subtract",
"posX": -52.25,
"posY": -175.75,
"posX": -45.0,
"posY": -210.0,
"inputSockets": [
{
"id": 1583749318304,
Expand Down Expand Up @@ -112,8 +112,8 @@
{
"id": 1583749318256,
"title": "Multiply",
"posX": -52.25,
"posY": -47.75,
"posX": -45.0,
"posY": -105.0,
"inputSockets": [
{
"id": 1583749318688,
Expand Down Expand Up @@ -145,8 +145,8 @@
{
"id": 1583749318640,
"title": "Divide",
"posX": -57.25,
"posY": 71.25,
"posX": -45.0,
"posY": 15.0,
"inputSockets": [
{
"id": 1583749319072,
Expand Down Expand Up @@ -178,8 +178,8 @@
{
"id": 1583749319792,
"title": "Output",
"posX": 245.0,
"posY": -297.5,
"posX": 240.0,
"posY": -330.0,
"inputSockets": [
{
"id": 1583749319888,
Expand All @@ -196,8 +196,8 @@
{
"id": 1583749804960,
"title": "Output",
"posX": 243.0,
"posY": -176.5,
"posX": 240.0,
"posY": -210.0,
"inputSockets": [
{
"id": 1583749805200,
Expand All @@ -214,8 +214,8 @@
{
"id": 1583749320560,
"title": "Output",
"posX": 238.0,
"posY": -48.5,
"posX": 240.0,
"posY": -105.0,
"inputSockets": [
{
"id": 1583749804288,
Expand All @@ -232,8 +232,8 @@
{
"id": 1583749320608,
"title": "Output",
"posX": 241.0,
"posY": 70.5,
"posX": 240.0,
"posY": 15.0,
"inputSockets": [
{
"id": 1583749804528,
Expand Down
14 changes: 14 additions & 0 deletions nodedge/graphics_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,20 @@ def mouseReleaseEvent(self, event):

# Handle when node moved
if self._wasMoved:
clipSize = self.node.scene.graphicsScene.gridSize
pos = event.scenePos() - event.pos()
newX = pos.x() - pos.x() % clipSize
newY = pos.y() - pos.y() % clipSize

self.setPos(newX, newY)
graphicsScene: GraphicsScene = cast(GraphicsScene, self.scene())
for node in graphicsScene.scene.nodes:
if node.graphicsNode.isSelected():
node.updateConnectedEdges()

self.__logger.debug(f"Current graphics node pos: {self.pos()}")
self.__logger.debug(f"Event pos: {event.scenePos()}")

self._wasMoved = False
self.node.scene.history.store("Move a node")

Expand Down
4 changes: 2 additions & 2 deletions nodedge/graphics_scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ def initStyle(self) -> None:

# noinspection PyAttributeOutsideInit
def initSizes(self) -> None:
"""Set up internal attributes like `grid_size`, `scene_width` and
`scene_height`. """
"""Set up internal attributes like `gridSize`, `sceneWidth` and
`sceneHeight`. """
self.gridSize = 15
self.gridSquares = 4
self.sceneWidth = 64000
Expand Down

0 comments on commit 97b85ce

Please sign in to comment.