Examples of Bounds


Examples of com.cburch.logisim.data.Bounds

  @Override
  public Bounds getOffsetBounds(AttributeSet attrs) {
    Direction facing = attrs.getValue(StdAttr.FACING);
    BitWidth select = attrs.getValue(Plexers.ATTR_SELECT);
    int outputs = 1 << select.getWidth();
    Bounds bds;
    if (outputs == 2) {
      bds = Bounds.create(0, -20, 30, 40);
    } else {
      bds = Bounds.create(0, -(outputs / 2) * 10 - 10,
          40, outputs * 10 + 20);
    }
    return bds.rotate(Direction.EAST, facing, 0, 0);
  }
View Full Code Here

Examples of com.cburch.logisim.data.Bounds

  }

  @Override
  public void paintInstance(InstancePainter painter) {
    Graphics g = painter.getGraphics();
    Bounds bds = painter.getBounds();
    Direction facing = painter.getAttributeValue(StdAttr.FACING);
    BitWidth select = painter.getAttributeValue(Plexers.ATTR_SELECT);
    boolean enable = painter.getAttributeValue(Plexers.ATTR_ENABLE).booleanValue();
    int outputs = 1 << select.getWidth();

    // draw select and enable inputs
    GraphicsUtil.switchToWidth(g, 3);
    boolean vertical = facing == Direction.NORTH || facing == Direction.SOUTH;
    Object selectLoc = painter.getAttributeValue(Plexers.ATTR_SELECT_LOC);
    int selMult = selectLoc == Plexers.SELECT_BOTTOM_LEFT ? 1 : -1;
    int dx = vertical ? selMult : 0;
    int dy = vertical ? 0 : -selMult;
    if (outputs == 2) { // draw select wire
      Location sel = painter.getInstance().getPortLocation(outputs);
      if (painter.getShowState()) {
        g.setColor(painter.getPort(outputs).getColor());
      }
      g.drawLine(sel.getX(), sel.getY(), sel.getX() + 2 * dx, sel.getY() + 2 * dy);
    }
    if (enable) {
      Location en = painter.getInstance().getPortLocation(outputs + 1);
      if (painter.getShowState()) {
        g.setColor(painter.getPort(outputs + 1).getColor());
      }
      int len = outputs == 2 ? 6 : 4;
      g.drawLine(en.getX(), en.getY(), en.getX() + len * dx, en.getY() + len * dy);
    }
    GraphicsUtil.switchToWidth(g, 1);
   
    // draw a circle indicating where the select input is located
    Multiplexer.drawSelectCircle(g, bds, painter.getInstance().getPortLocation(outputs));

    // draw "0" next to first input
    int x0;
    int y0;
    int halign;
    if (facing == Direction.WEST) {
      x0 = 3;
      y0 = 15;
      halign = GraphicsUtil.H_LEFT;
    } else if (facing == Direction.NORTH) {
      x0 = 10;
      y0 = 15;
      halign = GraphicsUtil.H_CENTER;
    } else if (facing == Direction.SOUTH) {
      x0 = 10;
      y0 = bds.getHeight() - 3;
      halign = GraphicsUtil.H_CENTER;
    } else {
      x0 = bds.getWidth() - 3;
      y0 = 15;
      halign = GraphicsUtil.H_RIGHT;
    }
    g.setColor(Color.GRAY);
    GraphicsUtil.drawText(g, "0", bds.getX() + x0, bds.getY() + y0,
        halign, GraphicsUtil.V_BASELINE);

    // draw trapezoid, "DMX" label, and ports
    g.setColor(Color.BLACK);
    Plexers.drawTrapezoid(g, bds, facing.reverse(), select.getWidth() == 1 ? 10 : 20);
    GraphicsUtil.drawCenteredText(g, "DMX",
        bds.getX() + bds.getWidth() / 2,
        bds.getY() + bds.getHeight() / 2);
    painter.drawPorts();
  }
View Full Code Here

