From: Daniel Kirschten Date: Wed, 15 May 2019 22:55:01 +0000 (+0200) Subject: A GUIWire now can trigger a redraw X-Git-Url: https://mograsim.net/gitweb/?a=commitdiff_plain;h=f58c5654c2ea4f3c66768f8f80aeb96bd40694b5;p=Mograsim.git A GUIWire now can trigger a redraw --- 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)