protected override void OnFillRegionComputed(Document document, Point[][] polygonSet) { var undoAction = new SelectionHistoryItem(Icon, Name); undoAction.TakeSnapshot(); document.PreviousSelection.Dispose(); document.PreviousSelection = document.Selection.Clone(); document.Selection.SelectionPolygons.Clear(); SelectionModeHandler.PerformSelectionMode(combine_mode, DocumentSelection.ConvertToPolygons(polygonSet)); document.History.PushNewItem(undoAction); document.Workspace.Invalidate(); }
protected override void OnFillRegionComputed(Point[][] polygonSet) { Document doc = PintaCore.Workspace.ActiveDocument; SelectionHistoryItem undoAction = new SelectionHistoryItem(this.Icon, this.Name); undoAction.TakeSnapshot(); //Convert Pinta's passed in Polygon Set to a Clipper Polygon collection. List <List <IntPoint> > newPolygons = DocumentSelection.ConvertToPolygons(polygonSet); using (Context g = new Context(PintaCore.Layers.CurrentLayer.Surface)) { //Make sure time isn't wasted if the CombineMode is Replace - Replace is much simpler than the other 4 selection modes. if (combineMode == CombineMode.Replace) { //Clear any previously stored Polygons. doc.Selection.SelectionPolygons.Clear(); //Set the resulting selection path to the new selection path. doc.Selection.SelectionPolygons = newPolygons; doc.Selection.SelectionPath = g.CreatePolygonPath(polygonSet); } else { List <List <IntPoint> > resultingPolygons = new List <List <IntPoint> >(); //Specify the Clipper Subject (the previous Polygons) and the Clipper Clip (the new Polygons). //Note: for Union, ignore the Clipper Library instructions - the new polygon(s) should be Clips, not Subjects! doc.Selection.SelectionClipper.AddPolygons(doc.Selection.SelectionPolygons, PolyType.ptSubject); doc.Selection.SelectionClipper.AddPolygons(newPolygons, PolyType.ptClip); switch (combineMode) { case CombineMode.Xor: //Xor means "Combine both Polygon sets, but leave out any areas of intersection between the two." doc.Selection.SelectionClipper.Execute(ClipType.ctXor, resultingPolygons); break; case CombineMode.Exclude: //Exclude == Difference //Exclude/Difference means "Subtract any overlapping areas of the new Polygon set from the old Polygon set." doc.Selection.SelectionClipper.Execute(ClipType.ctDifference, resultingPolygons); break; case CombineMode.Intersect: //Intersect means "Leave only the overlapping areas between the new and old Polygon sets." doc.Selection.SelectionClipper.Execute(ClipType.ctIntersection, resultingPolygons); break; default: //Default should only be *CombineMode.Union*, but just in case... //Union means "Combine both Polygon sets, and keep any overlapping areas as well." doc.Selection.SelectionClipper.Execute(ClipType.ctUnion, resultingPolygons); break; } //After using Clipper, it has to be cleared so there are no conflicts with its next usage. doc.Selection.SelectionClipper.Clear(); //Set the resulting selection path to the calculated ("clipped") selection path. doc.Selection.SelectionPolygons = resultingPolygons; doc.Selection.SelectionPath = g.CreatePolygonPath(DocumentSelection.ConvertToPolygonSet(resultingPolygons)); } } doc.History.PushNewItem(undoAction); doc.Workspace.Invalidate(); }