Пример #1
0
  /**
   * Render the View to the given graphic context. This implementation render the interior first,
   * then the outline.
   */
  public void paint(Graphics2D g, Rectangle2D a) {
    if (!a.intersects(getBounds())) return;
    if (image != null) { // paint bitmap
      g.drawImage(image, text2ModelTr, null);
      // debug:
      g.setPaint(Color.red);
      g.draw(this.bounds);
      super.paint(g, a); // possibly paint framebox if non-null
    } else { // paint textlayout
      super.paint(g, a); // possibly paint framebox if non-null

      AffineTransform oldAT = g.getTransform();
      // paint text in black
      g.setPaint(Color.black);
      // from now on, we work in Y-direct (<0) coordinates to avoid inextricable problems with font
      // being mirrored...
      g.transform(text2ModelTr); // also include rotation
      textLayout.draw(g, 0.0f, 0.0f);
      // [pending] ajouter un cadre si areDimensionsComputed (wysiwyg du pauvre)
      // get back to previous transform
      g.setTransform(oldAT);
      if (DEBUG) {
        g.setPaint(Color.red);
        g.draw(bounds);
      }
    }
  }
Пример #2
0
 public boolean isInRange(Point upperLeft, Dimension size) {
   Rectangle2D rect1 =
       new Rectangle2D.Double(
           upperLeft.getX(), upperLeft.getY(), size.getWidth(), size.getHeight());
   Rectangle2D rect2 = new Rectangle2D.Double(getX(), getY(), getWidth(), getHeight());
   return (rect1.intersects(rect2));
 }
  /** Test if this terminal is hit by the given rectangle. */
  @Override
  public boolean hit(Rectangle2D r) {
    if (!isVisible()) {
      return false;
    }

    boolean hit = intersects(r);

    // Do the end too. Does ConnectorEnd needs a proper hit() method?
    if (_end != null) {
      hit = hit || r.intersects(_end.getBounds());
    }

    return hit;
  }
Пример #4
0
  /**
   * Calculates the relative position between a line and a cubic curve. If the line is degenerated
   * (coincident start and end point) then -1 is returned if the line is outside the bounding box of
   * the cubic curve.
   *
   * @param lin the line
   * @param cub the cubic curve
   * @return the position of the curve relative to the line -1: curve is left of line +1: curve is
   *     right of line 0: curve (eventually) intersects the line
   */
  private static int _relativePosition(Line2D lin, CubicCurve2D cub) {
    // Is the line degenerated?
    if (isNull(lin)) {
      Rectangle2D rct = cub.getBounds2D();
      double x = lin.getX1() - 0.5 * mEps;
      double y = lin.getY1() - 0.5 * mEps;
      return rct.intersects(x, y, mEps, mEps) ? 0 : -1;
    }

    // Create a normalized vector perpendicular to the line
    final Vector2D vec1Left = new Vector2D(lin.getP1(), lin.getP2());
    vec1Left.left();
    vec1Left.normalize();

    // All four points/ control points must be left or right the line
    final Vector2D vec = new Vector2D();

    // P1
    vec.setLocation(lin.getP1(), cub.getP1());
    int ii = _relativePosition(vec1Left, vec);
    if (ii == 0) {
      return 0;
    }

    // P2
    vec.setLocation(lin.getP1(), cub.getP2());
    int i = _relativePosition(vec1Left, vec);
    if (i == 0 || i + ii == 0) {
      return 0;
    }

    // CtrlP1
    vec.setLocation(lin.getP1(), cub.getCtrlP1());
    i = _relativePosition(vec1Left, vec);
    if (i == 0 || i + ii == 0) {
      return 0;
    }

    // CtrlP2
    vec.setLocation(lin.getP1(), cub.getCtrlP2());
    i = _relativePosition(vec1Left, vec);
    if (i == 0 || i + ii == 0) {
      return 0;
    }

    return ii;
  }
Пример #5
0
 @Override
 public void paintThis(Rectangle2D clip, Graphics2D g) {
   if (!clip.intersects(getBounds())) return;
   Graphics2D gc = (Graphics2D) g.create();
   Image img = imageIcon.getImage();
   gc.setColor(new Color(1f, 1f, 1f, alpha));
   double sx = boundRect.getWidth() / imageIcon.getIconWidth();
   double sy = boundRect.getHeight() / imageIcon.getIconHeight();
   AffineTransform af = new AffineTransform(totalTransform);
   af.translate(boundRect.getX(), boundRect.getY());
   af.scale(sx, sy);
   gc.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha));
   gc.setRenderingHint(
       RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
   gc.drawImage(img, af, imageIcon.getImageObserver());
   gc.dispose();
 }
