Paints the line to the canvas
.
Source
void paint(Canvas canvas) { // Check input values assert(_points != null); if (_points.length < 2) return; assert(_points.length == colors.length); assert(_points.length == widths.length); _cachedPaint.transferMode = transferMode; // Calculate normals List<Vector2> vectors = <Vector2>[]; for (Point pt in _points) { vectors.add(new Vector2(pt.x, pt.y)); } List<Vector2> miters = _computeMiterList(vectors, false); List<Point> vertices = <Point>[]; List<int> indices = <int>[]; List<Color> verticeColors = <Color>[]; List<Point> textureCoordinates; double textureTop; double textureBottom; List<double> stops; // Add first point Point lastPoint = _points[0]; Vector2 lastMiter = miters[0]; // Add vertices and colors _addVerticesForPoint(vertices, lastPoint, lastMiter, widths[0]); verticeColors.add(colors[0]); verticeColors.add(colors[0]); if (texture != null) { assert(texture.rotated == false); // Setup for calculating texture coordinates textureTop = texture.frame.top; textureBottom = texture.frame.bottom; textureCoordinates = <Point>[]; // Use correct stops if (textureStops != null) { assert(_points.length == textureStops.length); stops = textureStops; } else { if (_calculatedTextureStops == null) _calculateTextureStops(); stops = _calculatedTextureStops; } // Texture coordinate points double xPos = _xPosForStop(stops[0]); textureCoordinates.add(new Point(xPos, textureTop)); textureCoordinates.add(new Point(xPos, textureBottom)); } // Add the rest of the points for (int i = 1; i < _points.length; i++) { // Add vertices Point currentPoint = _points[i]; Vector2 currentMiter = miters[i]; _addVerticesForPoint(vertices, currentPoint, currentMiter, widths[i]); // Add references to the triangles int lastIndex0 = (i - 1) * 2; int lastIndex1 = (i - 1) * 2 + 1; int currentIndex0 = i * 2; int currentIndex1 = i * 2 + 1; indices.addAll(<int>[lastIndex0, lastIndex1, currentIndex0]); indices.addAll(<int>[lastIndex1, currentIndex1, currentIndex0]); // Add colors verticeColors.add(colors[i]); verticeColors.add(colors[i]); if (texture != null) { // Texture coordinate points double xPos = _xPosForStop(stops[i]); textureCoordinates.add(new Point(xPos, textureTop)); textureCoordinates.add(new Point(xPos, textureBottom)); } // Update last values lastPoint = currentPoint; lastMiter = currentMiter; } canvas.drawVertices(VertexMode.triangles, vertices, textureCoordinates, verticeColors, TransferMode.modulate, indices, _cachedPaint); }