コード例 #1
0
ファイル: Ground.java プロジェクト: IsThisSparta/Logisim
  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();
  }
コード例 #2
0
  //
  // graphics methods
  //
  @Override
  public void paintInstance(InstancePainter painter) {
    Graphics g = painter.getGraphics();
    FontMetrics fm = g.getFontMetrics();
    int asc = fm.getAscent();

    painter.drawBounds();

    String s0;
    String type = getType(painter.getAttributeSet());
    if (type.equals("zero")) s0 = Strings.get("extenderZeroLabel");
    else if (type.equals("one")) s0 = Strings.get("extenderOneLabel");
    else if (type.equals("sign")) s0 = Strings.get("extenderSignLabel");
    else if (type.equals("input")) s0 = Strings.get("extenderInputLabel");
    else s0 = "???"; // should never happen
    String s1 = Strings.get("extenderMainLabel");
    Bounds bds = painter.getBounds();
    int x = bds.getX() + bds.getWidth() / 2;
    int y0 = bds.getY() + (bds.getHeight() / 2 + asc) / 2;
    int y1 = bds.getY() + (3 * bds.getHeight() / 2 + asc) / 2;
    GraphicsUtil.drawText(g, s0, x, y0, GraphicsUtil.H_CENTER, GraphicsUtil.V_BASELINE);
    GraphicsUtil.drawText(g, s1, x, y1, GraphicsUtil.H_CENTER, GraphicsUtil.V_BASELINE);

    BitWidth w0 = painter.getAttributeValue(ATTR_OUT_WIDTH);
    BitWidth w1 = painter.getAttributeValue(ATTR_IN_WIDTH);
    painter.drawPort(0, "" + w0.getWidth(), Direction.WEST);
    painter.drawPort(1, "" + w1.getWidth(), Direction.EAST);
    if (type.equals("input")) painter.drawPort(2);
  }
コード例 #3
0
ファイル: MemState.java プロジェクト: EricStudley/logisim
  public void paint(Graphics g, int leftX, int topY) {
    int addrBits = getAddrBits();
    int dataBits = contents.getWidth();
    int boxX = leftX + (addrBits <= 12 ? ENTRY_XOFFS12 : ENTRY_XOFFS32);
    int boxY = topY + ENTRY_YOFFS;
    int boxW = addrBits <= 12 ? TABLE_WIDTH12 : TABLE_WIDTH32;
    int boxH = ROWS * ENTRY_HEIGHT;

    GraphicsUtil.switchToWidth(g, 1);
    g.drawRect(boxX, boxY, boxW, boxH);
    int entryWidth = boxW / columns;
    for (int row = 0; row < ROWS; row++) {
      long addr = (curScroll / columns * columns) + columns * row;
      int x = boxX;
      int y = boxY + ENTRY_HEIGHT * row;
      int yoffs = ENTRY_HEIGHT - 3;
      if (isValidAddr(addr)) {
        g.setColor(Color.GRAY);
        GraphicsUtil.drawText(
            g,
            StringUtil.toHexString(getAddrBits(), (int) addr),
            x - 2,
            y + yoffs,
            GraphicsUtil.H_RIGHT,
            GraphicsUtil.V_BASELINE);
      }
      g.setColor(Color.BLACK);
      for (int col = 0; col < columns && isValidAddr(addr); col++) {
        int val = contents.get(addr);
        if (addr == curAddr) {
          g.fillRect(x, y, entryWidth, ENTRY_HEIGHT);
          g.setColor(Color.WHITE);
          GraphicsUtil.drawText(
              g,
              StringUtil.toHexString(dataBits, val),
              x + entryWidth / 2,
              y + yoffs,
              GraphicsUtil.H_CENTER,
              GraphicsUtil.V_BASELINE);
          g.setColor(Color.BLACK);
        } else {
          GraphicsUtil.drawText(
              g,
              StringUtil.toHexString(dataBits, val),
              x + entryWidth / 2,
              y + yoffs,
              GraphicsUtil.H_CENTER,
              GraphicsUtil.V_BASELINE);
        }
        addr++;
        x += entryWidth;
      }
    }
  }
