X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=net.mograsim.logic.ui%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fui%2Fmodel%2Fcomponents%2FSubmodelComponent.java;h=4b67650b9e6c037308801537b9eb752a5668c69f;hb=4c590b82bc039bec5669e8cbb40703057274ab8c;hp=eae636a9f9d4ca2e85b38c09cb209c013be57140;hpb=f4ecc0a914889474581caf5f4da0dad7a410ae3c;p=Mograsim.git diff --git a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/SubmodelComponent.java b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/SubmodelComponent.java index eae636a9..4b67650b 100644 --- a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/SubmodelComponent.java +++ b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/SubmodelComponent.java @@ -8,6 +8,7 @@ import java.util.Map.Entry; import net.haspamelodica.swt.helper.gcs.GCDefaultConfig; import net.haspamelodica.swt.helper.gcs.GeneralGC; import net.haspamelodica.swt.helper.gcs.TranslatedGC; +import net.haspamelodica.swt.helper.swtobjectwrappers.Point; import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle; import net.mograsim.logic.ui.LogicUIRenderer; import net.mograsim.logic.ui.model.ViewModel; @@ -24,12 +25,13 @@ public class SubmodelComponent extends GUIComponent private final Map supermodelPinsPerSubmodelPinUnmodifiable; private final SubmodelInterface submodelInterface; + private final String label; private double submodelScale; private double maxVisibleRegionFillRatioForAlpha0; private double minVisibleRegionFillRatioForAlpha1; private final LogicUIRenderer renderer; - public SubmodelComponent(ViewModelModifiable model) + public SubmodelComponent(ViewModelModifiable model, String label) { super(model); this.submodelModifiable = new ViewModelModifiable(); @@ -40,6 +42,7 @@ public class SubmodelComponent extends GUIComponent this.supermodelPinsPerSubmodelPinUnmodifiable = Collections.unmodifiableMap(supermodelPinsPerSubmodelPin); this.submodelInterface = new SubmodelInterface(submodelModifiable); + this.label = label; this.submodelScale = 1; this.maxVisibleRegionFillRatioForAlpha0 = 0.1; this.minVisibleRegionFillRatioForAlpha1 = 0.8; @@ -142,8 +145,12 @@ public class SubmodelComponent extends GUIComponent double alphaFactor = map(visibleRegionFillRatio, maxVisibleRegionFillRatioForAlpha0, minVisibleRegionFillRatioForAlpha1, 0, 1); alphaFactor = Math.max(0, Math.min(1, alphaFactor)); // we need to take the old alpha into account to support nested submodules better. - gc.setAlpha(Math.max(0, Math.min(255, (int) (gc.getAlpha() * alphaFactor)))); + int oldAlpha = gc.getAlpha(); + gc.setAlpha(Math.max(0, Math.min(255, (int) (oldAlpha * alphaFactor)))); renderer.render(tgc, visibleRegion.translate(posX, posY, submodelScale)); + gc.setAlpha(Math.max(0, Math.min(255, (int) (oldAlpha * (1 - alphaFactor))))); + Point textExtent = gc.textExtent(label); + gc.drawText(label, posX + (getBounds().width - textExtent.x) / 2, posY + (getBounds().height - textExtent.y) / 2, true); conf.reset(gc); // draw the "bounding box" after all other operations to make interface pins look better gc.drawRectangle(getBounds());