import era.mi.logic.components.gates.AndGate;\r
import era.mi.logic.components.gates.NotGate;\r
import era.mi.logic.wires.WireArray;\r
+import net.haspamelodica.swt.helper.gcs.GeneralGC;\r
import net.haspamelodica.swt.helper.gcs.TranslatedGC;\r
import net.haspamelodica.swt.helper.swtobjectwrappers.Point;\r
import net.haspamelodica.swt.helper.zoomablecanvas.ZoomableCanvas;\r
componentPositions = new HashMap<>();\r
initComponents();\r
\r
- canvas.addZoomedRenderer(gc -> components.forEach(\r
- component -> component.render(new TranslatedGC(gc, componentPositions.get(component)))));\r
+ canvas.addZoomedRenderer(gc -> components.forEach(component -> drawComponent(gc, component)));\r
new ZoomableCanvasUserInput(canvas).enableUserInput();\r
new ZoomableCanvasOverlay(canvas, null).enableScale();\r
}\r
new NotGate(1, f, g);\r
new Merger(h, c, g);\r
addComponent(new GUIMux(1, i, e, h, d), 10, 10);\r
+ addComponent(new GUIMux(1, a, new WireArray(10, 1), a, b, e, f), 100, 100);\r
new Splitter(i, k, j);\r
}\r
private void addComponent(BasicGUIComponent component, double x, double y)\r
components.add(component);\r
componentPositions.put(component, new Point(x, y));\r
}\r
+ private void drawComponent(GeneralGC gc, BasicGUIComponent component)\r
+ {\r
+ TranslatedGC tgc = new TranslatedGC(gc, componentPositions.get(component));\r
+ component.render(tgc);\r
+ tgc.setBackground(display.getSystemColor(SWT.COLOR_BLUE));\r
+ for(int i = 0; i < component.getConnectedWireArraysCount(); i ++)\r
+ {\r
+ Point connectionPoint = component.getWireArrayConnectionPoint(i);\r
+ if(connectionPoint != null)\r
+ tgc.fillOval(connectionPoint.x - 2, connectionPoint.y - 2, 4, 4);\r
+ }\r
+ }\r
public void run()\r
{\r
shell.open();\r
package era.mi.components.gui;\r
\r
+import java.util.List;\r
+\r
+import era.mi.logic.wires.WireArray;\r
import net.haspamelodica.swt.helper.gcs.GeneralGC;\r
+import net.haspamelodica.swt.helper.swtobjectwrappers.Point;\r
\r
public interface BasicGUIComponent\r
{\r
public void render(GeneralGC gc);\r
+\r
+ public int getConnectedWireArraysCount();\r
+ public WireArray getConnectedWireArray(int connectionIndex);\r
+ public Point getWireArrayConnectionPoint(int connectionIndex);\r
}
\ No newline at end of file
package era.mi.components.gui;\r
\r
+import java.util.ArrayList;\r
+import java.util.Arrays;\r
+import java.util.Collections;\r
+import java.util.List;\r
+\r
import era.mi.logic.components.Mux;\r
import era.mi.logic.wires.WireArray;\r
import net.haspamelodica.swt.helper.gcs.GeneralGC;\r
+import net.haspamelodica.swt.helper.swtobjectwrappers.Point;\r
\r
public class GUIMux extends Mux implements BasicGUIComponent\r
{\r
- private final int inputCount;\r
+ private final double height;\r
+ private final List<WireArray> connectedWireArrays;\r
+ private final List<Point> wireArrayConnectionPoints;\r
\r
public GUIMux(int processTime, WireArray out, WireArray select, WireArray... inputs)\r
{\r
super(processTime, out, select, inputs);\r
- this.inputCount = inputs.length;\r
+\r
+ double height = inputs.length * 10;\r
+ if(height < 10)\r
+ height = 10;\r
+ this.height = height;\r
+\r
+ List<WireArray> connectedWireArraysModifiable = new ArrayList<>();\r
+ List<Point> wireArrayConnectionPointsModifiable = new ArrayList<>();\r
+\r
+ connectedWireArraysModifiable.add(out);\r
+ wireArrayConnectionPointsModifiable.add(new Point(20, 10 + height / 2));\r
+\r
+ connectedWireArraysModifiable.add(select);\r
+ wireArrayConnectionPointsModifiable.add(new Point(10, 5));\r
+\r
+ {\r
+ connectedWireArraysModifiable.addAll(Arrays.asList(inputs));\r
+ double inputHeightIncrement = height / (inputs.length - 1);\r
+ double inputHeight = 10;\r
+ for(int i = 0; i < inputs.length; i ++, inputHeight += inputHeightIncrement)\r
+ wireArrayConnectionPointsModifiable.add(new Point(0, inputHeight));\r
+ }\r
+\r
+ this.connectedWireArrays = Collections.unmodifiableList(connectedWireArraysModifiable);\r
+ this.wireArrayConnectionPoints = Collections.unmodifiableList(wireArrayConnectionPointsModifiable);\r
}\r
@Override\r
public void render(GeneralGC gc)\r
{\r
- double height = inputCount * 10;\r
- if(height < 20)\r
- height = 20;\r
gc.drawPolygon(new double[] {\r
0, 0,\r
20, 10,\r
20, height + 10,\r
0, height + 20});\r
}\r
+ @Override\r
+ public int getConnectedWireArraysCount()\r
+ {\r
+ return connectedWireArrays.size();\r
+ }\r
+ @Override\r
+ public WireArray getConnectedWireArray(int connectionIndex)\r
+ {\r
+ return connectedWireArrays.get(connectionIndex);\r
+ }\r
+ @Override\r
+ public Point getWireArrayConnectionPoint(int connectionI)\r
+ {\r
+ return wireArrayConnectionPoints.get(connectionI);\r
+ }\r
}
\ No newline at end of file