Search in sources :

Example 86 with Image

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

the class FlipTransition method paint.

@Override
public void paint(Graphics g) {
    // this can happen if a transition is cut short
    if (destBuffer == null) {
        return;
    }
    int cx = g.getClipX();
    int cy = g.getClipY();
    int cw = g.getClipWidth();
    int ch = g.getClipHeight();
    int x = getSource().getAbsoluteX();
    int y = getSource().getAbsoluteY();
    int w = getSource().getWidth();
    int h = getSource().getHeight();
    g.setClip(x, y, w, h);
    if (getBgColor() >= 0) {
        int c = g.getColor();
        g.setColor(getBgColor());
        g.fillRect(x, y, w, h);
        g.setColor(c);
    } else {
        getSource().paintBackgrounds(g);
    }
    if (g.isPerspectiveTransformSupported()) {
        float displayH = Display.getInstance().getDisplayHeight();
        float displayW = Display.getInstance().getDisplayWidth();
        double midX = (float) x + (float) w / 2.0;
        if (perspectiveT == null) {
            perspectiveT = Transform.makeIdentity();
        }
        makePerspectiveTransform(perspectiveT);
        float[] bottomRight = perspectiveT.transformPoint(new float[] { displayW, displayH, zNear });
        if (currTransform == null) {
            currTransform = Transform.makeTranslation(0, 0, 0);
        } else {
            currTransform.setIdentity();
        }
        float xfactor = -displayW / bottomRight[0];
        float yfactor = -displayH / bottomRight[1];
        currTransform.scale(xfactor, yfactor, 0f);
        currTransform.translate((x + w / 2) / xfactor, (y + h / 2) / yfactor, 0);
        currTransform.concatenate(perspectiveT);
        float cameraZ = -zNear - w / 2 * zState;
        float cameraX = -x - w / 2;
        float cameraY = -y - h / 2;
        currTransform.translate(cameraX, cameraY, cameraZ);
        if (transitionState == STATE_FLIP) {
            currTransform.translate((float) midX, y, 0);
        }
        Image img = null;
        if (flipState < 0.5) {
            img = sourceBuffer;
            if (transitionState == STATE_FLIP) {
                // We are showing the front image
                // We will rotate it up to 90 degrees
                // 0 -> 0 degrees
                // 0.5 -> 90 degress
                double sin = flipState * 2.0;
                double angle = MathUtil.asin(sin);
                // rotate about y axis
                currTransform.rotate((float) angle, 0, 1, 0);
            }
        } else {
            img = destBuffer;
            if (transitionState == STATE_FLIP) {
                // We are showing the back image
                // We are showing the back of the image
                // We will rotate it from 90 degrees back to 0
                // 0.5 -> 90 degrees
                // 1.0 -> 0 degrees
                double sin = (1.0 - flipState) * 2.0;
                double angle = Math.PI - MathUtil.asin(sin);
                // rotate about y axis
                currTransform.rotate((float) angle, 0, 1, 0);
            }
        }
        if (transitionState == STATE_FLIP) {
            currTransform.translate(-(float) midX, -y, 0);
            if (flipState >= 0.5f) {
                // The rotation will leave the destination image flipped
                // backwards, so we need to transform it to be the
                // mirror image
                currTransform.scale(-1, 1, 1);
                currTransform.translate(-2 * x - w, 0, 0);
            }
        }
        if (tmpTransform == null) {
            tmpTransform = Transform.makeIdentity();
        }
        g.getTransform(tmpTransform);
        g.setTransform(currTransform);
        g.drawImage(img, x, y, w, h);
        g.setTransform(tmpTransform);
    } else {
        perspectiveSupported = false;
        if (flipState < 0.5) {
            int frontX = x + (int) (flipState * (float) w);
            int frontWidth = (int) ((float) w * (1.0 - flipState * 2.0));
            g.drawImage(sourceBuffer, frontX, y, frontWidth, h);
        } else {
            double backState = 1.0 - flipState;
            int backX = x + (int) (backState * (float) w);
            int backWidth = (int) ((float) w * (1.0 - backState * 2.0));
            g.drawImage(destBuffer, backX, y, backWidth, h);
        }
    }
    g.setClip(cx, cy, cw, ch);
}
Also used : Image(com.codename1.ui.Image)

Example 87 with Image

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

the class Timeline method scaled.

/**
 * {@inheritDoc}
 */
public Image scaled(int width, int height) {
    Timeline t = new Timeline();
    t.animationDelay = animationDelay;
    t.animations = animations;
    t.currentTime = currentTime;
    t.duration = duration;
    t.size = size;
    t.time = time;
    t.scaledTo = new Dimension(width, height);
    return t;
}
Also used : Dimension(com.codename1.ui.geom.Dimension)

Example 88 with Image

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

the class Timeline method getRGB.

/**
 * {@inheritDoc}
 */
public int[] getRGB() {
    Image i = Image.createImage(getWidth(), getHeight());
    paint(i.getGraphics(), new Rectangle(0, 0, getWidth(), getHeight()));
    return i.getRGB();
}
Also used : Rectangle(com.codename1.ui.geom.Rectangle) Image(com.codename1.ui.Image)

Example 89 with Image

use of com.codename1.ui.Image in project codenameone-google-maps by codenameone.

