123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- using PaintDotNet.Measurement.HistoryMementos;
- using System.Drawing;
- using System.Windows.Forms;
- namespace PaintDotNet.Measurement.Tools
- {
- public class PaintBucketTool : FloodToolBase
- {
- private Cursor cursorMouseUp;
- private Brush brush;
- protected override void OnMouseDown(MouseEventArgs e)
- {
- brush = AppEnvironment.CreateBrush((e.Button != MouseButtons.Left));
- Cursor = Cursors.WaitCursor;
- base.OnMouseDown(e);
- }
- protected override void OnMouseUp(MouseEventArgs e)
- {
- Cursor = cursorMouseUp;
- base.OnMouseUp(e);
- }
- protected override void OnFillRegionComputed(Point[][] polygonSet)
- {
- using (PdnGraphicsPath path = new PdnGraphicsPath())
- {
- path.AddPolygons(polygonSet);
- using (PdnRegion fillRegion = new PdnRegion(path))
- {
- Rectangle boundingBox = fillRegion.GetBoundsInt();
- Surface surface = ((BitmapLayer)ActiveLayer).Surface;
- RenderArgs ra = new RenderArgs(surface);
- HistoryMemento ha;
- using (PdnRegion affected = Utility.SimplifyAndInflateRegion(fillRegion))
- {
- ha = new BitmapHistoryMemento(Name, Image, DocumentWorkspace, DocumentWorkspace.GetActiveLayerIndex(), affected);
- }
- ra.Graphics.CompositingMode = AppEnvironment.GetCompositingMode();
- ra.Graphics.FillRegion(brush, fillRegion.GetRegionReadOnly());
- //HistoryStack.PushNewMemento(ha);
- ActiveLayer.Invalidate(boundingBox);
- Update();
- }
- }
- }
- protected override void OnActivate()
- {
- // cursor-transitions
- cursorMouseUp = new Cursor(PdnResources.GetResourceStream("Cursors.PaintBucketToolCursor.cur"));
- Cursor = cursorMouseUp;
- base.OnActivate();
- }
- protected override void OnDeactivate()
- {
- if (cursorMouseUp != null)
- {
- cursorMouseUp.Dispose();
- cursorMouseUp = null;
- }
- base.OnDeactivate();
- }
- public PaintBucketTool(IDocumentWorkspace documentWorkspace)
- : base(documentWorkspace,
- PdnResources.GetImageResource("Icons.PaintBucketIcon.png"),
- PdnResources.GetString("PaintBucketTool.Name"),
- PdnResources.GetString("PaintBucketTool.HelpText"),
- 'f',
- false,
- ToolBarConfigItems.Brush | ToolBarConfigItems.Antialiasing | ToolBarConfigItems.AlphaBlending)
- {
- }
- protected override void Dispose(bool disposing)
- {
- base.Dispose(disposing);
- if (disposing)
- {
- if (brush != null)
- {
- brush.Dispose();
- brush = null;
- }
- }
- }
- }
- }
|