Search in sources :

Example 1 with GeneralPath

use of java.awt.geom.GeneralPath in project WordCram by danbernier.

the class ProcessingWordRenderer method drawWord.

public void drawWord(EngineWord word, Color color) {
    GeneralPath path2d = new GeneralPath(word.getShape());
    //        Graphics2D g2 = (Graphics2D)destination.image.getGraphics();
    Graphics2D g2 = ((PGraphicsJava2D) destination).g2;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setPaint(color);
    g2.fill(path2d);
}
Also used : GeneralPath(java.awt.geom.GeneralPath) PGraphicsJava2D(processing.awt.PGraphicsJava2D) Graphics2D(java.awt.Graphics2D)

Example 2 with GeneralPath

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

the class Path_Delegate method offset.

/**
     * Offset the path by (dx,dy), returning true on success
     *
     * @param dx  The amount in the X direction to offset the entire path
     * @param dy  The amount in the Y direction to offset the entire path
     * @param dst The translated path is written here. If this is null, then
     *            the original path is modified.
     */
public void offset(float dx, float dy, Path_Delegate dst) {
    GeneralPath newPath = new GeneralPath();
    PathIterator iterator = mPath.getPathIterator(new AffineTransform(0, 0, dx, 0, 0, dy));
    newPath.append(iterator, false);
    if (dst != null) {
        dst.mPath = newPath;
    } else {
        mPath = newPath;
    }
}
Also used : GeneralPath(java.awt.geom.GeneralPath) PathIterator(java.awt.geom.PathIterator) AffineTransform(java.awt.geom.AffineTransform)

Example 3 with GeneralPath

use of java.awt.geom.GeneralPath in project openblocks by mikaelhg.

the class BlockConnectorShape method addDataConnection.

/**
     * Appends a specific data connection GeneralPath to a given GeneralPath.  startFromTop specifies 
     * that the end of the current generalPath is at the top of the data connection to be drawn.
     * convexRight means that the curve drawn points to the right.
     * 
     * The use of _lineTo and _curveTo are to reduce code clutter and to make it clear that
     * these are private methods and not the GeneralPath.lineTo or GeneralPath.curveTo.
     * _lineTo and _curveTo are relative to the starting point of the the data connection to be drawn.
     * 
     * @param blockPath is the current GeneralPath to be appended
     * @param connectionShape is the integer representing the kind and style of connection to be drawn
     * @param startFromTop true if end of the current generalPath is at the top of the data connection to be drawn
     * @param convexRight true if curve drawn points to the right
     */
