コード例 #1
0
ファイル: AbstractGate.java プロジェクト: EricStudley/logisim
  Location getInputOffset(GateAttributes attrs, int index) {
    int inputs = attrs.inputs;
    Direction facing = attrs.facing;
    int size = ((Integer) attrs.size.getValue()).intValue();
    int axisLength = size + bonusWidth + (negateOutput ? 10 : 0);
    int negated = attrs.negated;

    int skipStart;
    int skipDist;
    int skipLowerEven = 10;
    if (inputs <= 3) {
      if (size < 40) {
        skipStart = -5;
        skipDist = 10;
        skipLowerEven = 10;
      } else if (size < 60 || inputs <= 2) {
        skipStart = -10;
        skipDist = 20;
        skipLowerEven = 20;
      } else {
        skipStart = -15;
        skipDist = 30;
        skipLowerEven = 30;
      }
    } else if (inputs == 4 && size >= 60) {
      skipStart = -5;
      skipDist = 20;
      skipLowerEven = 0;
    } else {
      skipStart = -5;
      skipDist = 10;
      skipLowerEven = 10;
    }

    int dy;
    if ((inputs & 1) == 1) {
      dy = skipStart * (inputs - 1) + skipDist * index;
    } else {
      dy = skipStart * inputs + skipDist * index;
      if (index >= inputs / 2) {
        dy += skipLowerEven;
      }
    }

    int dx = axisLength;
    int negatedBit = (negated >> index) & 1;
    if (negatedBit == 1) {
      dx += 10;
    }

    if (facing == Direction.NORTH) {
      return Location.create(dy, dx);
    } else if (facing == Direction.SOUTH) {
      return Location.create(dy, -dx);
    } else if (facing == Direction.WEST) {
      return Location.create(dx, dy);
    } else {
      return Location.create(-dx, dy);
    }
  }
コード例 #2
0
ファイル: LineTool.java プロジェクト: pavelfatin/logisim
  private void updateMouse(Canvas canvas, int mx, int my, int mods) {
    if (active) {
      boolean shift = (mods & MouseEvent.SHIFT_DOWN_MASK) != 0;
      Location newEnd;
      if (shift) {
        newEnd = LineUtil.snapTo8Cardinals(mouseStart, mx, my);
      } else {
        newEnd = Location.create(mx, my);
      }

      if ((mods & InputEvent.CTRL_DOWN_MASK) != 0) {
        int x = newEnd.getX();
        int y = newEnd.getY();
        x = canvas.snapX(x);
        y = canvas.snapY(y);
        newEnd = Location.create(x, y);
      }

      if (!newEnd.equals(mouseEnd)) {
        mouseEnd = newEnd;
        repaintArea(canvas);
      }
    }
    lastMouseX = mx;
    lastMouseY = my;
  }
コード例 #3
0
ファイル: LineTool.java プロジェクト: pavelfatin/logisim
 static Location snapTo4Cardinals(Location from, int mx, int my) {
   int px = from.getX();
   int py = from.getY();
   if (mx != px && my != py) {
     if (Math.abs(my - py) < Math.abs(mx - px)) {
       return Location.create(mx, py);
     } else {
       return Location.create(px, my);
     }
   }
   return Location.create(mx, my); // should never happen
 }
コード例 #4
0
 public static AbstractCanvasObject createShape(Element elt, Map<Location, Instance> pins) {
   String name = elt.getTagName();
   if (name.equals("circ-anchor") || name.equals("circ-origin")) {
     Location loc = getLocation(elt);
     AbstractCanvasObject ret = new AppearanceAnchor(loc);
     if (elt.hasAttribute("facing")) {
       Direction facing = Direction.parse(elt.getAttribute("facing"));
       ret.setValue(AppearanceAnchor.FACING, facing);
     }
     return ret;
   } else if (name.equals("circ-port")) {
     Location loc = getLocation(elt);
     String[] pinStr = elt.getAttribute("pin").split(",");
     Location pinLoc =
         Location.create(Integer.parseInt(pinStr[0].trim()), Integer.parseInt(pinStr[1].trim()));
     Instance pin = pins.get(pinLoc);
     if (pin == null) {
       return null;
     } else {
       return new AppearancePort(loc, pin);
     }
   } else {
     return SvgReader.createShape(elt);
   }
 }
