/// <summary> /// Raised by <see cref="OnTool"/> to perform painting upon pressing left or right mouse button. /// </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 brush = e.IsLeftButtonPressed ? ToolUtility.SelectedBrush : ToolUtility.SelectedBrushSecondary; // Like with the regular paint tool, null brush is the eraser! if (brush != null && !PlopUtility.CanPlopWithBrush(brush)) { return; } if (brush == null) { if (ToolUtility.ActivePlop != null) { PlopUtility.ErasePlop(ToolUtility.ActivePlop); ToolUtility.ActivePlop = null; } } else { if (!this.allowOverpaint && ToolUtility.ActivePlop != null) { // Cycle to next variation if replacing plop with same brush. int nextVariation = ToolUtility.ActivePlop.VariationIndex; if (brush == ToolUtility.ActivePlop.Brush) { ++nextVariation; } ToolUtility.ActivePlop = PlopUtility.CyclePlop(context.TileSystem, ToolUtility.ActivePlop, brush, ToolUtility.Rotation, nextVariation); } else { var args = this.GetPaintingArgs(brush); if (args.variation == Brush.RANDOM_VARIATION) { args.variation = this.PreRandomizeVariation(brush, 0); this.RandomizeVariationShift(); } int nextVariation = args.ResolveVariation(0); var plop = PlopUtility.PaintPlop(context.TileSystem, this.ApplySnapping(this.localMousePoint), brush, ToolUtility.Rotation, nextVariation); ToolUtility.ActivePlop = plop; ToolUtility.PreviouslyPlopped = plop; } } }
/// <inheritdoc/> public override void OnTool(ToolEvent e, IToolContext context) { switch (e.Type) { case EventType.MouseDown: // Note: Left button for next; right button for previous. int offset = 0; if (e.IsLeftButtonPressed) { offset = -1; } else if (e.IsRightButtonPressed) { offset = +1; } if (ToolUtility.ActivePlop != null) { // Variation index to use next? int nextVariation = ToolUtility.ActivePlop.VariationIndex + offset; // Cycle through plop variations. ToolUtility.ActivePlop = PlopUtility.CyclePlop(context.TileSystem, ToolUtility.ActivePlop, ToolUtility.ActivePlop.Brush, ToolUtility.ActivePlop.PaintedRotation, nextVariation); } else { // Get tile at pointer var tile = context.TileSystem.GetTile(e.MousePointerTileIndex); if (tile == null || tile.brush == null) { return; } // Variation index to use next? int nextVariation = tile.variationIndex + offset; // Cycle through tile variations. tile.brush.CycleWithSimpleRotation(context.TileSystem, e.MousePointerTileIndex, tile.PaintedRotation, nextVariation); } break; } }