From: Daniel Kirschten Date: Sat, 22 Jun 2019 07:48:03 +0000 (+0200) Subject: Stopped creation of unneccessary Rectangle instances X-Git-Url: https://mograsim.net/gitweb/?a=commitdiff_plain;h=c223a9de7b0ef783bcb4f7612da350583ca29abd;p=Mograsim.git Stopped creation of unneccessary Rectangle instances --- diff --git a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/GUIBitDisplay.java b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/GUIBitDisplay.java index 0ca249ee..88ee120c 100644 --- a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/GUIBitDisplay.java +++ b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/GUIBitDisplay.java @@ -34,9 +34,6 @@ public class GUIBitDisplay extends GUIComponent @Override public void render(GeneralGC gc, Rectangle visibleRegion) { - double posX = getBounds().x; - double posY = getBounds().y; - gc.drawRectangle(getBounds()); String label = bitDisplay == null ? BitVectorFormatter.formatAsString(null) : BitVectorFormatter.formatAsString(bitDisplay.getDisplayedValue()); @@ -44,7 +41,7 @@ public class GUIBitDisplay extends GUIComponent Font labelFont = new Font(oldFont.getName(), fontHeight, oldFont.getStyle()); gc.setFont(labelFont); Point textExtent = gc.textExtent(label); - gc.drawText(label, posX + (width - textExtent.x) / 2, posY + (height - textExtent.y) / 2, true); + gc.drawText(label, getPosX() + (width - textExtent.x) / 2, getPosY() + (height - textExtent.y) / 2, true); gc.setFont(oldFont); } diff --git a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/GUIComponent.java b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/GUIComponent.java index 22f1fbf8..edc3d7b7 100644 --- a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/GUIComponent.java +++ b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/GUIComponent.java @@ -69,6 +69,26 @@ public abstract class GUIComponent return new Rectangle(bounds.x, bounds.y, bounds.width, bounds.height); } + public double getPosX() + { + return bounds.x; + } + + public double getPosY() + { + return bounds.y; + } + + public double getWidth() + { + return bounds.width; + } + + public double getHeight() + { + return bounds.height; + } + /** * Called when this component is clicked. Absolute coordinates of the click are given. Returns true if this component consumed this * click. diff --git a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/GUIManualSwitch.java b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/GUIManualSwitch.java index 03423508..7044dd56 100644 --- a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/GUIManualSwitch.java +++ b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/GUIManualSwitch.java @@ -36,9 +36,6 @@ public class GUIManualSwitch extends GUIComponent @Override public void render(GeneralGC gc, Rectangle visibleRegion) { - double posX = getBounds().x; - double posY = getBounds().y; - // TODO maybe draw switch state too? gc.drawRectangle(getBounds()); String label = BitVectorFormatter.formatValueAsString(end); @@ -46,7 +43,7 @@ public class GUIManualSwitch extends GUIComponent Font labelFont = new Font(oldFont.getName(), fontHeight, oldFont.getStyle()); gc.setFont(labelFont); Point textExtent = gc.textExtent(label); - gc.drawText(label, posX + (width - textExtent.x) / 2, posY + (height - textExtent.y) / 2, true); + gc.drawText(label, getPosX() + (width - textExtent.x) / 2, getPosY() + (height - textExtent.y) / 2, true); gc.setFont(oldFont); } 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 96bf11e6..d263f6de 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 @@ -63,19 +63,16 @@ public class SimpleRectangularGUIGate extends GUIComponent @Override public void render(GeneralGC gc, Rectangle visibleRegion) { - double posX = getBounds().x; - double posY = getBounds().y; - double height = (getPins().size() - 1) * pinDistance; - gc.drawRectangle(posX, posY, rectWidth, height); + gc.drawRectangle(getPosX(), getPosY(), rectWidth, height); 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); + 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); + gc.drawOval(getPosX() + rectWidth, getPosY() + (height - invertedCircleDiam) / 2, invertedCircleDiam, invertedCircleDiam); } @Override diff --git a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/SimpleRectangularSubmodelComponent.java b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/SimpleRectangularSubmodelComponent.java index 0c0bf301..7a7bb9d5 100644 --- a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/SimpleRectangularSubmodelComponent.java +++ b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/SimpleRectangularSubmodelComponent.java @@ -93,25 +93,22 @@ public class SimpleRectangularSubmodelComponent extends SubmodelComponent @Override protected void renderSymbol(GeneralGC gc, Rectangle visibleRegion) { - double posX = getBounds().x; - double posY = getBounds().y; - Font oldFont = gc.getFont(); gc.setFont(new Font(oldFont.getName(), labelFontHeight, oldFont.getStyle())); Point textExtent = gc.textExtent(label); - gc.drawText(label, posX + (getBounds().width - textExtent.x) / 2, posY + (getBounds().height - textExtent.y) / 2, true); + gc.drawText(label, getPosX() + (getWidth() - textExtent.x) / 2, getPosY() + (getHeight() - textExtent.y) / 2, true); gc.setFont(new Font(oldFont.getName(), pinNameFontHeight, oldFont.getStyle())); for (int i = 0; i < inputPinNames.size(); i++) { String pinName = inputPinNames.get(i); textExtent = gc.textExtent(pinName); - gc.drawText(pinName, posX + pinNameMargin, posY + i * pinDistance + (pinDistance - textExtent.y) / 2, true); + gc.drawText(pinName, getPosX() + pinNameMargin, getPosY() + i * pinDistance + (pinDistance - textExtent.y) / 2, true); } for (int i = 0; i < outputPinNames.size(); i++) { String pinName = outputPinNames.get(i); textExtent = gc.textExtent(pinName); - gc.drawText(pinName, posX + width - textExtent.x - pinNameMargin, posY + i * pinDistance + (pinDistance - textExtent.y) / 2, + gc.drawText(pinName, getPosX() + width - textExtent.x - pinNameMargin, getPosY() + i * pinDistance + (pinDistance - textExtent.y) / 2, true); } gc.setFont(oldFont); 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 be9b8548..8febda89 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 @@ -165,13 +165,10 @@ public abstract class SubmodelComponent extends GUIComponent @Override public void render(GeneralGC gc, Rectangle visibleRegion) { - double posX = getBounds().x; - double posY = getBounds().y; - GCConfig conf = new GCConfig(gc); - TranslatedGC tgc = new TranslatedGC(gc, posX, posY, submodelScale, true); + TranslatedGC tgc = new TranslatedGC(gc, getPosX(), getPosY(), submodelScale, true); conf.reset(tgc); - double visibleRegionFillRatio = Math.max(getBounds().width / visibleRegion.width, getBounds().height / visibleRegion.height); + double visibleRegionFillRatio = Math.max(getWidth() / visibleRegion.width, getHeight() / visibleRegion.height); 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. @@ -181,7 +178,7 @@ public abstract class SubmodelComponent extends GUIComponent if (submodelAlpha != 0) { gc.setAlpha(submodelAlpha); - renderer.render(tgc, visibleRegion.translate(posX / submodelScale, posY / submodelScale, 1 / submodelScale)); + renderer.render(tgc, visibleRegion.translate(getPosX() / submodelScale, getPosY() / submodelScale, 1 / submodelScale)); } if (labelAlpha != 0) { @@ -205,8 +202,8 @@ public abstract class SubmodelComponent extends GUIComponent @Override public boolean clicked(double x, double y) { - double scaledX = (x - getBounds().x) / submodelScale; - double scaledY = (y - getBounds().y) / submodelScale; + double scaledX = (x - getPosX()) / submodelScale; + double scaledY = (y - getPosY()) / submodelScale; for (GUIComponent component : submodel.getComponents()) if (component.getBounds().contains(scaledX, scaledY) && component.clicked(scaledX, scaledY)) return true; @@ -222,9 +219,8 @@ public abstract class SubmodelComponent extends GUIComponent params.type = SubmodelComponent.class.getSimpleName(); params.composition = calculateCompositionParams(); - Rectangle bounds = getBounds(); - params.width = bounds.width; - params.height = bounds.height; + params.width = getWidth(); + params.height = getHeight(); InterfacePinParams[] iPins = new InterfacePinParams[getPins().size()]; int i = 0; @@ -257,8 +253,7 @@ public abstract class SubmodelComponent extends GUIComponent InnerComponentParams inner = new InnerComponentParams(); comps[i] = inner; inner.params = component.getInstantiationParameters(); - Rectangle bounds = component.getBounds(); - inner.pos = new Point(bounds.x, bounds.y); + inner.pos = new Point(getPosX(), getPosY()); inner.type = component.getIdentifier(); i++; } diff --git a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/wires/Pin.java b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/wires/Pin.java index 9be08003..a6c40dd3 100644 --- a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/wires/Pin.java +++ b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/wires/Pin.java @@ -5,7 +5,6 @@ import java.util.List; import java.util.function.Consumer; import net.haspamelodica.swt.helper.swtobjectwrappers.Point; -import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle; import net.mograsim.logic.ui.model.components.GUIComponent; public class Pin @@ -51,8 +50,7 @@ public class Pin public Point getPos() { - Rectangle componentBounds = component.getBounds(); - return new Point(relX + componentBounds.x, relY + componentBounds.y); + return new Point(relX + component.getPosX(), relY + component.getPosY()); } protected void setRelPos(double relX, double relY) diff --git a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/wires/WireCrossPoint.java b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/wires/WireCrossPoint.java index 1124233b..2235376f 100644 --- a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/wires/WireCrossPoint.java +++ b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/wires/WireCrossPoint.java @@ -42,9 +42,8 @@ public class WireCrossPoint extends GUIComponent @Override public void render(GeneralGC gc, Rectangle visibleRegion) { - Rectangle bounds = getBounds(); ColorHelper.executeWithDifferentBackground(gc, BitVectorFormatter.formatAsColor(end), - () -> gc.fillOval(bounds.x, bounds.y, CIRCLE_DIAM, CIRCLE_DIAM)); + () -> gc.fillOval(getPosX(), getPosY(), CIRCLE_DIAM, CIRCLE_DIAM)); } public void setLogicModelBinding(ReadEnd end)