Example #1
0
 @Override
 public void updated(PropertyUpdateEvent<PPath> e) {
   switch (e.key) {
     case SNAP_X:
       gridVisual.setWidth((Integer) path.get(PPath.SNAP_X));
       repaint();
       break;
     case SNAP_Y:
       gridVisual.setHeight((Integer) path.get(PPath.SNAP_Y));
       repaint();
       break;
     case PRECISION:
       for (SmoothPathSegment s : spsMap.values()) s.validate();
       arrow.validate();
       break;
     case CLOSED:
     case SMOOTH:
       // TODO: Optimize
       updatePointList();
       break;
     case BACKGROUND_ROOM:
       ResourceReference<Room> r = path.get(PPath.BACKGROUND_ROOM);
       setRoom(r == null ? null : r.get());
   }
 }
Example #2
0
 @Override
 protected void validate() {
   if (segment == null) {
     PathPoint p = path.points.get(0);
     PathPoint p2 = path.points.get(1);
     int x = p.getX();
     int y = p.getY();
     calculatePoints(x, y, Math.atan2(y - p2.getY(), p2.getX() - x));
   } else {
     segment.validate();
     if (path.get(PPath.CLOSED)) {
       int i = segment.px.length - 1;
       int x = segment.px[i];
       int y = segment.py[i];
       int i2 = i - 1;
       while (i2 > 0 && sqrdist(segment.px[i2] - x, segment.py[i2] - y) < 4) i2--;
       calculatePoints(
           x + segment.bounds.x,
           y + segment.bounds.y,
           Math.atan2(segment.py[i2] - y, x - segment.px[i2]));
     } else {
       int x = segment.px[0];
       int y = segment.py[0];
       int i = 1;
       while (i < segment.px.length - 1 && sqrdist(segment.px[i] - x, segment.py[i] - y) < 4)
         i++;
       calculatePoints(
           x + segment.bounds.x,
           y + segment.bounds.y,
           Math.atan2(y - segment.py[i], segment.px[i] - x));
     }
   }
   Rectangle bounds = new Rectangle(-1, -1);
   for (int i = 0; i < 4; i++) bounds.add(px[i], py[i]);
   for (int i = 0; i < 4; i++) {
     px[i] -= bounds.x;
     py[i] -= bounds.y;
   }
   setBounds(bounds);
 }