Package com.cburch.draw.model

Examples of com.cburch.draw.model.Handle


  @Override
  public void translate(int dx, int dy) {
    Handle[] hs = handles;
    Handle[] is = new Handle[hs.length];
    for(int i = 0; i < hs.length; i++) {
      is[i] = new Handle(this, hs[i].getX() + dx, hs[i].getY() + dy);
    }
    setHandles(is);
  }
View Full Code Here


  public List<Handle> getHandles(HandleGesture gesture) {
    Handle[] hs = handles;
    if (gesture == null) {
      return UnmodifiableList.create(hs);
    } else {
      Handle g = gesture.getHandle();
      Handle[] ret = new Handle[hs.length];
      for (int i = 0, n = hs.length; i < n; i++) {
        Handle h = hs[i];
        if (h.equals(g)) {
          int x = h.getX() + gesture.getDeltaX();
          int y = h.getY() + gesture.getDeltaY();
          Location r;
          if (gesture.isShiftDown()) {
            Location prev = hs[(i + n - 1) % n].getLocation();
            Location next = hs[(i + 1) % n].getLocation();
            if (!closed) {
              if (i == 0) prev = null;
              if (i == n - 1) next = null;
            }
            if (prev == null) {
              r = LineUtil.snapTo8Cardinals(next, x, y);
            } else if (next == null) {
              r = LineUtil.snapTo8Cardinals(prev, x, y);
            } else {
              Location to = Location.create(x, y);
              Location a = LineUtil.snapTo8Cardinals(prev, x, y);
              Location b = LineUtil.snapTo8Cardinals(next, x, y);
              int ad = a.manhattanDistanceTo(to);
              int bd = b.manhattanDistanceTo(to);
              r = ad < bd ? a : b;
            }
          } else {
            r = Location.create(x, y);
          }
          ret[i] = new Handle(this, r);
        } else {
          ret[i] = h;
        }
      }
      return UnmodifiableList.create(ret);
View Full Code Here

  @Override
  public Handle moveHandle(HandleGesture gesture) {
    List<Handle> hs = getHandles(gesture);
    Handle[] is = new Handle[hs.size()];
    Handle ret = null;
    int i = -1;
    for (Handle h : hs) {
      i++;
      is[i] = h;
    }
View Full Code Here

      Location resLoc = result.getLocation();
      if (result.getPreviousHandle().isAt(resLoc)
          || result.getNextHandle().isAt(resLoc)) {
        return null;
      } else {
        return new Handle(this, result.getLocation());
      }
    } else {
      return null;
    }
  }
View Full Code Here

 
  @Override
  public void insertHandle(Handle desired, Handle previous) {
    Location loc = desired.getLocation();
    Handle[] hs = handles;
    Handle prev;
    if (previous == null) {
      PolyUtil.ClosestResult result = PolyUtil.getClosestPoint(loc,
          closed, hs);
      prev = result.getPreviousHandle();
    } else {
View Full Code Here

  @Override
  public Handle deleteHandle(Handle handle) {
    Handle[] hs = handles;
    int n = hs.length;
    Handle[] is = new Handle[n - 1];
    Handle previous = null;
    boolean deleted = false;
    for (int i = 0; i < n; i++) {
      if (deleted) {
        is[i - 1] = hs[i];
      } else if (hs[i].equals(handle)) {
View Full Code Here

    int xq = loc.getX();
    int yq = loc.getY();
    ClosestResult ret = new ClosestResult();
    ret.dist = Double.MAX_VALUE;
    if (hs.length > 0) {
      Handle h0 = hs[0];
      int x0 = h0.getX();
      int y0 = h0.getY();
      int stop = closed ? hs.length : (hs.length - 1);
      for(int i = 0; i < stop; i++) {
        Handle h1 = hs[(i + 1) % hs.length];
        int x1 = h1.getX();
        int y1 = h1.getY();
        double d = LineUtil.ptDistSqSegment(x0, y0, x1, y1, xq, yq);
        if (d < ret.dist) {
          ret.dist = d;
          ret.prevHandle = h0;
          ret.nextHandle = h1;
        }
        h0 = h1;
        x0 = x1;
        y0 = y1;
      }
    }
    if (ret.dist == Double.MAX_VALUE) {
      return null;
    } else {
      Handle h0 = ret.prevHandle;
      Handle h1 = ret.nextHandle;
      double[] p = LineUtil.nearestPointSegment(xq, yq,
          h0.getX(), h0.getY(), h1.getX(), h1.getY());
      ret.loc = Location.create((int) Math.round(p[0]),
          (int) Math.round(p[1]));
      return ret;
    }
  }
View Full Code Here

    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 {
      int hx = gesture.getHandle().getX();
      int hy = gesture.getHandle().getY();
      int dx = gesture.getDeltaX();
      int dy = gesture.getDeltaY();
      int newX0 = x0 == hx ? x0 + dx : x0;
      int newY0 = y0 == hy ? y0 + dy : y0;
      int newX1 = x1 == hx ? x1 + dx : x1;
      int newY1 = y1 == hy ? y1 + dy : y1;
      if (gesture.isShiftDown()) {
        if (gesture.isAltDown()) {
          if (x0 == hx) newX1 -= dx;
          if (x1 == hx) newX0 -= dx;
          if (y0 == hy) newY1 -= dy;
          if (y1 == hy) newY0 -= dy;

          int w = Math.abs(newX1 - newX0);
          int h = Math.abs(newY1 - newY0);
          if (w > h) { // reduce width to h
            int dw = (w - h) / 2;
            newX0 -= (newX0 > newX1 ? 1 : -1) * dw;
            newX1 -= (newX1 > newX0 ? 1 : -1) * dw;
          } else {
            int dh = (h - w) / 2;
            newY0 -= (newY0 > newY1 ? 1 : -1) * dh;
            newY1 -= (newY1 > newY0 ? 1 : -1) * dh;
          }
        } else {
          int w = Math.abs(newX1 - newX0);
          int h = Math.abs(newY1 - newY0);
          if (w > h) { // reduce width to h
            if (x0 == hx) {
              newX0 = newX1 + (newX0 > newX1 ? 1 : -1) * h;
            }
            if (x1 == hx) {
              newX1 = newX0 + (newX1 > newX0 ? 1 : -1) * h;
            }
          } else { // reduce height to w
            if (y0 == hy) {
              newY0 = newY1 + (newY0 > newY1 ? 1 : -1) * w;
            }
            if (y1 == hy) {
              newY1 = newY0 + (newY1 > newY0 ? 1 : -1) * w;
            }
          }
        }
      } else {
        if (gesture.isAltDown()) {
          if (x0 == hx) newX1 -= dx;
          if (x1 == hx) newX0 -= dx;
          if (y0 == hy) newY1 -= dy;
          if (y1 == hy) newY0 -= dy;
        } else {
          ; // already handled
        }
      }
      return new Handle[] { new Handle(this, newX0, newY0),
        new Handle(this, newX1, newY0), new Handle(this, newX1, newY1),
        new Handle(this, newX0, newY1) };
    }
  }
View Full Code Here

  @Override
  public Handle moveHandle(HandleGesture gesture) {
    Handle[] oldHandles = getHandleArray(null);
    Handle[] newHandles = getHandleArray(gesture);
    Handle moved = gesture == null ? null : gesture.getHandle();
    Handle result = null;
    int x0 = Integer.MAX_VALUE;
    int x1 = Integer.MIN_VALUE;
    int y0 = Integer.MAX_VALUE;
    int y1 = Integer.MIN_VALUE;
    int i = -1;
View Full Code Here

    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();
      int y0 = p0.getY();
      int x1 = p1.getX();
      int y1 = p1.getY();
      if (x1 < x0) { int t = x0; x0 = x1; x1 = t; }
      if (y1 < y0) { int t = y0; y0 = y1; y1 = t; }
 
      draw(g, x0, y0, x1 - x0, y1 - y0);
    }
View Full Code Here

TOP

Related Classes of com.cburch.draw.model.Handle

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.