private Point2D addDataConnection(GeneralPath blockPath, String connectionShape, boolean startFromTop, boolean convexRight) {
    //get the associated connection shape value
    int connectionShapeInt = getConnenctionShapeMapping(connectionShape);
    //get the initial point info and set the currentConnectorPath to use the _lineTo _curveTo methods
    startPoint = blockPath.getCurrentPoint();
    float xStart = (float) startPoint.getX();
    float yStart = (float) startPoint.getY();
    currentConnectorPath = new GeneralPath();
    currentConnectorPath.moveTo(xStart, yStart);
    Point2D socketPoint = new Point2D.Float((float) startPoint.getX(), (startFromTop ? ((float) startPoint.getY() + ((int) DATA_PLUG_HEIGHT / 2)) : ((float) startPoint.getY() - ((int) DATA_PLUG_HEIGHT / 2))));
    switch(connectionShapeInt) {
        //Starlogo Number
        case TRIANGLE_1:
            _lineTo(NORMAL_DATA_PLUG_WIDTH, DATA_PLUG_HEIGHT / 2);
            _lineTo(0, DATA_PLUG_HEIGHT);
            break;
        case TRIANGLE_2:
            _lineTo(NORMAL_DATA_PLUG_WIDTH, DATA_PLUG_HEIGHT / 4);
            _lineTo(0, DATA_PLUG_HEIGHT / 2);
            //shifted duplicate
            _lineTo(NORMAL_DATA_PLUG_WIDTH, DATA_PLUG_HEIGHT * 3 / 4);
            _lineTo(0, DATA_PLUG_HEIGHT);
            break;
        case TRIANGLE_3:
            _lineTo(NORMAL_DATA_PLUG_WIDTH, DATA_PLUG_HEIGHT / 4);
            _lineTo(0, DATA_PLUG_HEIGHT / 2);
            //inversion
            _lineTo(-NORMAL_DATA_PLUG_WIDTH, DATA_PLUG_HEIGHT * 3 / 4);
            _lineTo(0, DATA_PLUG_HEIGHT);
            break;
        //Starlogo Boolean
        case CIRCLE_1:
            _curveTo((NORMAL_DATA_PLUG_WIDTH) * 4 / 3, 0, (NORMAL_DATA_PLUG_WIDTH) * 4 / 3, DATA_PLUG_HEIGHT, 0, DATA_PLUG_HEIGHT);
            break;
        case CIRCLE_2:
            _curveTo(NORMAL_DATA_PLUG_WIDTH, 0, NORMAL_DATA_PLUG_WIDTH, DATA_PLUG_HEIGHT * 1 / 4, NORMAL_DATA_PLUG_WIDTH * 1 / 2, DATA_PLUG_HEIGHT * 1 / 2);
            _curveTo(NORMAL_DATA_PLUG_WIDTH, DATA_PLUG_HEIGHT * 3 / 4, NORMAL_DATA_PLUG_WIDTH, DATA_PLUG_HEIGHT, 0, DATA_PLUG_HEIGHT);
            break;
        case CIRCLE_3:
            _curveTo(NORMAL_DATA_PLUG_WIDTH, 0, NORMAL_DATA_PLUG_WIDTH, DATA_PLUG_HEIGHT * 1 / 4, NORMAL_DATA_PLUG_WIDTH * 1 / 2, DATA_PLUG_HEIGHT * 1 / 2);
            //inversion
            _curveTo(-NORMAL_DATA_PLUG_WIDTH, DATA_PLUG_HEIGHT * 3 / 4, -NORMAL_DATA_PLUG_WIDTH, DATA_PLUG_HEIGHT, 0, DATA_PLUG_HEIGHT);
            break;
        //Starlogo String
        case SQUARE_1:
            _lineTo(0, DATA_PLUG_HEIGHT * 0.15f);
            _lineTo(NORMAL_DATA_PLUG_WIDTH, DATA_PLUG_HEIGHT * 0.15f);
            _lineTo(NORMAL_DATA_PLUG_WIDTH, DATA_PLUG_HEIGHT * 0.85f);
            _lineTo(0, DATA_PLUG_HEIGHT * 0.85f);
            _lineTo(0, DATA_PLUG_HEIGHT);
            break;
        case SQUARE_2:
            _lineTo(0, DATA_PLUG_HEIGHT * 0.15f);
            _lineTo(NORMAL_DATA_PLUG_WIDTH, DATA_PLUG_HEIGHT * 0.15f);
            _lineTo(NORMAL_DATA_PLUG_WIDTH, DATA_PLUG_HEIGHT * 0.45f);
            _lineTo(0, DATA_PLUG_HEIGHT * 0.45f);
            _lineTo(0, DATA_PLUG_HEIGHT * 0.55f);
            _lineTo(NORMAL_DATA_PLUG_WIDTH, DATA_PLUG_HEIGHT * 0.55f);
            _lineTo(NORMAL_DATA_PLUG_WIDTH, DATA_PLUG_HEIGHT * 0.85f);
            _lineTo(0, DATA_PLUG_HEIGHT * 0.85f);
            _lineTo(0, DATA_PLUG_HEIGHT);
            break;
        case SQUARE_3:
            _lineTo(0, DATA_PLUG_HEIGHT * 0.15f);
            _lineTo(NORMAL_DATA_PLUG_WIDTH, DATA_PLUG_HEIGHT * 0.15f);
            _lineTo(NORMAL_DATA_PLUG_WIDTH, DATA_PLUG_HEIGHT * 0.50f);
            _lineTo(-NORMAL_DATA_PLUG_WIDTH, DATA_PLUG_HEIGHT * 0.50f);
            _lineTo(-NORMAL_DATA_PLUG_WIDTH, DATA_PLUG_HEIGHT * 0.85f);
            _lineTo(0, DATA_PLUG_HEIGHT * 0.85f);
            _lineTo(0, DATA_PLUG_HEIGHT);
            break;
        case POLYMORPHIC_1:
            _curveTo(0, DATA_PLUG_HEIGHT / 3, POLYMORPHIC_DATA_PLUG_WIDTH / 3, DATA_PLUG_HEIGHT / 3, POLYMORPHIC_DATA_PLUG_WIDTH / 2, DATA_PLUG_HEIGHT / 4);
            _curveTo(POLYMORPHIC_DATA_PLUG_WIDTH * 2 / 3, DATA_PLUG_HEIGHT / 6, POLYMORPHIC_DATA_PLUG_WIDTH, DATA_PLUG_HEIGHT / 6, POLYMORPHIC_DATA_PLUG_WIDTH, DATA_PLUG_HEIGHT / 2);
            _curveTo(POLYMORPHIC_DATA_PLUG_WIDTH, DATA_PLUG_HEIGHT * 5 / 6, POLYMORPHIC_DATA_PLUG_WIDTH * 2 / 3, DATA_PLUG_HEIGHT * 5 / 6, POLYMORPHIC_DATA_PLUG_WIDTH / 2, DATA_PLUG_HEIGHT * 3 / 4);
            _curveTo(POLYMORPHIC_DATA_PLUG_WIDTH / 3, DATA_PLUG_HEIGHT * 2 / 3, 0, DATA_PLUG_HEIGHT * 2 / 3, 0, DATA_PLUG_HEIGHT);
            break;
        case POLYMORPHIC_2:
            _curveTo(0, DATA_PLUG_HEIGHT / 6, POLYMORPHIC_DATA_PLUG_WIDTH / 3, DATA_PLUG_HEIGHT / 6, POLYMORPHIC_DATA_PLUG_WIDTH / 2, DATA_PLUG_HEIGHT / 8);
            _curveTo(POLYMORPHIC_DATA_PLUG_WIDTH * 2 / 3, DATA_PLUG_HEIGHT / 12, POLYMORPHIC_DATA_PLUG_WIDTH, DATA_PLUG_HEIGHT / 12, POLYMORPHIC_DATA_PLUG_WIDTH, DATA_PLUG_HEIGHT / 4);
            _curveTo(POLYMORPHIC_DATA_PLUG_WIDTH, DATA_PLUG_HEIGHT * 5 / 12, POLYMORPHIC_DATA_PLUG_WIDTH * 2 / 3, DATA_PLUG_HEIGHT * 5 / 12, POLYMORPHIC_DATA_PLUG_WIDTH / 2, DATA_PLUG_HEIGHT * 3 / 8);
            _curveTo(POLYMORPHIC_DATA_PLUG_WIDTH / 3, DATA_PLUG_HEIGHT * 2 / 6, 0, DATA_PLUG_HEIGHT * 2 / 6, 0, DATA_PLUG_HEIGHT / 2);
            //shifted duplicate
            _curveTo(0, DATA_PLUG_HEIGHT * 4 / 6, POLYMORPHIC_DATA_PLUG_WIDTH / 3, DATA_PLUG_HEIGHT * 4 / 6, POLYMORPHIC_DATA_PLUG_WIDTH / 2, DATA_PLUG_HEIGHT * 5 / 8);
            _curveTo(POLYMORPHIC_DATA_PLUG_WIDTH * 2 / 3, DATA_PLUG_HEIGHT * 7 / 12, POLYMORPHIC_DATA_PLUG_WIDTH, DATA_PLUG_HEIGHT * 7 / 12, POLYMORPHIC_DATA_PLUG_WIDTH, DATA_PLUG_HEIGHT * 3 / 4);
            _curveTo(POLYMORPHIC_DATA_PLUG_WIDTH, DATA_PLUG_HEIGHT * 11 / 12, POLYMORPHIC_DATA_PLUG_WIDTH * 2 / 3, DATA_PLUG_HEIGHT * 11 / 12, POLYMORPHIC_DATA_PLUG_WIDTH / 2, DATA_PLUG_HEIGHT * 7 / 8);
            _curveTo(POLYMORPHIC_DATA_PLUG_WIDTH / 3, DATA_PLUG_HEIGHT * 5 / 6, 0, DATA_PLUG_HEIGHT * 5 / 6, 0, DATA_PLUG_HEIGHT);
            break;
        case POLYMORPHIC_3:
            _lineTo(POLYMORPHIC_DATA_PLUG_WIDTH / 3, DATA_PLUG_HEIGHT / 8);
            _lineTo(POLYMORPHIC_DATA_PLUG_WIDTH / 2, DATA_PLUG_HEIGHT * 0.025f);
            _lineTo(POLYMORPHIC_DATA_PLUG_WIDTH * 3 / 4, DATA_PLUG_HEIGHT / 8);
            _curveTo(POLYMORPHIC_DATA_PLUG_WIDTH * 10 / 9, DATA_PLUG_HEIGHT * 0.15f, POLYMORPHIC_DATA_PLUG_WIDTH * 10 / 9, DATA_PLUG_HEIGHT * 0.35f, POLYMORPHIC_DATA_PLUG_WIDTH * 3 / 4, DATA_PLUG_HEIGHT * 3 / 8);
            _lineTo(POLYMORPHIC_DATA_PLUG_WIDTH / 2, DATA_PLUG_HEIGHT * 0.475f);
            _lineTo(POLYMORPHIC_DATA_PLUG_WIDTH / 3, DATA_PLUG_HEIGHT * 3 / 8);
            _lineTo(0, DATA_PLUG_HEIGHT / 2);
            //inversion
            _lineTo(-POLYMORPHIC_DATA_PLUG_WIDTH / 3, DATA_PLUG_HEIGHT / 8 + DATA_PLUG_HEIGHT / 2);
            _lineTo(-POLYMORPHIC_DATA_PLUG_WIDTH / 2, DATA_PLUG_HEIGHT * 0.025f + DATA_PLUG_HEIGHT / 2);
            _lineTo(-POLYMORPHIC_DATA_PLUG_WIDTH * 3 / 4, DATA_PLUG_HEIGHT / 8 + DATA_PLUG_HEIGHT / 2);
            _curveTo(-POLYMORPHIC_DATA_PLUG_WIDTH * 10 / 9, DATA_PLUG_HEIGHT * 0.15f + DATA_PLUG_HEIGHT / 2, -POLYMORPHIC_DATA_PLUG_WIDTH * 10 / 9, DATA_PLUG_HEIGHT * 0.35f + DATA_PLUG_HEIGHT / 2, -POLYMORPHIC_DATA_PLUG_WIDTH * 3 / 4, DATA_PLUG_HEIGHT * 3 / 8 + DATA_PLUG_HEIGHT / 2);
            _lineTo(-POLYMORPHIC_DATA_PLUG_WIDTH / 2, DATA_PLUG_HEIGHT * 0.475f + DATA_PLUG_HEIGHT / 2);
            _lineTo(-POLYMORPHIC_DATA_PLUG_WIDTH / 3, DATA_PLUG_HEIGHT * 3 / 8 + DATA_PLUG_HEIGHT / 2);
            _lineTo(0, DATA_PLUG_HEIGHT);
            break;
        //formally BlockGenus.PROC_PARAM
        case 13:
            _lineTo(0, DATA_PLUG_HEIGHT * 1 / 4);
            _lineTo(NORMAL_DATA_PLUG_WIDTH, DATA_PLUG_HEIGHT * 1 / 4);
            _lineTo(NORMAL_DATA_PLUG_WIDTH, DATA_PLUG_HEIGHT * 3 / 4);
            _lineTo(0, DATA_PLUG_HEIGHT * 3 / 4);
            _lineTo(0, DATA_PLUG_HEIGHT);
            break;
        default:
            //System.out.println("Connection Type Not Identified: " + connectionShape);
            break;
    }
    //flip the path if starting from the bottom or changing convex direction
    if (!startFromTop || !convexRight) {
        transformGeneralPath(currentConnectorPath, !convexRight, !startFromTop);
    }
    //finally append the correctly oriented currentConnectorPath to the blockPath
    blockPath.append(currentConnectorPath, true);
    //to catch bugs
    currentConnectorPath = null;
    return socketPoint;
}
Also used : GeneralPath(java.awt.geom.GeneralPath) Point2D(java.awt.geom.Point2D)

