Search in sources :

Example 51 with Paint

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

the class XYChart method drawYLabels.

/**
 * The graphical representation of the labels on the Y axis.
 *
 * @param allYLabels the Y labels values
 * @param canvas the canvas to paint to
 * @param paint the paint to be used for drawing
 * @param maxScaleNumber the maximum scale number
 * @param left the left value of the labels area
 * @param right the right value of the labels area
 * @param bottom the bottom value of the labels area
 * @param yPixelsPerUnit the amount of pixels per one unit in the chart labels
 * @param minY the minimum value on the Y axis in the chart
 */
protected void drawYLabels(Map<Integer, List<Double>> allYLabels, Canvas canvas, Paint paint, int maxScaleNumber, int left, int right, int bottom, double[] yPixelsPerUnit, double[] minY) {
    Orientation or = mRenderer.getOrientation();
    boolean showGridX = mRenderer.isShowGridX();
    boolean showLabels = mRenderer.isShowLabels();
    boolean showTickMarks = mRenderer.isShowTickMarks();
    paint.setTextSize(mRenderer.getLabelsTextSize());
    for (int i = 0; i < maxScaleNumber; i++) {
        paint.setTextAlign(mRenderer.getYLabelsAlign(i));
        List<Double> yLabels = allYLabels.get(i);
        int length = yLabels.size();
        for (int j = 0; j < length; j++) {
            double label = yLabels.get(j);
            int axisAlign = mRenderer.getYAxisAlign(i);
            boolean textLabel = mRenderer.getYTextLabel(label, i) != null;
            float yLabel = (float) (bottom - yPixelsPerUnit[i] * (label - minY[i]));
            if (or == Orientation.HORIZONTAL) {
                if (showLabels && !textLabel) {
                    paint.setColor(mRenderer.getYLabelsColor(i));
                    if (axisAlign == Align.LEFT) {
                        if (showTickMarks) {
                            canvas.drawLine(left + getLabelLinePos(axisAlign), yLabel, left, yLabel, paint);
                        }
                        drawText(canvas, getLabel(mRenderer.getYLabelFormat(i), label), left - mRenderer.getYLabelsPadding(), yLabel - mRenderer.getYLabelsVerticalPadding(), paint, mRenderer.getYLabelsAngle());
                    } else {
                        if (showTickMarks) {
                            canvas.drawLine(right, yLabel, right + getLabelLinePos(axisAlign), yLabel, paint);
                        }
                        drawText(canvas, getLabel(mRenderer.getYLabelFormat(i), label), right + mRenderer.getYLabelsPadding(), yLabel - mRenderer.getYLabelsVerticalPadding(), paint, mRenderer.getYLabelsAngle());
                    }
                }
                if (showGridX) {
                    paint.setColor(mRenderer.getGridColor(i));
                    canvas.drawLine(left, yLabel, right, yLabel, paint);
                }
            } else if (or == Orientation.VERTICAL) {
                if (showLabels && !textLabel) {
                    paint.setColor(mRenderer.getYLabelsColor(i));
                    if (showTickMarks) {
                        canvas.drawLine(right - getLabelLinePos(axisAlign), yLabel, right, yLabel, paint);
                    }
                    drawText(canvas, getLabel(mRenderer.getLabelFormat(), label), right + 10 + mRenderer.getYLabelsPadding(), yLabel - mRenderer.getYLabelsVerticalPadding(), paint, mRenderer.getYLabelsAngle());
                }
                if (showGridX) {
                    paint.setColor(mRenderer.getGridColor(i));
                    if (showTickMarks) {
                        canvas.drawLine(right, yLabel, left, yLabel, paint);
                    }
                }
            }
        }
    }
}
Also used : Orientation(com.codename1.charts.renderers.XYMultipleSeriesRenderer.Orientation) Point(com.codename1.charts.models.Point) Paint(com.codename1.charts.compat.Paint)

Example 52 with Paint

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

the class XYChart method drawXLabels.

/**
 * The graphical representation of the labels on the X axis.
 *
 * @param xLabels the X labels values
 * @param xTextLabelLocations the X text label locations
 * @param canvas the canvas to paint to
 * @param paint the paint to be used for drawing
 * @param left the left value of the labels area
 * @param top the top value of the labels area
 * @param bottom the bottom value of the labels area
 * @param xPixelsPerUnit the amount of pixels per one unit in the chart labels
 * @param minX the minimum value on the X axis in the chart
 * @param maxX the maximum value on the X axis in the chart
 */
protected void drawXLabels(List<Double> xLabels, Double[] xTextLabelLocations, Canvas canvas, Paint paint, int left, int top, int bottom, double xPixelsPerUnit, double minX, double maxX) {
    int length = xLabels.size();
    boolean showLabels = mRenderer.isShowLabels();
    boolean showGridY = mRenderer.isShowGridY();
    boolean showTickMarks = mRenderer.isShowTickMarks();
    for (int i = 0; i < length; i++) {
        double label = xLabels.get(i);
        float xLabel = (float) (left + xPixelsPerUnit * (label - minX));
        if (showLabels) {
            paint.setColor(mRenderer.getXLabelsColor());
            if (showTickMarks) {
                canvas.drawLine(xLabel, bottom, xLabel, bottom + mRenderer.getLabelsTextSize() / 3, paint);
            }
            drawText(canvas, getLabel(mRenderer.getXLabelFormat(), label), xLabel, bottom + mRenderer.getLabelsTextSize() * 4 / 3 + mRenderer.getXLabelsPadding(), paint, mRenderer.getXLabelsAngle());
        }
        if (showGridY) {
            paint.setColor(mRenderer.getGridColor(0));
            canvas.drawLine(xLabel, bottom, xLabel, top, paint);
        }
    }
    drawXTextLabels(xTextLabelLocations, canvas, paint, showLabels, left, top, bottom, xPixelsPerUnit, minX, maxX);
}
Also used : Point(com.codename1.charts.models.Point) Paint(com.codename1.charts.compat.Paint)

Example 53 with Paint

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

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

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

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