Completely changed the structure and switched to Eclipse Plugin.
[Mograsim.git] / net.mograsim.logic.ui / src / net / mograsim / logic / ui / model / wires / WireCrossPoint.java
index eb3028e..22868cc 100644 (file)
@@ -1,5 +1,7 @@
 package net.mograsim.logic.ui.model.wires;
 
+import java.util.Map;
+
 import net.haspamelodica.swt.helper.gcs.GeneralGC;
 import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle;
 import net.mograsim.logic.core.LogicObservable;
@@ -7,11 +9,16 @@ import net.mograsim.logic.core.LogicObserver;
 import net.mograsim.logic.core.types.BitVectorFormatter;
 import net.mograsim.logic.core.wires.Wire.ReadEnd;
 import net.mograsim.logic.ui.ColorHelper;
+import net.mograsim.logic.ui.model.ModelVisitor;
 import net.mograsim.logic.ui.model.ViewModelModifiable;
 import net.mograsim.logic.ui.model.components.GUIComponent;
+import net.mograsim.logic.ui.model.components.SimpleRectangularGUIGate;
 
 public class WireCrossPoint extends GUIComponent
 {
+       private static final int CIRCLE_RADIUS = 1;
+       private static final int CIRCLE_DIAM = CIRCLE_RADIUS * 2;
+
        private final Pin pin;
        private final int logicWidth;
 
@@ -24,16 +31,20 @@ public class WireCrossPoint extends GUIComponent
                logicObs = (i) -> requestRedraw();
 
                this.logicWidth = logicWidth;
-               setSize(0, 0);
-               addPin(this.pin = new Pin(this, logicWidth, 0, 0));
+               setSize(CIRCLE_DIAM, CIRCLE_DIAM);
+               addPin(this.pin = new Pin(this, "", logicWidth, CIRCLE_RADIUS, CIRCLE_RADIUS));
+       }
+
+       public void moveCenterTo(double x, double y)
+       {
+               moveTo(x - CIRCLE_RADIUS, y - CIRCLE_RADIUS);
        }
 
        @Override
        public void render(GeneralGC gc, Rectangle visibleRegion)
        {
-               Rectangle bounds = getBounds();
                ColorHelper.executeWithDifferentBackground(gc, BitVectorFormatter.formatAsColor(end),
-                               () -> gc.fillOval(bounds.x - 1, bounds.y - 1, 2, 2));
+                               () -> gc.fillOval(getPosX(), getPosY(), CIRCLE_DIAM, CIRCLE_DIAM));
        }
 
        public void setLogicModelBinding(ReadEnd end)
@@ -64,4 +75,18 @@ public class WireCrossPoint extends GUIComponent
        {
                return pin;
        }
+
+       @Override
+       public Map<String, Object> getInstantiationParameters()
+       {
+               Map<String, Object> m = super.getInstantiationParameters();
+               m.put(SimpleRectangularGUIGate.kLogicWidth, logicWidth);
+               return m;
+       }
+
+       @Override
+       public void accept(ModelVisitor mv)
+       {
+               mv.visit(this);
+       }
 }
\ No newline at end of file