Search in sources :

Example 91 with Graphics

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

the class SpinnerRenderer method drawCharPerspectivePosition.

/**
 * Draws the character with the given perspective effect
 */
private int drawCharPerspectivePosition(Graphics g, char c, int x, int y) {
    if (imageCache == null) {
        imageCache = new HashMap[PERSPECTIVES];
        for (int iter = 0; iter < PERSPECTIVES; iter++) {
            if (iter != FRONT_ANGLE) {
                imageCache[iter] = new HashMap<Character, Image>();
            }
        }
    }
    Character chr = new Character(c);
    Image i = imageCache[perspective].get(chr);
    if (i == null) {
        // UIManager.getInstance().getLookAndFeel().setFG(g, this);
        Font f = getStyle().getFont();
        int w = f.charWidth(c);
        int h = f.getHeight();
        i = Image.createImage(w, h, 0);
        g = i.getGraphics();
        UIManager.getInstance().getLookAndFeel().setFG(g, this);
        g.drawChar(c, 0, 0);
        i = Effects.verticalPerspective(i, TOP_SCALE[perspective], BOTTOM_SCALE[perspective], VERTICAL_SHRINK[perspective]);
        imageCache[perspective].put(chr, i);
    }
    g.drawImage(i, x, y);
    return i.getWidth();
}
Also used : Image(com.codename1.ui.Image) Font(com.codename1.ui.Font)

Example 92 with Graphics

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

the class SpinnerRenderer method paint.

@Override
public void paint(Graphics g) {
    if (!iOS7Mode || perspective == FRONT_ANGLE) {
        super.paint(g);
    } else {
        if (!isInClippingRegion(g)) {
            return;
        }
        Style s = getStyle();
        drawStringPerspectivePosition(g, getText(), getX() + s.getPaddingLeftNoRTL(), getY() + s.getPaddingTop());
    }
}
Also used : Style(com.codename1.ui.plaf.Style)

Example 93 with Graphics

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

the class Table method paintGlass.

/**
 * {@inheritDoc}
 */
protected void paintGlass(Graphics g) {
    if ((drawBorder) && (innerBorder != INNER_BORDERS_NONE)) {
        int xPos = getAbsoluteX();
        int yPos = getAbsoluteY();
        g.translate(xPos, yPos);
        int rows = model.getRowCount();
        int cols = model.getColumnCount();
        if (includeHeader) {
            rows++;
        }
        g.setColor(getStyle().getFgColor());
        TableLayout t = (TableLayout) getLayout();
        int actualWidth = Math.max(getWidth(), getScrollDimension().getWidth());
        int actualHeight = Math.max(getHeight(), getScrollDimension().getHeight());
        if (// inner borders cols/rows are supported only in collapsed mode
        (collapseBorder) || (innerBorder != INNER_BORDERS_ALL) || (t.hasHorizontalSpanning()) || (t.hasVerticalSpanning())) {
            // TODO - We currently don't support separate borders for tables with spanned cells
            if ((innerBorder == INNER_BORDERS_ALL) || (innerBorder == INNER_BORDERS_ROWS)) {
                if (t.hasVerticalSpanning()) {
                    // the components other than the ones that are at the last column.
                    for (int cellRow = 0; cellRow < rows - 1; cellRow++) {
                        for (int cellColumn = 0; cellColumn < cols; cellColumn++) {
                            // if this isn't the last row
                            if (cellRow + t.getCellVerticalSpan(cellRow, cellColumn) - 1 != rows - 1) {
                                // if this is a spanned through cell we don't want to draw a line here
                                if (t.isCellSpannedThroughHorizontally(cellRow, cellColumn)) {
                                    continue;
                                }
                                int x = t.getColumnPosition(cellColumn);
                                int y = t.getRowPosition(cellRow);
                                int rowHeight = t.getRowPosition(cellRow + t.getCellVerticalSpan(cellRow, cellColumn)) - y;
                                int columnWidth;
                                if (cellColumn < getModel().getColumnCount() - 1) {
                                    columnWidth = t.getColumnPosition(cellColumn + 1) - x;
                                } else {
                                    columnWidth = getWidth() - y;
                                }
                                if ((innerBorder != INNER_BORDERS_ROWS) || (shouldDrawInnerBorderAfterRow(cellRow))) {
                                    g.drawLine(x, y + rowHeight, x + columnWidth, y + rowHeight);
                                }
                            }
                        }
                    }
                } else {
                    // this is much faster since we don't need to check spanning
                    for (int row = 1; row < rows; row++) {
                        int y = t.getRowPosition(row);
                        if ((innerBorder != INNER_BORDERS_ROWS) || (shouldDrawInnerBorderAfterRow(row - 1))) {
                            g.drawLine(0, y, actualWidth, y);
                        }
                    // g.drawLine(0+2, y+2, actualWidth-2, y+2);
                    }
                }
            }
            if ((innerBorder == INNER_BORDERS_ALL) || (innerBorder == INNER_BORDERS_COLS)) {
                if (t.hasHorizontalSpanning()) {
                    // the components other than the ones that are at the last column.
                    for (int cellRow = 0; cellRow < rows; cellRow++) {
                        for (int cellColumn = 0; cellColumn < cols - 1; cellColumn++) {
                            // if this isn't the last column
                            if (cellColumn + t.getCellHorizontalSpan(cellRow, cellColumn) - 1 != cols - 1) {
                                // if this is a spanned through cell we don't want to draw a line here
                                if (t.isCellSpannedThroughVertically(cellRow, cellColumn)) {
                                    continue;
                                }
                                int x = t.getColumnPosition(cellColumn);
                                int y = t.getRowPosition(cellRow);
                                int rowHeight;
                                int columnWidth = t.getColumnPosition(cellColumn + t.getCellHorizontalSpan(cellRow, cellColumn)) - x;
                                if (cellRow < getModel().getRowCount() - 1) {
                                    rowHeight = t.getRowPosition(cellRow + 1) - y;
                                } else {
                                    rowHeight = getHeight() - y;
                                }
                                g.drawLine(x + columnWidth, y, x + columnWidth, y + rowHeight);
                            }
                            if (t.getCellHorizontalSpan(cellRow, cellColumn) > 1) {
                                cellColumn += t.getCellHorizontalSpan(cellRow, cellColumn) - 1;
                            }
                        }
                    }
                } else {
                    for (int col = 1; col < cols; col++) {
                        int x = t.getColumnPosition(col);
                        g.drawLine(x, 0, x, actualHeight);
                    // g.drawLine(x+2, 0+2, x+2, actualHeight-2);
                    }
                }
            }
        } else {
            // if ((!t.hasHorizontalSpanning()) && (!t.hasVerticalSpanning())) {
            for (int row = 0; row < rows; row++) {
                int y = t.getRowPosition(row);
                int h;
                if (row + 1 < rows) {
                    h = t.getRowPosition(row + 1) - y;
                } else {
                    h = getY() + actualHeight - y - 2;
                }
                for (int col = 0; col < cols; col++) {
                    int x = t.getColumnPosition(col);
                    int w;
                    if (col + 1 < cols) {
                        w = t.getColumnPosition(col + 1) - x;
                    } else {
                        w = getX() + actualWidth - x - 2;
                    }
                    Component comp = t.getComponentAt(row, col);
                    if ((comp.isVisible()) && ((drawEmptyCellsBorder) || ((comp.getWidth() - comp.getStyle().getPaddingRightNoRTL() - comp.getStyle().getPaddingLeftNoRTL() > 0) && (comp.getHeight() - comp.getStyle().getPaddingTop() - comp.getStyle().getPaddingBottom() > 0)))) {
                        int rightMargin = comp.getStyle().getMarginRightNoRTL();
                        int bottomMargin = comp.getStyle().getMarginBottom();
                        if (col == 0) {
                            // Since the first cell includes margins from both sides (left/right) so the next cell location is farther away - but we don't want to paint the border up to it
                            rightMargin *= 2;
                        }
                        if (row == 0) {
                            bottomMargin *= 2;
                        }
                        g.drawRect(x + comp.getStyle().getMarginLeftNoRTL(), y + comp.getStyle().getMarginTop(), w - 2 - rightMargin, h - 2 - bottomMargin);
                    }
                }
            }
        }
        g.translate(-xPos, -yPos);
    }
}
Also used : Component(com.codename1.ui.Component)

