@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());
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);
}
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.
@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);
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);
}
@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
@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);
@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.
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)
{
@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;
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;
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++;
}
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
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)
@Override\r
public void render(GeneralGC gc, Rectangle visibleRegion)\r
{\r
- Rectangle bounds = getBounds();\r
ColorHelper.executeWithDifferentBackground(gc, BitVectorFormatter.formatAsColor(end),\r
- () -> gc.fillOval(bounds.x, bounds.y, CIRCLE_DIAM, CIRCLE_DIAM));\r
+ () -> gc.fillOval(getPosX(), getPosY(), CIRCLE_DIAM, CIRCLE_DIAM));\r
}\r
\r
public void setLogicModelBinding(ReadEnd end)\r