Package com.cburch.logisim.data

Examples of com.cburch.logisim.data.Location


      State state = (State) painter.getData();
      if (state == null) {
        state = new State(0, 0);
        painter.setData(state);
      }
      Location loc = painter.getLocation();
      int x = loc.getX();
      int y = loc.getY();
      Graphics g = painter.getGraphics();
      g.setColor(Color.WHITE);
      g.fillRect(x - 20, y, 10, 10);
      GraphicsUtil.switchToWidth(g, 3);
      g.setColor(Color.BLACK);
View Full Code Here


  private void setMouse(Canvas canvas, int mx, int my, int mods) {
    lastMouseX = mx;
    lastMouseY = my;
    boolean shift = (mods & MouseEvent.SHIFT_DOWN_MASK) != 0;
    boolean ctrl = (mods & InputEvent.CTRL_DOWN_MASK) != 0;
    Location newEnd = Location.create(mx, my);
    dragEnd = newEnd;

    Location start = dragStart;
    int dx = newEnd.getX() - start.getX();
    int dy = newEnd.getY() - start.getY();
    if (!dragEffective) {
      if (Math.abs(dx) + Math.abs(dy) > DRAG_TOLERANCE) {
        dragEffective = true;
      } else {
        return;
View Full Code Here

  @Override
  public void draw(Canvas canvas, Graphics g) {
    Selection selection = canvas.getSelection();
    int action = curAction;

    Location start = dragStart;
    Location end = dragEnd;
    HandleGesture gesture = null;
    boolean drawHandles;
    switch (action) {
    case MOVE_ALL:
      drawHandles = !dragEffective;
      break;
    case MOVE_HANDLE:
      drawHandles = !dragEffective;
      if (dragEffective) gesture = curGesture;
      break;
    default:
      drawHandles = true;
    }

    CanvasObject moveHandleObj = null;
    if (gesture != null) moveHandleObj = gesture.getHandle().getObject();
    if (drawHandles) {
      // unscale the coordinate system so that the stroke width isn't scaled
      double zoom = 1.0;
      Graphics gCopy = g.create();
      if (gCopy instanceof Graphics2D) {
        zoom = canvas.getZoomFactor();
        if (zoom != 1.0) {
          ((Graphics2D) gCopy).scale(1.0 / zoom, 1.0 / zoom);
        }
      }
      GraphicsUtil.switchToWidth(gCopy, 1);

      int size = (int) Math.ceil(HANDLE_SIZE * Math.sqrt(zoom));
      int offs = size / 2;
      for (CanvasObject obj : selection.getSelected()) {
        List<Handle> handles;
        if (action == MOVE_HANDLE && obj == moveHandleObj) {
          handles = obj.getHandles(gesture);
        } else {
          handles = obj.getHandles(null);
        }
        for (Handle han : handles) {
          int x = han.getX();
          int y = han.getY();
          if (action == MOVE_ALL && dragEffective) {
            Location delta = selection.getMovingDelta();
            x += delta.getX();
            y += delta.getY();
          }
          x = (int) Math.round(zoom * x);
          y = (int) Math.round(zoom * y);
          gCopy.clearRect(x - offs, y - offs, size, size);
          gCopy.drawRect(x - offs, y - offs, size, size);
        }
      }
      Handle selHandle = selection.getSelectedHandle();
      if (selHandle != null) {
        int x = selHandle.getX();
        int y = selHandle.getY();
        if (action == MOVE_ALL && dragEffective) {
          Location delta = selection.getMovingDelta();
          x += delta.getX();
          y += delta.getY();
        }
        x = (int) Math.round(zoom * x);
        y = (int) Math.round(zoom * y);
        int[] xs = { x - offs, x, x + offs, x };
        int[] ys = { y, y - offs, y, y + offs };
View Full Code Here

    }
  }

  private static CanvasObject getObjectAt(CanvasModel model, int x, int y,
      boolean assumeFilled) {
    Location loc = Location.create(x, y);
    for (CanvasObject o : model.getObjectsFromTop()) {
      if (o.contains(loc, assumeFilled)) return o;
    }
    return null;
  }
View Full Code Here

    if (groups > 0) {
      while (groups != 1) { groups >>= 1; selectBits++; }
    }
    BitWidth select = BitWidth.create(selectBits);

    Location inPt;
    Location selPt;
    if (facing == Direction.WEST) {
      inPt  = Location.create(30, 0);
      selPt = Location.create(10, 10);
    } else if (facing == Direction.NORTH) {
      inPt  = Location.create0, 30);
      selPt = Location.create(-10, 10);
    } else if (facing == Direction.SOUTH) {
      inPt  = Location.create0, -30);
      selPt = Location.create(-10, -10);
    } else {
      inPt  = Location.create(-30, 0);
      selPt = Location.create(-10, 10);
    }
   
    Port[] ps = new Port[3];
    ps[0] = new Port(0, 0, Port.OUTPUT, group.getWidth());
    ps[1] = new Port(inPt.getX(), inPt.getY(), Port.INPUT, data.getWidth());
    ps[2] = new Port(selPt.getX(), selPt.getY(), Port.INPUT, select.getWidth());
    ps[0].setToolTip(Strings.getter("bitSelectorOutputTip"));
    ps[1].setToolTip(Strings.getter("bitSelectorDataTip"));
    ps[2].setToolTip(Strings.getter("bitSelectorSelectTip"));
    instance.setPorts(ps);
  }
View Full Code Here

    Direction facing = instance.getAttributeValue(StdAttr.FACING);
    int dx = size == SIZE_NARROW ? -20 : -30;

    Port[] ports = new Port[2];
    ports[0] = new Port(0, 0, Port.OUTPUT, StdAttr.WIDTH);
    Location out = Location.create(0, 0).translate(facing, dx);
    ports[1] = new Port(out.getX(), out.getY(), Port.INPUT, StdAttr.WIDTH);
    instance.setPorts(ports);
  }
