protected override void OnMouseDown(Gtk.DrawingArea canvas, Gtk.ButtonPressEventArgs args, PointD point) { Document doc = PintaCore.Workspace.ActiveDocument; Point pos = new Point((int)point.X, (int)point.Y); // Don't do anything if we're outside the canvas if (pos.X < 0 || pos.X >= doc.ImageSize.Width) { return; } if (pos.Y < 0 || pos.Y >= doc.ImageSize.Height) { return; } base.OnMouseDown(canvas, args, point); Gdk.Region currentRegion = Gdk.Region.Rectangle(doc.GetSelectedBounds(true)); // See if the mouse click is valid if (!currentRegion.PointIn(pos.X, pos.Y) && limitToSelection) { currentRegion.Dispose(); currentRegion = null; return; } ImageSurface surface = doc.CurrentUserLayer.Surface; ImageSurface stencil_surface = new ImageSurface(Format.Argb32, (int)surface.Width, (int)surface.Height); IBitVector2D stencilBuffer = new BitVector2DSurfaceAdapter(stencil_surface); int tol = (int)(Tolerance * Tolerance * 256); Rectangle boundingBox; if (IsContinguousMode) { FillStencilFromPoint(surface, stencilBuffer, pos, tol, out boundingBox, currentRegion, limitToSelection); } else { FillStencilByColor(surface, stencilBuffer, surface.GetColorBgra(pos.X, pos.Y), tol, out boundingBox, currentRegion, LimitToSelection); } stencil = stencilBuffer; OnFillRegionComputed(stencilBuffer); // If a derived tool is only going to use the stencil, // don't waste time building the polygon set if (CalculatePolygonSet) { Point[][] polygonSet = stencilBuffer.CreatePolygonSet(boundingBox, 0, 0); OnFillRegionComputed(polygonSet); } }
protected override void OnMouseDown(MouseEventArgs e) { Point pos = new Point(e.X, e.Y); this.contiguous = ((ModifierKeys & Keys.Shift) == 0); if (Document.Bounds.Contains(pos)) { base.OnMouseDown(e); PdnRegion currentRegion = Selection.CreateRegion(); // See if the mouse click is valid if (!currentRegion.IsVisible(pos) && limitToSelection) { currentRegion.Dispose(); currentRegion = null; return; } // Set the current surface, color picked and color to draw Surface surface = ((BitmapLayer)ActiveLayer).Surface; IBitVector2D stencilBuffer = new BitVector2DSurfaceAdapter(this.ScratchSurface); Rectangle boundingBox; int tolerance = (int)(AppEnvironment.Tolerance * AppEnvironment.Tolerance * 256); if (contiguous) { FillStencilFromPoint(surface, stencilBuffer, pos, tolerance, out boundingBox, currentRegion, limitToSelection); } else { FillStencilByColor(surface, stencilBuffer, surface[pos], tolerance, out boundingBox, currentRegion, limitToSelection); } Point[][] polygonSet = PdnGraphicsPath.PolygonSetFromStencil(stencilBuffer, boundingBox, 0, 0); OnFillRegionComputed(polygonSet); } base.OnMouseDown(e); }