X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=net.mograsim.logic.model%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fmodel%2Fmodel%2Fcomponents%2Fatomic%2FGUITriStateBuffer.java;h=7f04102c75c77e4ae1462bd37e093aa7bfb8b167;hb=0a04a4ed66ecebd4254541c4977599f6052c115a;hp=bfc49d84f0a340dff91ccbb3ae766036d014417d;hpb=46f282c4df36a8d734518d6517e05f44a32372bf;p=Mograsim.git diff --git a/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/GUITriStateBuffer.java b/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/GUITriStateBuffer.java index bfc49d84..7f04102c 100644 --- a/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/GUITriStateBuffer.java +++ b/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/GUITriStateBuffer.java @@ -2,19 +2,21 @@ package net.mograsim.logic.model.model.components.atomic; import org.eclipse.swt.graphics.Color; -import com.google.gson.Gson; -import com.google.gson.JsonElement; import com.google.gson.JsonSyntaxException; import net.haspamelodica.swt.helper.gcs.GeneralGC; import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle; import net.mograsim.logic.model.model.ViewModelModifiable; import net.mograsim.logic.model.model.components.GUIComponent; +import net.mograsim.logic.model.model.components.Orientation; +import net.mograsim.logic.model.model.components.OrientationCalculator; import net.mograsim.logic.model.model.wires.Pin; +import net.mograsim.logic.model.model.wires.PinUsage; import net.mograsim.logic.model.modeladapter.ViewLogicModelAdapter; import net.mograsim.logic.model.modeladapter.componentadapters.TriStateBufferAdapter; -import net.mograsim.logic.model.serializing.IdentifierGetter; +import net.mograsim.logic.model.serializing.IdentifyParams; import net.mograsim.logic.model.serializing.IndirectGUIComponentCreator; +import net.mograsim.logic.model.util.JsonHandler; import net.mograsim.preferences.Preferences; public class GUITriStateBuffer extends GUIComponent @@ -28,6 +30,7 @@ public class GUITriStateBuffer extends GUIComponent private double[] path; private GUITriStateBufferParams params; + private OrientationCalculator oc; public GUITriStateBuffer(ViewModelModifiable model, GUITriStateBufferParams params) { @@ -39,31 +42,39 @@ public class GUITriStateBuffer extends GUIComponent super(model, name); this.params = params; + oc = new OrientationCalculator(params.orientation, width, height); + double wHalf = width / 2; double hHalf = height / 2; - double wQuar = width / 4; double hQuar = height / 4; - int ordi = params.orientation.ordinal(); - int isVerti = (ordi % 4) / 2; - int isHori = 1 ^ isVerti; - int isAlt = ordi / 4; - int isInv = ordi % 2; - int isStd = 1 ^ isInv; - - this.input = new Pin(this, "IN", params.logicWidth, width * isInv * isHori + wHalf * isVerti, - height * isVerti * isStd + hHalf * isHori); - this.output = new Pin(this, "OUT", params.logicWidth, width * isStd * isHori + wHalf * isVerti, - height * isVerti * isInv + hHalf * isHori); - this.enable = new Pin(this, "EN", 1, wQuar * isVerti + wHalf * (isAlt | isHori), hQuar * isHori + hHalf * (isAlt | isVerti)); - this.path = new double[] { width * (isStd ^ isHori), height * (isStd ^ isHori), width * isInv, height * isStd, - width * isStd * isHori + wHalf * isVerti, height * isVerti * isInv + hHalf * isHori }; - - setSize(width, height); + + this.input = new Pin(this, "IN", params.logicWidth, PinUsage.INPUT, oc.newX(0, hHalf), oc.newY(0, hHalf)); + this.output = new Pin(this, "OUT", params.logicWidth, PinUsage.OUTPUT, oc.newX(width, hHalf), oc.newY(width, hHalf)); + this.enable = new Pin(this, "EN", 1, PinUsage.INPUT, oc.newX(wHalf, hQuar), oc.newY(wHalf, hQuar)); + this.path = new double[] { oc.newX(0, 0), oc.newY(0, 0), oc.newX(width, hHalf), oc.newY(width, hHalf), oc.newX(0, height), + oc.newY(0, height) }; + + setSize(oc.width(), oc.height()); addPin(input); addPin(output); addPin(enable); } + public final Pin getInputPin() + { + return input; + } + + public final Pin getOutputPin() + { + return output; + } + + public final Pin getEnablePin() + { + return enable; + } + @Override public void render(GeneralGC gc, Rectangle visibleRegion) { @@ -73,21 +84,18 @@ public class GUITriStateBuffer extends GUIComponent double x = getPosX(); double y = getPosY(); gc.drawPolygon(new double[] { x + path[0], y + path[1], x + path[2], y + path[3], x + path[4], y + path[5] }); -// Font oldFont = gc.getFont(); -// Font labelFont = new Font(oldFont.getName(), fontHeight, oldFont.getStyle()); -// gc.setFont(labelFont); -// Point textExtent = gc.textExtent(label); -// Color textColor = Preferences.current().getColor("net.mograsim.logic.model.color.text"); -// if (textColor != null) -// gc.setForeground(textColor); -// gc.drawText(label, getPosX() + (rectWidth - textExtent.x) / 2, getPosY() + (height - textExtent.y) / 2, true); -// gc.setFont(oldFont); } @Override - public JsonElement getParamsForSerializing(IdentifierGetter idGetter) + public String getIDForSerializing(IdentifyParams idParams) { - return new Gson().toJsonTree(params); + return "GUITriStateBuffer"; + } + + @Override + public GUITriStateBufferParams getParamsForSerializing(IdentifyParams idParams) + { + return params; } static @@ -95,21 +103,22 @@ public class GUITriStateBuffer extends GUIComponent ViewLogicModelAdapter.addComponentAdapter(new TriStateBufferAdapter()); IndirectGUIComponentCreator.setComponentSupplier(GUITriStateBuffer.class.getName(), (m, p, n) -> { - GUITriStateBufferParams params = new Gson().fromJson(p, GUITriStateBufferParams.class); + GUITriStateBufferParams params = JsonHandler.fromJsonTree(p, GUITriStateBufferParams.class); if (params == null) throw new JsonSyntaxException("Invalid!!!"); return new GUITriStateBuffer(m, params, n); }); } - private static class GUITriStateBufferParams + public static class GUITriStateBufferParams { int logicWidth; Orientation orientation; - } - public enum Orientation - { - RIGHT, LEFT, UP, DOWN, RIGHT_ALT, LEFT_ALT, UP_ALT, DOWN_ALT; + public GUITriStateBufferParams(int logicWidth, Orientation orientation) + { + this.logicWidth = logicWidth; + this.orientation = orientation; + } } }