Search in sources :

Example 46 with GeneralPath

use of java.awt.geom.GeneralPath in project platform_frameworks_base by android.

the class Path_Delegate method transform.

/**
     * Transform the points in this path by matrix, and write the answer
     * into dst. If dst is null, then the the original path is modified.
     *
     * @param matrix The matrix to apply to the path
     * @param dst    The transformed path is written here. If dst is null,
     *               then the the original path is modified
     */
public void transform(Matrix_Delegate matrix, Path_Delegate dst) {
    if (matrix.hasPerspective()) {
        assert false;
        Bridge.getLog().fidelityWarning(LayoutLog.TAG_MATRIX_AFFINE, "android.graphics.Path#transform() only " + "supports affine transformations.", null, null);
    }
    GeneralPath newPath = new GeneralPath();
    PathIterator iterator = mPath.getPathIterator(matrix.getAffineTransform());
    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)

Example 47 with GeneralPath

use of java.awt.geom.GeneralPath in project gephi by gephi.

the class ArrowRenderer method render.

@Override
public void render(final Item item, final RenderTarget target, final PreviewProperties properties) {
    final Helper h = new Helper(item, properties);
    final Color color = EdgeRenderer.getColor(item, properties);
    if (target instanceof G2DTarget) {
        Graphics2D graphics = ((G2DTarget) target).getGraphics();
        graphics.setColor(color);
        final GeneralPath gpath = new GeneralPath();
        gpath.moveTo(h.p1.x, h.p1.y);
        gpath.lineTo(h.p2.x, h.p2.y);
        gpath.lineTo(h.p3.x, h.p3.y);
        gpath.closePath();
        graphics.fill(gpath);
    } else if (target instanceof SVGTarget) {
        final SVGTarget svgTarget = (SVGTarget) target;
        final Element arrowElem = svgTarget.createElement("polyline");
        arrowElem.setAttribute("points", String.format(Locale.ENGLISH, "%f,%f %f,%f %f,%f", h.p1.x, h.p1.y, h.p2.x, h.p2.y, h.p3.x, h.p3.y));
        arrowElem.setAttribute("class", String.format("%s %s", ((Node) h.sourceItem.getSource()).getId(), ((Node) h.targetItem.getSource()).getId()));
        arrowElem.setAttribute("fill", svgTarget.toHexString(color));
        arrowElem.setAttribute("fill-opacity", (color.getAlpha() / 255f) + "");
        arrowElem.setAttribute("stroke", "none");
        svgTarget.getTopElement(SVGTarget.TOP_ARROWS).appendChild(arrowElem);
    } else if (target instanceof PDFTarget) {
        final PDFTarget pdfTarget = (PDFTarget) target;
        final PdfContentByte cb = pdfTarget.getContentByte();
        cb.moveTo(h.p1.x, -h.p1.y);
        cb.lineTo(h.p2.x, -h.p2.y);
        cb.lineTo(h.p3.x, -h.p3.y);
        cb.closePath();
        cb.setRGBColorFill(color.getRed(), color.getGreen(), color.getBlue());
        if (color.getAlpha() < 255) {
            cb.saveState();
            float alpha = color.getAlpha() / 255f;
            PdfGState gState = new PdfGState();
            gState.setFillOpacity(alpha);
            cb.setGState(gState);
        }
        cb.fill();
        if (color.getAlpha() < 255) {
            cb.restoreState();
        }
    }
}
Also used : GeneralPath(java.awt.geom.GeneralPath) Color(java.awt.Color) Element(org.w3c.dom.Element) PdfContentByte(com.itextpdf.text.pdf.PdfContentByte) Graphics2D(java.awt.Graphics2D) PdfGState(com.itextpdf.text.pdf.PdfGState)

Example 48 with GeneralPath

use of java.awt.geom.GeneralPath in project processing by processing.

the class EditorHeader method paintComponent.

