Search in sources :

Example 1 with Arc2D

use of java.awt.geom.Arc2D in project tomcat by apache.

the class DrawMessage method draw.

/**
     * Draws this DrawMessage onto the given Graphics2D.
     *
     * @param g The target for the DrawMessage
     */
public void draw(Graphics2D g) {
    g.setStroke(new BasicStroke((float) thickness, BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER));
    g.setColor(new Color(colorR & 0xFF, colorG & 0xFF, colorB & 0xFF, colorA & 0xFF));
    if (x1 == x2 && y1 == y2) {
        // Always draw as arc to meet the behavior in the HTML5 Canvas.
        Arc2D arc = new Arc2D.Double(x1, y1, 0, 0, 0d, 360d, Arc2D.OPEN);
        g.draw(arc);
    } else if (type == 1 || type == 2) {
        // Draw a line.
        Line2D line = new Line2D.Double(x1, y1, x2, y2);
        g.draw(line);
    } else if (type == 3 || type == 4) {
        double x1 = this.x1, x2 = this.x2, y1 = this.y1, y2 = this.y2;
        if (x1 > x2) {
            x1 = this.x2;
            x2 = this.x1;
        }
        if (y1 > y2) {
            y1 = this.y2;
            y2 = this.y1;
        }
        if (type == 3) {
            // Draw a rectangle.
            Rectangle2D rect = new Rectangle2D.Double(x1, y1, x2 - x1, y2 - y1);
            g.draw(rect);
        } else if (type == 4) {
            // Draw an ellipse.
            Arc2D arc = new Arc2D.Double(x1, y1, x2 - x1, y2 - y1, 0d, 360d, Arc2D.OPEN);
            g.draw(arc);
        }
    }
}
Also used : BasicStroke(java.awt.BasicStroke) Color(java.awt.Color) Rectangle2D(java.awt.geom.Rectangle2D) Arc2D(java.awt.geom.Arc2D) Line2D(java.awt.geom.Line2D)

Example 2 with Arc2D

use of java.awt.geom.Arc2D in project android_frameworks_base by ParanoidAndroid.

the class Path_Delegate method arcTo.

/**
     * Append the specified arc to the path as a new contour. If the start of
     * the path is different from the path's current last point, then an
     * automatic lineTo() is added to connect the current contour to the
     * start of the arc. However, if the path is empty, then we call moveTo()
     * with the first point of the arc. The sweep angle is tread mod 360.
     *
     * @param oval        The bounds of oval defining shape and size of the arc
     * @param startAngle  Starting angle (in degrees) where the arc begins
     * @param sweepAngle  Sweep angle (in degrees) measured clockwise, treated
     *                    mod 360.
     * @param forceMoveTo If true, always begin a new contour with the arc
     */
private void arcTo(RectF oval, float startAngle, float sweepAngle, boolean forceMoveTo) {
    Arc2D arc = new Arc2D.Float(oval.left, oval.top, oval.width(), oval.height(), -startAngle, -sweepAngle, Arc2D.OPEN);
    mPath.append(arc, true);
    resetLastPointFromPath();
}
Also used : Arc2D(java.awt.geom.Arc2D)

Example 3 with Arc2D

use of java.awt.geom.Arc2D in project android_frameworks_base by AOSPA.

the class Path_Delegate method arcTo.

/**
     * Append the specified arc to the path as a new contour. If the start of
     * the path is different from the path's current last point, then an
     * automatic lineTo() is added to connect the current contour to the
     * start of the arc. However, if the path is empty, then we call moveTo()
     * with the first point of the arc. The sweep angle is tread mod 360.
     *
     * @param left        The left of oval defining shape and size of the arc
     * @param top         The top of oval defining shape and size of the arc
     * @param right       The right of oval defining shape and size of the arc
     * @param bottom      The bottom of oval defining shape and size of the arc
     * @param startAngle  Starting angle (in degrees) where the arc begins
     * @param sweepAngle  Sweep angle (in degrees) measured clockwise, treated
     *                    mod 360.
     * @param forceMoveTo If true, always begin a new contour with the arc
     */
public void arcTo(float left, float top, float right, float bottom, float startAngle, float sweepAngle, boolean forceMoveTo) {
    Arc2D arc = new Arc2D.Float(left, top, right - left, bottom - top, -startAngle, -sweepAngle, Arc2D.OPEN);
    mPath.append(arc, true);
    resetLastPointFromPath();
}
Also used : Arc2D(java.awt.geom.Arc2D)

Example 4 with Arc2D