View Full Code Here

    Graphics g = painter.getGraphics();
    painter.drawBounds();
    painter.drawPorts();
   
    GraphicsUtil.switchToWidth(g, 2);
    Location loc = painter.getLocation();
    int x = loc.getX() - 10;
    int y = loc.getY();
    g.drawLine(x - 2, y - 5, x - 2, y + 5);
    g.drawLine(x + 2, y - 5, x + 2, y + 5);
    g.drawLine(x - 5, y - 2, x + 5, y - 2);
    g.drawLine(x - 5, y + 2, x + 5, y + 2);
  }
View Full Code Here

  }

  private void paintBase(InstancePainter painter) {
    Graphics g = painter.getGraphics();
    Direction facing = painter.getAttributeValue(StdAttr.FACING);
    Location loc = painter.getLocation();
    int x = loc.getX();
    int y = loc.getY();
    g.translate(x, y);
    double rotate = 0.0;
    if (facing != null && facing != Direction.EAST && g instanceof Graphics2D) {
      rotate = -facing.toRadians();
      ((Graphics2D) g).rotate(rotate);
View Full Code Here

    return "w" + from + "-" + to;
  }

  void addWire(Circuit dest, CircuitMutator mutator, Element elt)
      throws XmlReaderException {
    Location pt0;
    try {
      String str = elt.getAttribute("from");
      if (str == null || str.equals("")) {
        throw new XmlReaderException(Strings.get("wireStartMissingError"));
      }
      pt0 = Location.parse(str);
    } catch (NumberFormatException e) {
      throw new XmlReaderException(Strings.get("wireStartInvalidError"));
    }

    Location pt1;
    try {
      String str = elt.getAttribute("to");
      if (str == null || str.equals("")) {
        throw new XmlReaderException(Strings.get("wireEndMissingError"));
      }
View Full Code Here

    // Create component if location known
    if (loc_str == null || loc_str.equals("")) {
      throw new XmlReaderException(Strings.get("compLocMissingError", source.getName()));
    } else {
      try {
        Location loc = Location.parse(loc_str);
        return source.createComponent(loc, attrs);
      } catch (NumberFormatException e) {
        throw new XmlReaderException(Strings.get("compLocInvalidError",
          source.getName(), loc_str));
      }
View Full Code Here

TOP

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

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.