Search in sources :

Example 16 with Graphics

use of com.codename1.ui.Graphics in project CodenameOne by codenameone.

the class ImageIO method save.

/**
 * Saves an image object to the given format
 *
 * @param img the image object
 * @param response resulting image output will be written to this stream
 * @param format the format for the image either FORMAT_PNG or FORMAT_JPEG
 * @param quality the quality for the resulting image output (applicable mostly for JPEG), a value between 0 and 1 notice that
 * this isn't implemented in all platforms.
 */
public void save(Image img, OutputStream response, String format, float quality) throws IOException {
    if (img instanceof EncodedImage) {
        EncodedImage i = (EncodedImage) img;
        save(new ByteArrayInputStream(i.getImageData()), response, format, i.getWidth(), i.getHeight(), quality);
    } else {
        if (img.getImage() == null) {
            Image img2 = Image.createImage(img.getWidth(), img.getHeight(), 0);
            Graphics g = img2.getGraphics();
            g.drawImage(img, 0, 0);
            saveImage(img2, response, format, quality);
        } else {
            saveImage(img, response, format, quality);
        }
    }
}
Also used : Graphics(com.codename1.ui.Graphics) ByteArrayInputStream(java.io.ByteArrayInputStream) Image(com.codename1.ui.Image) EncodedImage(com.codename1.ui.EncodedImage) EncodedImage(com.codename1.ui.EncodedImage)

Example 17 with Graphics

use of com.codename1.ui.Graphics in project CodenameOne by codenameone.

the class SwipeBackSupport method startBackTransition.

void startBackTransition(final Form currentForm, Form destination) {
    final Transition t = destination.getTransitionOutAnimator().copy(true);
    if (t instanceof CommonTransitions) {
        Transition originalTransition = currentForm.getTransitionOutAnimator();
        currentForm.setTransitionOutAnimator(CommonTransitions.createEmpty());
        Form blank = new Form() {

            protected boolean shouldSendPointerReleaseToOtherForm() {
                return true;
            }
        };
        blank.addPointerDraggedListener(pointerDragged);
        blank.addPointerReleasedListener(pointerReleased);
        blank.addPointerPressedListener(pointerPressed);
        blank.setTransitionInAnimator(CommonTransitions.createEmpty());
        blank.setTransitionOutAnimator(CommonTransitions.createEmpty());
        blank.show();
        currentForm.setTransitionOutAnimator(originalTransition);
        ((CommonTransitions) t).setMotion(new LazyValue<Motion>() {

            public Motion get(Object... args) {
                return new ManualMotion(((Integer) args[0]).intValue(), ((Integer) args[1]).intValue(), ((Integer) args[2]).intValue());
            }
        });
        t.init(currentForm, destination);
        t.initTransition();
        blank.setGlassPane(new Painter() {

            public void paint(Graphics g, Rectangle rect) {
                t.animate();
                t.paint(g);
            }
        });
    }
}
Also used : Graphics(com.codename1.ui.Graphics) Motion(com.codename1.ui.animations.Motion) CommonTransitions(com.codename1.ui.animations.CommonTransitions) Form(com.codename1.ui.Form) Transition(com.codename1.ui.animations.Transition) Painter(com.codename1.ui.Painter) Rectangle(com.codename1.ui.geom.Rectangle)

Example 18 with Graphics

use of com.codename1.ui.Graphics in project CodenameOne by codenameone.

the class ArrowLinesLayer method paintSegment.

/**
 * Paints arrows on each segment. arrowSegmentLength decides how many
 * arrows will be on each segment.
 * @param g
 * @param segment
 * @param tile
 */