コード例 #4
0
ファイル: NotGate.java プロジェクト: pavelfatin/logisim
 private void paintRectangularBase(Graphics g, InstancePainter painter) {
   GraphicsUtil.switchToWidth(g, 2);
   if (painter.getAttributeValue(ATTR_SIZE) == SIZE_NARROW) {
     g.drawRect(-20, -9, 14, 18);
     GraphicsUtil.drawCenteredText(g, RECT_LABEL, -13, 0);
     g.drawOval(-6, -3, 6, 6);
   } else {
     g.drawRect(-30, -9, 20, 18);
     GraphicsUtil.drawCenteredText(g, RECT_LABEL, -20, 0);
     g.drawOval(-10, -5, 9, 9);
   }
   GraphicsUtil.switchToWidth(g, 1);
 }
コード例 #5
0
ファイル: Wire.java プロジェクト: cs3410/logisim-evolution
 public void draw(ComponentDrawContext context) {
   CircuitState state = context.getCircuitState();
   Graphics g = context.getGraphics();
   GraphicsUtil.switchToWidth(g, WIDTH);
   g.setColor(state.getValue(e0).getColor());
   g.drawLine(e0.getX(), e0.getY(), e1.getX(), e1.getY());
 }
コード例 #6
0
ファイル: AbstractGate.java プロジェクト: EricStudley/logisim
  protected void paintIconRectangular(InstancePainter painter) {
    Graphics g = painter.getGraphics();
    g.drawRect(1, 2, 16, 16);
    if (negateOutput) {
      g.drawOval(16, 8, 4, 4);
    }

    String label = getRectangularLabel(painter.getAttributeSet());
    GraphicsUtil.drawCenteredText(g, label, 9, 8);
  }
コード例 #7
0
ファイル: TablePanel.java プロジェクト: sivart73/Brandonsim
  @Override
  public void paintComponent(Graphics g) {
    super.paintComponent(g);

    Dimension sz = getSize();
    int top = Math.max(0, (sz.height - tableHeight) / 2);
    int left = Math.max(0, (sz.width - tableWidth) / 2);
    Model model = getModel();
    if (model == null) return;
    Selection sel = model.getSelection();
    int columns = sel.size();
    if (columns == 0) {
      g.setFont(BODY_FONT);
      GraphicsUtil.drawCenteredText(
          g, Strings.get("tableEmptyMessage"), sz.width / 2, sz.height / 2);
      return;
    }

    g.setColor(Color.GRAY);
    int lineY = top + cellHeight + HEADER_SEP / 2;
    g.drawLine(left, lineY, left + tableWidth, lineY);

    g.setColor(Color.BLACK);
    g.setFont(HEAD_FONT);
    FontMetrics headerMetric = g.getFontMetrics();
    int x = left;
    int y = top + headerMetric.getAscent() + 1;
    for (int i = 0; i < columns; i++) {
      x = paintHeader(sel.get(i).toShortString(), x, y, g, headerMetric);
    }

    g.setFont(BODY_FONT);
    FontMetrics bodyMetric = g.getFontMetrics();
    Rectangle clip = g.getClipBounds();
    int firstRow = Math.max(0, (clip.y - y) / cellHeight - 1);
    int lastRow = Math.min(rowCount, 2 + (clip.y + clip.height - y) / cellHeight);
    int y0 = top + cellHeight + HEADER_SEP;
    x = left;
    for (int col = 0; col < columns; col++) {
      SelectionItem item = sel.get(col);
      ValueLog log = model.getValueLog(item);
      int radix = item.getRadix();
      int offs = rowCount - log.size();
      y = y0 + Math.max(offs, firstRow) * cellHeight;
      for (int row = Math.max(offs, firstRow); row < lastRow; row++) {
        Value val = log.get(row - offs);
        String label = val.toDisplayString(radix);
        int width = bodyMetric.stringWidth(label);
        g.drawString(label, x + (cellWidth - width) / 2, y + bodyMetric.getAscent());
        y += cellHeight;
      }
      x += cellWidth + COLUMN_SEP;
    }
  }
