--- /dev/null
+package net.mograsim.logic.model.model.components.atomic;\r
+\r
+import org.eclipse.swt.graphics.Color;\r
+\r
+import com.google.gson.JsonElement;\r
+import com.google.gson.JsonObject;\r
+import com.google.gson.JsonParseException;\r
+import com.google.gson.JsonPrimitive;\r
+import com.google.gson.JsonSyntaxException;\r
+\r
+import net.haspamelodica.swt.helper.gcs.GeneralGC;\r
+import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle;\r
+import net.mograsim.logic.model.model.ViewModelModifiable;\r
+import net.mograsim.logic.model.model.components.GUIComponent;\r
+import net.mograsim.logic.model.model.wires.Pin;\r
+import net.mograsim.logic.model.modeladapter.ViewLogicModelAdapter;\r
+import net.mograsim.logic.model.modeladapter.componentadapters.TriStateBufferAdapter;\r
+import net.mograsim.logic.model.serializing.IdentifierGetter;\r
+import net.mograsim.logic.model.serializing.IndirectGUIComponentCreator;\r
+import net.mograsim.preferences.Preferences;\r
+\r
+public class GUITriStateBuffer extends GUIComponent\r
+{\r
+\r
+ private static final double width = 20;\r
+ private static final double height = 20;\r
+ private Pin input;\r
+ private Pin output;\r
+ private Pin enable;\r
+ private Orientation orientation;\r
+ private double[] path;\r
+\r
+ public GUITriStateBuffer(ViewModelModifiable model, int logicWidth, Orientation orientation)\r
+ {\r
+ this(model, logicWidth, orientation, null);\r
+ }\r
+\r
+ public GUITriStateBuffer(ViewModelModifiable model, int logicWidth, Orientation orientation, String name)\r
+ {\r
+ super(model, name);\r
+ this.orientation = orientation;\r
+\r
+ double wHalf = width / 2;\r
+ double hHalf = height / 2;\r
+ double wQuar = width / 4;\r
+ double hQuar = height / 4;\r
+ int ordi = orientation.ordinal();\r
+ int isVerti = (ordi % 4) / 2;\r
+ int isHori = 1 ^ isVerti;\r
+ int isAlt = ordi / 4;\r
+ int isInv = ordi % 2;\r
+ int isStd = 1 ^ isInv;\r
+\r
+ this.input = new Pin(this, "IN", logicWidth, width * isInv * isHori + wHalf * isVerti, height * isVerti * isStd + hHalf * isHori);\r
+ this.output = new Pin(this, "OUT", logicWidth, width * isStd * isHori + wHalf * isVerti, height * isVerti * isInv + hHalf * isHori);\r
+ this.enable = new Pin(this, "EN", 1, wQuar * isVerti + wHalf * (isAlt | isHori), hQuar * isHori + hHalf * (isAlt | isVerti));\r
+ this.path = new double[] { width * (isStd ^ isHori), height * (isStd ^ isHori), width * isInv, height * isStd,\r
+ width * isStd * isHori + wHalf * isVerti, height * isVerti * isInv + hHalf * isHori };\r
+\r
+ setSize(width, height);\r
+ addPin(input);\r
+ addPin(output);\r
+ addPin(enable);\r
+ }\r
+\r
+ @Override\r
+ public void render(GeneralGC gc, Rectangle visibleRegion)\r
+ {\r
+ Color foreground = Preferences.current().getColor("net.mograsim.logic.model.color.foreground");\r
+ if (foreground != null)\r
+ gc.setForeground(foreground);\r
+ double x = getPosX();\r
+ double y = getPosY();\r
+ gc.drawPolygon(new double[] { x + path[0], y + path[1], x + path[2], y + path[3], x + path[4], y + path[5] });\r
+// Font oldFont = gc.getFont();\r
+// Font labelFont = new Font(oldFont.getName(), fontHeight, oldFont.getStyle());\r
+// gc.setFont(labelFont);\r
+// Point textExtent = gc.textExtent(label);\r
+// Color textColor = Preferences.current().getColor("net.mograsim.logic.model.color.text");\r
+// if (textColor != null)\r
+// gc.setForeground(textColor);\r
+// gc.drawText(label, getPosX() + (rectWidth - textExtent.x) / 2, getPosY() + (height - textExtent.y) / 2, true);\r
+// gc.setFont(oldFont);\r
+ }\r
+\r
+ @Override\r
+ public JsonElement getParamsForSerializing(IdentifierGetter idGetter)\r
+ {\r
+ JsonObject jo = new JsonObject();\r
+ jo.addProperty("logicWidth", input.logicWidth);\r
+ jo.addProperty("orientation", orientation.name());\r
+ return jo;\r
+ }\r
+\r
+ static\r
+ {\r
+ ViewLogicModelAdapter.addComponentAdapter(new TriStateBufferAdapter());\r
+ IndirectGUIComponentCreator.setComponentSupplier(GUITriStateBuffer.class.getName(), (m, p, n) ->\r
+ {\r
+ if (!p.isJsonObject())\r
+ throw new JsonSyntaxException("TriStateBuffer Params are not a JsonObject");\r
+ JsonObject jo = p.getAsJsonObject();\r
+ return new GUITriStateBuffer(m, jo.getAsJsonPrimitive("logicWidth").getAsInt(),\r
+ Orientation.valueOf(jo.getAsJsonPrimitive("orientation").getAsString()), n);\r
+ });\r
+ }\r
+\r
+ public enum Orientation\r
+ {\r
+ RIGHT, LEFT, UP, DOWN, RIGHT_ALT, LEFT_ALT, UP_ALT, DOWN_ALT;\r
+ }\r
+}\r
--- /dev/null
+package net.mograsim.logic.model.modeladapter.componentadapters;\r
+\r
+import java.util.Map;\r
+\r
+import net.mograsim.logic.core.components.TriStateBuffer;\r
+import net.mograsim.logic.core.timeline.Timeline;\r
+import net.mograsim.logic.core.wires.Wire;\r
+import net.mograsim.logic.core.wires.Wire.ReadEnd;\r
+import net.mograsim.logic.core.wires.Wire.ReadWriteEnd;\r
+import net.mograsim.logic.model.model.components.atomic.GUITriStateBuffer;\r
+import net.mograsim.logic.model.model.wires.Pin;\r
+import net.mograsim.logic.model.modeladapter.LogicModelParameters;\r
+\r
+public class TriStateBufferAdapter implements ComponentAdapter<GUITriStateBuffer>\r
+{\r
+\r
+ @Override\r
+ public Class<GUITriStateBuffer> getSupportedClass()\r
+ {\r
+ return GUITriStateBuffer.class;\r
+ }\r
+\r
+ @SuppressWarnings("unused")\r
+ @Override\r
+ public void createAndLinkComponent(Timeline timeline, LogicModelParameters params, GUITriStateBuffer guiTsb,\r
+ Map<Pin, Wire> logicWiresPerPin)\r
+ {\r
+ ReadEnd in = logicWiresPerPin.get(guiTsb.getPin("IN")).createReadOnlyEnd();\r
+ ReadEnd enable = logicWiresPerPin.get(guiTsb.getPin("EN")).createReadOnlyEnd();\r
+ ReadWriteEnd out = logicWiresPerPin.get(guiTsb.getPin("OUT")).createReadWriteEnd();\r
+ new TriStateBuffer(timeline, params.gateProcessTime, in, out, enable);\r
+ }\r
+\r
+}\r