Search in sources :

Example 1 with Rectangle

use of com.codename1.ui.geom.Rectangle in project CodenameOne by codenameone.

the class BackgroundPainter method paint.

/**
 * {@inheritDoc}
 */
public void paint(Graphics g, Rectangle rect) {
    Style s = parent.getStyle();
    int x = rect.getX();
    int y = rect.getY();
    int width = rect.getSize().getWidth();
    int height = rect.getSize().getHeight();
    if (width <= 0 || height <= 0) {
        return;
    }
    Image bgImage = s.getBgImage();
    if (bgImage == null) {
        g.setColor(s.getBgColor());
        g.fillRect(x, y, width, height, s.getBgTransparency());
    } else {
        if (s.getBackgroundType() == Style.BACKGROUND_IMAGE_SCALED) {
            if (bgImage.getWidth() != width || bgImage.getHeight() != height) {
                bgImage = bgImage.scaled(width, height);
                s.setBgImage(bgImage, true);
            }
        } else {
            int iW = bgImage.getWidth();
            int iH = bgImage.getHeight();
            for (int xPos = 0; xPos < width; xPos += iW) {
                for (int yPos = 0; yPos < height; yPos += iH) {
                    g.drawImage(s.getBgImage(), x + xPos, y + yPos);
                }
            }
            return;
        }
        g.drawImage(s.getBgImage(), x, y);
    }
}
Also used : Style(com.codename1.ui.plaf.Style) Image(com.codename1.ui.Image)

Example 2 with Rectangle

use of com.codename1.ui.geom.Rectangle in project CodenameOne by codenameone.

the class Border method paint.

