use of com.cburch.logisim.data.Direction in project logisim-evolution by reds-heig.
the class PainterShaped method paintInputLines.
static void paintInputLines(InstancePainter painter, AbstractGate factory) {
Location loc = painter.getLocation();
boolean printView = painter.isPrintView();
GateAttributes attrs = (GateAttributes) painter.getAttributeSet();
Direction facing = attrs.facing;
int inputs = attrs.inputs;
int negated = attrs.negated;
int[] lengths = getInputLineLengths(attrs, factory);
if (painter.getInstance() == null) {
// only
for (int i = 0; i < inputs; i++) {
boolean iNegated = ((negated >> i) & 1) == 1;
if (iNegated) {
Location offs = factory.getInputOffset(attrs, i);
Location loci = loc.translate(offs.getX(), offs.getY());
Location cent = loci.translate(facing, lengths[i] + 5);
painter.drawDongle(cent.getX(), cent.getY());
}
}
} else {
Graphics g = painter.getGraphics();
Color baseColor = g.getColor();
GraphicsUtil.switchToWidth(g, 3);
for (int i = 0; i < inputs; i++) {
Location offs = factory.getInputOffset(attrs, i);
Location src = loc.translate(offs.getX(), offs.getY());
int len = lengths[i];
if (len != 0 && (!printView || painter.isPortConnected(i + 1))) {
if (painter.getShowState()) {
Value val = painter.getPortValue(i + 1);
g.setColor(val.getColor());
} else {
g.setColor(baseColor);
}
Location dst = src.translate(facing, len);
g.drawLine(src.getX(), src.getY(), dst.getX(), dst.getY());
}
if (((negated >> i) & 1) == 1) {
Location cent = src.translate(facing, lengths[i] + 5);
g.setColor(baseColor);
painter.drawDongle(cent.getX(), cent.getY());
GraphicsUtil.switchToWidth(g, 3);
}
}
}
}
use of com.cburch.logisim.data.Direction in project logisim-evolution by reds-heig.
the class AppearanceEditHandler method delete.
@Override
public void delete() {
Selection sel = canvas.getSelection();
int n = sel.getSelected().size();
List<CanvasObject> select = new ArrayList<CanvasObject>(n);
List<CanvasObject> remove = new ArrayList<CanvasObject>(n);
Location anchorLocation = null;
Direction anchorFacing = null;
for (CanvasObject o : sel.getSelected()) {
if (o.canRemove()) {
remove.add(o);
} else {
select.add(o);
if (o instanceof AppearanceAnchor) {
AppearanceAnchor anchor = (AppearanceAnchor) o;
anchorLocation = anchor.getLocation();
anchorFacing = anchor.getFacing();
}
}
}
if (!remove.isEmpty()) {
canvas.getProject().doAction(new SelectionAction(canvas, Strings.getter("deleteSelectionAction"), remove, null, select, anchorLocation, anchorFacing));
}
}
use of com.cburch.logisim.data.Direction in project logisim-evolution by reds-heig.
the class Power method drawInstance.
private void drawInstance(InstancePainter painter, boolean isGhost) {
Graphics2D g = (Graphics2D) painter.getGraphics().create();
Location loc = painter.getLocation();
g.translate(loc.getX(), loc.getY());
Direction from = painter.getAttributeValue(StdAttr.FACING);
int degrees = Direction.EAST.toDegrees() - from.toDegrees();
double radians = Math.toRadians((degrees + 360) % 360);
g.rotate(radians);
GraphicsUtil.switchToWidth(g, Wire.WIDTH);
if (!isGhost && painter.getShowState()) {
g.setColor(painter.getPortValue(0).getColor());
}
g.drawLine(0, 0, 5, 0);
GraphicsUtil.switchToWidth(g, 1);
if (!isGhost && painter.shouldDrawColor()) {
BitWidth width = painter.getAttributeValue(StdAttr.WIDTH);
g.setColor(Value.repeat(Value.TRUE, width.getWidth()).getColor());
}
g.drawPolygon(new int[] { 6, 14, 6 }, new int[] { -8, 0, 8 }, 3);
g.dispose();
}
use of com.cburch.logisim.data.Direction in project logisim-evolution by reds-heig.
the class AddTool method getFacing.
private Direction getFacing() {
ComponentFactory source = getFactory();
if (source == null)
return Direction.NORTH;
AttributeSet base = getBaseAttributes();
Object feature = source.getFeature(ComponentFactory.FACING_ATTRIBUTE_KEY, base);
@SuppressWarnings("unchecked") Attribute<Direction> attr = (Attribute<Direction>) feature;
if (attr != null)
return base.getValue(attr);
else
return Direction.NORTH;
}
use of com.cburch.logisim.data.Direction in project logisim-evolution by reds-heig.
the class EditTool method getFacingAttribute.
private Attribute<Direction> getFacingAttribute(Component comp) {
AttributeSet attrs = comp.getAttributeSet();
Object key = ComponentFactory.FACING_ATTRIBUTE_KEY;
Attribute<?> a = (Attribute<?>) comp.getFactory().getFeature(key, attrs);
@SuppressWarnings("unchecked") Attribute<Direction> ret = (Attribute<Direction>) a;
return ret;
}
Aggregations