protected void paintSegment(Graphics g, Coord[] segment, Tile tile) {
    super.paintSegment(g, segment, tile);
    int pointsNo = segment.length;
    for (int i = 1; i < pointsNo; i++) {
        Coord start = segment[i - 1];
        Coord end = segment[i];
        Point s = tile.pointPosition(start);
        Point e = tile.pointPosition(end);
        int noOfSegments = calculateLength(s, e) / arrowSegmentLength;
        if (noOfSegments == 0 && calculateLength(s, e) > minArrowSementLength) {
            noOfSegments = 1;
        }
        for (int j = 1; j <= noOfSegments; j++) {
            if (j == 1) {
                double div = 1.0 / noOfSegments;
                drawArrow(g, new Point(s.getX(), s.getY()), new Point((int) (div * e.getX() + s.getX() * (1 - div)), (int) (div * e.getY() + s.getY() * (1 - div))));
            } else if (j == noOfSegments) {
                double div = (noOfSegments - 1) / (noOfSegments * 1.0);
                drawArrow(g, new Point((int) (div * e.getX() + s.getX() * (1 - div)), (int) (div * e.getY() + s.getY() * (1 - div))), new Point(e.getX(), e.getY()));
            } else {
                double div = ((j - 1) * 1.0) / noOfSegments;
                double div2 = (j * 1.0) / noOfSegments;
                drawArrow(g, new Point((int) (div * e.getX() + s.getX() * (1 - div)), (int) (div * e.getY() + s.getY() * (1 - div))), new Point((int) (div2 * e.getX() + s.getX() * (1 - div2)), (int) (div2 * e.getY() + s.getY() * (1 - div2))));
            }
        }
    }
}
Also used : Coord(com.codename1.maps.Coord) Point(com.codename1.ui.geom.Point) Point(com.codename1.ui.geom.Point)

Example 19 with Graphics

use of com.codename1.ui.Graphics in project CodenameOne by codenameone.

the class LinesLayer method paintSegment.

/**
 * Paint a segment.
 *
 * @param g a Graphics Object to paint on
 * @param segment array of Coord to draw a Line.
 * @param tile
 */
protected void paintSegment(Graphics g, Coord[] segment, Tile tile) {
    int pointsNo = segment.length;
    for (int i = 1; i < pointsNo; i++) {
        Coord start = (Coord) segment[i - 1];
        Coord end = (Coord) segment[i];
        Point s = tile.pointPosition(start);
        Point e = tile.pointPosition(end);
        g.drawLine(s.getX(), s.getY(), e.getX(), e.getY());
        // lame & simple way to make line thicker
        g.drawLine(s.getX() - 1, s.getY(), e.getX() - 1, e.getY());
        g.drawLine(s.getX() + 1, s.getY(), e.getX() + 1, e.getY());
        g.drawLine(s.getX(), s.getY() - 1, e.getX(), e.getY() - 1);
        g.drawLine(s.getX(), s.getY() + 1, e.getX(), e.getY() + 1);
    }
}
Also used : Coord(com.codename1.maps.Coord) Point(com.codename1.ui.geom.Point) Point(com.codename1.ui.geom.Point)

Example 20 with Graphics

use of com.codename1.ui.Graphics in project CodenameOne by codenameone.

the class LayerWithZoomLevels method drawAttribution.

private void drawAttribution(Graphics g, String attribution) {
    if (attribution == null) {
        return;
    }
    g.setColor(0);
    g.setFont(attributionFont);
    Font f = g.getFont();
    g.drawString(attribution, getWidth() - f.stringWidth(attribution) - 2, getHeight() - f.getHeight() - 2);
}
Also used : Font(com.codename1.ui.Font)

Aggregations

Image (com.codename1.ui.Image)18 Component (com.codename1.ui.Component)17 Point (com.codename1.ui.geom.Point)16 Style (com.codename1.ui.plaf.Style)15 Graphics (com.codename1.ui.Graphics)14 Form (com.codename1.ui.Form)12 Font (com.codename1.ui.Font)11 GeneralPath (com.codename1.ui.geom.GeneralPath)9 Rectangle (com.codename1.ui.geom.Rectangle)9 Animation (com.codename1.ui.animations.Animation)8 Dialog (com.codename1.ui.Dialog)7 Dimension (com.codename1.ui.geom.Dimension)6 Painter (com.codename1.ui.Painter)5 ActionEvent (com.codename1.ui.events.ActionEvent)5 FontImage (com.codename1.ui.FontImage)4 RGBImage (com.codename1.ui.RGBImage)4 Motion (com.codename1.ui.animations.Motion)4 ActionListener (com.codename1.ui.events.ActionListener)4 BorderLayout (com.codename1.ui.layouts.BorderLayout)4 IOException (java.io.IOException)4