X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=net.mograsim.logic.ui%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fui%2Fmodel%2Fcomponents%2FSimpleRectangularGUIGate.java;h=0dd4c40318c73c6ffd492dc104e23169f4833237;hb=64031e27d6b607e5475d081f93581960ef5a82b4;hp=9058d2e0204470ea2ff7f9c905685a7c30bf9281;hpb=19ee1a7fdb06a1df65cd7df78fed935124496707;p=Mograsim.git diff --git a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/SimpleRectangularGUIGate.java b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/SimpleRectangularGUIGate.java index 9058d2e0..0dd4c403 100644 --- a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/SimpleRectangularGUIGate.java +++ b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/SimpleRectangularGUIGate.java @@ -2,6 +2,9 @@ package net.mograsim.logic.ui.model.components; import java.util.ArrayList; import java.util.List; +import java.util.Map; + +import org.eclipse.swt.graphics.Color; import net.haspamelodica.swt.helper.gcs.GeneralGC; import net.haspamelodica.swt.helper.swtobjectwrappers.Font; @@ -10,6 +13,7 @@ import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle; import net.mograsim.logic.ui.model.ViewModelModifiable; import net.mograsim.logic.ui.model.wires.MovablePin; import net.mograsim.logic.ui.model.wires.Pin; +import net.mograsim.preferences.Preferences; public class SimpleRectangularGUIGate extends GUIComponent { @@ -26,6 +30,8 @@ public class SimpleRectangularGUIGate extends GUIComponent private MovablePin outputPin; private final List inputPins; + public static final String kLogicWidth = "logicWidth"; + protected SimpleRectangularGUIGate(ViewModelModifiable model, int logicWidth, String label, boolean isInverted) { super(model); @@ -60,18 +66,29 @@ public class SimpleRectangularGUIGate extends GUIComponent @Override public void render(GeneralGC gc, Rectangle visibleRegion) { - double posX = getBounds().x; - double posY = getBounds().y; - + Color foreground = Preferences.current().getColor("net.mograsim.logic.ui.color.foreground"); + if (foreground != null) + gc.setForeground(foreground); double height = (getPins().size() - 1) * pinDistance; - gc.drawRectangle(posX, posY, rectWidth, height); + gc.drawRectangle(getPosX(), getPosY(), rectWidth, height); + if (isInverted) + gc.drawOval(getPosX() + rectWidth, getPosY() + (height - invertedCircleDiam) / 2, invertedCircleDiam, invertedCircleDiam); Font oldFont = gc.getFont(); Font labelFont = new Font(oldFont.getName(), fontHeight, oldFont.getStyle()); gc.setFont(labelFont); Point textExtent = gc.textExtent(label); - gc.drawText(label, posX + (rectWidth - textExtent.x) / 2, posY + (height - textExtent.y) / 2, true); + Color textColor = Preferences.current().getColor("net.mograsim.logic.ui.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); - if (isInverted) - gc.drawOval(posX + rectWidth, posY + (height - invertedCircleDiam) / 2, invertedCircleDiam, invertedCircleDiam); + } + + @Override + public Map getInstantiationParameters() + { + Map m = super.getInstantiationParameters(); + m.put(kLogicWidth, logicWidth); + return m; } } \ No newline at end of file