Examples of com.cburch.logisim.data.Bounds

    }
  }

  private void configurePorts(Instance instance) {
    Direction facing = instance.getAttributeValue(StdAttr.FACING);
    Bounds bds = getOffsetBounds(instance.getAttributeSet());
    int d = Math.max(bds.getWidth(), bds.getHeight()) - 20;
    Location loc0 = Location.create(0, 0);
    Location loc1 = loc0.translate(facing.reverse(), 20 + d);
    Location loc2;
    if (instance.getAttributeValue(ATTR_CONTROL) == LEFT_HANDED) {
      loc2 = loc0.translate(facing.reverse(), 10 + d, 10);
View Full Code Here

Examples of com.cburch.logisim.data.Bounds

    InstanceDataSingleton data = (InstanceDataSingleton) painter.getData();
    int summ = (data == null ? 0 : ((Integer) data.getValue()).intValue());
    Boolean active = painter.getAttributeValue(Io.ATTR_ACTIVE);
    int desired = active == null || active.booleanValue() ? 1 : 0;
   
    Bounds bds = painter.getBounds();
    int x = bds.getX() + 5;
    int y = bds.getY();

    Graphics g = painter.getGraphics();
    Color onColor = painter.getAttributeValue(Io.ATTR_ON_COLOR);
    Color offColor = painter.getAttributeValue(Io.ATTR_OFF_COLOR);
    Color bgColor = painter.getAttributeValue(Io.ATTR_BACKGROUND);
    if (painter.shouldDrawColor() && bgColor.getAlpha() != 0) {
      g.setColor(bgColor);
      g.fillRect(bds.getX(), bds.getY(), bds.getWidth(), bds.getHeight());
      g.setColor(Color.BLACK);
    }
    painter.drawBounds();
    g.setColor(Color.DARK_GRAY);
    for (int i = 0; i <= 7; i++) {
      if (painter.getShowState()) {
        g.setColor(((summ >> i) & 1) == desired ? onColor : offColor);
      }
      if (i < 7) {
        Bounds seg = SEGMENTS[i];
        g.fillRect(x + seg.getX(), y + seg.getY(), seg.getWidth(), seg.getHeight());
      } else {
        g.fillOval(x + 28, y + 48, 5, 5); // draw decimal point
      }
    }
    painter.drawPorts();
View Full Code Here

Examples of com.cburch.logisim.data.Bounds

    return Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR);
  }
 
  @Override
  public void toolDeselected(Canvas canvas) {
    Bounds bds = currentBounds;
    active = false;
    repaintArea(canvas, bds);
  }
View Full Code Here

Examples of com.cburch.logisim.data.Bounds

  }
 
  @Override
  public void mousePressed(Canvas canvas, MouseEvent e) {
    Location loc = Location.create(e.getX(), e.getY());
    Bounds bds = Bounds.create(loc);
    dragStart = loc;
    lastMouseX = loc.getX();
    lastMouseY = loc.getY();
    active = canvas.getModel() != null;
    repaintArea(canvas, bds);
View Full Code Here

Examples of com.cburch.logisim.data.Bounds

  }
 
  @Override
  public void mouseReleased(Canvas canvas, MouseEvent e) {
    if (active) {
      Bounds oldBounds = currentBounds;
      Bounds bds = computeBounds(canvas, e.getX(), e.getY(), e.getModifiersEx());
      currentBounds = Bounds.EMPTY_BOUNDS;
      active = false;
      CanvasObject add = null;
      if (bds.getWidth() != 0 && bds.getHeight() != 0) {
        CanvasModel model = canvas.getModel();
        add = createShape(bds.getX(), bds.getY(),
            bds.getWidth(), bds.getHeight());
        canvas.doAction(new ModelAddAction(model, add));
        repaintArea(canvas, oldBounds.add(bds));
      }
      canvas.toolGestureComplete(this, add);
    }
View Full Code Here

Examples of com.cburch.logisim.data.Bounds

  public void keyReleased(Canvas canvas, KeyEvent e) {
    keyPressed(canvas, e);
  }
 
  private void updateMouse(Canvas canvas, int mx, int my, int mods) {
    Bounds oldBounds = currentBounds;
    Bounds bds = computeBounds(canvas, mx, my, mods);
    if (!bds.equals(oldBounds)) {
      currentBounds = bds;
      repaintArea(canvas, oldBounds.add(bds));
    }
  }
View Full Code Here

Examples of com.cburch.logisim.data.Bounds

     */
  }
 
  @Override
  public void draw(Canvas canvas, Graphics g) {
    Bounds bds = currentBounds;
    if (active && bds != null && bds != Bounds.EMPTY_BOUNDS) {
      g.setColor(Color.GRAY);
      drawShape(g, bds.getX(), bds.getY(), bds.getWidth(), bds.getHeight());
    }
  }
View Full Code Here

Examples of com.cburch.logisim.data.Bounds

  public List<Handle> getHandles(HandleGesture gesture) {
    return UnmodifiableList.create(getHandleArray(gesture));
  }
   
  private Handle[] getHandleArray(HandleGesture gesture) {
    Bounds bds = bounds;
    int x0 = bds.getX();
    int y0 = bds.getY();
    int x1 = x0 + bds.getWidth();
    int y1 = y0 + bds.getHeight();
    if (gesture == null) {
      return new Handle[] { new Handle(this, x0, y0),
          new Handle(this, x1, y0), new Handle(this, x1, y1),
          new Handle(this, x0, y1) };
    } else {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.