1 package net.mograsim.logic.model.model.components.atomic;
\r
3 import com.google.gson.JsonElement;
\r
4 import com.google.gson.JsonPrimitive;
\r
6 import net.haspamelodica.swt.helper.gcs.GeneralGC;
\r
7 import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle;
\r
8 import net.mograsim.logic.core.types.BitVectorFormatter;
\r
9 import net.mograsim.logic.core.wires.Wire.ReadEnd;
\r
10 import net.mograsim.logic.model.model.ViewModelModifiable;
\r
11 import net.mograsim.logic.model.model.components.GUIComponent;
\r
12 import net.mograsim.logic.model.model.wires.Pin;
\r
13 import net.mograsim.logic.model.modeladapter.ViewLogicModelAdapter;
\r
14 import net.mograsim.logic.model.modeladapter.componentadapters.SplitterAdapter;
\r
15 import net.mograsim.logic.model.serializing.IdentifierGetter;
\r
16 import net.mograsim.logic.model.serializing.IndirectGUIComponentCreator;
\r
17 import net.mograsim.preferences.ColorDefinition;
\r
18 import net.mograsim.preferences.ColorManager;
\r
19 import net.mograsim.preferences.Preferences;
\r
21 public class GUISplitter extends GUIComponent
\r
23 private static final double width = 10;
\r
24 private static final double heightPerPin = 10;
\r
26 public final int logicWidth;
\r
28 private ReadEnd inputEnd;
\r
29 private final ReadEnd[] outputEnds;
\r
31 public GUISplitter(ViewModelModifiable model, int logicWidth, String name)
\r
34 this.logicWidth = logicWidth;
\r
35 setSize(width, logicWidth * heightPerPin);
\r
36 addPin(new Pin(this, "I", logicWidth, 0, logicWidth * heightPerPin / 2));
\r
37 double outputHeight = 0;
\r
38 for (int i = 0; i < logicWidth; i++, outputHeight += 10)
\r
39 addPin(new Pin(this, "O" + i, 1, width, outputHeight));
\r
40 outputEnds = new ReadEnd[logicWidth];
\r
44 public void render(GeneralGC gc, Rectangle visibleRegion)
\r
46 double posX = getPosX();
\r
47 double posY = getPosY();
\r
49 ColorDefinition c = BitVectorFormatter.formatAsColor(inputEnd);
\r
51 gc.setForeground(ColorManager.current().toColor(c));
\r
52 gc.drawLine(posX, posY + heightPerPin * logicWidth / 2, posX + width / 2, posY + heightPerPin * logicWidth / 2);
\r
53 gc.setForeground(Preferences.current().getColor("net.mograsim.logic.model.color.foreground"));
\r
54 gc.drawLine(posX + width / 2, posY, posX + width / 2, posY + heightPerPin * (logicWidth - 1));
\r
55 double outputHeight = posY;
\r
56 for (int i = 0; i < logicWidth; i++, outputHeight += 10)
\r
58 c = BitVectorFormatter.formatAsColor(outputEnds[i]);
\r
60 gc.setForeground(ColorManager.current().toColor(c));
\r
61 gc.drawLine(posX + width / 2, outputHeight, posX + width, outputHeight);
\r
66 public JsonElement getParamsForSerializing(IdentifierGetter idGetter)
\r
68 return new JsonPrimitive(logicWidth);
\r
71 public void setLogicModelBinding(ReadEnd inputEnd, ReadEnd[] outputEnds)
\r
73 this.inputEnd = inputEnd;
\r
74 System.arraycopy(outputEnds, 0, this.outputEnds, 0, logicWidth);
\r
79 ViewLogicModelAdapter.addComponentAdapter(new SplitterAdapter());
\r
80 IndirectGUIComponentCreator.setComponentSupplier(GUISplitter.class.getCanonicalName(),
\r
81 (m, p, n) -> new GUISplitter(m, p.getAsInt(), n));
\r