Search in sources :

Example 51 with Graphics

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

the class RoundRectBorder method fillShape.

private void fillShape(Graphics g, int color, int opacity, int width, int height, boolean stroke) {
    g.setColor(color);
    g.setAlpha(opacity);
    GeneralPath gp = createShape(width, height);
    g.fillShape(gp);
    if (stroke && this.stroke != null) {
        g.setAlpha(strokeOpacity);
        g.setColor(strokeColor);
        g.drawShape(gp, this.stroke);
    }
}
Also used : GeneralPath(com.codename1.ui.geom.GeneralPath)

Example 52 with Graphics

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

the class RoundRectBorder method createTargetImage.

private Image createTargetImage(Component c, int w, int h, boolean fast) {
    Image target = Image.createImage(w, h, 0);
    int shapeX = 0;
    int shapeY = 0;
    int shapeW = w;
    int shapeH = h;
    Graphics tg = target.getGraphics();
    tg.setAntiAliased(true);
    int shadowSpreadL = Display.getInstance().convertToPixels(shadowSpread);
    if (shadowOpacity > 0) {
        shapeW -= shadowSpreadL;
        shapeH -= shadowSpreadL;
        shapeX += Math.round(((float) shadowSpreadL) * shadowX);
        shapeY += Math.round(((float) shadowSpreadL) * shadowY);
        // draw a gradient of sort for the shadow
        for (int iter = shadowSpreadL - 1; iter >= 0; iter--) {
            tg.translate(iter, iter);
            fillShape(tg, 0, shadowOpacity / shadowSpreadL, w - (iter * 2), h - (iter * 2), false);
            tg.translate(-iter, -iter);
        }
        if (Display.getInstance().isGaussianBlurSupported() && !fast) {
            Image blured = Display.getInstance().gaussianBlurImage(target, shadowBlur / 2);
            target = Image.createImage(w, h, 0);
            tg = target.getGraphics();
            tg.drawImage(blured, 0, 0);
            tg.setAntiAliased(true);
        }
    }
    tg.translate(shapeX, shapeY);
    GeneralPath gp = createShape(shapeW, shapeH);
    Style s = c.getStyle();
    if (s.getBgImage() == null) {
        byte type = s.getBackgroundType();
        if (type == Style.BACKGROUND_IMAGE_SCALED || type == Style.BACKGROUND_NONE) {
            byte bgt = c.getStyle().getBgTransparency();
            if (bgt != 0) {
                tg.setAlpha(bgt & 0xff);
                tg.setColor(s.getBgColor());
                tg.fillShape(gp);
            }
            if (this.stroke != null && strokeOpacity > 0 && strokeThickness > 0) {
                tg.setAlpha(strokeOpacity);
                tg.setColor(strokeColor);
                tg.drawShape(gp, this.stroke);
            }
            return target;
        }
    }
    c.getStyle().setBorder(Border.createEmpty());
    tg.setClip(gp);
    s.getBgPainter().paint(tg, new Rectangle(0, 0, w, h));
    if (this.stroke != null && strokeOpacity > 0 && strokeThickness > 0) {
        tg.setClip(0, 0, w, h);
        tg.setAlpha(strokeOpacity);
        tg.setColor(strokeColor);
        tg.drawShape(gp, this.stroke);
    }
    c.getStyle().setBorder(this);
    return target;
}
Also used : Graphics(com.codename1.ui.Graphics) GeneralPath(com.codename1.ui.geom.GeneralPath) Rectangle(com.codename1.ui.geom.Rectangle) Image(com.codename1.ui.Image)

Example 53 with Graphics

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

the class DefaultLookAndFeel method drawComboBox.

/**
 * {@inheritDoc}
 */
public void drawComboBox(Graphics g, List cb) {
    int border = 2;
    Style style = cb.getStyle();
    int leftPadding = style.getPaddingLeft(cb.isRTL());
    int rightPadding = style.getPaddingRight(cb.isRTL());
    setFG(g, cb);
    ListModel model = cb.getModel();
    ListCellRenderer renderer = cb.getRenderer();
    Object value = model.getItemAt(model.getSelectedIndex());
    int comboImageWidth;
    if (comboImage != null) {
        comboImageWidth = comboImage.getWidth();
    } else {
        comboImageWidth = style.getFont().getHeight();
    }
    int cellX = cb.getX() + style.getPaddingTop();
    if (cb.isRTL()) {
        cellX += comboImageWidth;
    }
    if (model.getSize() > 0) {
        Component cmp = renderer.getListCellRendererComponent(cb, value, model.getSelectedIndex(), cb.hasFocus());
        cmp.setX(cellX);
        cmp.setY(cb.getY() + style.getPaddingTop());
        cmp.setWidth(cb.getWidth() - comboImageWidth - rightPadding - leftPadding);
        cmp.setHeight(cb.getHeight() - style.getPaddingTop() - style.getPaddingBottom());
        cmp.paint(g);
    }
    g.setColor(style.getBgColor());
    int y = cb.getY();
    int height = cb.getHeight();
    int width = comboImageWidth + border;
    int x = cb.getX();
    if (cb.isRTL()) {
        x += leftPadding;
    } else {
        x += cb.getWidth() - comboImageWidth - rightPadding;
    }
    if (comboImage != null) {
        g.drawImage(comboImage, x, y + height / 2 - comboImage.getHeight() / 2);
    } else {
        int color = g.getColor();
        // brighten or darken the color slightly
        int destColor = findDestColor(color);
        g.fillLinearGradient(g.getColor(), destColor, x, y, width, height, false);
        g.setColor(color);
        g.drawRect(x, y, width, height - 1);
        width--;
        height--;
        // g.drawRect(x, y, width, height);
        g.translate(x + 1, y + 1);
        g.setColor(0x111111);
        int x1 = scaleCoordinate(2.5652081f, 16, width);
        int y1 = scaleCoordinate(4.4753664f, 16, height);
        int x2 = scaleCoordinate(8.2872691f, 16, width);
        int y2 = scaleCoordinate(10f, 16, height);
        int x3 = scaleCoordinate(13.516078f, 16, width);
        int y3 = y1;
        g.fillTriangle(x1, y1, x2, y2, x3, y3);
        g.translate(-1, -1);
        g.setColor(style.getFgColor());
        g.fillTriangle(x1, y1, x2, y2, x3, y3);
        // g.setColor(style.getFgColor());
        // g.fillTriangle(x1 + 2, y1 + 2, x2, y2 - 2, x3 - 2, y3 + 2);
        g.translate(-x, -y);
    }
}
Also used : ListModel(com.codename1.ui.list.ListModel) ListCellRenderer(com.codename1.ui.list.ListCellRenderer) Component(com.codename1.ui.Component)

