Package com.cburch.draw.model

Examples of com.cburch.draw.model.Handle


 
  @Override
  public List<Handle> getHandles(HandleGesture gesture) {
    Location c = getLocation();
    Location end = c.translate(facing, RADIUS + INDICATOR_LENGTH);
    return UnmodifiableList.create(new Handle[] { new Handle(this, c),
        new Handle(this, end) });
  }
View Full Code Here


  public List<Handle> getHandles(HandleGesture gesture) {
    Location loc = getLocation();
   
    int r = isInput() ? INPUT_RADIUS : OUTPUT_RADIUS;
    return UnmodifiableList.create(new Handle[] {
        new Handle(this, loc.translate(-r, -r)),
        new Handle(this, loc.translate(r, -r)),
        new Handle(this, loc.translate(r, r)),
        new Handle(this, loc.translate(-r, r)) });
  }
View Full Code Here

    return UnmodifiableList.create(getHandleArray(gesture));
  }
 
  private Handle[] getHandleArray(HandleGesture gesture) {
    if (gesture == null) {
      return new Handle[] { new Handle(this, p0), new Handle(this, p1),
          new Handle(this, p2) };
    } else {
      Handle g = gesture.getHandle();
      int gx = g.getX() + gesture.getDeltaX();
      int gy = g.getY() + gesture.getDeltaY();
      Handle[] ret = { new Handle(this, p0), new Handle(this, p1),
          new Handle(this, p2) };
      if (g.isAt(p0)) {
        if (gesture.isShiftDown()) {
          Location p = LineUtil.snapTo8Cardinals(p2, gx, gy);
          ret[0] = new Handle(this, p);
        } else {
          ret[0] = new Handle(this, gx, gy);
        }
      } else if (g.isAt(p2)) {
        if (gesture.isShiftDown()) {
          Location p = LineUtil.snapTo8Cardinals(p0, gx, gy);
          ret[2] = new Handle(this, p);
        } else {
          ret[2] = new Handle(this, gx, gy);
        }
      } else if (g.isAt(p1)) {
        if (gesture.isShiftDown()) {
          double x0 = p0.getX();
          double y0 = p0.getY();
          double x1 = p2.getX();
          double y1 = p2.getY();
          double midx = (x0 + x1) / 2;
          double midy = (y0 + y1) / 2;
          double dx = x1 - x0;
          double dy = y1 - y0;
          double[] p = LineUtil.nearestPointInfinite(gx, gy,
              midx, midy, midx - dy, midy + dx);
          gx = (int) Math.round(p[0]);
          gy = (int) Math.round(p[1]);
        }
        if (gesture.isAltDown()) {
          double[] e0 = { p0.getX(), p0.getY() };
          double[] e1 = { p2.getX(), p2.getY() };
          double[] mid = { gx, gy };
          double[] ct = CurveUtil.interpolate(e0, e1, mid);
          gx = (int) Math.round(ct[0]);
          gy = (int) Math.round(ct[1]);
        }
        ret[1] = new Handle(this, gx, gy);
      }
      return ret;
    }
  }
View Full Code Here

  }
 
  @Override
  public Handle moveHandle(HandleGesture gesture) {
    Handle[] hs = getHandleArray(gesture);
    Handle ret = null;
    if (!hs[0].equals(p0)) {
      p0 = hs[0].getLocation();
      ret = hs[0];
    }
    if (!hs[1].equals(p1)) {
View Full Code Here

    int x = bds.getX();
    int y = bds.getY();
    int w = bds.getWidth();
    int h = bds.getHeight();
    return UnmodifiableList.create(new Handle[] {
        new Handle(this, x, y), new Handle(this, x + w, y),
        new Handle(this, x + w, y + h), new Handle(this, x, y + h) });
  }
View Full Code Here

 
  @Override
  public List<Handle> getHandles(HandleGesture gesture) {
    if (gesture == null) {
      return UnmodifiableList.create(new Handle[] {
          new Handle(this, x0, y0), new Handle(this, x1, y1) });
    } else {
      Handle h = gesture.getHandle();
      int dx = gesture.getDeltaX();
      int dy = gesture.getDeltaY();
      Handle[] ret = new Handle[2];
      ret[0] = new Handle(this, h.isAt(x0, y0)
          ? Location.create(x0 + dx, y0 + dy) : Location.create(x0, y0));
      ret[1] = new Handle(this, h.isAt(x1, y1)
          ? Location.create(x1 + dx, y1 + dy) : Location.create(x1, y1));
      return UnmodifiableList.create(ret);
    }
  }
View Full Code Here

    return true;
  }
 
  @Override
  public Handle moveHandle(HandleGesture gesture) {
    Handle h = gesture.getHandle();
    int dx = gesture.getDeltaX();
    int dy = gesture.getDeltaY();
    Handle ret = null;
    if (h.isAt(x0, y0)) {
      x0 += dx;
      y0 += dy;
      ret = new Handle(this, x0, y0);
    }
    if (h.isAt(x1, y1)) {
      x1 += dx;
      y1 += dy;
      ret = new Handle(this, x1, y1);
    }
    bounds = Bounds.create(x0, y0, 0, 0).add(x1, y1);
    return ret;
  }
View Full Code Here

    if (setForStroke(g)) {
      int x0 = this.x0;
      int y0 = this.y0;
      int x1 = this.x1;
      int y1 = this.y1;
      Handle h = gesture.getHandle();
      if (h.isAt(x0, y0)) {
        x0 += gesture.getDeltaX();
        y0 += gesture.getDeltaY();
      }
      if (h.isAt(x1, y1)) {
        x1 += gesture.getDeltaX();
        y1 += gesture.getDeltaY();
      }
      g.drawLine(x0, y0, x1, y1);
    }
View Full Code Here

  public Poly(boolean closed, List<Location> locations) {
    Handle[] hs = new Handle[locations.size()];
    int i = -1;
    for (Location loc : locations) {
      i++;
      hs[i] = new Handle(this, loc.getX(), loc.getY());
    }
   
    this.closed = closed;
    handles = hs;
    recomputeBounds();
View Full Code Here

      lens = ls;
    }
    double pos = ls[ls.length - 1] * rand.nextDouble();
    for (int i = 0; true; i++) {
      if (pos < ls[i]) {
        Handle p = hs[i];
        Handle q = hs[(i + 1) % hs.length];
        double u = Math.random();
        int x = (int) Math.round(p.getX() + u * (q.getX() - p.getX()));
        int y = (int) Math.round(p.getY() + u * (q.getY() - p.getY()));
        return Location.create(x, y);
      }
    }
  }
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.