Search in sources :

Example 6 with GeneralPath

use of com.codename1.ui.geom.GeneralPath in project CodenameOne by codenameone.

the class AbstractChart method drawPath.

/**
 * The graphical representation of a path.
 *
 * @param canvas the canvas to paint to
 * @param points the points that are contained in the path to paint
 * @param paint the paint to be used for painting
 * @param circular if the path ends with the start point
 */
protected void drawPath(Canvas canvas, float[] points, Paint paint, boolean circular) {
    GeneralPath path = new GeneralPath();
    int height = canvas.getHeight();
    int width = canvas.getWidth();
    float[] tempDrawPoints;
    if (points.length < 4) {
        return;
    }
    tempDrawPoints = calculateDrawPoints(points[0], points[1], points[2], points[3], height, width);
    path.moveTo(tempDrawPoints[0], tempDrawPoints[1]);
    path.lineTo(tempDrawPoints[2], tempDrawPoints[3]);
    int length = points.length;
    for (int i = 4; i < length; i += 2) {
        if ((points[i - 1] < 0 && points[i + 1] < 0) || (points[i - 1] > height && points[i + 1] > height)) {
            continue;
        }
        tempDrawPoints = calculateDrawPoints(points[i - 2], points[i - 1], points[i], points[i + 1], height, width);
        if (!circular) {
            path.moveTo(tempDrawPoints[0], tempDrawPoints[1]);
        }
        path.lineTo(tempDrawPoints[2], tempDrawPoints[3]);
    }
    if (circular) {
        path.lineTo(points[0], points[1]);
    }
    canvas.drawPath(path, paint);
}
Also used : GeneralPath(com.codename1.ui.geom.GeneralPath) Point(com.codename1.charts.models.Point) Paint(com.codename1.charts.compat.Paint)

Example 7 with GeneralPath

use of com.codename1.ui.geom.GeneralPath in project CodenameOne by codenameone.

the class RoundRectBorder method fillShape.

private void fillShape(Graphics g, int color, int opacity, int width, int height, boolean stroke) {
    g.setColor(color);
    g.setAlpha(opacity);
    GeneralPath gp = createShape(width, height);
    g.fillShape(gp);
    if (stroke && this.stroke != null) {
        g.setAlpha(strokeOpacity);
        g.setColor(strokeColor);
        g.drawShape(gp, this.stroke);
    }
}
Also used : GeneralPath(com.codename1.ui.geom.GeneralPath)

Example 8 with GeneralPath

use of com.codename1.ui.geom.GeneralPath in project CodenameOne by codenameone.

the class RoundRectBorder method createTargetImage.

