use of com.cburch.logisim.data.Bounds in project logisim-evolution by reds-heig.
the class PortIO method paintInstance.
@Override
public void paintInstance(InstancePainter painter) {
/*
* State state = (State) painter.getData(); if (state == null) { state =
* new State(0,painter.getAttributeValue(ATTR_SIZE));
* painter.setData(state); }
*/
Bounds bds = painter.getBounds().expand(-1);
Graphics g = painter.getGraphics();
GraphicsUtil.switchToWidth(g, 2);
g.setColor(Color.darkGray);
g.fillRect(bds.getX(), bds.getY(), bds.getWidth(), bds.getHeight());
GraphicsUtil.switchToWidth(g, 1);
if (painter.getAttributeValue(ATTR_BUS).equals(PINS)) {
// TODO YSY PINS
g.setColor(Color.white);
g.setFont(StdAttr.DEFAULT_LABEL_FONT.deriveFont(StdAttr.DEFAULT_LABEL_FONT.getSize2D() * 0.6f));
for (int i = 0; i < painter.getAttributeValue(ATTR_SIZE); i++) {
g.fillRect(bds.getX() + 6 + (i * 10), bds.getY() + 15, 6, 6);
if (i == 0 || i == painter.getAttributeValue(ATTR_SIZE) - 1) {
g.drawChars(Integer.toString(i).toCharArray(), 0, Integer.toString(i).toCharArray().length, bds.getX() + 6 + (i < 10 ? 0 : -2) + i * 10, bds.getY() + 12);
}
}
} else {
g.setColor(Color.LIGHT_GRAY);
for (int i = 0; i < 9; i++) {
g.fillRect(bds.getX() + 6 + (i * 10), bds.getY() + 15, 6, 6);
g.fillRect(bds.getX() + 6 + (i * 10), bds.getY() + 25, 6, 6);
}
g.setColor(Color.WHITE);
g.setFont(StdAttr.DEFAULT_LABEL_FONT);
String text = painter.getAttributeValue(ATTR_SIZE).toString() + " PIN";
g.drawChars(text.toCharArray(), 0, text.toCharArray().length, bds.getX() + 6, bds.getY() + 12);
}
painter.drawLabel();
painter.drawPorts();
}
use of com.cburch.logisim.data.Bounds in project logisim-evolution by reds-heig.
the class RGBLed method paintInstance.
@Override
public void paintInstance(InstancePainter painter) {
InstanceDataSingleton data = (InstanceDataSingleton) painter.getData();
int summ = (data == null ? 0 : ((Integer) data.getValue()).intValue());
Bounds bds = painter.getBounds().expand(-1);
Graphics g = painter.getGraphics();
if (painter.getShowState()) {
Boolean activ = painter.getAttributeValue(Io.ATTR_ACTIVE);
int mask = activ.booleanValue() ? 0 : 7;
summ ^= mask;
int red = ((summ >> RED) & 1) * 0xFF;
int green = ((summ >> GREEN) & 1) * 0xFF;
int blue = ((summ >> BLUE) & 1) * 0xFF;
Color LedColor = new Color(red, green, blue);
g.setColor(LedColor);
g.fillOval(bds.getX(), bds.getY(), bds.getWidth(), bds.getHeight());
}
g.setColor(Color.BLACK);
GraphicsUtil.switchToWidth(g, 2);
g.drawOval(bds.getX(), bds.getY(), bds.getWidth(), bds.getHeight());
GraphicsUtil.switchToWidth(g, 1);
painter.drawLabel();
painter.drawPorts();
}
use of com.cburch.logisim.data.Bounds in project logisim-evolution by reds-heig.
the class Tty method paintInstance.
@Override
public void paintInstance(InstancePainter painter) {
boolean showState = painter.getShowState();
Graphics g = painter.getGraphics();
Bounds bds = painter.getBounds();
painter.drawClock(CK, Direction.EAST);
if (painter.shouldDrawColor()) {
g.setColor(painter.getAttributeValue(Io.ATTR_BACKGROUND));
g.fillRoundRect(bds.getX(), bds.getY(), bds.getWidth(), bds.getHeight(), 10, 10);
}
GraphicsUtil.switchToWidth(g, 2);
g.setColor(Color.BLACK);
g.drawRoundRect(bds.getX(), bds.getY(), bds.getWidth(), bds.getHeight(), 2 * BORDER, 2 * BORDER);
GraphicsUtil.switchToWidth(g, 1);
painter.drawPort(CLR);
painter.drawPort(WE);
painter.drawPort(IN);
int rows = getRowCount(painter.getAttributeValue(ATTR_ROWS));
int cols = getColumnCount(painter.getAttributeValue(ATTR_COLUMNS));
if (showState) {
String[] rowData = new String[rows];
int curRow;
int curCol;
TtyState state = getTtyState(painter);
synchronized (state) {
for (int i = 0; i < rows; i++) {
rowData[i] = state.getRowString(i);
}
curRow = state.getCursorRow();
curCol = state.getCursorColumn();
}
g.setFont(DEFAULT_FONT);
g.setColor(painter.getAttributeValue(Io.ATTR_COLOR));
FontMetrics fm = g.getFontMetrics();
int x = bds.getX() + BORDER;
int y = bds.getY() + BORDER + (ROW_HEIGHT + fm.getAscent()) / 2;
for (int i = 0; i < rows; i++) {
g.drawString(rowData[i], x, y);
if (i == curRow) {
int x0 = x + fm.stringWidth(rowData[i].substring(0, curCol));
g.drawLine(x0, y - fm.getAscent(), x0, y);
}
y += ROW_HEIGHT;
}
} else {
String str = Strings.get("ttyDesc", "" + rows, "" + cols);
FontMetrics fm = g.getFontMetrics();
int strWidth = fm.stringWidth(str);
if (strWidth + BORDER > bds.getWidth()) {
str = Strings.get("ttyDescShort");
strWidth = fm.stringWidth(str);
}
int x = bds.getX() + (bds.getWidth() - strWidth) / 2;
int y = bds.getY() + (bds.getHeight() + fm.getAscent()) / 2;
g.drawString(str, x, y);
}
}
use of com.cburch.logisim.data.Bounds in project logisim-evolution by reds-heig.
the class Button method computeTextField.
private void computeTextField(Instance instance) {
Direction facing = instance.getAttributeValue(StdAttr.FACING);
Object labelLoc = instance.getAttributeValue(Io.ATTR_LABEL_LOC);
Bounds bds = instance.getBounds();
int x = bds.getX() + bds.getWidth() / 2;
int y = bds.getY() + bds.getHeight() / 2;
int halign = GraphicsUtil.H_CENTER;
int valign = GraphicsUtil.V_CENTER;
if (labelLoc == Io.LABEL_CENTER) {
x = bds.getX() + (bds.getWidth() - DEPTH) / 2;
y = bds.getY() + (bds.getHeight() - DEPTH) / 2;
} else if (labelLoc == Direction.NORTH) {
y = bds.getY() - 2;
valign = GraphicsUtil.V_BOTTOM;
} else if (labelLoc == Direction.SOUTH) {
y = bds.getY() + bds.getHeight() + 2;
valign = GraphicsUtil.V_TOP;
} else if (labelLoc == Direction.EAST) {
x = bds.getX() + bds.getWidth() + 2;
halign = GraphicsUtil.H_LEFT;
} else if (labelLoc == Direction.WEST) {
x = bds.getX() - 2;
halign = GraphicsUtil.H_RIGHT;
}
if (labelLoc == facing) {
if (labelLoc == Direction.NORTH || labelLoc == Direction.SOUTH) {
x += 2;
halign = GraphicsUtil.H_LEFT;
} else {
y -= 2;
valign = GraphicsUtil.V_BOTTOM;
}
}
instance.setTextField(StdAttr.LABEL, StdAttr.LABEL_FONT, x, y, halign, valign);
}
use of com.cburch.logisim.data.Bounds in project logisim-evolution by reds-heig.
the class DipSwitch method computeTextField.
private void computeTextField(Instance instance) {
Direction facing = Direction.NORTH;
Object labelLoc = instance.getAttributeValue(Io.ATTR_LABEL_LOC);
Bounds bds = instance.getBounds();
int x = bds.getX() + bds.getWidth() / 2;
int y = bds.getY() + bds.getHeight() / 2;
int halign = GraphicsUtil.H_CENTER;
int valign = GraphicsUtil.V_CENTER;
if (labelLoc == Direction.NORTH) {
y = bds.getY() - 2;
valign = GraphicsUtil.V_BOTTOM;
} else if (labelLoc == Direction.SOUTH) {
y = bds.getY() + bds.getHeight() + 2;
valign = GraphicsUtil.V_TOP;
} else if (labelLoc == Direction.EAST) {
x = bds.getX() + bds.getWidth() + 2;
halign = GraphicsUtil.H_LEFT;
} else if (labelLoc == Direction.WEST) {
x = bds.getX() - 2;
halign = GraphicsUtil.H_RIGHT;
}
if (labelLoc == facing) {
if (labelLoc == Direction.NORTH || labelLoc == Direction.SOUTH) {
x += 2;
halign = GraphicsUtil.H_LEFT;
} else {
y -= 2;
valign = GraphicsUtil.V_BOTTOM;
}
}
instance.setTextField(StdAttr.LABEL, StdAttr.LABEL_FONT, x, y, halign, valign);
}
Aggregations