Search in sources :

Example 11 with GeneralPath

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

the class BubbleTransition method paint.

@Override
public void paint(Graphics g) {
    Component source = getSource();
    Component dest = getDestination();
    Component srcCmp = source;
    Component destCmp = dest;
    if ((source instanceof Dialog && dest instanceof Form) || originDest != null) {
        srcCmp = dest;
        destCmp = source;
    }
    paint(g, srcCmp, -srcCmp.getAbsoluteX(), -srcCmp.getAbsoluteY(), true);
    int[] clip = g.getClip();
    if (destCmp instanceof Dialog) {
        destCmp = getDialogParent(destCmp);
    }
    if (roundBubble && g.isShapeClipSupported()) {
        GeneralPath p = getBubbleShape();
        p.reset();
        p.arc(x + destCmp.getWidth() / 2 - clipSize / 2, y + destCmp.getHeight() / 2 - clipSize / 2, clipSize, clipSize, 0, Math.toRadians(360));
        g.setClip(p);
    } else {
        g.setClip(x + destCmp.getWidth() / 2 - clipSize / 2, y + destCmp.getHeight() / 2 - clipSize / 2, clipSize, clipSize);
    }
    g.drawImage(destBuffer, x, y);
    g.setClip(clip);
}
Also used : GeneralPath(com.codename1.ui.geom.GeneralPath) Form(com.codename1.ui.Form) Dialog(com.codename1.ui.Dialog) Component(com.codename1.ui.Component)

Example 12 with GeneralPath

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

the class Graphics method setClip.

/**
 * Clips the Graphics context to the Shape.
 * <p>This is not supported on all platforms and contexts currently.
 * Use {@link #isShapeClipSupported} to check if the current
 * context supports clipping shapes.</p>
 *
 * <script src="https://gist.github.com/codenameone/65f531adae2e8c22afc8.js"></script>
 * <img src="https://www.codenameone.com/img/blog/shaped-clipping.png" alt="Shaped clipping in action" />
 *
 * @param shape The shape to clip.
 * @see #isShapeClipSupported
 */
public void setClip(Shape shape) {
    if (xTranslate != 0 || yTranslate != 0) {
        GeneralPath p = tmpClipShape();
        p.setShape(shape, translation());
        shape = p;
    }
    impl.setClip(nativeGraphics, shape);
}
Also used : GeneralPath(com.codename1.ui.geom.GeneralPath)

Example 13 with GeneralPath

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

the class Graphics method drawShape.

// --------------------------------------------------------------------------
// START SHAPE DRAWING STUFF
// --------------------------------------------------------------------------
/**
 * Draws a outline shape inside the specified bounding box.  The bounding box will resize the shape to fit in its dimensions.
 * <p>This is not supported on
 * all platforms and contexts currently.  Use {@link #isShapeSupported} to check if the current
 * context supports drawing shapes.</p>
 *
 * <script src="https://gist.github.com/codenameone/3f2f8cdaabb7780eae6f.js"></script>
 * <img src="https://www.codenameone.com/img/developer-guide/graphics-shape-fill.png" alt="Fill a shape general path" />
 *
 * @param shape The shape to be drawn.
 * @param stroke the stroke to use
 *
 * @see #setStroke
 * @see #isShapeSupported
 */
public void drawShape(Shape shape, Stroke stroke) {
    if (isShapeSupported()) {
        if (xTranslate != 0 || yTranslate != 0) {
            GeneralPath p = tmpClipShape();
            p.setShape(shape, translation());
            shape = p;
        }
        impl.drawShape(nativeGraphics, shape, stroke);
    }
}
Also used : GeneralPath(com.codename1.ui.geom.GeneralPath)

Example 14 with GeneralPath

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

the class Graphics method fillShape.

/**
 * Fills the given shape using the current alpha and color settings.
 *  <p>This is not supported on
 * all platforms and contexts currently.  Use {@link #isShapeSupported} to check if the current
 * context supports drawing shapes.</p>
 *
 * <script src="https://gist.github.com/codenameone/3f2f8cdaabb7780eae6f.js"></script>
 * <img src="https://www.codenameone.com/img/developer-guide/graphics-shape-fill.png" alt="Fill a shape general path" />
 *
 * @param shape The shape to be filled.
 *
 * @see #isShapeSupported
 */
public void fillShape(Shape shape) {
    if (isShapeSupported()) {
        if (xTranslate != 0 || yTranslate != 0) {
            GeneralPath p = tmpClipShape();
            p.setShape(shape, translation());
            shape = p;
        }
        impl.fillShape(nativeGraphics, shape);
    }
}
Also used : GeneralPath(com.codename1.ui.geom.GeneralPath)

Example 15 with GeneralPath

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

the class ChartComponent method chartToScreenShape.

/**
 * Converts a screen coordinate spaced shape to the same shape in the chart  coordinate space
 * @param s shape in chart  coordinates
 * @return same shape using screen coordinate space
 */
public Shape chartToScreenShape(Shape s) {
    GeneralPath p = new GeneralPath();
    Transform inverse = Transform.makeTranslation(getAbsoluteX(), getAbsoluteY());
    if (currentTransform != null) {
        inverse.concatenate(currentTransform);
    }
    p.append(s.getPathIterator(inverse), false);
    return p;
}
Also used : GeneralPath(com.codename1.ui.geom.GeneralPath) Transform(com.codename1.ui.Transform)

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