Пример #1
0
 boolean touches(Block b, int x, int y) {
   DrawFBP.Side side = null;
   if (driver.nearpln(
       x, y, b.cx - b.width / 2, b.cy - b.height / 2, b.cx - b.width / 2, b.cy + b.height / 2)) {
     side = Side.LEFT;
   }
   if (driver.nearpln(
       x, y, b.cx - b.width / 2, b.cy - b.height / 2, b.cx + b.width / 2, b.cy - b.height / 2)) {
     side = Side.TOP;
   }
   if (driver.nearpln(
       x, y, b.cx + b.width / 2, b.cy - b.height / 2, b.cx + b.width / 2, b.cy + b.height / 2)) {
     side = Side.RIGHT;
   }
   if (driver.nearpln(
       x, y, b.cx - b.width / 2, b.cy + b.height / 2, b.cx + b.width / 2, b.cy + b.height / 2)) {
     side = Side.BOTTOM;
   }
   if (side != null) {
     if (tailMarked) fromSide = side;
     if (headMarked) toSide = side;
     return true;
   }
   return false;
 }
Пример #2
0
  void createBend(int bendx, int bendy) {
    Bend bn = null;
    int index = 0;
    if (bends == null) {
      if (driver.nearpln(bendx, bendy, fromX, fromY, toX, toY)) {
        bends = new LinkedList<Bend>();
        bn = new Bend(bendx, bendy);
        if (fromX == toX) // if line vertical
        bn.x = fromX;
        if (fromY == toY) // if line horizontal
        bn.y = fromY;
        bends.add(bn);
        bn.marked = true;
        driver.bendForDragging = bn;
        return;
      }
    } else {
      int x = fromX;
      int y = fromY;
      Object[] oa = bends.toArray();
      for (Object o : oa) {
        Bend b = (Bend) o;
        if (sameBend(bendx, bendy, b)) {
          bn = b;
          bn.marked = true;
          driver.bendForDragging = bn;
          return;
        }
        if (driver.nearpln(bendx, bendy, x, y, b.x, b.y)) {
          bn = new Bend(bendx, bendy);
          if (x == b.x) // if line vertical
          bn.x = x;
          if (y == b.y) // if line horizontal
          bn.y = y;
          bends.add(index, bn);
          bn.marked = true;
          driver.bendForDragging = bn;
          return;
        }
        x = b.x;
        y = b.y;
        index++;
      }

      if (driver.nearpln(bendx, bendy, x, y, toX, toY)) {
        bn = new Bend(bendx, bendy);
        if (x == toX) // if line vertical
        bn.x = x;
        if (y == toY) // if line horizontal
        bn.y = y;
        bends.add(bn);
        bn.marked = true;
        driver.bendForDragging = bn;
      }
    }
  }