use of java.awt.geom.Arc2D in project poi by apache.

the class PPGraphics2D method drawArc.

/**
     * Draws the outline of a circular or elliptical arc
     * covering the specified rectangle.
     * <p>
     * The resulting arc begins at <code>startAngle</code> and extends
     * for <code>arcAngle</code> degrees, using the current color.
     * Angles are interpreted such that 0&nbsp;degrees
     * is at the 3&nbsp;o'clock position.
     * A positive value indicates a counter-clockwise rotation
     * while a negative value indicates a clockwise rotation.
     * <p>
     * The center of the arc is the center of the rectangle whose origin
     * is (<i>x</i>,&nbsp;<i>y</i>) and whose size is specified by the
     * <code>width</code> and <code>height</code> arguments.
     * <p>
     * The resulting arc covers an area
     * <code>width&nbsp;+&nbsp;1</code> pixels wide
     * by <code>height&nbsp;+&nbsp;1</code> pixels tall.
     * <p>
     * The angles are specified relative to the non-square extents of
     * the bounding rectangle such that 45 degrees always falls on the
     * line from the center of the ellipse to the upper right corner of
     * the bounding rectangle. As a result, if the bounding rectangle is
     * noticeably longer in one axis than the other, the angles to the
     * start and end of the arc segment will be skewed farther along the
     * longer axis of the bounds.
     * @param        x the <i>x</i> coordinate of the
     *                    upper-left corner of the arc to be drawn.
     * @param        y the <i>y</i>  coordinate of the
     *                    upper-left corner of the arc to be drawn.
     * @param        width the width of the arc to be drawn.
     * @param        height the height of the arc to be drawn.
     * @param        startAngle the beginning angle.
     * @param        arcAngle the angular extent of the arc,
     *                    relative to the start angle.
     * @see         java.awt.Graphics#fillArc
     */
public void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle) {
    Arc2D arc = new Arc2D.Float(x, y, width, height, startAngle, arcAngle, Arc2D.OPEN);
    draw(arc);
}
Also used : Arc2D(java.awt.geom.Arc2D)

Example 5 with Arc2D

use of java.awt.geom.Arc2D in project poi by apache.

the class PPGraphics2D method fillArc.

/**
     * Fills a circular or elliptical arc covering the specified rectangle.
     * <p>
     * The resulting arc begins at <code>startAngle</code> and extends
     * for <code>arcAngle</code> degrees.
     * Angles are interpreted such that 0&nbsp;degrees
     * is at the 3&nbsp;o'clock position.
     * A positive value indicates a counter-clockwise rotation
     * while a negative value indicates a clockwise rotation.
     * <p>
     * The center of the arc is the center of the rectangle whose origin
     * is (<i>x</i>,&nbsp;<i>y</i>) and whose size is specified by the
     * <code>width</code> and <code>height</code> arguments.
     * <p>
     * The resulting arc covers an area
     * <code>width&nbsp;+&nbsp;1</code> pixels wide
     * by <code>height&nbsp;+&nbsp;1</code> pixels tall.
     * <p>
     * The angles are specified relative to the non-square extents of
     * the bounding rectangle such that 45 degrees always falls on the
     * line from the center of the ellipse to the upper right corner of
     * the bounding rectangle. As a result, if the bounding rectangle is
     * noticeably longer in one axis than the other, the angles to the
     * start and end of the arc segment will be skewed farther along the
     * longer axis of the bounds.
     * @param        x the <i>x</i> coordinate of the
     *                    upper-left corner of the arc to be filled.
     * @param        y the <i>y</i>  coordinate of the
     *                    upper-left corner of the arc to be filled.
     * @param        width the width of the arc to be filled.
     * @param        height the height of the arc to be filled.
     * @param        startAngle the beginning angle.
     * @param        arcAngle the angular extent of the arc,
     *                    relative to the start angle.
     * @see         java.awt.Graphics#drawArc
     */
public void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle) {
    Arc2D arc = new Arc2D.Float(x, y, width, height, startAngle, arcAngle, Arc2D.PIE);
    fill(arc);
}
Also used : Arc2D(java.awt.geom.Arc2D)

Aggregations

Arc2D (java.awt.geom.Arc2D)16 Point2D (java.awt.geom.Point2D)3 BasicStroke (java.awt.BasicStroke)1 Color (java.awt.Color)1 AffineTransform (java.awt.geom.AffineTransform)1 Line2D (java.awt.geom.Line2D)1 Rectangle2D (java.awt.geom.Rectangle2D)1