/// <summary>Fills the current path with a solid colour. The colour used originates from the fillStyle.</summary> public void fill() { if (Path.FirstPathNode == null) { return; } if (Rasteriser == null) { // Setup and start the rasteriser: Rasteriser = new Scanner(); Rasteriser.SDFSize = 0; Rasteriser.ScaleY = -1f; Rasteriser.Start(); } // Figure out bounds: Path.RecalculateBounds(); DynamicTexture img = ImageData_; int rWidth = img.Width; int rHeight = img.Height; Rasteriser.Rasterise(Path, img.Pixels, rWidth, 0, rWidth, rHeight, 0f, -rHeight, FillColour, false); img.RequestPaint(); }
/// <summary>Draws the outline of path you created, and doesn't reset the path, using the stroke style.</summary> public void stroke() { if (Clip_) { // Clip the path first. Clip_ = false; // Clip with a 50px safety zone on all sides for strokes. Path.Clip(-50f, -50f, ImageData.Width + 50f, ImageData.Height + 50f); } // For each line.. DynamicTexture img = ImageData_; VectorPoint node = Path.FirstPathNode; // For each one.. while (node != null) { // Render it as a line (if it has one; checks internally): if (node.HasLine) { // Render the line from the next nodes point of view: node.RenderLine(this); } // Hop to the next one: node = node.Next; } // Request a paint: img.RequestPaint(); }
/// <summary>Fills the specified box region using the given colour.</summary> public void fillRect(int xStart, int yStart, int rectWidth, int rectHeight, Color32 colour) { // First invert y. This is because the canvas API is from the top left corner. DynamicTexture img = ImageData_; int yEnd = img.Height - yStart; int xEnd = xStart + rectWidth; yStart = yEnd - rectHeight; // Clip the region to the available space: if (xStart < 0) { xStart = 0; } if (yStart < 0) { yStart = 0; } if (xEnd > img.Width) { xEnd = img.Width; } if (yEnd > img.Height) { yEnd = img.Height; } // Fill each pixel: for (int y = yStart; y < yEnd; y++) { // Get the index of this row of pixels. int index = (y * img.Width); for (int x = xStart; x < xEnd; x++) { img.Pixels[x + index] = colour; } } img.RequestPaint(); }
/// <summary>Fills the current path with a solid colour. The colour used originates from the fillStyle.</summary> public void fill() { if (Path.FirstPathNode == null) { return; } if (Clip_) { // Clip the path first. Clip_ = false; // Clip with a 50px safety zone on all sides for strokes. Path.Clip(-50f, -50f, ImageData.Width + 50f, ImageData.Height + 50f); } if (Rasteriser == null) { // Setup and start the rasteriser: Rasteriser = new Scanner(); Rasteriser.SDFSize = 0; Rasteriser.ScaleY = -1f; Rasteriser.Start(); } // Figure out bounds: Path.RecalculateBounds(); DynamicTexture img = ImageData_; int rWidth = img.Width; int rHeight = img.Height; Rasteriser.Rasterise(Path, img.Pixels, rWidth, 0, rWidth, rHeight, 0f, -rHeight, FillColour, false); img.RequestPaint(); }
/// <summary>Draws the outline of path you created, and doesn't reset the path, using the stroke style.</summary> public void stroke() { // For each line.. DynamicTexture img = ImageData_; VectorPoint node = Path.FirstPathNode; // For each one.. while (node != null) { // Render it as a line (if it has one; checks internally): if (node.HasLine) { // Render the line from the next nodes point of view: node.RenderLine(this); } // Hop to the next one: node = node.Next; } // Request a paint: img.RequestPaint(); }