use of com.cburch.logisim.data.Direction in project logisim-evolution by reds-heig.
the class SplitterPainter method drawLegacy.
static void drawLegacy(ComponentDrawContext context, SplitterAttributes attrs, Location origin) {
Graphics g = context.getGraphics();
CircuitState state = context.getCircuitState();
Direction facing = attrs.facing;
int fanout = attrs.fanout;
SplitterParameters parms = attrs.getParameters();
g.setColor(Color.BLACK);
int x0 = origin.getX();
int y0 = origin.getY();
int x1 = x0 + parms.getEnd0X();
int y1 = y0 + parms.getEnd0Y();
int dx = parms.getEndToEndDeltaX();
int dy = parms.getEndToEndDeltaY();
if (facing == Direction.NORTH || facing == Direction.SOUTH) {
int ySpine = (y0 + y1) / 2;
GraphicsUtil.switchToWidth(g, Wire.WIDTH);
g.drawLine(x0, y0, x0, ySpine);
int xi = x1;
int yi = y1;
for (int i = 1; i <= fanout; i++) {
if (context.getShowState()) {
g.setColor(state.getValue(Location.create(xi, yi)).getColor());
}
int xSpine = xi + (xi == x0 ? 0 : (xi < x0 ? 10 : -10));
g.drawLine(xi, yi, xSpine, ySpine);
xi += dx;
yi += dy;
}
if (fanout > 3) {
GraphicsUtil.switchToWidth(g, SPINE_WIDTH);
g.setColor(Color.BLACK);
g.drawLine(x1 + dx, ySpine, x1 + (fanout - 2) * dx, ySpine);
} else {
g.setColor(Color.BLACK);
g.fillOval(x0 - SPINE_DOT / 2, ySpine - SPINE_DOT / 2, SPINE_DOT, SPINE_DOT);
}
} else {
int xSpine = (x0 + x1) / 2;
GraphicsUtil.switchToWidth(g, Wire.WIDTH);
g.drawLine(x0, y0, xSpine, y0);
int xi = x1;
int yi = y1;
for (int i = 1; i <= fanout; i++) {
if (context.getShowState()) {
g.setColor(state.getValue(Location.create(xi, yi)).getColor());
}
int ySpine = yi + (yi == y0 ? 0 : (yi < y0 ? 10 : -10));
g.drawLine(xi, yi, xSpine, ySpine);
xi += dx;
yi += dy;
}
if (fanout >= 3) {
GraphicsUtil.switchToWidth(g, SPINE_WIDTH);
g.setColor(Color.BLACK);
g.drawLine(xSpine, y1 + dy, xSpine, y1 + (fanout - 2) * dy);
} else {
g.setColor(Color.BLACK);
g.fillOval(xSpine - SPINE_DOT / 2, y0 - SPINE_DOT / 2, SPINE_DOT, SPINE_DOT);
}
}
GraphicsUtil.switchToWidth(g, 1);
}
use of com.cburch.logisim.data.Direction in project logisim-evolution by reds-heig.
the class CircuitAppearance method paintSubcircuit.
public void paintSubcircuit(Graphics g, Direction facing) {
Direction defaultFacing = getFacing();
double rotate = 0.0;
if (facing != defaultFacing && g instanceof Graphics2D) {
rotate = defaultFacing.toRadians() - facing.toRadians();
((Graphics2D) g).rotate(rotate);
}
Location offset = findAnchorLocation();
g.translate(-offset.getX(), -offset.getY());
for (CanvasObject shape : getObjectsFromBottom()) {
if (!(shape instanceof AppearanceElement)) {
Graphics dup = g.create();
shape.paint(dup, null);
dup.dispose();
}
}
g.translate(offset.getX(), offset.getY());
if (rotate != 0.0) {
((Graphics2D) g).rotate(-rotate);
}
}
use of com.cburch.logisim.data.Direction in project logisim-evolution by reds-heig.
the class CircuitAppearance method getPortOffsets.
public SortedMap<Location, Instance> getPortOffsets(Direction facing) {
Location anchor = null;
Direction defaultFacing = Direction.EAST;
List<AppearancePort> ports = new ArrayList<AppearancePort>();
for (CanvasObject shape : getObjectsFromBottom()) {
if (shape instanceof AppearancePort) {
ports.add((AppearancePort) shape);
} else if (shape instanceof AppearanceAnchor) {
AppearanceAnchor o = (AppearanceAnchor) shape;
anchor = o.getLocation();
defaultFacing = o.getFacing();
}
}
SortedMap<Location, Instance> ret = new TreeMap<Location, Instance>();
for (AppearancePort port : ports) {
Location loc = port.getLocation();
if (anchor != null) {
loc = loc.translate(-anchor.getX(), -anchor.getY());
}
if (facing != defaultFacing) {
loc = loc.rotate(defaultFacing, facing, 0, 0);
}
ret.put(loc, port.getPin());
}
return ret;
}
use of com.cburch.logisim.data.Direction in project logisim-evolution by reds-heig.
the class AbstractGate method contains.
@Override
public boolean contains(Location loc, AttributeSet attrsBase) {
GateAttributes attrs = (GateAttributes) attrsBase;
if (super.contains(loc, attrs)) {
if (attrs.negated == 0) {
return true;
} else {
Direction facing = attrs.facing;
Bounds bds = getOffsetBounds(attrsBase);
int delt;
if (facing == Direction.NORTH) {
delt = loc.getY() - (bds.getY() + bds.getHeight());
} else if (facing == Direction.SOUTH) {
delt = loc.getY() - bds.getY();
} else if (facing == Direction.WEST) {
delt = loc.getX() - (bds.getX() + bds.getHeight());
} else {
delt = loc.getX() - bds.getX();
}
if (Math.abs(delt) > 5) {
return true;
} else {
int inputs = attrs.inputs;
for (int i = 1; i <= inputs; i++) {
Location offs = getInputOffset(attrs, i);
if (loc.manhattanDistanceTo(offs) <= 5)
return true;
}
return false;
}
}
} else {
return false;
}
}
use of com.cburch.logisim.data.Direction in project logisim-evolution by reds-heig.
the class AbstractGate method getOffsetBounds.
@Override
public Bounds getOffsetBounds(AttributeSet attrsBase) {
GateAttributes attrs = (GateAttributes) attrsBase;
Direction facing = attrs.facing;
int size = ((Integer) attrs.size.getValue()).intValue();
int inputs = attrs.inputs;
if (inputs % 2 == 0) {
inputs++;
}
int negated = attrs.negated;
int width = size + bonusWidth + (negateOutput ? 10 : 0);
if (negated != 0) {
width += 10;
}
int height = Math.max(10 * inputs, size);
if (facing == Direction.SOUTH) {
return Bounds.create(-height / 2, -width, height, width);
} else if (facing == Direction.NORTH) {
return Bounds.create(-height / 2, 0, height, width);
} else if (facing == Direction.WEST) {
return Bounds.create(0, -height / 2, width, height);
} else {
return Bounds.create(-width, -height / 2, width, height);
}
}
Aggregations