Exemple #1
0
  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.getPort(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.FALSE, width.getWidth()).getColor());
    }
    g.drawLine(6, -8, 6, 8);
    g.drawLine(9, -5, 9, 5);
    g.drawLine(12, -2, 12, 2);

    g.dispose();
  }
Exemple #2
0
 @Override
 public void paintInstance(InstancePainter painter) {
   Location loc = painter.getLocation();
   int x = loc.getX();
   int y = loc.getY();
   Graphics g = painter.getGraphics();
   g.translate(x, y);
   Value pull = getPullValue(painter.getAttributeSet());
   Value actual = painter.getPort(0);
   paintBase(painter, pull, pull.getColor(), actual.getColor());
   g.translate(-x, -y);
   painter.drawPorts();
 }
Exemple #3
0
  private void drawInstance(InstancePainter painter, boolean isGhost) {
    Bounds bds = painter.getBounds();
    Object powerLoc = painter.getAttributeValue(Wiring.ATTR_GATE);
    Direction facing = painter.getAttributeValue(StdAttr.FACING);
    boolean flip =
        (facing == Direction.SOUTH || facing == Direction.WEST)
            == (powerLoc == Wiring.GATE_TOP_LEFT);

    int degrees = Direction.WEST.toDegrees() - facing.toDegrees();
    if (flip) {
      degrees += 180;
    }

    double radians = Math.toRadians((degrees + 360) % 360);

    Graphics2D g = (Graphics2D) painter.getGraphics().create();
    g.rotate(radians, bds.getX() + 20, bds.getY() + 20);
    g.translate(bds.getX(), bds.getY());
    GraphicsUtil.switchToWidth(g, Wire.WIDTH);

    Color gate0 = g.getColor();
    Color gate1 = gate0;
    Color input = gate0;
    Color output = gate0;
    Color platform = gate0;
    if (!isGhost && painter.getShowState()) {
      gate0 = painter.getPort(GATE0).getColor();
      gate1 = painter.getPort(GATE0).getColor();
      input = painter.getPort(INPUT).getColor();
      output = painter.getPort(OUTPUT).getColor();
      platform = computeOutput(painter).getColor();
    }

    g.setColor(flip ? input : output);
    g.drawLine(0, 20, 11, 20);
    g.drawLine(11, 13, 11, 27);

    g.setColor(flip ? output : input);
    g.drawLine(29, 20, 40, 20);
    g.drawLine(29, 13, 29, 27);

    g.setColor(gate0);
    g.drawLine(20, 35, 20, 40);
    GraphicsUtil.switchToWidth(g, 1);
    g.drawOval(18, 30, 4, 4);
    g.drawLine(10, 30, 30, 30);
    GraphicsUtil.switchToWidth(g, Wire.WIDTH);

    g.setColor(gate1);
    g.drawLine(20, 9, 20, 0);
    GraphicsUtil.switchToWidth(g, 1);
    g.drawLine(10, 10, 30, 10);

    g.setColor(platform);
    g.drawLine(9, 12, 31, 12);
    g.drawLine(9, 28, 31, 28);
    // arrow
    if (flip) {
      g.drawLine(18, 17, 21, 20);
      g.drawLine(18, 23, 21, 20);
    } else {
      g.drawLine(22, 17, 19, 20);
      g.drawLine(22, 23, 19, 20);
    }

    g.dispose();
  }