X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=plugins%2Fnet.mograsim.logic.model%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fmodel%2Fmodel%2Fcomponents%2Fatomic%2FModelBitDisplay.java;h=68e8d45673691207848d1211810f7d7a9730fdcd;hb=13577856cd85c46f2cd4ad956332697bc820f425;hp=5be3e22de69b9c7aae2f6fd6265c27b8c19ea112;hpb=ce59b30bcd1139d2cdd497e2903f239a2d0084dd;p=Mograsim.git diff --git a/plugins/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/ModelBitDisplay.java b/plugins/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/ModelBitDisplay.java index 5be3e22d..68e8d456 100644 --- a/plugins/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/ModelBitDisplay.java +++ b/plugins/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/ModelBitDisplay.java @@ -4,11 +4,9 @@ import org.eclipse.swt.graphics.Color; import net.haspamelodica.swt.helper.gcs.GeneralGC; import net.haspamelodica.swt.helper.swtobjectwrappers.Font; -import net.haspamelodica.swt.helper.swtobjectwrappers.Point; import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle; import net.mograsim.logic.core.LogicObserver; import net.mograsim.logic.core.components.CoreBitDisplay; -import net.mograsim.logic.core.types.BitVector; import net.mograsim.logic.core.types.BitVectorFormatter; import net.mograsim.logic.model.model.LogicModelModifiable; import net.mograsim.logic.model.model.components.ModelComponent; @@ -18,13 +16,15 @@ import net.mograsim.logic.model.modeladapter.LogicCoreAdapter; import net.mograsim.logic.model.modeladapter.componentadapters.BitDisplayAdapter; import net.mograsim.logic.model.serializing.IdentifyParams; import net.mograsim.logic.model.serializing.IndirectModelComponentCreator; +import net.mograsim.logic.model.util.TextRenderingHelper; import net.mograsim.preferences.Preferences; public class ModelBitDisplay extends ModelComponent { private static final double width = 20; - private static final double height = 15; + private static final double height = 10; private static final double fontHeight = 5; + private static final double textMargin = 0.5; public final int logicWidth; private final Pin inputPin; @@ -56,23 +56,14 @@ public class ModelBitDisplay extends ModelComponent if (foreground != null) gc.setForeground(foreground); gc.drawRectangle(getBounds()); - String label; - if (bitDisplay == null) - label = BitVectorFormatter.formatAsString(null); - else - { - BitVector toDisplay = bitDisplay.getDisplayedValue(); - label = toDisplay != null && toDisplay.isHighImpedance() ? "-" - : BitVectorFormatter.formatAsString(bitDisplay.getDisplayedValue()); - } + String label = BitVectorFormatter.formatAsString(bitDisplay == null ? null : bitDisplay.getDisplayedValue(), true); 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() + (width - textExtent.x) / 2, getPosY() + (height - textExtent.y) / 2, true); + TextRenderingHelper.drawTextFitting(gc, label, getBounds(), textMargin, true); gc.setFont(oldFont); }