private Image createTargetImage(Component c, int w, int h, boolean fast) {
    Image target = Image.createImage(w, h, 0);
    int shapeX = 0;
    int shapeY = 0;
    int shapeW = w;
    int shapeH = h;
    Graphics tg = target.getGraphics();
    tg.setAntiAliased(true);
    int shadowSpreadL = Display.getInstance().convertToPixels(shadowSpread);
    if (shadowOpacity > 0) {
        shapeW -= shadowSpreadL;
        shapeH -= shadowSpreadL;
        shapeX += Math.round(((float) shadowSpreadL) * shadowX);
        shapeY += Math.round(((float) shadowSpreadL) * shadowY);
        // draw a gradient of sort for the shadow
        for (int iter = shadowSpreadL - 1; iter >= 0; iter--) {
            tg.translate(iter, iter);
            fillShape(tg, 0, shadowOpacity / shadowSpreadL, w - (iter * 2), h - (iter * 2), false);
            tg.translate(-iter, -iter);
        }
        if (Display.getInstance().isGaussianBlurSupported() && !fast) {
            Image blured = Display.getInstance().gaussianBlurImage(target, shadowBlur / 2);
            target = Image.createImage(w, h, 0);
            tg = target.getGraphics();
            tg.drawImage(blured, 0, 0);
            tg.setAntiAliased(true);
        }
    }
    tg.translate(shapeX, shapeY);
    GeneralPath gp = createShape(shapeW, shapeH);
    Style s = c.getStyle();
    if (s.getBgImage() == null) {
        byte type = s.getBackgroundType();
        if (type == Style.BACKGROUND_IMAGE_SCALED || type == Style.BACKGROUND_NONE) {
            byte bgt = c.getStyle().getBgTransparency();
            if (bgt != 0) {
                tg.setAlpha(bgt & 0xff);
                tg.setColor(s.getBgColor());
                tg.fillShape(gp);
            }
            if (this.stroke != null && strokeOpacity > 0 && strokeThickness > 0) {
                tg.setAlpha(strokeOpacity);
                tg.setColor(strokeColor);
                tg.drawShape(gp, this.stroke);
            }
            return target;
        }
    }
    c.getStyle().setBorder(Border.createEmpty());
    tg.setClip(gp);
    s.getBgPainter().paint(tg, new Rectangle(0, 0, w, h));
    if (this.stroke != null && strokeOpacity > 0 && strokeThickness > 0) {
        tg.setClip(0, 0, w, h);
        tg.setAlpha(strokeOpacity);
        tg.setColor(strokeColor);
        tg.drawShape(gp, this.stroke);
    }
    c.getStyle().setBorder(this);
    return target;
}
Also used : Graphics(com.codename1.ui.Graphics) GeneralPath(com.codename1.ui.geom.GeneralPath) Rectangle(com.codename1.ui.geom.Rectangle) Image(com.codename1.ui.Image)

Example 9 with GeneralPath

use of com.codename1.ui.geom.GeneralPath in project CodenameOne by codenameone.

the class RoundBorder method fillShape.

private void fillShape(Graphics g, int color, int opacity, int width, int height, boolean stroke) {
    g.setColor(color);
    g.setAlpha(opacity);
    if (!rectangle || width <= height) {
        int x = 0;
        int y = 0;
        int size = width;
        if (width != height) {
            if (width > height) {
                size = height;
                x = (width - height) / 2;
            } else {
                size = width;
                y = (height - width) / 2;
            }
        }
        if (size < 5) {
            // probably won't be visible anyway so do nothing, otherwise it might throw an exception
            return;
        }
        if (stroke && this.stroke != null) {
            int sw = (int) Math.ceil((stroke && this.stroke != null) ? this.stroke.getLineWidth() : 0);
            GeneralPath arc = new GeneralPath();
            arc.arc(x + sw / 2, y + sw / 2, size - 2 * sw, size - 2 * sw, 0, 2 * Math.PI);
            g.fillShape(arc);
            g.setColor(strokeColor);
            g.setAlpha(strokeOpacity);
            if (strokeAngle != 360) {
                arc = new GeneralPath();
                arc.arc(x + sw / 2, y + sw / 2, size - 2 * sw, size - 2 * sw, Math.PI / 2, -Math.toRadians(strokeAngle));
            }
            g.drawShape(arc, this.stroke);
        } else {
            g.fillArc(x, y, size, size, 0, 360);
        }
    } else {
        GeneralPath gp = new GeneralPath();
        float sw = (stroke && this.stroke != null) ? this.stroke.getLineWidth() : 0;
        gp.moveTo(height / 2.0, sw);
        gp.lineTo(width - (height / 2.0), sw);
        gp.arcTo(width - (height / 2.0), height / 2.0, width - (height / 2.0), height - sw, true);
        gp.lineTo(height / 2.0, height - sw);
        gp.arcTo(height / 2.0, height / 2.0, height / 2.0, sw, true);
        gp.closePath();
        g.fillShape(gp);
        if (stroke && this.stroke != null) {
            g.setAlpha(strokeOpacity);
            g.setColor(strokeColor);
            g.drawShape(gp, this.stroke);
        }
    }
}
Also used : GeneralPath(com.codename1.ui.geom.GeneralPath)

Example 10 with GeneralPath

use of com.codename1.ui.geom.GeneralPath in project CodenameOne by codenameone.

