Search in sources :

Example 76 with Graphics

use of com.codename1.ui.Graphics 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 77 with Graphics

use of com.codename1.ui.Graphics 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 78 with Graphics

use of com.codename1.ui.Graphics 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 79 with Graphics

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

the class SideMenuBar method setMenuGlassPane.

private void setMenuGlassPane(Form m, final String placement) {
    boolean isRTLValue = m.isRTL();
    if (placement == COMMAND_PLACEMENT_VALUE_RIGHT) {
        isRTLValue = !isRTLValue;
    }
    final boolean isRTL = isRTLValue;
    final Image image = rightPanel.getStyle().getBgImage();
    UIManager uim = rightPanel.getUIManager();
    Image sh = (Image) uim.getThemeImageConstant("sideMenuShadowImage");
    if (sh == null) {
        sh = Resources.getSystemResource().getImage("sidemenu-shadow.png");
    }
    if (isRTL) {
        sh = sh.flipHorizontally(true);
    }
    final Image shadow = sh;
    if (m.getGlassPane() == null) {
        m.setGlassPane(new Painter() {

            Image img = image;

            public void paint(Graphics g, Rectangle rect) {
                if (img == null) {
                    // will happen for areMutableImagesFast returning false on iOS and Windows Phone
                    Component c = (Component) rightPanel.getClientProperty("$parent");
                    // not sure what is happening here
                    if (c == null) {
                        return;
                    }
                    boolean b = c.isVisible();
                    c.setVisible(true);
                    if (isRTL) {
                        int x = Math.max(draggedX, rightPanel.getWidth()) - c.getWidth();
                        g.translate(x, 0);
                        Container.sidemenuBarTranslation = x;
                        if (shadow != null) {
                            g.tileImage(shadow, x + c.getWidth() - shadow.getWidth(), 0, shadow.getWidth(), rightPanel.getHeight());
                        }
                        c.paintComponent(g, true);
                        Container.sidemenuBarTranslation = 0;
                        g.translate(-x, 0);
                    } else {
                        int x = Math.min(draggedX, rightPanel.getX());
                        g.translate(x, 0);
                        Container.sidemenuBarTranslation = x;
                        if (shadow != null) {
                            g.tileImage(shadow, x - shadow.getWidth(), 0, shadow.getWidth(), rightPanel.getHeight());
                        }
                        c.paintComponent(g, true);
                        Container.sidemenuBarTranslation = 0;
                        g.translate(-x, 0);
                    }
                    c.setVisible(b);
                } else {
                    if (Display.getInstance().areMutableImagesFast()) {
                        if (img.getHeight() != Display.getInstance().getDisplayHeight()) {
                            img = updateRightPanelBgImage(placement, parent);
                        }
                    }
                    if (isRTL) {
                        int x = Math.max(draggedX, rightPanel.getWidth()) - img.getWidth();
                        if (shadow != null) {
                            g.tileImage(shadow, x + img.getWidth() - shadow.getWidth(), 0, shadow.getWidth(), rightPanel.getHeight());
                        }
                        g.drawImage(img, x, 0);
                    } else {
                        int x = Math.min(draggedX, rightPanel.getX());
                        if (shadow != null) {
                            g.tileImage(shadow, x - shadow.getWidth(), 0, shadow.getWidth(), rightPanel.getHeight());
                        }
                        g.drawImage(img, x, 0);
                    }
                }
            }
        });
    }
}
Also used : Rectangle(com.codename1.ui.geom.Rectangle) UIManager(com.codename1.ui.plaf.UIManager)

Example 80 with Graphics

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

the class AndroidImplementation method captureAudio.

public void captureAudio(final ActionListener response) {
    if (!checkForPermission(Manifest.permission.RECORD_AUDIO, "This is required to record the audio")) {
        return;
    }
    try {
        final Form current = Display.getInstance().getCurrent();
        final File temp = File.createTempFile("mtmp", ".3gpp");
        temp.deleteOnExit();
        if (recorder != null) {
            recorder.release();
        }
        recorder = new MediaRecorder();
        recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
        recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
        recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_WB);
        recorder.setOutputFile(temp.getAbsolutePath());
        final Form recording = new Form("Recording");
        recording.setTransitionInAnimator(CommonTransitions.createEmpty());
        recording.setTransitionOutAnimator(CommonTransitions.createEmpty());
        recording.setLayout(new BorderLayout());
        recorder.prepare();
        recorder.start();
        final Label time = new Label("00:00");
        time.getAllStyles().setAlignment(Component.CENTER);
        Font f = Font.createSystemFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_LARGE);
        f = f.derive(getDisplayHeight() / 10, Font.STYLE_PLAIN);
        time.getAllStyles().setFont(f);
        recording.addComponent(BorderLayout.CENTER, time);
        recording.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) {
                int seconds = sec % 60;
                int minutes = sec / 60;
                String secStr = seconds < 10 ? "0" + seconds : "" + seconds;
                String minStr = minutes < 10 ? "0" + minutes : "" + minutes;
                String txt = minStr + ":" + secStr;
                time.setText(txt);
            }
        });
        Container south = new Container(new com.codename1.ui.layouts.GridLayout(1, 2));
        Command cancel = new Command("Cancel") {

            @Override
            public void actionPerformed(ActionEvent evt) {
                if (recorder != null) {
                    recorder.stop();
                    recorder.release();
                    recorder = null;
                }
                current.showBack();
                response.actionPerformed(null);
            }
        };
        recording.setBackCommand(cancel);
        south.add(new com.codename1.ui.Button(cancel));
        south.add(new com.codename1.ui.Button(new Command("Save") {

            @Override
            public void actionPerformed(ActionEvent evt) {
                if (recorder != null) {
                    recorder.stop();
                    recorder.release();
                    recorder = null;
                }
                current.showBack();
                response.actionPerformed(new ActionEvent(temp.getAbsolutePath()));
            }
        }));
        recording.addComponent(BorderLayout.SOUTH, south);
        recording.show();
    } catch (IOException ex) {
        ex.printStackTrace();
        throw new RuntimeException("failed to start audio recording");
    }
}
Also used : ActionEvent(com.codename1.ui.events.ActionEvent) IOException(java.io.IOException) Font(com.codename1.ui.Font) Paint(android.graphics.Paint) BorderLayout(com.codename1.ui.layouts.BorderLayout) com.codename1.ui(com.codename1.ui) Animation(com.codename1.ui.animations.Animation) MediaRecorder(android.media.MediaRecorder) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File)

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