the class MapContainer method addMarker.

/**
 * Adds a marker to the map with the given attributes
 * @param opts The marker options.
 * @return marker reference object that should be used when removing the marker
 */
public MapObject addMarker(MarkerOptions opts) {
    // public MapObject addMarker(EncodedImage icon, Coord location, String text, String longText, final ActionListener onClick) {
    EncodedImage icon = opts.getIcon();
    Coord location = opts.getLocation();
    String text = opts.getText();
    String longText = opts.getLongText();
    ActionListener onClick = opts.getOnClick();
    if (internalNative != null) {
        byte[] iconData = null;
        if (icon != null) {
            iconData = icon.getImageData();
            internalNative.setMarkerSize(icon.getWidth(), icon.getHeight());
        }
        long key = internalNative.addMarker(iconData, location.getLatitude(), location.getLongitude(), text, longText, onClick != null, opts.anchorU, opts.anchorV);
        MapObject o = new MapObject();
        o.mapKey = key;
        o.callback = onClick;
        markers.add(o);
        return o;
    } else {
        if (internalLightweightCmp != null) {
            PointLayer pl = new PointLayer(location, text, icon);
            if (points == null) {
                points = new PointsLayer();
                internalLightweightCmp.addLayer(points);
            }
            points.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent evt) {
                    PointLayer point = (PointLayer) evt.getSource();
                    for (MapObject o : markers) {
                        if (o.point == point) {
                            if (o.callback != null) {
                                o.callback.actionPerformed(new ActionEvent(o));
                            }
                            evt.consume();
                            return;
                        }
                    }
                }
            });
            points.addPoint(pl);
            MapObject o = new MapObject();
            o.point = pl;
            o.callback = onClick;
            markers.add(o);
            internalLightweightCmp.revalidate();
            return o;
        } else {
            String uri = null;
            int iconWidth = 0;
            int iconHeight = 0;
            int anchorU = 0;
            int anchorV = 0;
            if (icon != null) {
                uri = WebBrowser.createDataURI(icon.getImageData(), "image/png");
                iconWidth = icon.getWidth();
                iconHeight = icon.getHeight();
                anchorU = (int) (icon.getWidth() * opts.anchorU);
                anchorV = (int) (icon.getHeight() * opts.anchorV);
            }
            // browserBridge.waitForReady();
            MapObject o = new MapObject();
            o.callback = onClick;
            o.pending = true;
            final String fUri = uri;
            final int fIconWidth = iconWidth;
            final int fIconHeight = iconHeight;
            final float fAnchorU = anchorU;
            final float fAnchorV = anchorV;
            browserBridge.ready(() -> {
                internalBrowser.execute("callback.onSuccess(" + BRIDGE + ".addMarker(${0}, ${1}, ${2}, ${3}, ${4}, ${5}, ${6}, ${7}, ${8}))", new Object[] { // long key = ((Double)browserBridge.bridge.call("addMarker", new Object[]{
                fUri, location.getLatitude(), location.getLongitude(), text, longText, fIconWidth, fIconHeight, fAnchorU, fAnchorV }, jsres -> {
                    o.mapKey = jsres.getInt();
                    o.pending = false;
                });
            });
            // MapObject o = new MapObject();
            // o.mapKey = res.getInt();
            // o.callback = onClick;
            markers.add(o);
            // System.out.println("MapKey added "+o.mapKey);
            return o;
        }
    }
}
Also used : Coord(com.codename1.maps.Coord) PointsLayer(com.codename1.maps.layers.PointsLayer) ActionListener(com.codename1.ui.events.ActionListener) PointLayer(com.codename1.maps.layers.PointLayer) ActionEvent(com.codename1.ui.events.ActionEvent) EncodedImage(com.codename1.ui.EncodedImage) Point(com.codename1.ui.geom.Point)

Example 90 with Image

use of com.codename1.ui.Image in project codenameone-google-maps by codenameone.

the class MapInfoPanel method createMarkerButton.

private Button createMarkerButton(MapObject mo, String label, Image icon, final Coord location) {
    Button b = new Button(label, icon);
    b.addActionListener(e -> {
        map.zoom(location, (int) map.getZoom());
    });
    return b;
}
Also used : Button(com.codename1.ui.Button)

Aggregations

Image (com.codename1.ui.Image)82 EncodedImage (com.codename1.ui.EncodedImage)46 IOException (java.io.IOException)29 Hashtable (java.util.Hashtable)19 AnimationObject (com.codename1.ui.animations.AnimationObject)18 BufferedImage (java.awt.image.BufferedImage)18 Style (com.codename1.ui.plaf.Style)16 Form (com.codename1.ui.Form)15 ActionEvent (com.codename1.ui.events.ActionEvent)14 Dimension (com.codename1.ui.geom.Dimension)14 FontImage (com.codename1.ui.FontImage)13 BorderLayout (com.codename1.ui.layouts.BorderLayout)13 Timeline (com.codename1.ui.animations.Timeline)12 ActionListener (com.codename1.ui.events.ActionListener)12 Border (com.codename1.ui.plaf.Border)12 Container (com.codename1.ui.Container)11 InputStream (java.io.InputStream)11 Graphics (com.codename1.ui.Graphics)10 Label (com.codename1.ui.Label)10 Button (com.codename1.ui.Button)9