コード例 #8
0
ファイル: ALU.java プロジェクト: rjnogales/logisim-diku
 static void drawALU(Graphics g, Bounds bds) {
   int wid = bds.getWidth();
   int ht = bds.getHeight();
   int x0 = bds.getX();
   int x1 = x0 + wid;
   int y0 = bds.getY();
   int y1 = y0 + ht;
   int xp[] = {x0, x1, x1, x0, x0, x0 + 20, x0};
   int yp[] = {y0, y0 + 30, y1 - 30, y1, y1 - 40, y1 - 50, y1 - 60};
   GraphicsUtil.switchToWidth(g, 2);
   g.drawPolygon(xp, yp, 7);
 }
コード例 #9
0
ファイル: NotGate.java プロジェクト: pavelfatin/logisim
 //
 // painting methods
 //
 @Override
 public void paintIcon(InstancePainter painter) {
   Graphics g = painter.getGraphics();
   g.setColor(Color.black);
   if (painter.getGateShape() == AppPreferences.SHAPE_RECTANGULAR) {
     if (toolIconRect != null) {
       toolIconRect.paintIcon(painter.getDestination(), g, 2, 2);
     } else {
       g.drawRect(0, 2, 16, 16);
       GraphicsUtil.drawCenteredText(g, RECT_LABEL, 8, 8);
       g.drawOval(16, 8, 4, 4);
     }
   } else if (painter.getGateShape() == AppPreferences.SHAPE_DIN40700) {
     if (toolIconDin != null) {
       toolIconDin.paintIcon(painter.getDestination(), g, 2, 2);
     } else {
       g.drawRect(0, 2, 16, 16);
       GraphicsUtil.drawCenteredText(g, RECT_LABEL, 8, 8);
       g.drawOval(16, 8, 4, 4);
     }
   } else {
     if (toolIcon != null) {
       toolIcon.paintIcon(painter.getDestination(), g, 2, 2);
     } else {
       int[] xp = new int[4];
       int[] yp = new int[4];
       xp[0] = 15;
       yp[0] = 10;
       xp[1] = 1;
       yp[1] = 3;
       xp[2] = 1;
       yp[2] = 17;
       xp[3] = 15;
       yp[3] = 10;
       g.drawPolyline(xp, yp, 4);
       g.drawOval(15, 8, 4, 4);
     }
   }
 }
コード例 #10
0
ファイル: PullResistor.java プロジェクト: pavelfatin/logisim
  private void paintBase(InstancePainter painter, Value pullValue, Color inColor, Color outColor) {
    boolean color = painter.shouldDrawColor();
    Direction facing = painter.getAttributeValue(StdAttr.FACING);
    Graphics g = painter.getGraphics();
    Color baseColor = g.getColor();
    GraphicsUtil.switchToWidth(g, 3);
    if (color && inColor != null) g.setColor(inColor);
    if (facing == Direction.EAST) {
      GraphicsUtil.drawText(
          g, pullValue.toDisplayString(), -32, 0, GraphicsUtil.H_RIGHT, GraphicsUtil.V_CENTER);
    } else if (facing == Direction.WEST) {
      GraphicsUtil.drawText(
          g, pullValue.toDisplayString(), 32, 0, GraphicsUtil.H_LEFT, GraphicsUtil.V_CENTER);
    } else if (facing == Direction.NORTH) {
      GraphicsUtil.drawText(
          g, pullValue.toDisplayString(), 0, 32, GraphicsUtil.H_CENTER, GraphicsUtil.V_TOP);
    } else {
      GraphicsUtil.drawText(
          g, pullValue.toDisplayString(), 0, -32, GraphicsUtil.H_CENTER, GraphicsUtil.V_BASELINE);
    }

    double rotate = 0.0;
    if (g instanceof Graphics2D) {
      rotate = Direction.SOUTH.toRadians() - facing.toRadians();
      if (rotate != 0.0) ((Graphics2D) g).rotate(rotate);
    }
    g.drawLine(0, -30, 0, -26);
    g.drawLine(-6, -30, 6, -30);
    if (color && outColor != null) g.setColor(outColor);
    g.drawLine(0, -4, 0, 0);
    g.setColor(baseColor);
    GraphicsUtil.switchToWidth(g, 2);
    if (painter.getGateShape() == AppPreferences.SHAPE_SHAPED) {
      int[] xp = {0, -5, 5, -5, 5, -5, 0};
      int[] yp = {-25, -23, -19, -15, -11, -7, -5};
      g.drawPolyline(xp, yp, xp.length);
    } else {
      g.drawRect(-5, -25, 10, 20);
    }
    if (rotate != 0.0) {
      ((Graphics2D) g).rotate(-rotate);
    }
  }