コード例 #5
0
ファイル: SelectTool.java プロジェクト: pavelfatin/logisim
  @Override
  public void mousePressed(Canvas canvas, Graphics g, MouseEvent e) {
    Project proj = canvas.getProject();
    Selection sel = proj.getSelection();
    Circuit circuit = canvas.getCircuit();
    start = Location.create(e.getX(), e.getY());
    curDx = 0;
    curDy = 0;
    moveGesture = null;

    // if the user clicks into the selection,
    // selection is being modified
    Collection<Component> in_sel = sel.getComponentsContaining(start, g);
    if (!in_sel.isEmpty()) {
      if ((e.getModifiers() & InputEvent.SHIFT_MASK) == 0) {
        setState(proj, MOVING);
        proj.repaintCanvas();
        return;
      } else {
        Action act = SelectionActions.drop(sel, in_sel);
        if (act != null) {
          proj.doAction(act);
        }
      }
    }

    // if the user clicks into a component outside selection, user
    // wants to add/reset selection
    Collection<Component> clicked = circuit.getAllContaining(start, g);
    if (!clicked.isEmpty()) {
      if ((e.getModifiers() & InputEvent.SHIFT_MASK) == 0) {
        if (sel.getComponentsContaining(start).isEmpty()) {
          Action act = SelectionActions.dropAll(sel);
          if (act != null) {
            proj.doAction(act);
          }
        }
      }
      for (Component comp : clicked) {
        if (!in_sel.contains(comp)) {
          sel.add(comp);
        }
      }
      setState(proj, MOVING);
      proj.repaintCanvas();
      return;
    }

    // The user clicked on the background. This is a rectangular
    // selection (maybe with the shift key down).
    if ((e.getModifiers() & InputEvent.SHIFT_MASK) == 0) {
      Action act = SelectionActions.dropAll(sel);
      if (act != null) {
        proj.doAction(act);
      }
    }
    setState(proj, RECT_SELECT);
    proj.repaintCanvas();
  }
コード例 #6
0
 private static Location getLocation(Element elt) {
   double x = Double.parseDouble(elt.getAttribute("x"));
   double y = Double.parseDouble(elt.getAttribute("y"));
   double w = Double.parseDouble(elt.getAttribute("width"));
   double h = Double.parseDouble(elt.getAttribute("height"));
   int px = (int) Math.round(x + w / 2);
   int py = (int) Math.round(y + h / 2);
   return Location.create(px, py);
 }
コード例 #7
0
ファイル: TransmissionGate.java プロジェクト: r0the/logisim
 @Override
 public boolean contains(Location loc, AttributeSet attrs) {
   if (super.contains(loc, attrs)) {
     Direction facing = attrs.getValue(StdAttr.FACING);
     Location center = Location.create(0, 0).translate(facing, -20);
     return center.manhattanDistanceTo(loc) < 24;
   } else {
     return false;
   }
 }
コード例 #8
0
ファイル: SvgReader.java プロジェクト: sivart73/Brandonsim
 private static List<Location> parsePoints(String points) {
   Pattern patt = Pattern.compile("[ ,\n\r\t]+");
   String[] toks = patt.split(points);
   Location[] ret = new Location[toks.length / 2];
   for (int i = 0; i < ret.length; i++) {
     int x = Integer.parseInt(toks[2 * i]);
     int y = Integer.parseInt(toks[2 * i + 1]);
     ret[i] = Location.create(x, y);
   }
   return UnmodifiableList.create(ret);
 }
コード例 #9
0
ファイル: NotGate.java プロジェクト: pavelfatin/logisim
  private void configurePorts(Instance instance) {
    Object size = instance.getAttributeValue(ATTR_SIZE);
    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);
  }
コード例 #10
0
ファイル: LineTool.java プロジェクト: pavelfatin/logisim
 @Override
 public void mousePressed(Canvas canvas, MouseEvent e) {
   int x = e.getX();
   int y = e.getY();
   int mods = e.getModifiersEx();
   if ((mods & InputEvent.CTRL_DOWN_MASK) != 0) {
     x = canvas.snapX(x);
     y = canvas.snapY(y);
   }
   Location loc = Location.create(x, y);
   mouseStart = loc;
   mouseEnd = loc;
   lastMouseX = loc.getX();
   lastMouseY = loc.getY();
   active = canvas.getModel() != null;
   repaintArea(canvas);
 }
コード例 #11
0
 public void mousePressed(MouseEvent e) {
   long sincePopup = System.currentTimeMillis() - curPopupTime;
   if (sincePopup > 50) hideCurrentPopup();
   dragStart = Location.create(e.getX(), e.getY());
 }