Example 94 with Graphics

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

the class GameCanvasImplementation method captureVideo.

public void captureVideo(ActionListener response) {
    captureResponse = response;
    try {
        final Form current = Display.getInstance().getCurrent();
        final MMAPIPlayer player = MMAPIPlayer.createPlayer("capture://video", null);
        RecordControl record = (RecordControl) player.nativePlayer.getControl("RecordControl");
        if (record == null) {
            player.cleanup();
            throw new RuntimeException("Capture Video 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();
        MIDPVideoComponent video = new MIDPVideoComponent(player, canvas);
        video.play();
        video.setVisible(true);
        cam.addComponent(BorderLayout.CENTER, video);
        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 videoPath = 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("mpeg")) {
                        prefix = ".mpeg";
                    } else if (type.endsWith("4")) {
                        prefix = ".mp4";
                    } else if (type.endsWith("3gpp")) {
                        prefix = ".3gp";
                    } else if (type.endsWith("avi")) {
                        prefix = ".avi";
                    }
                    videoPath = getOutputMediaFile() + prefix;
                    try {
                        out = FileSystemStorage.getInstance().openOutputStream(videoPath);
                        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 video to " + videoPath);
                    } finally {
                    }
                } else {
                    if (out != null) {
                        try {
                            record.stopRecord();
                            record.commit();
                            out.close();
                            player.cleanup();
                        } catch (Exception ex) {
                            ex.printStackTrace();
                        }
                    }
                    captureResponse.actionPerformed(new ActionEvent(videoPath));
                    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)

Example 95 with Graphics

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

the class BlackBerryCanvas method clipOnLWUITBounds.

/*public void subpaint(Graphics g) {
        paint(g);
    }*/
/**
 * Clips the RIM native graphics based on the component hierarchy within LWUIT
 * so the native RIM component doesn't paint itself above other components such
 * as the forms title.
 */
private int clipOnLWUITBounds(Component lwuitComponent, Graphics rimGraphics) {
    int result = 0;
    Component parent = lwuitComponent;
    while (parent != null) {
        int x = parent.getAbsoluteX() + parent.getScrollX();
        int y = parent.getAbsoluteY() + parent.getScrollY();
        rimGraphics.pushRegion(x, y, parent.getWidth(), parent.getHeight(), 0, 0);
        rimGraphics.translate(-rimGraphics.getTranslateX(), -rimGraphics.getTranslateY());
        parent = parent.getParent();
        result++;
    }
    return result;
}
Also used : Component(com.codename1.ui.Component) PeerComponent(com.codename1.ui.PeerComponent)

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