/// <summary> /// Raised by <see cref="OnTool"/> to perform painting upon releasing left or right /// mouse button when a tile has been anchored on the active tile system. /// </summary> /// <param name="e">Tool event data.</param> /// <param name="context">Context that tool is being used in.</param> protected virtual void OnPaint(ToolEvent e, IToolContext context) { var tileSystem = context.TileSystem; try { // Avoid updating procedural meshes multiple times whilst painting tiles. // In most circumstances this would not happen anyhow, but for performance // it's better to play it safe. tileSystem.BeginProceduralEditing(); var brush = (e.WasLeftButtonPressed ? ToolUtility.SelectedBrush : ToolUtility.SelectedBrushSecondary); TileIndex from, to; MathUtility.GetRectangleBoundsClamp(tileSystem, this.anchorIndex, e.MousePointerTileIndex, out from, out to, this.IsTargetPointConstrained); if (from != to) { PaintingUtility.PaintRectangle(tileSystem, from, to, ToolUtility.FillCenter, this.GetPaintingArgs(brush)); } else { this.PaintPoint(tileSystem, from, brush); } } finally { tileSystem.EndProceduralEditing(); } }
/// <inheritdoc/> public override void OnTool(ToolEvent e, IToolContext context) { switch (e.Type) { case EventType.MouseDown: case EventType.MouseDrag: var brush = e.IsLeftButtonPressed ? ToolUtility.SelectedBrush : ToolUtility.SelectedBrushSecondary; int restoreMaximumFillCount = PaintingUtility.MaximumFillCount; PaintingUtility.MaximumFillCount = this.MaximumFillCount; try { PaintingUtility.FloodFill(context.TileSystem, e.MousePointerTileIndex, this.GetPaintingArgs(brush)); } finally { PaintingUtility.MaximumFillCount = restoreMaximumFillCount; } break; } }
/// <summary> /// Paint line of tiles using tool configuration. /// </summary> /// <param name="system">Tile system.</param> /// <param name="from">Index of tile at start of line.</param> /// <param name="to">Index of tile at end of line.</param> /// <param name="brush">Brush to paint with or specify <c>null</c> to erase existing tiles.</param> protected void PaintLine(TileSystem system, TileIndex from, TileIndex to, Brush brush) { var args = this.GetPaintingArgs(brush); if (args.variation == Brush.RANDOM_VARIATION) { // Use pre-randomized variation when painting individual tiles? if (brush != null && from == to && this.NozzleSize == 1) { int orientationMask = OrientationUtility.DetermineTileOrientation(system, from, brush, args.rotation); args.variation = this.PreRandomizeVariation(brush, orientationMask); this.RandomizeVariationShift(); } } switch (ToolUtility.BrushNozzle) { default: case BrushNozzle.Round: PaintingUtility.StrokeLineWithCircle( system: system, from: from, to: to, radius: this.NozzleRadius, args: args ); break; case BrushNozzle.Square: PaintingUtility.StrokeLineWithSquare( system: system, from: from, to: to, size: this.NozzleSize, args: args ); break; } }