use of com.cburch.logisim.data.Bounds in project logisim-evolution by reds-heig.
the class Random method paintInstance.
@Override
public void paintInstance(InstancePainter painter) {
Bounds bds = painter.getBounds();
int x = bds.getX();
int y = bds.getY();
StateData state = (StateData) painter.getData();
int val = state == null ? 0 : state.value;
BitWidth widthVal = painter.getAttributeValue(StdAttr.WIDTH);
int width = widthVal == null ? 8 : widthVal.getWidth();
painter.drawLabel();
DrawControl(painter, x, y, width);
DrawData(painter, x, y + 70, width, val);
}
use of com.cburch.logisim.data.Bounds in project logisim-evolution by reds-heig.
the class Pin method paintGhost.
@Override
public void paintGhost(InstancePainter painter) {
PinAttributes attrs = (PinAttributes) painter.getAttributeSet();
Location loc = painter.getLocation();
Bounds bds = painter.getOffsetBounds();
int x = loc.getX();
int y = loc.getY();
Graphics g = painter.getGraphics();
GraphicsUtil.switchToWidth(g, 2);
boolean output = attrs.isOutput();
if (output) {
BitWidth width = attrs.getValue(StdAttr.WIDTH);
if (width == BitWidth.ONE) {
g.drawOval(x + bds.getX() + 1, y + bds.getY() + 1, bds.getWidth() - 1, bds.getHeight() - 1);
} else {
g.drawRoundRect(x + bds.getX() + 1, y + bds.getY() + 1, bds.getWidth() - 1, bds.getHeight() - 1, 6, 6);
}
} else {
g.drawRect(x + bds.getX() + 1, y + bds.getY() + 1, bds.getWidth() - 1, bds.getHeight() - 1);
}
}
use of com.cburch.logisim.data.Bounds in project logisim-evolution by reds-heig.
the class Pin method paintInstance.
@Override
public void paintInstance(InstancePainter painter) {
PinAttributes attrs = (PinAttributes) painter.getAttributeSet();
Graphics g = painter.getGraphics();
// intentionally with no
Bounds bds = painter.getInstance().getBounds();
// graphics object - we
// don't want label
// included
int x = bds.getX();
int y = bds.getY();
GraphicsUtil.switchToWidth(g, 2);
g.setColor(Color.black);
if (attrs.type == EndData.OUTPUT_ONLY) {
if (attrs.width.getWidth() == 1) {
g.drawOval(x + 1, y + 1, bds.getWidth() - 1, bds.getHeight() - 1);
} else {
g.drawRoundRect(x + 1, y + 1, bds.getWidth() - 1, bds.getHeight() - 1, 12, 12);
}
} else {
g.drawRect(x + 1, y + 1, bds.getWidth() - 1, bds.getHeight() - 1);
}
painter.drawLabel();
if (!painter.getShowState()) {
g.setColor(Color.BLACK);
GraphicsUtil.drawCenteredText(g, "x" + attrs.width.getWidth(), bds.getX() + bds.getWidth() / 2, bds.getY() + bds.getHeight() / 2);
} else {
PinState state = getState(painter);
if (attrs.width.getWidth() <= 1) {
Value found = state.foundValue;
g.setColor(found.getColor());
g.fillOval(x + 4, y + 4, 13, 13);
if (attrs.width.getWidth() == 1) {
g.setColor(Color.WHITE);
GraphicsUtil.drawCenteredText(g, state.intendedValue.toDisplayString(), x + 11, y + 9);
}
} else {
Probe.paintValue(painter, state.intendedValue);
}
}
painter.drawPorts();
}
use of com.cburch.logisim.data.Bounds in project logisim-evolution by reds-heig.
the class PowerOnReset method paintInstance.
@Override
public void paintInstance(InstancePainter painter) {
java.awt.Graphics g = painter.getGraphics();
Bounds bds = painter.getInstance().getBounds();
int x = bds.getX();
int y = bds.getY();
GraphicsUtil.switchToWidth(g, 2);
g.setColor(Color.ORANGE);
g.fillRect(x, y, bds.getWidth(), bds.getHeight());
g.setColor(Color.BLACK);
g.drawRect(x, y, bds.getWidth(), bds.getHeight());
Font old = g.getFont();
g.setFont(old.deriveFont(18.0f).deriveFont(Font.BOLD));
FontMetrics fm = g.getFontMetrics();
String txt = "Power-On Reset";
int wide = Math.max(bds.getWidth(), bds.getHeight());
int offset = (wide - fm.stringWidth(txt)) / 2;
Direction facing = painter.getAttributeValue(StdAttr.FACING);
if (((facing == Direction.NORTH) || (facing == Direction.SOUTH)) && (g instanceof Graphics2D)) {
Graphics2D g2 = (Graphics2D) g;
int xpos = facing == Direction.NORTH ? x + 20 - fm.getDescent() : x + 20 + fm.getDescent();
int ypos = facing == Direction.NORTH ? y + offset : y + bds.getHeight() - offset;
g2.translate(xpos, ypos);
g2.rotate(facing.toRadians());
g.drawString(txt, 0, 0);
g2.rotate(-facing.toRadians());
g2.translate(-xpos, -ypos);
} else {
g.drawString(txt, x + offset, y + fm.getDescent() + 20);
}
painter.drawPorts();
}
use of com.cburch.logisim.data.Bounds in project logisim-evolution by reds-heig.
the class Probe method configureLabel.
static void configureLabel(Instance instance, Direction labelLoc, Direction facing) {
Bounds bds = instance.getBounds();
int x;
int y;
int halign;
int valign;
if (labelLoc == Direction.NORTH) {
halign = TextField.H_CENTER;
valign = TextField.V_BOTTOM;
x = bds.getX() + bds.getWidth() / 2;
y = bds.getY() - 2;
if (facing == labelLoc) {
halign = TextField.H_LEFT;
x += 2;
}
} else if (labelLoc == Direction.SOUTH) {
halign = TextField.H_CENTER;
valign = TextField.V_TOP;
x = bds.getX() + bds.getWidth() / 2;
y = bds.getY() + bds.getHeight() + 2;
if (facing == labelLoc) {
halign = TextField.H_LEFT;
x += 2;
}
} else if (labelLoc == Direction.EAST) {
halign = TextField.H_LEFT;
valign = TextField.V_CENTER;
x = bds.getX() + bds.getWidth() + 2;
y = bds.getY() + bds.getHeight() / 2;
if (facing == labelLoc) {
valign = TextField.V_BOTTOM;
y -= 2;
}
} else {
// WEST
halign = TextField.H_RIGHT;
valign = TextField.V_CENTER;
x = bds.getX() - 2;
y = bds.getY() + bds.getHeight() / 2;
if (facing == labelLoc) {
valign = TextField.V_BOTTOM;
y -= 2;
}
}
instance.setTextField(StdAttr.LABEL, StdAttr.LABEL_FONT, x, y, halign, valign);
}
Aggregations