the class RoundBorder method createTargetImage.

private Image createTargetImage(Component c, int w, int h, boolean fast) {
    Image target = Image.createImage(w, h, 0);
    int shapeX = 0;
    int shapeY = 0;
    int shapeW = w;
    int shapeH = h;
    Graphics tg = target.getGraphics();
    tg.setAntiAliased(true);
    int shadowSpreadL = shadowSpread;
    if (shadowMM) {
        shadowSpreadL = Display.getInstance().convertToPixels(shadowSpreadL);
    }
    if (shadowOpacity > 0) {
        shapeW -= shadowSpreadL;
        shapeW -= (shadowBlur / 2);
        shapeH -= shadowSpreadL;
        shapeH -= (shadowBlur / 2);
        shapeX += Math.round((shadowSpreadL + (shadowBlur / 2)) * shadowX);
        shapeY += Math.round((shadowSpreadL + (shadowBlur / 2)) * shadowY);
        // draw a gradient of sort for the shadow
        for (int iter = shadowSpreadL - 1; iter >= 0; iter--) {
            tg.translate(iter, iter);
            fillShape(tg, 0, shadowOpacity / shadowSpreadL, w - (iter * 2), h - (iter * 2), false);
            tg.translate(-iter, -iter);
        }
        if (Display.getInstance().isGaussianBlurSupported() && !fast) {
            Image blured = Display.getInstance().gaussianBlurImage(target, shadowBlur / 2);
            target = Image.createImage(w, h, 0);
            tg = target.getGraphics();
            tg.drawImage(blured, 0, 0);
            tg.setAntiAliased(true);
        }
    }
    tg.translate(shapeX, shapeY);
    if (uiid && tg.isShapeClipSupported()) {
        c.getStyle().setBorder(Border.createEmpty());
        GeneralPath gp = new GeneralPath();
        if (rectangle) {
            float sw = this.stroke != null ? this.stroke.getLineWidth() : 0;
            gp.moveTo(shapeH / 2.0, sw);
            gp.lineTo(shapeW - (shapeH / 2.0), sw);
            gp.arcTo(shapeW - (shapeH / 2.0), shapeH / 2.0, shapeW - (shapeH / 2.0), shapeH - sw, true);
            gp.lineTo(shapeH / 2.0, shapeH - sw);
            gp.arcTo(shapeH / 2.0, shapeH / 2.0, shapeH / 2.0, sw, true);
            gp.closePath();
        } else {
            int size = shapeW;
            int xPos = 0;
            int yPos = 0;
            if (shapeW != shapeH) {
                if (shapeW > shapeH) {
                    size = shapeH;
                    xPos = (shapeW - shapeH) / 2;
                } else {
                    size = shapeW;
                    yPos = (shapeH - shapeW) / 2;
                }
            }
            gp.arc(xPos, yPos, size, size, 0, 2 * Math.PI);
        }
        tg.setClip(gp);
        c.getStyle().getBgPainter().paint(tg, new Rectangle(0, 0, w, h));
        c.getStyle().setBorder(this);
    } else {
        fillShape(tg, color, opacity, shapeW, shapeH, true);
    }
    return target;
}
Also used : Graphics(com.codename1.ui.Graphics) GeneralPath(com.codename1.ui.geom.GeneralPath) Rectangle(com.codename1.ui.geom.Rectangle) Image(com.codename1.ui.Image)

Aggregations

GeneralPath (com.codename1.ui.geom.GeneralPath)16 Paint (com.codename1.charts.compat.Paint)3 Point (com.codename1.charts.models.Point)3 Image (com.codename1.ui.Image)3 Graphics (com.codename1.ui.Graphics)2 Transform (com.codename1.ui.Transform)2 Rectangle (com.codename1.ui.geom.Rectangle)2 PathMeasure (com.codename1.charts.compat.PathMeasure)1 Component (com.codename1.ui.Component)1 Dialog (com.codename1.ui.Dialog)1 Form (com.codename1.ui.Form)1