Package com.cburch.logisim.data

Examples of com.cburch.logisim.data.Bounds


public class MemPoker extends InstancePoker {
  private MemPoker sub;

  @Override
  public boolean init(InstanceState state, MouseEvent event) {
    Bounds bds = state.getInstance().getBounds();
    MemState data = (MemState) state.getData();
    long addr = data.getAddressAt(event.getX() - bds.getX(),
        event.getY() - bds.getY());

    // See if outside box
    if (addr < 0) {
      sub = new AddrPoker();
    } else {
View Full Code Here


  }
 
  @Override
  public void paint(Graphics g, HandleGesture gesture) {
    if (gesture == null) {
      Bounds bds = bounds;
      draw(g, bds.getX(), bds.getY(), bds.getWidth(), bds.getHeight());
    } else {
      Handle[] handles = getHandleArray(gesture);
      Handle p0 = handles[0];
      Handle p1 = handles[2];
      int x0 = p0.getX();
View Full Code Here

  public void paintInstance(InstancePainter painter) {
    Graphics g = painter.getGraphics();
    Direction facing = painter.getAttributeValue(StdAttr.FACING);

    painter.drawBounds();
    Bounds bds = painter.getBounds();
    g.setColor(Color.GRAY);
    int x0;
    int y0;
    int halign;
    if (facing == Direction.WEST) {
      x0 = bds.getX() + bds.getWidth() - 3;
      y0 = bds.getY() + 15;
      halign = GraphicsUtil.H_RIGHT;
    } else if (facing == Direction.NORTH) {
      x0 = bds.getX() + 10;
      y0 = bds.getY() + bds.getHeight() - 2;
      halign = GraphicsUtil.H_CENTER;
    } else if (facing == Direction.SOUTH) {
      x0 = bds.getX() + 10;
      y0 = bds.getY() + 12;
      halign = GraphicsUtil.H_CENTER;
    } else {
      x0 = bds.getX() + 3;
      y0 = bds.getY() + 15;
      halign = GraphicsUtil.H_LEFT;
    }
    GraphicsUtil.drawText(g, "0", x0, y0, halign, GraphicsUtil.V_BASELINE);
    g.setColor(Color.BLACK);
    GraphicsUtil.drawCenteredText(g, "Pri",
        bds.getX() + bds.getWidth() / 2,
        bds.getY() + bds.getHeight() / 2);
    painter.drawPorts();
  }
View Full Code Here

  private void computeTextField(Instance instance) {
    Direction facing = instance.getAttributeValue(StdAttr.FACING);
    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;
View Full Code Here

  public boolean contains(Location loc, boolean assumeFilled) {
    Object type = getPaintType();
    if (assumeFilled && type == DrawAttr.PAINT_STROKE) {
      type = DrawAttr.PAINT_STROKE_FILL;
    }
    Bounds b = bounds;
    int x = b.getX();
    int y = b.getY();
    int w = b.getWidth();
    int h = b.getHeight();
    int qx = loc.getX();
    int qy = loc.getY();
    if (type == DrawAttr.PAINT_FILL) {
      return isInRect(qx, qy, x, y, w, h) && contains(x, y, w, h, loc);
    } else if (type == DrawAttr.PAINT_STROKE) {
View Full Code Here

    }
 
    @Override
    public Bounds getBounds(InstancePainter painter) {
      MemState data = (MemState) painter.getData();
      Bounds inBounds = painter.getInstance().getBounds();
      return data.getBounds(data.getCursor(), inBounds);
    }
View Full Code Here

      return data.getBounds(data.getCursor(), inBounds);
    }
 
    @Override
    public void paint(InstancePainter painter) {
      Bounds bds = getBounds(painter);
      Graphics g = painter.getGraphics();
      g.setColor(Color.RED);
      g.drawRect(bds.getX(), bds.getY(), bds.getWidth(), bds.getHeight());
      g.setColor(Color.BLACK);
    }
View Full Code Here

  }

  @Override
  public void paintInstance(InstancePainter painter) {
    Graphics g = painter.getGraphics();
    Bounds bds = painter.getBounds();

    // draw boundary
    painter.drawBounds();

    // draw contents
    if (painter.getShowState()) {
      MemState state = getState(painter);
      state.paint(painter.getGraphics(), bds.getX(), bds.getY());
    } else {
      BitWidth addr = painter.getAttributeValue(ADDR_ATTR);
      int addrBits = addr.getWidth();
      int bytes = 1 << addrBits;
      String label;
      if (this instanceof Rom) {
        if (addrBits >= 30) {
          label = StringUtil.format(Strings.get("romGigabyteLabel"), ""
              + (bytes >>> 30));
        } else if (addrBits >= 20) {
          label = StringUtil.format(Strings.get("romMegabyteLabel"), ""
              + (bytes >> 20));
        } else if (addrBits >= 10) {
          label = StringUtil.format(Strings.get("romKilobyteLabel"), ""
              + (bytes >> 10));
        } else {
          label = StringUtil.format(Strings.get("romByteLabel"), ""
              + bytes);
        }
      } else {
        if (addrBits >= 30) {
          label = StringUtil.format(Strings.get("ramGigabyteLabel"), ""
              + (bytes >>> 30));
        } else if (addrBits >= 20) {
          label = StringUtil.format(Strings.get("ramMegabyteLabel"), ""
              + (bytes >> 20));
        } else if (addrBits >= 10) {
          label = StringUtil.format(Strings.get("ramKilobyteLabel"), ""
              + (bytes >> 10));
        } else {
          label = StringUtil.format(Strings.get("ramByteLabel"), ""
              + bytes);
        }
      }
      GraphicsUtil.drawCenteredText(g, label, bds.getX() + bds.getWidth()
          / 2, bds.getY() + bds.getHeight() / 2);
    }

    // draw input and output ports
    painter.drawPort(DATA, Strings.get("ramDataLabel"), Direction.WEST);
    painter.drawPort(ADDR, Strings.get("ramAddrLabel"), Direction.EAST);
View Full Code Here

        dispStart = state.getDisplayStart();
        dispEnd = state.getDisplayEnd();
      }
     
      if (str.length() > 0) {
        Bounds bds = painter.getBounds();
        drawBuffer(g, fm, str, dispStart, dispEnd, specials, bds);
      }
    } else {
      Bounds bds = painter.getBounds();
      int len = getBufferLength(painter.getAttributeValue(ATTR_BUFFER));
      String str = Strings.get("keybDesc", "" + len);
      FontMetrics fm = g.getFontMetrics();
      int x = bds.getX() + (WIDTH - fm.stringWidth(str)) / 2;
      int y = bds.getY() + (HEIGHT + fm.getAscent()) / 2;
      g.drawString(str, x, y);
    }
  }
View Full Code Here

    setPorts(ps);
  }
 
  @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);
  }
View Full Code Here

TOP

Related Classes of com.cburch.logisim.data.Bounds

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.