コード例 #12
0
ファイル: SvgReader.java プロジェクト: sivart73/Brandonsim
  private static AbstractCanvasObject createPath(Element elt) {
    Matcher patt = PATH_REGEX.matcher(elt.getAttribute("d"));
    List<String> tokens = new ArrayList<String>();
    int type = -1; // -1 error, 0 start, 1 curve, 2 polyline
    while (patt.find()) {
      String token = patt.group();
      tokens.add(token);
      if (Character.isLetter(token.charAt(0))) {
        switch (token.charAt(0)) {
          case 'M':
            if (type == -1) type = 0;
            else type = -1;
            break;
          case 'Q':
          case 'q':
            if (type == 0) type = 1;
            else type = -1;
            break;
            /* not supported
            case 'L': case 'l':
            case 'H': case 'h':
            case 'V': case 'v':
            	if (type == 0 || type == 2) type = 2;
            	else type = -1;
            	break;
            */
          default:
            type = -1;
        }
        if (type == -1) {
          throw new NumberFormatException("Unrecognized path command '" + token.charAt(0) + "'");
        }
      }
    }

    if (type == 1) {
      if (tokens.size() == 8
          && tokens.get(0).equals("M")
          && tokens.get(3).toUpperCase().equals("Q")) {
        int x0 = Integer.parseInt(tokens.get(1));
        int y0 = Integer.parseInt(tokens.get(2));
        int x1 = Integer.parseInt(tokens.get(4));
        int y1 = Integer.parseInt(tokens.get(5));
        int x2 = Integer.parseInt(tokens.get(6));
        int y2 = Integer.parseInt(tokens.get(7));
        if (tokens.get(3).equals("q")) {
          x1 += x0;
          y1 += y0;
          x2 += x0;
          y2 += y0;
        }
        Location e0 = Location.create(x0, y0);
        Location e1 = Location.create(x2, y2);
        Location ct = Location.create(x1, y1);
        return new Curve(e0, e1, ct);
      } else {
        throw new NumberFormatException("Unexpected format for curve");
      }
    } else {
      throw new NumberFormatException("Unrecognized path");
    }
  }
コード例 #13
0
ファイル: Selection.java プロジェクト: IsThisSparta/Logisim
 public Location getMovingDelta() {
   return Location.create(moveDx, moveDy);
 }
コード例 #14
0
ファイル: TextTool.java プロジェクト: pavelfatin/logisim
  @Override
  public void mousePressed(Canvas canvas, Graphics g, MouseEvent e) {
    Project proj = canvas.getProject();
    Circuit circ = canvas.getCircuit();

    if (!proj.getLogisimFile().contains(circ)) {
      if (caret != null) caret.cancelEditing();
      canvas.setErrorMessage(Strings.getter("cannotModifyError"));
      return;
    }

    // Maybe user is clicking within the current caret.
    if (caret != null) {
      if (caret.getBounds(g).contains(e.getX(), e.getY())) { // Yes
        caret.mousePressed(e);
        proj.repaintCanvas();
        return;
      } else { // No. End the current caret.
        caret.stopEditing();
      }
    }
    // caret will be null at this point

    // Otherwise search for a new caret.
    int x = e.getX();
    int y = e.getY();
    Location loc = Location.create(x, y);
    ComponentUserEvent event = new ComponentUserEvent(canvas, x, y);

    // First search in selection.
    for (Component comp : proj.getSelection().getComponentsContaining(loc, g)) {
      TextEditable editable = (TextEditable) comp.getFeature(TextEditable.class);
      if (editable != null) {
        caret = editable.getTextCaret(event);
        if (caret != null) {
          proj.getFrame().viewComponentAttributes(circ, comp);
          caretComponent = comp;
          caretCreatingText = false;
          break;
        }
      }
    }

    // Then search in circuit
    if (caret == null) {
      for (Component comp : circ.getAllContaining(loc, g)) {
        TextEditable editable = (TextEditable) comp.getFeature(TextEditable.class);
        if (editable != null) {
          caret = editable.getTextCaret(event);
          if (caret != null) {
            proj.getFrame().viewComponentAttributes(circ, comp);
            caretComponent = comp;
            caretCreatingText = false;
            break;
          }
        }
      }
    }

    // if nothing found, create a new label
    if (caret == null) {
      if (loc.getX() < 0 || loc.getY() < 0) return;
      AttributeSet copy = (AttributeSet) attrs.clone();
      caretComponent = Text.FACTORY.createComponent(loc, copy);
      caretCreatingText = true;
      TextEditable editable = (TextEditable) caretComponent.getFeature(TextEditable.class);
      if (editable != null) {
        caret = editable.getTextCaret(event);
        proj.getFrame().viewComponentAttributes(circ, caretComponent);
      }
    }

    if (caret != null) {
      caretCanvas = canvas;
      caretCircuit = canvas.getCircuit();
      caret.addCaretListener(listener);
      caretCircuit.addCircuitListener(listener);
    }
    proj.repaintCanvas();
  }
コード例 #15
0
 public Location getLocation() {
   InstanceComponent c = comp;
   return c == null ? Location.create(0, 0) : c.getLocation();
 }
コード例 #16
0
ファイル: Handle.java プロジェクト: sivart73/Brandonsim
 public Location getLocation() {
   return Location.create(x, y);
 }