Further improvements in LogicUI:
authorDaniel Kirschten <daniel.kirschten@gmx.de>
Mon, 13 May 2019 20:53:58 +0000 (22:53 +0200)
committerDaniel Kirschten <daniel.kirschten@gmx.de>
Mon, 13 May 2019 20:53:58 +0000 (22:53 +0200)
-GUIMux knows where its connection points are
-Connection points get drawn

LogicUI/src/LogicUI.java
LogicUI/src/era/mi/components/gui/BasicGUIComponent.java
LogicUI/src/era/mi/components/gui/GUIMux.java

index 6b8b500..97a5c75 100644 (file)
@@ -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();
index 29df4f6..f39d320 100644 (file)
@@ -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
index d5b7c48..509a8cc 100644 (file)
@@ -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<WireArray>   connectedWireArrays;
+       private final List<Point>               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<WireArray> connectedWireArraysModifiable = new ArrayList<>();
+               List<Point> 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