Search in sources :

Example 26 with Graphics

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

the class InfiniteProgress method paint.

/**
 * {@inheritDoc}
 */
public void paint(Graphics g) {
    if (this.getComponentForm() != null && Display.getInstance().getCurrent() != this.getComponentForm()) {
        return;
    }
    super.paint(g);
    if (animation == null) {
        return;
    }
    int v = angle % 360;
    Style s = getStyle();
    /*if(g.isAffineSupported()) {
            g.rotate(((float)v) / 57.2957795f, getAbsoluteX() + s.getPadding(LEFT) + getWidth() / 2, getAbsoluteY() + s.getPadding(TOP) + getHeight() / 2);
            g.drawImage(getAnimation(), getX() + s.getPadding(LEFT), getY() + s.getPadding(TOP));
            g.resetAffine();
        } else {*/
    Image rotated;
    if (animation instanceof FontImage) {
        rotated = animation.rotate(v);
    } else {
        Integer angle = new Integer(v);
        rotated = cache.get(angle);
        if (rotated == null) {
            rotated = animation.rotate(v);
            cache.put(v, rotated);
        }
    }
    g.drawImage(rotated, getX() + s.getPaddingLeftNoRTL(), getY() + s.getPaddingTop());
// }
}
Also used : Style(com.codename1.ui.plaf.Style) Image(com.codename1.ui.Image) FontImage(com.codename1.ui.FontImage) FontImage(com.codename1.ui.FontImage)

Example 27 with Graphics

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

the class OnOffSwitch method animateTo.

private void animateTo(final boolean value, final int position) {
    int switchButtonPadInt = UIManager.getInstance().getThemeConstant("switchButtonPadInt", 16);
    if (Display.getInstance().getDisplayWidth() > 480) {
        // is retina
        switchButtonPadInt *= 2;
    }
    final Motion current = Motion.createEaseInOutMotion(Math.abs(position), switchMaskImage.getWidth() - 2 * switchButtonPadInt, 100);
    current.start();
    deltaX = position;
    getComponentForm().registerAnimated(new Animation() {

        public boolean animate() {
            deltaX = current.getValue();
            if (value) {
                deltaX *= -1;
            }
            dragged = true;
            if (current.isFinished()) {
                dragged = false;
                Form f = getComponentForm();
                if (f != null) {
                    f.deregisterAnimated(this);
                }
                OnOffSwitch.this.setValue(value);
            }
            repaint();
            return false;
        }

        public void paint(Graphics g) {
        }
    });
    dragged = true;
}
Also used : Graphics(com.codename1.ui.Graphics) Motion(com.codename1.ui.animations.Motion) Form(com.codename1.ui.Form) Animation(com.codename1.ui.animations.Animation)

Example 28 with Graphics

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

the class JavaSEPort method setTransform.

@Override
public void setTransform(Object graphics, Transform transform) {
    checkEDT();
    Graphics2D g = getGraphics(graphics);
    AffineTransform t = (graphics == g) ? new AffineTransform() : AffineTransform.getScaleInstance(zoomLevel, zoomLevel);
    t.concatenate((AffineTransform) transform.getNativeTransform());
    clamp(t);
    g.setTransform(t);
    Transform existing = getNativeScreenGraphicsTransform(graphics);
    if (existing == null) {
        existing = transform.copy();
        setNativeScreenGraphicsTransform(graphics, existing);
    } else {
        existing.setTransform(transform);
    }
}
Also used : AffineTransform(java.awt.geom.AffineTransform) AffineTransform(java.awt.geom.AffineTransform) Transform(com.codename1.ui.Transform) Graphics2D(java.awt.Graphics2D)

Example 29 with Graphics

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

the class JavaSEPort method getTransform.

@Override
public void getTransform(Object graphics, Transform transform) {
    checkEDT();
    com.codename1.ui.Transform t = getNativeScreenGraphicsTransform(graphics);
    if (t == null) {
        transform.setIdentity();
    } else {
        transform.setTransform(t);
    }
}
Also used : Transform(com.codename1.ui.Transform)