コード例 #11
0
ファイル: TransmissionGate.java プロジェクト: r0the/logisim
  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();
  }
コード例 #12
0
ファイル: SelectTool.java プロジェクト: pavelfatin/logisim
  @Override
  public void draw(Canvas canvas, ComponentDrawContext context) {
    Project proj = canvas.getProject();
    int dx = curDx;
    int dy = curDy;
    if (state == MOVING) {
      proj.getSelection().drawGhostsShifted(context, dx, dy);

      MoveGesture gesture = moveGesture;
      if (gesture != null && drawConnections && (dx != 0 || dy != 0)) {
        MoveResult result = gesture.findResult(dx, dy);
        if (result != null) {
          Collection<Wire> wiresToAdd = result.getWiresToAdd();
          Graphics g = context.getGraphics();
          GraphicsUtil.switchToWidth(g, 3);
          g.setColor(Color.GRAY);
          for (Wire w : wiresToAdd) {
            Location loc0 = w.getEnd0();
            Location loc1 = w.getEnd1();
            g.drawLine(loc0.getX(), loc0.getY(), loc1.getX(), loc1.getY());
          }
          GraphicsUtil.switchToWidth(g, 1);
          g.setColor(COLOR_UNMATCHED);
          for (Location conn : result.getUnconnectedLocations()) {
            int connX = conn.getX();
            int connY = conn.getY();
            g.fillOval(connX - 3, connY - 3, 6, 6);
            g.fillOval(connX + dx - 3, connY + dy - 3, 6, 6);
          }
        }
      }
    } else if (state == RECT_SELECT) {
      int left = start.getX();
      int right = left + dx;
      if (left > right) {
        int i = left;
        left = right;
        right = i;
      }
      int top = start.getY();
      int bot = top + dy;
      if (top > bot) {
        int i = top;
        top = bot;
        bot = i;
      }

      Graphics gBase = context.getGraphics();
      int w = right - left - 1;
      int h = bot - top - 1;
      if (w > 2 && h > 2) {
        gBase.setColor(BACKGROUND_RECT_SELECT);
        gBase.fillRect(left + 1, top + 1, w - 1, h - 1);
      }

      Circuit circ = canvas.getCircuit();
      Bounds bds = Bounds.create(left, top, right - left, bot - top);
      for (Component c : circ.getAllWithin(bds)) {
        Location cloc = c.getLocation();
        Graphics gDup = gBase.create();
        context.setGraphics(gDup);
        c.getFactory()
            .drawGhost(context, COLOR_RECT_SELECT, cloc.getX(), cloc.getY(), c.getAttributeSet());
        gDup.dispose();
      }

      gBase.setColor(COLOR_RECT_SELECT);
      GraphicsUtil.switchToWidth(gBase, 2);
      if (w < 0) w = 0;
      if (h < 0) h = 0;
      gBase.drawRect(left, top, w, h);
    }
  }