void paint(Graphics g, int x, int y, int width, int height, Component c) {
    int originalColor = g.getColor();
    if (!themeColors) {
        g.setColor(colorA);
    }
    int ac = 1;
    if (thickness > 0) {
        if (millimeters) {
            ac = Display.getInstance().convertToPixels(thickness);
        } else {
            ac = (int) thickness;
        }
    }
    switch(type) {
        case TYPE_LINE:
            if (borderTitle == null) {
                if (millimeters) {
                    g.drawRect(x, y, width, height, ac);
                } else {
                    g.drawRect(x, y, width, height, ac);
                }
            } else {
                Font f = c.getStyle().getFont();
                int titleW = f.stringWidth(borderTitle);
                int topPad = c.getStyle().getPaddingTop();
                int topY = y + (topPad - ac) / 2;
                if (c.isRTL()) {
                    // top (segment before the title)
                    g.fillRect(x + width - TITLE_MARGIN, topY, TITLE_MARGIN, ac);
                    // top (segment after the title)
                    g.fillRect(x, topY, width - (TITLE_MARGIN + titleW + TITLE_SPACE * 2), ac);
                    g.drawString(borderTitle, x + width - (TITLE_MARGIN + titleW + TITLE_SPACE), y + (topPad - f.getHeight()) / 2);
                } else {
                    // top (segment before the title)
                    g.fillRect(x, topY, TITLE_MARGIN, ac);
                    // top (segment after the title)
                    g.fillRect(x + TITLE_MARGIN + titleW + TITLE_SPACE * 2, topY, width - (TITLE_MARGIN + titleW + TITLE_SPACE * 2), ac);
                    g.drawString(borderTitle, x + TITLE_MARGIN + TITLE_SPACE, y + (topPad - f.getHeight()) / 2);
                }
                // bottom
                g.fillRect(x, y + height - ac, width, ac);
                // left
                g.fillRect(x, topY, ac, height);
                // right
                g.fillRect(x + width - ac, topY, ac, height);
            }
            break;
        case TYPE_DASHED:
        case TYPE_DOTTED:
            int segWidth = ac;
            if (type == TYPE_DASHED) {
                segWidth = ac * 3;
            }
            int ix = x;
            for (; ix < x + width; ix += segWidth * 2) {
                g.fillRect(ix, y, segWidth, ac);
                g.fillRect(ix, y + height - ac, segWidth, ac);
            }
            if (ix - segWidth < x + width) {
                // fill in the gap if any
                g.fillRect(ix - segWidth, y, x + width - ix + segWidth, ac);
                g.fillRect(ix - segWidth, y + height - ac, x + width - ix + segWidth, ac);
            }
            int iy = y;
            for (; iy < y + height; iy += segWidth * 2) {
                g.fillRect(x, iy, ac, segWidth);
                g.fillRect(x + width - ac, iy, ac, segWidth);
            }
            if (iy - segWidth < y + height) {
                // fill in the gap if any
                g.fillRect(x, iy - segWidth, ac, y + height - iy + segWidth);
                g.fillRect(x + width - ac, iy - segWidth, ac, y + height - iy + segWidth);
            }
            break;
        case TYPE_DOUBLE:
            width--;
            height--;
            for (int iter = 0; iter < ac; iter++) {
                if ((iter * 100 / ac <= 33) || (iter * 100 / ac >= 66)) {
                    g.drawRect(x + iter, y + iter, width, height);
                }
                width -= 2;
                height -= 2;
            }
            break;
        case TYPE_INSET:
        case TYPE_OUTSET:
            for (int i = 0; i < ac; i++) {
                g.drawLine(x + i, y + i, x + i, y + height - i);
                g.drawLine(x + i, y + i, x + width - i, y + i);
            }
            if (type == TYPE_INSET) {
                g.lighterColor(50);
            } else {
                g.darkerColor(50);
            }
            for (int i = 0; i < ac; i++) {
                g.drawLine(x + i, y + height - i, x + width - i, y + height - i);
                g.drawLine(x + width - i, y + i, x + width - i, y + height - i);
            }
            break;
        case TYPE_GROOVE:
        case TYPE_RIDGE:
            for (int i = 0; i < ac / 2; i++) {
                g.drawLine(x + i, y + i, x + i, y + height - i);
                g.drawLine(x + i, y + i, x + width - i, y + i);
            }
            for (int i = ac / 2; i < ac; i++) {
                g.drawLine(x + i, y + height - i, x + width - i, y + height - i);
                g.drawLine(x + width - i, y + i, x + width - i, y + height - i);
            }
            if (type == TYPE_GROOVE) {
                g.lighterColor(50);
            } else {
                g.darkerColor(50);
            }
            for (int i = 0; i < ac / 2; i++) {
                g.drawLine(x + i, y + height - i, x + width - i, y + height - i);
                g.drawLine(x + width - i, y + i, x + width - i, y + height - i);
            }
            for (int i = ac / 2; i < ac; i++) {
                g.drawLine(x + i, y + i, x + i, y + height - i);
                g.drawLine(x + i, y + i, x + width - i, y + i);
            }
            break;
        case TYPE_ROUNDED_PRESSED:
            x++;
            y++;
            width -= 2;
            height -= 2;
        case TYPE_ROUNDED:
            width--;
            height--;
            if (outline) {
                g.drawRoundRect(x, y, width, height, arcWidth, arcHeight);
            }
            break;
        case TYPE_ETCHED_LOWERED:
        case TYPE_ETCHED_RAISED:
            g.drawRect(x, y, width - 2, height - 2);
            if (themeColors) {
                if (type == TYPE_ETCHED_LOWERED) {
                    g.lighterColor(40);
                } else {
                    g.darkerColor(40);
                }
            } else {
                g.setColor(colorB);
            }
            g.drawLine(x + 1, y + height - 3, x + 1, y + 1);
            g.drawLine(x + 1, y + 1, x + width - 3, y + 1);
            g.drawLine(x, y + height - 1, x + width - 1, y + height - 1);
            g.drawLine(x + width - 1, y + height - 1, x + width - 1, y);
            break;
        case TYPE_BEVEL_RAISED:
            if (themeColors) {
                g.setColor(getBackgroundColor(c));
                g.lighterColor(50);
            } else {
                g.setColor(colorA);
            }
            g.drawLine(x, y, x, y + height - 2);
            g.drawLine(x + 1, y, x + width - 2, y);
            if (themeColors) {
                g.darkerColor(25);
            } else {
                g.setColor(colorB);
            }
            g.drawLine(x + 1, y + 1, x + 1, y + height - 3);
            g.drawLine(x + 2, y + 1, x + width - 3, y + 1);
            if (themeColors) {
                g.darkerColor(50);
            } else {
                g.setColor(colorC);
            }
            g.drawLine(x, y + height - 1, x + width - 1, y + height - 1);
            g.drawLine(x + width - 1, y, x + width - 1, y + height - 2);
            if (themeColors) {
                g.darkerColor(25);
            } else {
                g.setColor(colorD);
            }
            g.drawLine(x + 1, y + height - 2, x + width - 2, y + height - 2);
            g.drawLine(x + width - 2, y + 1, x + width - 2, y + height - 3);
            break;
        case TYPE_UNDERLINE:
            g.fillRect(x, y + height - ac - 1, width, ac);
            break;
        case TYPE_BEVEL_LOWERED:
            if (themeColors) {
                g.setColor(getBackgroundColor(c));
                g.darkerColor(50);
            } else {
                g.setColor(colorD);
            }
            g.drawLine(x, y, x, y + height - 1);
            g.drawLine(x + 1, y, x + width - 1, y);
            if (themeColors) {
                g.lighterColor(25);
            } else {
                g.setColor(colorC);
            }
            g.drawLine(x + 1, y + 1, x + 1, y + height - 2);
            g.drawLine(x + 2, y + 1, x + width - 2, y + 1);
            if (themeColors) {
                g.lighterColor(50);
            } else {
                g.setColor(colorC);
            }
            g.drawLine(x + 1, y + height - 1, x + width - 1, y + height - 1);
            g.drawLine(x + width - 1, y + 1, x + width - 1, y + height - 2);
            if (themeColors) {
                g.lighterColor(25);
            } else {
                g.setColor(colorA);
            }
            g.drawLine(x + 2, y + height - 2, x + width - 2, y + height - 2);
            g.drawLine(x + width - 2, y + 2, x + width - 2, y + height - 3);
            break;
        case TYPE_COMPOUND:
            Style style = c.getStyle();
            boolean drawLeft = true;
            boolean drawRight = true;
            if (c.getUIManager().getLookAndFeel().isRTL()) {
                boolean temp = drawLeft;
                drawLeft = drawRight;
                drawRight = temp;
            }
            Border top = compoundBorders[Component.TOP];
            Border bottom = compoundBorders[Component.BOTTOM];
            Border left = compoundBorders[Component.LEFT];
            Border right = compoundBorders[Component.RIGHT];
            int topThickness = 0;
            int bottomThickness = 0;
            if (top != null) {
                Rectangle clip = saveClip(g);
                // g.pushClip();
                topThickness = (int) top.thickness;
                g.clipRect(x, y, width, topThickness);
                // top.paint(g, c);
                top.paint(g, x, y, width, height, c);
                restoreClip(g, clip);
            // g.popClip();
            }
            if (bottom != null) {
                Rectangle clip = saveClip(g);
                // g.pushClip();
                bottomThickness = (int) bottom.thickness;
                g.clipRect(x, y + height - bottomThickness, width, bottomThickness);
                // bottom.paint(g, c);
                bottom.paint(g, x, y, width, height, c);
                restoreClip(g, clip);
            // g.popClip();
            }
            if ((drawLeft) && (left != null)) {
                Rectangle clip = saveClip(g);
                // g.pushClip();
                g.clipRect(x, y + topThickness, (int) left.thickness, height - topThickness - bottomThickness);
                // left.paint(g, c);
                left.paint(g, x, y, width, height, c);
                restoreClip(g, clip);
            // g.popClip();
            }
            if ((drawRight) && (right != null)) {
                Rectangle clip = saveClip(g);
                // g.pushClip();
                g.clipRect(x + width - (int) right.thickness, y + topThickness, (int) right.thickness, height - topThickness - bottomThickness);
                // right.paint(g, c);
                right.paint(g, x, y, width, height, c);
                restoreClip(g, clip);
            // g.popClip();
            }
            break;
        case TYPE_IMAGE:
        case TYPE_IMAGE_SCALED:
        case TYPE_IMAGE_HORIZONTAL:
        case TYPE_IMAGE_VERTICAL:
            break;
    }
    g.setColor(originalColor);
}
Also used : Rectangle(com.codename1.ui.geom.Rectangle) Font(com.codename1.ui.Font)

