From f58c5654c2ea4f3c66768f8f80aeb96bd40694b5 Mon Sep 17 00:00:00 2001 From: Daniel Kirschten Date: Thu, 16 May 2019 00:55:01 +0200 Subject: [PATCH] A GUIWire now can trigger a redraw --- LogicUI/src/era/mi/examples/gui/LogicUI.java | 2 +- LogicUI/src/era/mi/wires/gui/GUIWire.java | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/LogicUI/src/era/mi/examples/gui/LogicUI.java b/LogicUI/src/era/mi/examples/gui/LogicUI.java index 5c77574f..82528d1d 100644 --- a/LogicUI/src/era/mi/examples/gui/LogicUI.java +++ b/LogicUI/src/era/mi/examples/gui/LogicUI.java @@ -100,7 +100,7 @@ public class LogicUI } private void addWire(BasicGUIComponent component1, int component1ConnectionIndex, BasicGUIComponent component2, int component2ConnectionIndex, Point... path) { - wires.add(new GUIWire(component1, component1ConnectionIndex, componentPositions.get(component1), component2, component2ConnectionIndex, componentPositions.get(component2), path)); + wires.add(new GUIWire(canvas::redrawThreadsafe, component1, component1ConnectionIndex, componentPositions.get(component1), component2, component2ConnectionIndex, componentPositions.get(component2), path)); } private void drawComponent(GeneralGC gc, BasicGUIComponent component) { diff --git a/LogicUI/src/era/mi/wires/gui/GUIWire.java b/LogicUI/src/era/mi/wires/gui/GUIWire.java index 7cfa796a..1de3e9ef 100644 --- a/LogicUI/src/era/mi/wires/gui/GUIWire.java +++ b/LogicUI/src/era/mi/wires/gui/GUIWire.java @@ -12,7 +12,7 @@ public class GUIWire private final WireArray wa; private final double[] path; - public GUIWire(BasicGUIComponent component1, int component1ConnectionIndex, Point component1Pos, BasicGUIComponent component2, int component2ConnectionIndex, Point component2Pos, Point... path) + public GUIWire(Runnable redraw, BasicGUIComponent component1, int component1ConnectionIndex, Point component1Pos, BasicGUIComponent component2, int component2ConnectionIndex, Point component2Pos, Point... path) { this.wa = component1.getConnectedWireArray(component1ConnectionIndex); if(!Objects.equals(wa, component2.getConnectedWireArray(component2ConnectionIndex))) @@ -29,6 +29,8 @@ public class GUIWire Point component2ConnectionPoint = component2.getWireArrayConnectionPoint(component2ConnectionIndex); this.path[this.path.length - 2] = component2Pos.x + component2ConnectionPoint.x; this.path[this.path.length - 1] = component2Pos.y + component2ConnectionPoint.y; + + wa.addObserver((initiator, oldValues) -> redraw.run()); } public void render(GeneralGC gc) -- 2.17.1