Example 30 with Graphics

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

the class GameCanvasImplementation method captureAudio.

public void captureAudio(ActionListener response) {
    captureResponse = response;
    try {
        final Form current = Display.getInstance().getCurrent();
        final MMAPIPlayer player = MMAPIPlayer.createPlayer("capture://audio", null);
        RecordControl record = (RecordControl) player.nativePlayer.getControl("RecordControl");
        if (record == null) {
            player.cleanup();
            throw new RuntimeException("Capture Audio is not supported on this device");
        }
        final Form cam = new Form();
        cam.setTransitionInAnimator(CommonTransitions.createEmpty());
        cam.setTransitionOutAnimator(CommonTransitions.createEmpty());
        cam.setLayout(new BorderLayout());
        cam.show();
        player.play();
        final Label time = new Label("0:00");
        cam.addComponent(BorderLayout.SOUTH, time);
        cam.revalidate();
        ActionListener l = new ActionListener() {

            boolean recording = false;

            OutputStream out = null;

            String audioPath = null;

            RecordControl record;

            public void actionPerformed(ActionEvent evt) {
                if (!recording) {
                    record = (RecordControl) player.nativePlayer.getControl("RecordControl");
                    recording = true;
                    String type = record.getContentType();
                    String prefix = "";
                    if (type.endsWith("wav")) {
                        prefix = ".wav";
                    } else if (type.endsWith("amr")) {
                        prefix = ".amr";
                    } else if (type.endsWith("3gpp")) {
                        prefix = ".3gp";
                    }
                    audioPath = getOutputMediaFile() + prefix;
                    try {
                        out = FileSystemStorage.getInstance().openOutputStream(audioPath);
                        record.setRecordStream(out);
                        record.startRecord();
                        cam.registerAnimated(new Animation() {

                            long current = System.currentTimeMillis();

                            long zero = current;

                            int sec = 0;

                            public boolean animate() {
                                long now = System.currentTimeMillis();
                                if (now - current > 1000) {
                                    current = now;
                                    sec++;
                                    return true;
                                }
                                return false;
                            }

                            public void paint(Graphics g) {
                                String txt = sec / 60 + ":" + sec % 60;
                                time.setText(txt);
                            }
                        });
                    } catch (IOException ex) {
                        ex.printStackTrace();
                        System.out.println("failed to store audio to " + audioPath);
                    } finally {
                    }
                } else {
                    if (out != null) {
                        try {
                            record.stopRecord();
                            record.commit();
                            out.close();
                            player.cleanup();
                        } catch (Exception ex) {
                            ex.printStackTrace();
                        }
                    }
                    captureResponse.actionPerformed(new ActionEvent(audioPath));
                    current.showBack();
                }
            }
        };
        cam.addGameKeyListener(Display.GAME_FIRE, l);
        cam.addPointerReleasedListener(l);
    } catch (IOException ex) {
        ex.printStackTrace();
        throw new RuntimeException("failed to start camera");
    }
}
Also used : Form(com.codename1.ui.Form) ActionEvent(com.codename1.ui.events.ActionEvent) DataOutputStream(java.io.DataOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BufferedOutputStream(com.codename1.io.BufferedOutputStream) OutputStream(java.io.OutputStream) IOException(java.io.IOException) RecordStoreException(javax.microedition.rms.RecordStoreException) MediaException(javax.microedition.media.MediaException) IOException(java.io.IOException) ConnectionNotFoundException(javax.microedition.io.ConnectionNotFoundException) Graphics(com.codename1.ui.Graphics) BorderLayout(com.codename1.ui.layouts.BorderLayout) ActionListener(com.codename1.ui.events.ActionListener) Animation(com.codename1.ui.animations.Animation) RecordControl(javax.microedition.media.control.RecordControl)

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