Search in sources :

Example 76 with Style

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

the class InfiniteProgress method calcPreferredSize.

/**
 * {@inheritDoc}
 */
protected Dimension calcPreferredSize() {
    if (animation == null) {
        animation = UIManager.getInstance().getThemeImageConstant("infiniteImage");
        if (animation == null) {
            int size = Display.getInstance().convertToPixels(7, true);
            String f = getUIManager().getThemeConstant("infiniteDefaultColor", null);
            int color = 0x777777;
            if (f != null) {
                color = Integer.parseInt(f, 16);
            }
            FontImage fi = FontImage.createFixed("" + FontImage.MATERIAL_AUTORENEW, FontImage.getMaterialDesignFont(), color, size, size, 0);
            animation = fi.toImage();
        }
    }
    if (animation == null) {
        return new Dimension(100, 100);
    }
    Style s = getStyle();
    return new Dimension(s.getHorizontalPadding() + animation.getWidth(), s.getVerticalPadding() + animation.getHeight());
}
Also used : Style(com.codename1.ui.plaf.Style) Dimension(com.codename1.ui.geom.Dimension) FontImage(com.codename1.ui.FontImage)

Example 77 with Style

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

the class XYChart method drawSeries.

/**
 * Draws the series.
 *
 * @param series the series
 * @param canvas the canvas
 * @param paint the paint object
 * @param pointsList the points to be rendered
 * @param seriesRenderer the series renderer
 * @param yAxisValue the y axis value in pixels
 * @param seriesIndex the series index
 * @param or the orientation
 * @param startIndex the start index of the rendering points
 */
protected void drawSeries(XYSeries series, Canvas canvas, Paint paint, List<Float> pointsList, XYSeriesRenderer seriesRenderer, float yAxisValue, int seriesIndex, Orientation or, int startIndex) {
    BasicStroke stroke = seriesRenderer.getStroke();
    int cap = paint.getStrokeCap();
    int join = paint.getStrokeJoin();
    float miter = paint.getStrokeMiter();
    // PathEffect pathEffect = paint.getPathEffect();
    Style style = paint.getStyle();
    if (stroke != null) {
        setStroke(stroke.getCap(), stroke.getJoin(), stroke.getMiter(), Style.FILL_AND_STROKE, paint);
    }
    // float[] points = MathHelper.getFloats(pointsList);
    drawSeries(canvas, paint, pointsList, seriesRenderer, yAxisValue, seriesIndex, startIndex);
    drawPoints(canvas, paint, pointsList, seriesRenderer, yAxisValue, seriesIndex, startIndex);
    paint.setTextSize(seriesRenderer.getChartValuesTextSize());
    if (or == Orientation.HORIZONTAL) {
        paint.setTextAlign(Align.CENTER);
    } else {
        paint.setTextAlign(Align.LEFT);
    }
    if (seriesRenderer.isDisplayChartValues()) {
        paint.setTextAlign(seriesRenderer.getChartValuesTextAlign());
        drawChartValuesText(canvas, series, seriesRenderer, paint, pointsList, seriesIndex, startIndex);
    }
    if (stroke != null) {
        setStroke(cap, join, miter, style, paint);
    }
}
Also used : BasicStroke(com.codename1.charts.renderers.BasicStroke) Style(com.codename1.charts.compat.Paint.Style) Point(com.codename1.charts.models.Point) Paint(com.codename1.charts.compat.Paint)

Example 78 with Style

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

the class ToastBar method showMessage.

/**
 * Simplifies a common use case of showing a message with an icon that fades out after a few seconds
 * @param msg the message
 * @param icon the material icon to show from {@link com.codename1.ui.FontImage}
 * @param timeout the timeout value in milliseconds
 * @param listener the action to perform when the ToastBar is tapped
 */
public static void showMessage(String msg, char icon, int timeout, ActionListener listener) {
    ToastBar.Status s = ToastBar.getInstance().createStatus();
    Style stl = UIManager.getInstance().getComponentStyle(s.getMessageUIID());
    s.setIcon(FontImage.createMaterial(icon, stl, 4));
    s.setMessage(msg);
    if (listener != null) {
        s.setListener(listener);
    }
    s.setExpires(timeout);
    s.show();
}
Also used : Style(com.codename1.ui.plaf.Style)

Example 79 with Style

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

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

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