Example 3 with Rectangle

use of com.codename1.ui.geom.Rectangle in project CodenameOne by codenameone.

the class Border method paintBorderBackground.

private void paintBorderBackground(Graphics g, final int xParameter, final int yParameter, final int widthParameter, final int heightParameter, Component c) {
    int originalColor = g.getColor();
    int x = xParameter;
    int y = yParameter;
    int width = widthParameter;
    int height = heightParameter;
    switch(type) {
        case TYPE_ROUNDED_PRESSED:
            x++;
            y++;
            width -= 2;
            height -= 2;
        case TYPE_ROUNDED:
            // Removing this due to issue 301, not sure regarding this...
            // width--;
            // height--;
            // rounded is also responsible for drawing the background
            Style s = c.getStyle();
            if ((s.getBgImage() != null && s.getBackgroundType() == Style.BACKGROUND_IMAGE_SCALED) || s.getBackgroundType() > 1) {
                Object w = s.roundRectCache;
                Image i = null;
                if (w != null) {
                    i = (Image) Display.getInstance().extractHardRef(w);
                }
                if (i != null && i.getWidth() == width && i.getHeight() == height) {
                    g.drawImage(i, x, y);
                } else {
                    // we need to draw a background image!
                    i = Image.createImage(width, height);
                    Graphics imageG = i.getGraphics();
                    imageG.setColor(0);
                    imageG.fillRoundRect(0, 0, width, height, arcWidth, arcHeight);
                    int[] rgb = i.getRGBCached();
                    int transColor = rgb[0];
                    int[] imageRGB;
                    if (s.getBackgroundType() == Style.BACKGROUND_IMAGE_SCALED) {
                        imageRGB = s.getBgImage().scaled(width, height).getRGBCached();
                    } else {
                        Image bgPaint = Image.createImage(width, height);
                        Painter p = s.getBgPainter();
                        // might occur during temporary conditions in the theme switching
                        if (p == null) {
                            return;
                        }
                        p.paint(bgPaint.getGraphics(), new Rectangle(0, 0, width, height));
                        imageRGB = bgPaint.getRGB();
                    }
                    int rlen = rgb.length;
                    for (int iter = 0; iter < rlen; iter++) {
                        if (rgb[iter] == transColor) {
                            imageRGB[iter] = 0;
                        }
                    }
                    i = Image.createImage(imageRGB, width, height);
                    s.roundRectCache = Display.getInstance().createSoftWeakRef(i);
                    g.drawImage(i, x, y);
                }
            } else {
                int foreground = g.getColor();
                g.setColor(s.getBgColor());
                // Its opaque much easier job!
                if (s.getBgTransparency() == ((byte) 0xff)) {
                    g.fillRoundRect(x, y, width, height, arcWidth, arcHeight);
                } else {
                    if (g.isAlphaSupported()) {
                        int alpha = g.getAlpha();
                        g.setAlpha(s.getBgTransparency() & 0xff);
                        g.fillRoundRect(x, y, width, height, arcWidth, arcHeight);
                        g.setAlpha(alpha);
                    } else {
                        // translucent... well....
                        if (s.getBgTransparency() != 0) {
                            Image i = Image.createImage(width, height);
                            int[] imageRgb;
                            if (g.getColor() != 0xffffff) {
                                Graphics imageG = i.getGraphics();
                                imageG.setColor(g.getColor());
                                imageG.fillRoundRect(0, 0, width, height, arcWidth, arcHeight);
                                imageRgb = i.getRGBCached();
                            } else {
                                // background color is white we need to remove a different color
                                // black is the only other "reliable" color on the device
                                Graphics imageG = i.getGraphics();
                                imageG.setColor(0);
                                imageG.fillRect(0, 0, width, height);
                                imageG.setColor(g.getColor());
                                imageG.fillRoundRect(0, 0, width, height, arcWidth, arcHeight);
                                imageRgb = i.getRGBCached();
                            }
                            int removeColor = imageRgb[0];
                            int size = width * height;
                            int alphaInt = ((s.getBgTransparency() & 0xff) << 24) & 0xff000000;
                            for (int iter = 0; iter < size; iter++) {
                                if (removeColor == imageRgb[iter]) {
                                    imageRgb[iter] = 0;
                                    continue;
                                }
                                if ((imageRgb[iter] & 0xff000000) != 0) {
                                    imageRgb[iter] = (imageRgb[iter] & 0xffffff) | alphaInt;
                                }
                            }
                            g.drawImage(new RGBImage(imageRgb, width, height), x, y);
                        }
                    }
                }
                g.setColor(foreground);
            }
            break;
        case TYPE_IMAGE:
            {
                Image topLeft = images[4];
                Image topRight = images[5];
                Image bottomLeft = images[6];
                Image center = images[8];
                x += topLeft.getWidth();
                y += topLeft.getHeight();
                height -= (topLeft.getHeight() + bottomLeft.getHeight());
                width -= (topLeft.getWidth() + topRight.getWidth());
                if (center != null) {
                    g.tileImage(center, x, y, width, height);
                }
                Image top = images[0];
                Image bottom = images[1];
                Image left = images[2];
                Image right = images[3];
                Image bottomRight = images[7];
                x = xParameter;
                y = yParameter;
                width = widthParameter;
                height = heightParameter;
                g.drawImage(topLeft, x, y);
                g.drawImage(bottomLeft, x, y + height - bottomLeft.getHeight());
                g.drawImage(topRight, x + width - topRight.getWidth(), y);
                g.drawImage(bottomRight, x + width - bottomRight.getWidth(), y + height - bottomRight.getHeight());
                Image arrowDownImage = null;
                Image arrowUpImage = null;
                Image arrowLeftImage = null;
                Image arrowRightImage = null;
                int arrowPosition = 0;
                // we need to draw an arrow on one of the sides
                if (trackComponent != null) {
                    int cabsY = c.getAbsoluteY();
                    int trackY = trackComponent.getY();
                    int trackX = trackComponent.getX();
                    int cabsX = c.getAbsoluteX();
                    if (cabsY >= trackY + trackComponent.getHeight()) {
                        // we are below the component
                        arrowUpImage = specialTile[0];
                        arrowPosition = (trackX + trackComponent.getWidth() / 2) - cabsX - arrowUpImage.getWidth() / 2;
                    } else {
                        if (cabsY + c.getHeight() <= trackY) {
                            // we are above the component
                            arrowDownImage = specialTile[1];
                            arrowPosition = (trackX + trackComponent.getWidth() / 2) - cabsX - arrowDownImage.getWidth() / 2;
                        } else {
                            if (cabsX >= trackX + trackComponent.getWidth()) {
                                // we are to the right of the component
                                arrowLeftImage = specialTile[2];
                                arrowPosition = (trackY + trackComponent.getHeight() / 2) - cabsY - arrowLeftImage.getHeight() / 2;
                            } else {
                                if (cabsX + c.getWidth() <= trackX) {
                                    // we are to the left of the component
                                    arrowRightImage = specialTile[3];
                                    arrowPosition = (trackY + trackComponent.getHeight() / 2) - cabsY - arrowRightImage.getHeight() / 2;
                                }
                            }
                        }
                    }
                }
                drawImageBorderLine(g, topLeft, topRight, top, x, y, width, arrowUpImage, arrowPosition, false);
                drawImageBorderLine(g, bottomLeft, bottomRight, bottom, x, y + height - bottom.getHeight(), width, arrowDownImage, arrowPosition, true);
                drawImageBorderColumn(g, topLeft, bottomLeft, left, x, y, height, arrowLeftImage, arrowPosition, false);
                drawImageBorderColumn(g, topRight, bottomRight, right, x + width - right.getWidth(), y, height, arrowRightImage, arrowPosition, true);
                break;
            }
        case TYPE_IMAGE_SCALED:
            {
                int clipX = g.getClipX();
                int clipY = g.getClipY();
                int clipWidth = g.getClipWidth();
                int clipHeight = g.getClipHeight();
                // g.pushClip();
                Image topLeft = images[4];
                Image topRight = images[5];
                Image bottomLeft = images[6];
                Image center = images[8];
                x += topLeft.getWidth();
                y += topLeft.getHeight();
                height -= (topLeft.getHeight() + bottomLeft.getHeight());
                width -= (topLeft.getWidth() + topRight.getWidth());
                g.clipRect(x, y, width, height);
                if (center != null && width > 0 && height > 0) {
                    int centerWidth = center.getWidth();
                    int centerHeight = center.getHeight();
                    g.drawImage(center, x, y, width, height);
                }
                Image top = images[0];
                Image bottom = images[1];
                Image left = images[2];
                Image right = images[3];
                Image bottomRight = images[7];
                g.setClip(clipX, clipY, clipWidth, clipHeight);
                // g.popClip();
                // g.pushClip();
                x = xParameter;
                y = yParameter;
                width = widthParameter;
                height = heightParameter;
                g.drawImage(topLeft, x, y);
                g.drawImage(bottomLeft, x, y + height - bottomLeft.getHeight());
                g.drawImage(topRight, x + width - topRight.getWidth(), y);
                g.drawImage(bottomRight, x + width - bottomRight.getWidth(), y + height - bottomRight.getHeight());
                drawImageBorderLineScale(g, topLeft, topRight, top, x, y, width);
                drawImageBorderLineScale(g, bottomLeft, bottomRight, bottom, x, y + height - bottom.getHeight(), width);
                drawImageBorderColumnScale(g, topLeft, bottomLeft, left, x, y, height);
                drawImageBorderColumnScale(g, topRight, bottomRight, right, x + width - right.getWidth(), y, height);
                g.setClip(clipX, clipY, clipWidth, clipHeight);
                // g.popClip();
                break;
            }
        case TYPE_IMAGE_HORIZONTAL:
            {
                Image left = images[0];
                Image right = images[1];
                Image center = images[2];
                if (c.getUIManager().isThemeConstant("centerAlignHBorderBool", false)) {
                    y += Math.max(0, height / 2 - center.getHeight() / 2);
                }
                g.drawImage(left, x, y);
                g.drawImage(right, x + width - right.getWidth(), y);
                g.tileImage(center, x + left.getWidth(), y, width - left.getWidth() - right.getWidth(), center.getHeight());
                break;
            }
        case TYPE_IMAGE_VERTICAL:
            {
                Image top = images[0];
                Image bottom = images[1];
                Image center = images[2];
                g.drawImage(top, x, y);
                g.drawImage(bottom, x, y + height - bottom.getHeight());
                g.tileImage(center, x, y + top.getHeight(), center.getWidth(), height - top.getHeight() - bottom.getHeight());
                break;
            }
    }
    g.setColor(originalColor);
}
Also used : Graphics(com.codename1.ui.Graphics) Painter(com.codename1.ui.Painter) Rectangle(com.codename1.ui.geom.Rectangle) RGBImage(com.codename1.ui.RGBImage) Image(com.codename1.ui.Image) RGBImage(com.codename1.ui.RGBImage)

