Search in sources :

Example 6 with Stroke

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

the class ScatterChart method drawSeries.

/**
 * The graphical representation of a series.
 *
 * @param canvas the canvas to paint to
 * @param paint the paint to be used for drawing
 * @param points the array of points to be used for drawing the series
 * @param seriesRenderer the series renderer
 * @param yAxisValue the minimum value of the y axis
 * @param seriesIndex the index of the series currently being drawn
 * @param startIndex the start index of the rendering points
 */
@Override
public void drawSeries(Canvas canvas, Paint paint, List<Float> points, XYSeriesRenderer renderer, float yAxisValue, int seriesIndex, int startIndex) {
    paint.setColor(renderer.getColor());
    final float stroke = paint.getStrokeWidth();
    if (renderer.isFillPoints()) {
        paint.setStyle(Style.FILL);
    } else {
        paint.setStrokeWidth(renderer.getPointStrokeWidth());
        paint.setStyle(Style.STROKE);
    }
    int length = points.size();
    // switch on ENUM's generates reflection code that screws up J2ME
    PointStyle ps = renderer.getPointStyle();
    if (ps == PointStyle.X) {
        paint.setStrokeWidth(renderer.getPointStrokeWidth());
        for (int i = 0; i < length; i += 2) {
            drawX(canvas, paint, points.get(i), points.get(i + 1));
        }
    } else {
        if (ps == PointStyle.CIRCLE) {
            for (int i = 0; i < length; i += 2) {
                drawCircle(canvas, paint, points.get(i), points.get(i + 1));
            }
        } else {
            if (ps == PointStyle.TRIANGLE) {
                float[] path = new float[6];
                for (int i = 0; i < length; i += 2) {
                    drawTriangle(canvas, paint, path, points.get(i), points.get(i + 1));
                }
            } else {
                if (ps == PointStyle.SQUARE) {
                    for (int i = 0; i < length; i += 2) {
                        drawSquare(canvas, paint, points.get(i), points.get(i + 1));
                    }
                } else {
                    if (ps == PointStyle.DIAMOND) {
                        float[] path = new float[8];
                        for (int i = 0; i < length; i += 2) {
                            drawDiamond(canvas, paint, path, points.get(i), points.get(i + 1));
                        }
                    } else {
                        if (ps == PointStyle.POINT) {
                            for (int i = 0; i < length; i += 2) {
                                canvas.drawPoint(points.get(i), points.get(i + 1), paint);
                            }
                        }
                    }
                }
            }
        }
    }
    /*switch (renderer.getPointStyle()) {
    case X:
      paint.setStrokeWidth(renderer.getPointStrokeWidth());
      for (int i = 0; i < length; i += 2) {
        drawX(canvas, paint, points.get(i), points.get(i + 1));
      }
      break;
    case CIRCLE:
      for (int i = 0; i < length; i += 2) {
        drawCircle(canvas, paint, points.get(i), points.get(i + 1));
      }
      break;
    case TRIANGLE:
      float[] path = new float[6];
      for (int i = 0; i < length; i += 2) {
        drawTriangle(canvas, paint, path, points.get(i), points.get(i + 1));
      }
      break;
    case SQUARE:
      for (int i = 0; i < length; i += 2) {
        drawSquare(canvas, paint, points.get(i), points.get(i + 1));
      }
      break;
    case DIAMOND:
      path = new float[8];
      for (int i = 0; i < length; i += 2) {
        drawDiamond(canvas, paint, path, points.get(i), points.get(i + 1));
      }
      break;
    case POINT:
      for (int i = 0; i < length; i += 2) {
        canvas.drawPoint(points.get(i), points.get(i + 1), paint);
      }
      break;
    }*/
    paint.setStrokeWidth(stroke);
}
Also used : Paint(com.codename1.charts.compat.Paint)

Example 7 with Stroke

use of com.codename1.ui.Stroke 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 8 with Stroke

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

