Search in sources :

Example 1 with Style

use of com.codename1.ui.plaf.Style 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 Style

use of com.codename1.ui.plaf.Style 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 Style

use of com.codename1.ui.plaf.Style 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 Style

use of com.codename1.ui.plaf.Style in project CodenameOne by codenameone.

the class RoundRectBorder method paintBorderBackground.

@Override
public void paintBorderBackground(Graphics g, final Component c) {
    final int w = c.getWidth();
    final int h = c.getHeight();
    int x = c.getX();
    int y = c.getY();
    if (shadowOpacity == 0) {
        Style s = c.getStyle();
        if (s.getBgImage() == null) {
            byte type = s.getBackgroundType();
            if (type == Style.BACKGROUND_IMAGE_SCALED || type == Style.BACKGROUND_NONE) {
                GeneralPath gp = createShape(w, h);
                byte bgt = c.getStyle().getBgTransparency();
                if (bgt != 0) {
                    int a = g.getAlpha();
                    g.setAlpha(bgt & 0xff);
                    g.setColor(s.getBgColor());
                    g.translate(x, y);
                    g.fillShape(gp);
                    if (this.stroke != null && strokeOpacity > 0 && strokeThickness > 0) {
                        g.setAlpha(strokeOpacity);
                        g.setColor(strokeColor);
                        g.drawShape(gp, this.stroke);
                    }
                    g.translate(-x, -y);
                    g.setAlpha(a);
                }
                if (this.stroke != null && strokeOpacity > 0 && strokeThickness > 0) {
                    int a = g.getAlpha();
                    g.setAlpha(strokeOpacity);
                    g.setColor(strokeColor);
                    g.translate(x, y);
                    g.drawShape(gp, this.stroke);
                    g.translate(-x, -y);
                    g.setAlpha(a);
                }
                return;
            }
        }
    }
    if (w > 0 && h > 0) {
        Image background = (Image) c.getClientProperty(CACHE_KEY + instanceVal);
        if (background != null && background.getWidth() == w && background.getHeight() == h) {
            g.drawImage(background, x, y);
            return;
        }
    } else {
        return;
    }
    Image target = createTargetImage(c, w, h, true);
    g.drawImage(target, x, y);
    c.putClientProperty(CACHE_KEY + instanceVal, target);
    // update the cache with a more refined version and repaint
    Display.getInstance().callSeriallyOnIdle(new Runnable() {

        public void run() {
            if (w == c.getWidth() && h == c.getHeight()) {
                Image target = createTargetImage(c, w, h, false);
                c.putClientProperty(CACHE_KEY + instanceVal, target);
                c.repaint();
            }
        }
    });
}
Also used : GeneralPath(com.codename1.ui.geom.GeneralPath) Image(com.codename1.ui.Image)

Example 5 with Style

use of com.codename1.ui.plaf.Style in project CodenameOne by codenameone.

the class DefaultLookAndFeel method drawTextFieldCursor.

/**
 * {@inheritDoc}
 */
public void drawTextFieldCursor(Graphics g, TextArea ta) {
    Style style = ta.getStyle();
    Font f = style.getFont();
    int cursorY;
    if (ta.isSingleLineTextArea()) {
        switch(ta.getVerticalAlignment()) {
            case Component.BOTTOM:
                cursorY = ta.getY() + ta.getHeight() - f.getHeight();
                break;
            case Component.CENTER:
                cursorY = ta.getY() + ta.getHeight() / 2 - f.getHeight() / 2;
                break;
            default:
                cursorY = ta.getY() + style.getPaddingTop();
                break;
        }
    } else {
        cursorY = ta.getY() + style.getPaddingTop() + ta.getCursorY() * (ta.getRowsGap() + f.getHeight());
    }
    int cursorX = getTextFieldCursorX(ta);
    int align = reverseAlignForBidi(ta);
    int x = 0;
    if (align == Component.RIGHT) {
        String inputMode = ta.getInputMode();
        int inputModeWidth = f.stringWidth(inputMode);
        int baseX = ta.getX() + style.getPaddingLeftNoRTL() + inputModeWidth;
        if (cursorX < baseX) {
            x = baseX - cursorX;
        }
    }
    int oldColor = g.getColor();
    if (getTextFieldCursorColor() == 0) {
        g.setColor(style.getFgColor());
    } else {
        g.setColor(getTextFieldCursorColor());
    }
    g.drawLine(cursorX + x, cursorY, cursorX + x, cursorY + f.getHeight());
    g.setColor(oldColor);
}
Also used : Font(com.codename1.ui.Font)

Aggregations

Style (com.codename1.ui.plaf.Style)103 Dimension (com.codename1.ui.geom.Dimension)28 Component (com.codename1.ui.Component)25 Image (com.codename1.ui.Image)20 Rectangle (com.codename1.ui.geom.Rectangle)13 Container (com.codename1.ui.Container)11 Font (com.codename1.ui.Font)11 FontImage (com.codename1.ui.FontImage)11 Border (com.codename1.ui.plaf.Border)8 Form (com.codename1.ui.Form)6 Label (com.codename1.ui.Label)6 ActionEvent (com.codename1.ui.events.ActionEvent)6 IOException (java.io.IOException)6 UIManager (com.codename1.ui.plaf.UIManager)5 Vector (java.util.Vector)5 Dialog (com.codename1.ui.Dialog)4 EncodedImage (com.codename1.ui.EncodedImage)4 Graphics (com.codename1.ui.Graphics)4 TextArea (com.codename1.ui.TextArea)4 SpanButton (com.codename1.components.SpanButton)3