Example 4 with Rectangle

use of com.codename1.ui.geom.Rectangle in project CodenameOne by codenameone.

the class GlassTutorial method paint.

/**
 * {@inheritDoc}
 */
public void paint(Graphics g, Rectangle rect) {
    if (internal == null) {
        internal = new Label(" ");
        internal.setUIID("GlassTutorial");
    }
    internal.setSize(rect.getSize());
    internal.paintComponent(g);
    int componentCount = vec.size();
    for (int iter = 0; iter < componentCount; iter++) {
        Component current = (Component) vec.elementAt(iter);
        String pos = (String) current.getClientProperty(POS);
        Component dest = (Component) current.getClientProperty(DEST);
        int xpos = dest.getAbsoluteX();
        int ypos = dest.getAbsoluteY();
        int w = dest.getWidth();
        int h = dest.getHeight();
        if (pos.equals(BorderLayout.CENTER)) {
            current.setX(xpos);
            current.setY(ypos);
            current.setWidth(w);
            current.setHeight(h);
            current.paintComponent(g);
            continue;
        }
        Dimension d = current.getPreferredSize();
        current.setWidth(d.getWidth());
        current.setHeight(d.getHeight());
        if (pos.equals(BorderLayout.SOUTH)) {
            current.setX(xpos + w / 2 - d.getWidth() / 2);
            current.setY(ypos + h);
            current.paintComponent(g);
            continue;
        }
        if (pos.equals(BorderLayout.NORTH)) {
            current.setX(xpos + w / 2 - d.getWidth() / 2);
            current.setY(ypos - d.getHeight());
            current.paintComponent(g);
            continue;
        }
        if (pos.equals(BorderLayout.EAST)) {
            current.setX(xpos + w);
            current.setY(ypos + h / 2 - d.getHeight() / 2);
            current.paintComponent(g);
            continue;
        }
        if (pos.equals(BorderLayout.WEST)) {
            current.setX(xpos - d.getWidth());
            current.setY(ypos + h / 2 - d.getHeight() / 2);
            current.paintComponent(g);
            continue;
        }
    }
}
Also used : Label(com.codename1.ui.Label) Dimension(com.codename1.ui.geom.Dimension) Component(com.codename1.ui.Component)

Example 5 with Rectangle

use of com.codename1.ui.geom.Rectangle 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)

Aggregations

Rectangle (com.codename1.ui.geom.Rectangle)41 Dimension (com.codename1.ui.geom.Dimension)16 Style (com.codename1.ui.plaf.Style)13 Image (com.codename1.ui.Image)10 ActionEvent (com.codename1.ui.events.ActionEvent)5 Border (com.codename1.ui.plaf.Border)5 Component (com.codename1.ui.Component)4 Graphics (com.codename1.ui.Graphics)4 UIManager (com.codename1.ui.plaf.UIManager)4 Form (com.codename1.ui.Form)3 Label (com.codename1.ui.Label)3 GeneralPath (com.codename1.ui.geom.GeneralPath)3 Point (com.codename1.ui.geom.Point)3 BorderLayout (com.codename1.ui.layouts.BorderLayout)3 Paint (com.codename1.charts.compat.Paint)2 Button (com.codename1.ui.Button)2 EncodedImage (com.codename1.ui.EncodedImage)2 Painter (com.codename1.ui.Painter)2 ActionListener (com.codename1.ui.events.ActionListener)2 RoundBorder (com.codename1.ui.plaf.RoundBorder)2