Example 4 with GeneralPath

use of java.awt.geom.GeneralPath in project openblocks by mikaelhg.

the class ShapeBevel method createShapeBevel.

public static void createShapeBevel(Graphics2D g2, Shape theShape, double flatness, int numBands, float bevelSize, float[] light) {
    // draw bands from inside of shape to outside (important)
    for (int i = numBands - 1; i >= 0; i--) {
        // get the path around the block area, flattening any curves
        // 0.2 is flattening tolerance, big == faster, small == smoother
        BevelIterator bi = new BevelIterator(theShape, flatness);
        // cos and sin of angle between surface normal and screen plane
        // center of band
        float theCos = 1f - ((float) i + 0.5f) / numBands;
        float theSin = (float) Math.sqrt(1 - theCos * theCos);
        // draw strips from outer edge,
        float from = 0;
        // to this distance
        float to = 1f / numBands * (i + 1) * bevelSize;
        // the overlap makes sure there is no tiny space between the bands
        g2.setStroke(new BasicStroke(to - from));
        float[] p = { 0, 0 };
        float[] norm = { 0, 0, 0 };
        // receives gray and alpha
        float[] grayAlpha = { 0, 0 };
        while (!bi.isDone()) {
            //count++;
            bi.nextSegment();
            norm[0] = bi.perpVec[0] * theCos;
            norm[1] = bi.perpVec[1] * theCos;
            norm[2] = theSin;
            getLightingOverlay(norm, light, grayAlpha);
            g2.setColor(new Color(grayAlpha[0], grayAlpha[0], grayAlpha[0], grayAlpha[1]));
            g2.setComposite(AlphaComposite.Src);
            GeneralPath gp = new GeneralPath();
            bi.insetPoint2(from, p);
            gp.moveTo(p[0], p[1]);
            bi.insetPoint3(from, p);
            gp.lineTo(p[0], p[1]);
            bi.insetPoint3(to, p);
            gp.lineTo(p[0], p[1]);
            bi.insetPoint2(to, p);
            gp.lineTo(p[0], p[1]);
            gp.closePath();
            g2.fill(gp);
        }
    }
}
Also used : BasicStroke(java.awt.BasicStroke) GeneralPath(java.awt.geom.GeneralPath) Color(java.awt.Color)