Пример #6
0
  public boolean moveArea(Player player) {
    double dx = (display.getWidth() / 2) - display.getX() + 26;
    double dy = (display.getHeight() / 2) - display.getY() + 26;

    Rectangle2D area =
        new Rectangle2D.Double(
            (int) dx,
            (int) dy,
            (int) (getWidth() - display.getWidth() - 52),
            (int) (getHeight() - display.getHeight() - 52));

    if (area.intersects(player)) {
      return true;
    } else {
      return false;
    }
  }
Пример #7
0
  private static boolean _collision(Shape shp1, Shape shp2) {
    // Get shape bounds ...
    Rectangle2D bounds1 = shp1.getBounds2D();
    Rectangle2D bounds2 = shp2.getBounds2D();

    // ... and extend by eps
    bounds1.setFrame(
        bounds1.getX() - mEps,
        bounds1.getY() - mEps,
        bounds1.getWidth() + mEps + mEps,
        bounds1.getHeight() + mEps + mEps);
    bounds2.setFrame(
        bounds2.getX() - mEps,
        bounds2.getY() - mEps,
        bounds2.getWidth() + mEps + mEps,
        bounds2.getHeight() + mEps + mEps);
    return bounds1.intersects(bounds2);
  }
 @Override
 public boolean mouseInside() {
   Rectangle2D s = new Rectangle2D.Double(ShotGunLane.x, ShotGunLane.y, 10, 10),
       r = new Rectangle2D.Double(this.x, this.y, this.width, this.height);
   return r.intersects(s);
 }
Пример #9
0
 @Override
 public void draw(final Graphics2D gfx, final KanvasContext ctx) {
   ensureLayout();
   if (layout != null) {
     final Graphics2D g = (Graphics2D) gfx.create();
     final Rectangle2D bbox = new Rectangle2D.Double();
     getBoundingBox(bbox);
     layout.drawBackground(g, ctx, bbox, members);
     g.dispose();
   }
   gfx.setColor(java.awt.Color.GREEN);
   RenderpassPainter.draw(nlBack, gfx, ctx);
   final Rectangle2D view = ctx.getVisibleCanvas();
   boolean changed = false;
   T last = null;
   for (final RenderpassPosition<T> p : members) {
     final T r = p.pass;
     if (!r.isVisible()) {
       continue;
     }
     if (p.checkBBoxChange()) {
       changed = true;
     }
     final Rectangle2D bbox = p.getPassBBox();
     if (!view.intersects(bbox)) {
       continue;
     }
     final Graphics2D g = (Graphics2D) gfx.create();
     g.clip(bbox);
     final double dx = r.getOffsetX();
     final double dy = r.getOffsetY();
     g.translate(dx, dy);
     final KanvasContext c = RenderpassPainter.getContextFor(r, ctx);
     r.draw(g, c);
     g.dispose();
     drawBetween(gfx, ctx, last, r);
     last = r;
   }
   drawBetween(gfx, ctx, last, null);
   if (jkanvas.Canvas.DEBUG_BBOX) {
     final Graphics2D g = (Graphics2D) gfx.create();
     PaintUtil.setAlpha(g, 0.3);
     g.setColor(java.awt.Color.BLUE);
     for (final RenderpassPosition<T> rp : members) {
       final Renderpass r = rp.pass;
       if (!r.isVisible()) {
         continue;
       }
       if (rp.checkBBoxChange()) {
         changed = true;
       }
       final Rectangle2D bbox = rp.getPassBBox();
       if (!view.intersects(bbox)) {
         continue;
       }
       g.fill(bbox);
     }
   }
   gfx.setColor(java.awt.Color.GREEN);
   RenderpassPainter.draw(nlFront, gfx, ctx);
   if (changed) {
     invalidate();
   }
 }
Пример #10
0
  /**
   * Tests if the interior of this <code>Polygon</code> intersects the interior of a specified set
   * of rectangular coordinates.
   *
   * @param x the x coordinate of the specified rectangular shape's top-left corner
   * @param y the y coordinate of the specified rectangular shape's top-left corner
   * @param w the width of the specified rectangular shape
   * @param h the height of the specified rectangular shape
   * @return <code>true</code> if the interior of this <code>Polygon</code> and the interior of the
   *     specified set of rectangular coordinates intersect each other; <code>false</code>
   *     otherwise.
   */
  @Override
  public boolean intersects(double x, double y, double w, double h) {
    if ((path == null) || !bounds.intersects(x, y, w, h)) return false;

    return path.intersects(x, y, w, h);
  }
Пример #11
0
 public boolean intersects(IGameObject actor) {
   Rectangle2D predmet = new Rectangle2D.Float(actor.getX(), actor.getY(), 48f, 48f);
   Rectangle2D objekt = new Rectangle2D.Float(this.getX(), this.getY(), 48f, 48f);
   return objekt.intersects(predmet);
 }