1 package net.mograsim.logic.ui.model.wires;
3 import net.haspamelodica.swt.helper.gcs.GeneralGC;
4 import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle;
5 import net.mograsim.logic.core.LogicObservable;
6 import net.mograsim.logic.core.LogicObserver;
7 import net.mograsim.logic.core.types.BitVectorFormatter;
8 import net.mograsim.logic.core.wires.Wire.ReadEnd;
9 import net.mograsim.logic.ui.ColorHelper;
10 import net.mograsim.logic.ui.model.ViewModelModifiable;
11 import net.mograsim.logic.ui.model.components.GUIComponent;
13 public class WireCrossPoint extends GUIComponent
15 private static final int CIRCLE_RADIUS = 1;
16 private static final int CIRCLE_DIAM = CIRCLE_RADIUS * 2;
18 private final Pin pin;
19 private final int logicWidth;
21 private final LogicObserver logicObs;
24 public WireCrossPoint(ViewModelModifiable model, int logicWidth)
27 logicObs = (i) -> requestRedraw();
29 this.logicWidth = logicWidth;
30 setSize(CIRCLE_DIAM, CIRCLE_DIAM);
31 addPin(this.pin = new Pin(this, logicWidth, CIRCLE_RADIUS, CIRCLE_RADIUS));
34 public void moveCenterTo(double x, double y)
36 moveTo(x - CIRCLE_RADIUS, y - CIRCLE_RADIUS);
40 public void render(GeneralGC gc, Rectangle visibleRegion)
42 Rectangle bounds = getBounds();
43 ColorHelper.executeWithDifferentBackground(gc, BitVectorFormatter.formatAsColor(end),
44 () -> gc.fillOval(bounds.x, bounds.y, CIRCLE_DIAM, CIRCLE_DIAM));
47 public void setLogicModelBinding(ReadEnd end)
49 deregisterLogicObs(this.end);
51 registerLogicObs(end);
54 private void registerLogicObs(LogicObservable observable)
56 if (observable != null)
57 observable.registerObserver(logicObs);
60 private void deregisterLogicObs(LogicObservable observable)
62 if (observable != null)
63 observable.deregisterObserver(logicObs);
66 public int getLogicWidth()