use of com.cburch.logisim.data.Bounds in project logisim-evolution by reds-heig.
the class GrayCounter method configureNewInstance.
/**
* The configureNewInstance method is invoked every time a new instance is
* created. In the superclass, the method doesn't do anything, since the new
* instance is pretty thoroughly configured already by default. But
* sometimes you need to do something particular to each instance, so you
* would override the method. In this case, we need to set up the location
* for its label.
*/
@Override
protected void configureNewInstance(Instance instance) {
Bounds bds = instance.getBounds();
instance.setTextField(StdAttr.LABEL, StdAttr.LABEL_FONT, bds.getX() + bds.getWidth() / 2, bds.getY() - 3, GraphicsUtil.H_CENTER, GraphicsUtil.V_BASELINE);
}
use of com.cburch.logisim.data.Bounds in project logisim-evolution by reds-heig.
the class SimpleGrayCounter method paintInstance.
@Override
public void paintInstance(InstancePainter painter) {
painter.drawBounds();
// draw a triangle on port 0
painter.drawClock(0, Direction.EAST);
// draw port 1 as just a dot
painter.drawPort(1);
// printer output), then skip this.
if (painter.getShowState()) {
CounterData state = CounterData.get(painter, BIT_WIDTH);
Bounds bds = painter.getBounds();
GraphicsUtil.drawCenteredText(painter.getGraphics(), StringUtil.toHexString(BIT_WIDTH.getWidth(), state.getValue().toIntValue()), bds.getX() + bds.getWidth() / 2, bds.getY() + bds.getHeight() / 2);
}
}
use of com.cburch.logisim.data.Bounds in project logisim-evolution by reds-heig.
the class Circuit method getBounds.
public Bounds getBounds(Graphics g) {
Bounds ret = wires.getWireBounds();
int xMin = ret.getX();
int yMin = ret.getY();
int xMax = xMin + ret.getWidth();
int yMax = yMin + ret.getHeight();
if (ret == Bounds.EMPTY_BOUNDS) {
xMin = Integer.MAX_VALUE;
yMin = Integer.MAX_VALUE;
xMax = Integer.MIN_VALUE;
yMax = Integer.MIN_VALUE;
}
for (Component c : comps) {
Bounds bds = c.getBounds(g);
if (bds != null && bds != Bounds.EMPTY_BOUNDS) {
int x0 = bds.getX();
int x1 = x0 + bds.getWidth();
int y0 = bds.getY();
int y1 = y0 + bds.getHeight();
if (x0 < xMin)
xMin = x0;
if (x1 > xMax)
xMax = x1;
if (y0 < yMin)
yMin = y0;
if (y1 > yMax)
yMax = y1;
}
}
if (xMin > xMax || yMin > yMax)
return Bounds.EMPTY_BOUNDS;
return Bounds.create(xMin, yMin, xMax - xMin, yMax - yMin);
}
use of com.cburch.logisim.data.Bounds in project logisim-evolution by reds-heig.
the class AbstractGate method paintBase.
private void paintBase(InstancePainter painter) {
GateAttributes attrs = (GateAttributes) painter.getAttributeSet();
Direction facing = attrs.facing;
int inputs = attrs.inputs;
int negated = attrs.negated;
Object shape = painter.getGateShape();
Location loc = painter.getLocation();
Bounds bds = painter.getOffsetBounds();
int width = bds.getWidth();
int height = bds.getHeight();
if (facing == Direction.NORTH || facing == Direction.SOUTH) {
int t = width;
width = height;
height = t;
}
if (negated != 0) {
width -= 10;
}
Graphics g = painter.getGraphics();
Color baseColor = g.getColor();
if (shape == AppPreferences.SHAPE_SHAPED && paintInputLines) {
PainterShaped.paintInputLines(painter, this);
} else if (negated != 0) {
for (int i = 0; i < inputs; i++) {
int negatedBit = (negated >> i) & 1;
if (negatedBit == 1) {
Location in = getInputOffset(attrs, i);
Location cen = in.translate(facing, 5);
painter.drawDongle(loc.getX() + cen.getX(), loc.getY() + cen.getY());
}
}
}
g.setColor(baseColor);
g.translate(loc.getX(), loc.getY());
double rotate = 0.0;
if (facing != Direction.EAST && g instanceof Graphics2D) {
rotate = -facing.toRadians();
Graphics2D g2 = (Graphics2D) g;
g2.rotate(rotate);
}
if (shape == AppPreferences.SHAPE_RECTANGULAR) {
paintRectangular(painter, width, height);
} else if (shape == AppPreferences.SHAPE_DIN40700) {
paintDinShape(painter, width, height, inputs);
} else {
// SHAPE_SHAPED
if (negateOutput) {
g.translate(-10, 0);
paintShape(painter, width - 10, height);
painter.drawDongle(5, 0);
g.translate(10, 0);
} else {
paintShape(painter, width, height);
}
}
if (rotate != 0.0) {
((Graphics2D) g).rotate(-rotate);
}
g.translate(-loc.getX(), -loc.getY());
painter.drawLabel();
}
use of com.cburch.logisim.data.Bounds in project logisim-evolution by reds-heig.
the class PortIO 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