Search in sources :

Example 1 with BasicStroke

use of com.codename1.charts.renderers.BasicStroke 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 2 with BasicStroke

use of com.codename1.charts.renderers.BasicStroke in project CodenameOne by codenameone.

the class CodenameOneImageRenderer method paintComponent.

@Override
public void paintComponent(Graphics g) {
    g.setColor(new Color(CheckerBoardColorCalibration.getColorA()));
    g.fillRect(0, 0, getWidth(), getHeight());
    g.setColor(new Color(CheckerBoardColorCalibration.getColorB()));
    int width = getWidth();
    int height = getHeight();
    for (int x = 0; x < width; x += 8) {
        if (x % 16 == 0) {
            for (int y = 0; y < height; y += 16) {
                g.fillRect(x, y, 8, 8);
            }
        } else {
            for (int y = 8; y < height; y += 16) {
                g.fillRect(x, y, 8, 8);
            }
        }
    }
    if (drawBorder) {
        g.setColor(Color.BLACK);
        g.drawRect(0, 0, image.getWidth() + 1, image.getHeight() + 1);
    }
    if (zoom != 1) {
        ((Graphics2D) g).scale(zoom, zoom);
    }
    if (animationObjectList != null) {
        if (((Timeline) image).isPause()) {
            int selectedRow = animationObjectList.getSelectedRow();
            AnimationObject sel = null;
            if (selectedRow > -1) {
                sel = ((TimelineEditor.AnimationObjectTableModel) animationObjectList.getModel()).getElementAt(selectedRow);
            }
            if (dragging != null) {
                if (draggingImage == null) {
                    draggingImage = new BufferedImage(AnimationAccessor.getWidthInt(dragging), AnimationAccessor.getHeightInt(dragging), BufferedImage.TYPE_INT_ARGB);
                    draggingImage.setRGB(0, 0, draggingImage.getWidth(), draggingImage.getHeight(), AnimationAccessor.getImageMethod(dragging).modifyAlpha((byte) 110).getRGB(), 0, draggingImage.getWidth());
                }
            } else {
                draggingImage = null;
            }
            if (sel != null) {
                Graphics2D g2d = (Graphics2D) g.create();
                g2d.drawImage(buffer[currentFrame], 0, 0, this);
                g2d.setColor(Color.BLUE);
                g2d.setStroke(new BasicStroke(3, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
                g2d.drawRect(AnimationAccessor.getX(sel), AnimationAccessor.getY(sel), AnimationAccessor.getWidthInt(sel), AnimationAccessor.getHeightInt(sel));
                if (draggingImage != null) {
                    g2d.drawImage(draggingImage, dragX, dragY, null);
                }
                g2d.dispose();
                return;
            }
        }
    }
    g.drawImage(buffer[currentFrame], 0, 0, this);
    if (draggingImage != null) {
        g.drawImage(draggingImage, dragX, dragY, null);
    }
}
Also used : BasicStroke(java.awt.BasicStroke) Timeline(com.codename1.ui.animations.Timeline) Color(java.awt.Color) AnimationObject(com.codename1.ui.animations.AnimationObject) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D)

Aggregations

Paint (com.codename1.charts.compat.Paint)1 Style (com.codename1.charts.compat.Paint.Style)1 Point (com.codename1.charts.models.Point)1 BasicStroke (com.codename1.charts.renderers.BasicStroke)1 AnimationObject (com.codename1.ui.animations.AnimationObject)1 Timeline (com.codename1.ui.animations.Timeline)1 BasicStroke (java.awt.BasicStroke)1 Color (java.awt.Color)1 Graphics2D (java.awt.Graphics2D)1 BufferedImage (java.awt.image.BufferedImage)1