using PaintDotNet.Measurement.HistoryMementos; using System.Drawing; using System.Drawing.Drawing2D; using System.Windows.Forms; namespace PaintDotNet.Measurement.Tools { public class MagicWandTool : FloodToolBase { private Cursor cursorMouseUp; private Cursor cursorMouseUpMinus; private Cursor cursorMouseUpPlus; private CombineMode combineMode; private Cursor GetCursor(bool ctrlDown, bool altDown) { Cursor cursor; if (ctrlDown) { cursor = this.cursorMouseUpPlus; } else if (altDown) { cursor = this.cursorMouseUpMinus; } else { cursor = this.cursorMouseUp; } return cursor; } private Cursor GetCursor() { return GetCursor((ModifierKeys & Keys.Control) != 0, (ModifierKeys & Keys.Alt) != 0); } protected override void OnActivate() { DocumentWorkspace.SetEnableSelectionTinting(true); this.cursorMouseUp = new Cursor(PdnResources.GetResourceStream("Cursors.MagicWandToolCursor.cur")); this.cursorMouseUpMinus = new Cursor(PdnResources.GetResourceStream("Cursors.MagicWandToolCursorMinus.cur")); this.cursorMouseUpPlus = new Cursor(PdnResources.GetResourceStream("Cursors.MagicWandToolCursorPlus.cur")); this.Cursor = GetCursor(); base.OnActivate(); } protected override void OnDeactivate() { if (this.cursorMouseUp != null) { this.cursorMouseUp.Dispose(); this.cursorMouseUp = null; } if (this.cursorMouseUpMinus != null) { this.cursorMouseUpMinus.Dispose(); this.cursorMouseUpMinus = null; } if (this.cursorMouseUpPlus != null) { this.cursorMouseUpPlus.Dispose(); this.cursorMouseUpPlus = null; } DocumentWorkspace.SetEnableSelectionTinting(false); base.OnDeactivate(); } protected override void OnKeyDown(KeyEventArgs e) { Cursor = GetCursor(); base.OnKeyDown(e); } protected override void OnKeyUp(KeyEventArgs e) { Cursor = GetCursor(); base.OnKeyUp(e); } protected override void OnMouseUp(MouseEventArgs e) { Cursor = GetCursor(); base.OnMouseUp(e); } protected override void OnMouseDown(MouseEventArgs e) { Cursor = Cursors.WaitCursor; if ((ModifierKeys & Keys.Control) != 0 && e.Button == MouseButtons.Left) { this.combineMode = CombineMode.Union; } else if ((ModifierKeys & Keys.Alt) != 0 && e.Button == MouseButtons.Left) { this.combineMode = CombineMode.Exclude; } else if ((ModifierKeys & Keys.Control) != 0 && e.Button == MouseButtons.Right) { this.combineMode = CombineMode.Xor; } else if ((ModifierKeys & Keys.Alt) != 0 && e.Button == MouseButtons.Right) { this.combineMode = CombineMode.Intersect; } else { this.combineMode = AppEnvironment.SelectionCombineMode(); } base.OnMouseDown(e); } protected override void OnFillRegionComputed(Point[][] polygonSet) { SelectionHistoryMemento undoAction = new SelectionHistoryMemento(this.Name, this.Image, this.DocumentWorkspace); Selection.PerformChanging(); Selection.SetContinuation(polygonSet, this.combineMode); Selection.CommitContinuation(); Selection.PerformChanged(); //HistoryStack.PushNewMemento(undoAction); } public MagicWandTool(IDocumentWorkspace documentWorkspace) : base(documentWorkspace, PdnResources.GetImageResource("Icons.MagicWandToolIcon.png"), PdnResources.GetString("MagicWandTool.Name"), PdnResources.GetString("MagicWandTool.HelpText"), 's', false, ToolBarConfigItems.SelectionCombineMode) { ClipToSelection = false; } } }