the class RoundRectBorder method stroke.

/**
 * Sets the stroke of the border
 * @param stroke the thickness of the stroke object
 * @param mm set to true to indicate the value is in millimeters, false indicates pixels
 * @return border instance so these calls can be chained
 */
public RoundRectBorder stroke(float stroke, boolean mm) {
    strokeThickness = stroke;
    if (strokeThickness == 0) {
        this.stroke = null;
        return this;
    }
    strokeMM = mm;
    if (mm) {
        stroke = Display.getInstance().convertToPixels(stroke);
    }
    return stroke(new Stroke(stroke, Stroke.CAP_SQUARE, Stroke.JOIN_MITER, 1));
}
Also used : Stroke(com.codename1.ui.Stroke)

Example 9 with Stroke

use of com.codename1.ui.Stroke 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 10 with Stroke

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

the class RoundBorder method fillShape.

private void fillShape(Graphics g, int color, int opacity, int width, int height, boolean stroke) {
    g.setColor(color);
    g.setAlpha(opacity);
    if (!rectangle || width <= height) {
        int x = 0;
        int y = 0;
        int size = width;
        if (width != height) {
            if (width > height) {
                size = height;
                x = (width - height) / 2;
            } else {
                size = width;
                y = (height - width) / 2;
            }
        }
        if (size < 5) {
            // probably won't be visible anyway so do nothing, otherwise it might throw an exception
            return;
        }
        if (stroke && this.stroke != null) {
            int sw = (int) Math.ceil((stroke && this.stroke != null) ? this.stroke.getLineWidth() : 0);
            GeneralPath arc = new GeneralPath();
            arc.arc(x + sw / 2, y + sw / 2, size - 2 * sw, size - 2 * sw, 0, 2 * Math.PI);
            g.fillShape(arc);
            g.setColor(strokeColor);
            g.setAlpha(strokeOpacity);
            if (strokeAngle != 360) {
                arc = new GeneralPath();
                arc.arc(x + sw / 2, y + sw / 2, size - 2 * sw, size - 2 * sw, Math.PI / 2, -Math.toRadians(strokeAngle));
            }
            g.drawShape(arc, this.stroke);
        } else {
            g.fillArc(x, y, size, size, 0, 360);
        }
    } else {
        GeneralPath gp = new GeneralPath();
        float sw = (stroke && this.stroke != null) ? this.stroke.getLineWidth() : 0;
        gp.moveTo(height / 2.0, sw);
        gp.lineTo(width - (height / 2.0), sw);
        gp.arcTo(width - (height / 2.0), height / 2.0, width - (height / 2.0), height - sw, true);
        gp.lineTo(height / 2.0, height - sw);
        gp.arcTo(height / 2.0, height / 2.0, height / 2.0, sw, true);
        gp.closePath();
        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)

Aggregations

Stroke (com.codename1.ui.Stroke)4 GeneralPath (com.codename1.ui.geom.GeneralPath)3 Paint (com.codename1.charts.compat.Paint)2 Image (com.codename1.ui.Image)2 Rectangle (com.codename1.ui.geom.Rectangle)2 CodenameOneComponentWrapper (com.codename1.ui.resource.util.CodenameOneComponentWrapper)2 JButton (javax.swing.JButton)2 Bitmap (android.graphics.Bitmap)1 Canvas (android.graphics.Canvas)1 Matrix (android.graphics.Matrix)1 Paint (android.graphics.Paint)1 Path (android.graphics.Path)1 RectF (android.graphics.RectF)1 Style (com.codename1.charts.compat.Paint.Style)1 Point (com.codename1.charts.models.Point)1 BasicStroke (com.codename1.charts.renderers.BasicStroke)1 Button (com.codename1.ui.Button)1 PathIterator (com.codename1.ui.geom.PathIterator)1 Border (com.codename1.ui.plaf.Border)1 RoundBorder (com.codename1.ui.plaf.RoundBorder)1