Search in sources :

Example 1 with Paint

use of com.codename1.charts.compat.Paint 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 Paint

use of com.codename1.charts.compat.Paint 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 Paint

use of com.codename1.charts.compat.Paint 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 4 with Paint

use of com.codename1.charts.compat.Paint in project CodenameOne by codenameone.

the class Spinner method paint.

/**
 * {@inheritDoc}
 */
public void paint(Graphics g) {
    super.paint(g);
    if (spinnerHandle != null) {
        Style s = getStyle();
        g.drawImage(spinnerHandle, getX() + getWidth() - spinnerHandle.getWidth() - s.getHorizontalPadding(), getY() + s.getPaddingTop());
    }
    if (System.currentTimeMillis() - inputSkipDelay < lastKeyInteraction || quickType.isPendingCommit()) {
        quickType.setWidth(Math.min(getWidth(), quickType.getPreferredW()));
        quickType.setHeight(Math.min(getHeight(), quickType.getPreferredH()));
        Style s = quickType.getStyle();
        quickType.setY(getScrollY() + getY());
        // positioning based on date/time
        if (getRenderer() instanceof DateTimeRenderer) {
            switch(currentInputAlign) {
                case LEFT:
                    quickType.setX(getX());
                    break;
                case RIGHT:
                    quickType.setX(getX() + quickType.getStyle().getFont().charWidth(TextArea.getWidestChar()) * 4 + s.getMarginRightNoRTL());
                    break;
                default:
                    quickType.setX(getX() + quickType.getStyle().getFont().charWidth(TextArea.getWidestChar()) * 2 + s.getMarginLeftNoRTL());
                    break;
            }
        } else {
            quickType.setX(getX());
        }
        quickType.paintComponent(g, true);
    }
}
Also used : Style(com.codename1.ui.plaf.Style)

Example 5 with Paint

use of com.codename1.charts.compat.Paint 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

Paint (com.codename1.charts.compat.Paint)28 Component (com.codename1.ui.Component)16 Point (com.codename1.charts.models.Point)14 Style (com.codename1.ui.plaf.Style)13 Form (com.codename1.ui.Form)12 Image (com.codename1.ui.Image)11 Graphics (com.codename1.ui.Graphics)10 Animation (com.codename1.ui.animations.Animation)10 Rectangle (com.codename1.ui.geom.Rectangle)9 Dialog (com.codename1.ui.Dialog)7 GeneralPath (com.codename1.ui.geom.GeneralPath)6 Point (com.codename1.ui.geom.Point)6 Paint (android.graphics.Paint)5 ActionEvent (com.codename1.ui.events.ActionEvent)5 Rectangle2D (com.codename1.ui.geom.Rectangle2D)5 IOException (java.io.IOException)5 TextArea (com.codename1.ui.TextArea)4 ActionListener (com.codename1.ui.events.ActionListener)4 BorderLayout (com.codename1.ui.layouts.BorderLayout)4 Motion (com.codename1.ui.animations.Motion)3