Example 54 with Graphics

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

the class DefaultLookAndFeel method drawLabelString.

/**
 * Implements the drawString for the text component and adjust the valign
 * assuming the icon is in one of the sides
 */
private int drawLabelString(Graphics g, Label l, String text, int x, int y, int textSpaceW) {
    Style style = l.getStyle();
    int cx = g.getClipX();
    int cy = g.getClipY();
    int cw = g.getClipWidth();
    int ch = g.getClipHeight();
    // g.pushClip();
    g.clipRect(x, cy, textSpaceW, ch);
    if (l.isTickerRunning()) {
        Font font = style.getFont();
        if (l.getShiftText() > 0) {
            if (l.getShiftText() > textSpaceW) {
                l.setShiftText(x - l.getX() - l.getStringWidth(font));
            }
        } else if (l.getShiftText() + l.getStringWidth(font) < 0) {
            l.setShiftText(textSpaceW);
        }
    }
    int drawnW = drawLabelText(g, l, text, x, y, textSpaceW);
    g.setClip(cx, cy, cw, ch);
    return drawnW;
}
Also used : Font(com.codename1.ui.Font)

Example 55 with Graphics

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

the class DefaultLookAndFeel method drawPullToRefresh.

/**
 * {@inheritDoc}
 */
public void drawPullToRefresh(Graphics g, final Component cmp, boolean taskExecuted) {
    final Form parentForm = cmp.getComponentForm();
    final int scrollY = cmp.getScrollY();
    Component cmpToDraw;
    if (taskExecuted) {
        cmpToDraw = updating;
    } else {
        if (-scrollY > getPullToRefreshHeight()) {
            cmpToDraw = releaseToRefresh;
        } else {
            cmpToDraw = pullDown;
        }
    }
    if (pull.getComponentAt(0) != updating && cmpToDraw != pull.getComponentAt(0)) {
        parentForm.registerAnimated(new Animation() {

            int counter = 0;

            Image i;

            {
                i = UIManager.getInstance().getThemeImageConstant("pullToRefreshImage");
                if (i == null) {
                    i = getDefaultRefreshIcon();
                }
            }

            public boolean animate() {
                counter++;
                if (pull.getComponentAt(0) == releaseToRefresh) {
                    ((Label) releaseToRefresh).setIcon(i.rotate(180 - (180 / 6) * counter));
                } else {
                    ((Label) pullDown).setIcon(i.rotate(180 * counter / 6));
                }
                if (counter == 6) {
                    ((Label) releaseToRefresh).setIcon(i);
                    ((Label) pullDown).setIcon(i.rotate(180));
                    parentForm.deregisterAnimated(this);
                }
                cmp.repaint(cmp.getAbsoluteX(), cmp.getAbsoluteY() - getPullToRefreshHeight(), cmp.getWidth(), getPullToRefreshHeight());
                return false;
            }

            public void paint(Graphics g) {
            }
        });
    }
    if (pull.getComponentAt(0) != cmpToDraw && cmpToDraw instanceof Label && (pull.getComponentAt(0) instanceof Label)) {
        ((Label) cmpToDraw).setIcon(((Label) pull.getComponentAt(0)).getIcon());
    }
    Component current = pull.getComponentAt(0);
    if (current != cmpToDraw) {
        pull.replace(current, cmpToDraw, null);
    }
    pull.setWidth(cmp.getWidth());
    pull.setX(cmp.getAbsoluteX());
    pull.setY(cmp.getY() - scrollY - getPullToRefreshHeight());
    pull.layoutContainer();
    pull.paintComponent(g);
}
Also used : Graphics(com.codename1.ui.Graphics) Form(com.codename1.ui.Form) Label(com.codename1.ui.Label) Animation(com.codename1.ui.animations.Animation) Component(com.codename1.ui.Component) Image(com.codename1.ui.Image) FontImage(com.codename1.ui.FontImage)

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