public void paintComponent(Graphics screen) {
    if (screen == null)
        return;
    Sketch sketch = editor.getSketch();
    // possible?
    if (sketch == null)
        return;
    Dimension size = getSize();
    if ((size.width != sizeW) || (size.height != sizeH)) {
        if ((size.width > imageW) || (size.height > imageH)) {
            // nix the image and recreate, it's too small
            offscreen = null;
        } else {
            // if the image is larger than necessary, no need to change
            sizeW = size.width;
            sizeH = size.height;
        }
    }
    if (offscreen == null) {
        sizeW = size.width;
        sizeH = size.height;
        imageW = sizeW;
        imageH = sizeH;
        offscreen = Toolkit.offscreenGraphics(this, imageW, imageH);
    }
    Graphics g = offscreen.getGraphics();
    // need to set this each time through
    g.setFont(font);
    if (fontAscent == 0) {
        fontAscent = (int) Toolkit.getAscent(g);
    }
    Graphics2D g2 = Toolkit.prepareGraphics(g);
    //    Toolkit.dpiStroke(g2);
    g.drawImage(gradient, 0, 0, imageW, imageH, this);
    if (tabs.length != sketch.getCodeCount()) {
        tabs = new Tab[sketch.getCodeCount()];
        for (int i = 0; i < tabs.length; i++) {
            tabs[i] = new Tab(i);
        }
        visitOrder = new Tab[sketch.getCodeCount() - 1];
    }
    int leftover = TAB_BETWEEN + ARROW_TAB_WIDTH;
    int tabMax = getWidth() - leftover;
    // reset all tab positions
    for (Tab tab : tabs) {
        SketchCode code = sketch.getCode(tab.index);
        tab.textVisible = true;
        tab.lastVisited = code.lastVisited();
        // hide extensions for .pde files
        boolean hide = editor.getMode().hideExtension(code.getExtension());
        tab.text = hide ? code.getPrettyName() : code.getFileName();
        // if modified, add the li'l glyph next to the name
        //      if (code.isModified()) {
        //        tab.text += " ยง";
        //      }
        tab.textWidth = (int) font.getStringBounds(tab.text, g2.getFontRenderContext()).getWidth();
    }
    // try to make everything fit
    if (!placeTabs(Editor.LEFT_GUTTER, tabMax, null)) {
        // always show the tab with the sketch's name
        int index = 0;
        // stock the array backwards so the rightmost tabs are closed by default
        for (int i = tabs.length - 1; i > 0; --i) {
            visitOrder[index++] = tabs[i];
        }
        // sort on when visited
        Arrays.sort(visitOrder);
        // Keep shrinking the tabs one-by-one until things fit properly
        for (int i = 0; i < visitOrder.length; i++) {
            tabs[visitOrder[i].index].textVisible = false;
            if (placeTabs(Editor.LEFT_GUTTER, tabMax, null)) {
                break;
            }
        }
    }
    // now actually draw the tabs
    if (!placeTabs(Editor.LEFT_GUTTER, tabMax - ARROW_TAB_WIDTH, g2)) {
        // draw the dropdown menu target at the right of the window
        menuRight = tabMax;
        menuLeft = menuRight - ARROW_TAB_WIDTH;
    } else {
        // draw the dropdown menu target next to the tabs
        menuLeft = tabs[tabs.length - 1].right + TAB_BETWEEN;
        menuRight = menuLeft + ARROW_TAB_WIDTH;
    }
    // draw the two pixel line that extends left/right below the tabs
    g.setColor(tabColor[SELECTED]);
    // can't be done with lines, b/c retina leaves tiny hairlines
    g.fillRect(Editor.LEFT_GUTTER, TAB_BOTTOM, editor.getTextArea().getWidth() - Editor.LEFT_GUTTER, Toolkit.zoom(2));
    // draw the tab for the menu
    g.setColor(tabColor[UNSELECTED]);
    drawTab(g, menuLeft, menuRight, false, true);
    // draw the arrow on the menu tab
    g.setColor(arrowColor);
    GeneralPath trianglePath = new GeneralPath();
    float x1 = menuLeft + (ARROW_TAB_WIDTH - ARROW_WIDTH) / 2f;
    float x2 = menuLeft + (ARROW_TAB_WIDTH + ARROW_WIDTH) / 2f;
    trianglePath.moveTo(x1, ARROW_TOP);
    trianglePath.lineTo(x2, ARROW_TOP);
    trianglePath.lineTo((x1 + x2) / 2, ARROW_BOTTOM);
    trianglePath.closePath();
    g2.fill(trianglePath);
    screen.drawImage(offscreen, 0, 0, imageW, imageH, null);
}
Also used : SketchCode(processing.app.SketchCode) GeneralPath(java.awt.geom.GeneralPath) Sketch(processing.app.Sketch)

Example 49 with GeneralPath

use of java.awt.geom.GeneralPath in project processing by processing.

the class PdeTextAreaPainter method drawDiamond.

private static void drawDiamond(Graphics g, float x, float y, float w, float h) {
    Graphics2D g2 = (Graphics2D) g;
    GeneralPath path = new GeneralPath();
    path.moveTo(x + w / 2, y);
    path.lineTo(x + w, y + h / 2);
    path.lineTo(x + w / 2, y + h);
    path.lineTo(x, y + h / 2);
    path.closePath();
    g2.fill(path);
}
Also used : GeneralPath(java.awt.geom.GeneralPath) Graphics2D(java.awt.Graphics2D)

Example 50 with GeneralPath

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

the class Path_Delegate method transform.

/**
     * Transform the points in this path by matrix, and write the answer
     * into dst. If dst is null, then the the original path is modified.
     *
     * @param matrix The matrix to apply to the path
     * @param dst    The transformed path is written here. If dst is null,
     *               then the the original path is modified
     */
public void transform(Matrix_Delegate matrix, Path_Delegate dst) {
    if (matrix.hasPerspective()) {
        assert false;
        Bridge.getLog().fidelityWarning(LayoutLog.TAG_MATRIX_AFFINE, "android.graphics.Path#transform() only " + "supports affine transformations.", null, null);
    }
    GeneralPath newPath = new GeneralPath();
    PathIterator iterator = mPath.getPathIterator(matrix.getAffineTransform());
    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)

Aggregations

GeneralPath (java.awt.geom.GeneralPath)96 Point (java.awt.Point)14 AffineTransform (java.awt.geom.AffineTransform)14 PathIterator (java.awt.geom.PathIterator)14 Graphics2D (java.awt.Graphics2D)8 Rectangle2D (java.awt.geom.Rectangle2D)8 Color (java.awt.Color)7 Paint (java.awt.Paint)7 BasicStroke (java.awt.BasicStroke)6 Point2D (java.awt.geom.Point2D)6 Stroke (java.awt.Stroke)5 Area (java.awt.geom.Area)4 Shape (java.awt.Shape)3 CubicCurve2D (java.awt.geom.CubicCurve2D)3 LayoutPathImpl (sun.font.LayoutPathImpl)3 GradientPaint (java.awt.GradientPaint)2 Rectangle (java.awt.Rectangle)2 Line2D (java.awt.geom.Line2D)2 RoundRectangle2D (java.awt.geom.RoundRectangle2D)2 JBColor (com.intellij.ui.JBColor)1