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=43ec22b02fb9c866f2e7fbbb4a9c7d9f8b0329d5;hb=efb72d6a77c6e8d71ad86c311f2c60c66219a468;hp=7dceec8cca92f86abc236c14ff65f1b556d86d22;hpb=bb7fca85767fbcf2377586e81fd3dc77bcdcb662;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 7dceec8c..43ec22b0 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,15 +8,13 @@ import java.util.Map.Entry; import net.haspamelodica.swt.helper.gcs.GCConfig; import net.haspamelodica.swt.helper.gcs.GeneralGC; import net.haspamelodica.swt.helper.gcs.TranslatedGC; -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.ui.LogicUIRenderer; import net.mograsim.logic.ui.model.ViewModel; import net.mograsim.logic.ui.model.ViewModelModifiable; import net.mograsim.logic.ui.model.wires.Pin; -public class SubmodelComponent extends GUIComponent +public abstract class SubmodelComponent extends GUIComponent { protected final ViewModelModifiable submodelModifiable; public final ViewModel submodel; @@ -26,13 +24,12 @@ 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, String label) + public SubmodelComponent(ViewModelModifiable model) { super(model); this.submodelModifiable = new ViewModelModifiable(); @@ -43,7 +40,6 @@ public class SubmodelComponent extends GUIComponent this.supermodelPinsPerSubmodelPinUnmodifiable = Collections.unmodifiableMap(supermodelPinsPerSubmodelPin); this.submodelInterface = new SubmodelInterface(submodelModifiable); - this.label = label; this.submodelScale = 1; this.maxVisibleRegionFillRatioForAlpha0 = 0.4; this.minVisibleRegionFillRatioForAlpha1 = 0.8; @@ -62,6 +58,11 @@ public class SubmodelComponent extends GUIComponent requestRedraw();// needed if there is no submodel interface pin } + protected double getSubmodelScale() + { + return submodelScale; + } + /** * Returns the submodel pin. */ @@ -152,23 +153,22 @@ public class SubmodelComponent extends GUIComponent if (submodelAlpha != 0) { gc.setAlpha(submodelAlpha); - renderer.render(tgc, visibleRegion.translate(-posX, -posY, 1 / submodelScale)); + renderer.render(tgc, visibleRegion.translate(posX / submodelScale, posY / submodelScale, 1 / submodelScale)); } if (labelAlpha != 0) { gc.setAlpha(labelAlpha); - Font oldFont = gc.getFont(); - Font labelFont = new Font(oldFont.getName(), 6, oldFont.getStyle()); - gc.setFont(labelFont); - Point textExtent = gc.textExtent(label); - gc.drawText(label, posX + (getBounds().width - textExtent.x) / 2, posY + (getBounds().height - textExtent.y) / 2, true); - gc.setFont(oldFont); + renderSymbol(gc, visibleRegion); } conf.reset(gc); - // draw the "bounding box" after all other operations to make interface pins look better - gc.drawRectangle(getBounds()); + // draw the outline after all other operations to make interface pins look better + renderOutline(gc, visibleRegion); } + protected abstract void renderOutline(GeneralGC gc, Rectangle visibleRegion); + + protected abstract void renderSymbol(GeneralGC gc, Rectangle visibleRegion); + private static double map(double val, double valMin, double valMax, double mapMin, double mapMax) { return mapMin + (val - valMin) * (mapMax - mapMin) / (valMax - valMin);