1 package era.mi.gui.model.components;
3 import era.mi.gui.model.ViewModel;
4 import era.mi.gui.model.wires.Pin;
5 import era.mi.logic.components.ManualSwitch;
6 import era.mi.logic.types.BitVectorFormatter;
7 import era.mi.logic.wires.Wire.ReadEnd;
8 import net.haspamelodica.swt.helper.gcs.GeneralGC;
9 import net.haspamelodica.swt.helper.swtobjectwrappers.Font;
10 import net.haspamelodica.swt.helper.swtobjectwrappers.Point;
11 import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle;
13 public class GUIManualSwitch extends GUIComponent
15 private static final double width = 20;
16 private static final double height = 15;
17 private static final double fontHeight = 5;
19 private final Pin outputPin;
21 private ManualSwitch logicSwitch;
24 public GUIManualSwitch(ViewModel model)
27 setSize(width, height);
28 addPin(this.outputPin = new Pin(this, 1, width, height / 2));
32 public void render(GeneralGC gc, Rectangle visibleRegion)
34 double posX = getBounds().x;
35 double posY = getBounds().y;
37 gc.drawRectangle(posX, posY, width, height);
38 String label = BitVectorFormatter.formatValueAsString(end);
39 Font oldFont = gc.getFont();
40 Font labelFont = new Font(oldFont.getName(), fontHeight, oldFont.getStyle());
41 gc.setFont(labelFont);
42 Point textExtent = gc.textExtent(label);
43 gc.drawText(label, posX + (width - textExtent.x) / 2, posY + (height - textExtent.y) / 2, true);
47 public void setLogicModelBinding(ManualSwitch logicSwitch, ReadEnd end)
49 this.logicSwitch = logicSwitch;
51 // TODO when ManualSwitch supports it, add listeners
52 end.addObserver((i, o) -> callComponentLookChangedListeners());
56 public boolean clicked(double x, double y)
58 if (logicSwitch != null)
63 public Pin getOutputPin()