From: Daniel Kirschten Date: Mon, 13 May 2019 20:53:58 +0000 (+0200) Subject: Further improvements in LogicUI: X-Git-Url: https://mograsim.net/gitweb/?a=commitdiff_plain;h=70aaa694028a17acf0ac07ee6870659947ba28f0;p=Mograsim.git Further improvements in LogicUI: -GUIMux knows where its connection points are -Connection points get drawn --- diff --git a/LogicUI/src/LogicUI.java b/LogicUI/src/LogicUI.java index 6b8b500f..97a5c75b 100644 --- a/LogicUI/src/LogicUI.java +++ b/LogicUI/src/LogicUI.java @@ -16,6 +16,7 @@ import era.mi.logic.components.Splitter; import era.mi.logic.components.gates.AndGate; import era.mi.logic.components.gates.NotGate; import era.mi.logic.wires.WireArray; +import net.haspamelodica.swt.helper.gcs.GeneralGC; import net.haspamelodica.swt.helper.gcs.TranslatedGC; import net.haspamelodica.swt.helper.swtobjectwrappers.Point; import net.haspamelodica.swt.helper.zoomablecanvas.ZoomableCanvas; @@ -40,8 +41,7 @@ public class LogicUI componentPositions = new HashMap<>(); initComponents(); - canvas.addZoomedRenderer(gc -> components.forEach( - component -> component.render(new TranslatedGC(gc, componentPositions.get(component))))); + canvas.addZoomedRenderer(gc -> components.forEach(component -> drawComponent(gc, component))); new ZoomableCanvasUserInput(canvas).enableUserInput(); new ZoomableCanvasOverlay(canvas, null).enableScale(); } @@ -54,6 +54,7 @@ public class LogicUI new NotGate(1, f, g); new Merger(h, c, g); addComponent(new GUIMux(1, i, e, h, d), 10, 10); + addComponent(new GUIMux(1, a, new WireArray(10, 1), a, b, e, f), 100, 100); new Splitter(i, k, j); } private void addComponent(BasicGUIComponent component, double x, double y) @@ -61,6 +62,18 @@ public class LogicUI components.add(component); componentPositions.put(component, new Point(x, y)); } + private void drawComponent(GeneralGC gc, BasicGUIComponent component) + { + TranslatedGC tgc = new TranslatedGC(gc, componentPositions.get(component)); + component.render(tgc); + tgc.setBackground(display.getSystemColor(SWT.COLOR_BLUE)); + for(int i = 0; i < component.getConnectedWireArraysCount(); i ++) + { + Point connectionPoint = component.getWireArrayConnectionPoint(i); + if(connectionPoint != null) + tgc.fillOval(connectionPoint.x - 2, connectionPoint.y - 2, 4, 4); + } + } public void run() { shell.open(); diff --git a/LogicUI/src/era/mi/components/gui/BasicGUIComponent.java b/LogicUI/src/era/mi/components/gui/BasicGUIComponent.java index 29df4f64..f39d3202 100644 --- a/LogicUI/src/era/mi/components/gui/BasicGUIComponent.java +++ b/LogicUI/src/era/mi/components/gui/BasicGUIComponent.java @@ -1,8 +1,16 @@ package era.mi.components.gui; +import java.util.List; + +import era.mi.logic.wires.WireArray; import net.haspamelodica.swt.helper.gcs.GeneralGC; +import net.haspamelodica.swt.helper.swtobjectwrappers.Point; public interface BasicGUIComponent { public void render(GeneralGC gc); + + public int getConnectedWireArraysCount(); + public WireArray getConnectedWireArray(int connectionIndex); + public Point getWireArrayConnectionPoint(int connectionIndex); } \ No newline at end of file diff --git a/LogicUI/src/era/mi/components/gui/GUIMux.java b/LogicUI/src/era/mi/components/gui/GUIMux.java index d5b7c488..509a8ccd 100644 --- a/LogicUI/src/era/mi/components/gui/GUIMux.java +++ b/LogicUI/src/era/mi/components/gui/GUIMux.java @@ -1,28 +1,72 @@ package era.mi.components.gui; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + import era.mi.logic.components.Mux; import era.mi.logic.wires.WireArray; import net.haspamelodica.swt.helper.gcs.GeneralGC; +import net.haspamelodica.swt.helper.swtobjectwrappers.Point; public class GUIMux extends Mux implements BasicGUIComponent { - private final int inputCount; + private final double height; + private final List connectedWireArrays; + private final List wireArrayConnectionPoints; public GUIMux(int processTime, WireArray out, WireArray select, WireArray... inputs) { super(processTime, out, select, inputs); - this.inputCount = inputs.length; + + double height = inputs.length * 10; + if(height < 10) + height = 10; + this.height = height; + + List connectedWireArraysModifiable = new ArrayList<>(); + List wireArrayConnectionPointsModifiable = new ArrayList<>(); + + connectedWireArraysModifiable.add(out); + wireArrayConnectionPointsModifiable.add(new Point(20, 10 + height / 2)); + + connectedWireArraysModifiable.add(select); + wireArrayConnectionPointsModifiable.add(new Point(10, 5)); + + { + connectedWireArraysModifiable.addAll(Arrays.asList(inputs)); + double inputHeightIncrement = height / (inputs.length - 1); + double inputHeight = 10; + for(int i = 0; i < inputs.length; i ++, inputHeight += inputHeightIncrement) + wireArrayConnectionPointsModifiable.add(new Point(0, inputHeight)); + } + + this.connectedWireArrays = Collections.unmodifiableList(connectedWireArraysModifiable); + this.wireArrayConnectionPoints = Collections.unmodifiableList(wireArrayConnectionPointsModifiable); } @Override public void render(GeneralGC gc) { - double height = inputCount * 10; - if(height < 20) - height = 20; gc.drawPolygon(new double[] { 0, 0, 20, 10, 20, height + 10, 0, height + 20}); } + @Override + public int getConnectedWireArraysCount() + { + return connectedWireArrays.size(); + } + @Override + public WireArray getConnectedWireArray(int connectionIndex) + { + return connectedWireArrays.get(connectionIndex); + } + @Override + public Point getWireArrayConnectionPoint(int connectionI) + { + return wireArrayConnectionPoints.get(connectionI); + } } \ No newline at end of file