123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- 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;
- }
- }
- }
|