Example 5 with GeneralPath

use of java.awt.geom.GeneralPath in project openblocks by mikaelhg.

the class CArrowButton method getShape.

private Shape getShape(Direction dir) {
    if (dir == Direction.NORTH) {
        return new GeneralPath();
    } else if (dir == Direction.SOUTH) {
        return new GeneralPath();
    } else if (dir == Direction.EAST) {
        GeneralPath arrow = new GeneralPath();
        arrow.moveTo(m, m);
        arrow.lineTo(this.getWidth() - m, this.getHeight() / 2);
        arrow.lineTo(m, this.getHeight() - m);
        arrow.lineTo(m, m);
        arrow.closePath();
        return arrow;
    } else {
        //if(dir == WEST){
        GeneralPath arrow = new GeneralPath();
        arrow.moveTo(this.getWidth() - m, m);
        arrow.lineTo(m, this.getHeight() / 2);
        arrow.lineTo(this.getWidth() - m, this.getHeight() - m);
        arrow.lineTo(this.getWidth() - m, m);
        arrow.closePath();
        return arrow;
    }
}
Also used : GeneralPath(java.awt.geom.GeneralPath)

Aggregations

GeneralPath (java.awt.geom.GeneralPath)84 AffineTransform (java.awt.geom.AffineTransform)14 PathIterator (java.awt.geom.PathIterator)14 Rectangle2D (java.awt.geom.Rectangle2D)8 Graphics2D (java.awt.Graphics2D)6 Point (java.awt.Point)6 Paint (java.awt.Paint)5 Color (java.awt.Color)4 Area (java.awt.geom.Area)4 Shape (java.awt.Shape)3 Point2D (java.awt.geom.Point2D)3 LayoutPathImpl (sun.font.LayoutPathImpl)3 BasicStroke (java.awt.BasicStroke)2 GradientPaint (java.awt.GradientPaint)2 RoundRectangle2D (java.awt.geom.RoundRectangle2D)2 JBColor (com.intellij.ui.JBColor)1 PdfContentByte (com.itextpdf.text.pdf.PdfContentByte)1 PdfGState (com.itextpdf.text.pdf.PdfGState)1 AlphaComposite (java.awt.AlphaComposite)1 Composite (java.awt.Composite)1