private void OnSelectionChanged(object sender, EventArgs e) { this.render = true; PdnGraphicsPath path = this.selection.CreatePath(); if (this.selectedPath == null) { Invalidate(); } else { this.selectedPath.Dispose(); this.selectedPath = null; } bool fullInvalidate = false; this.selectedPath = path; // HACK: Sometimes the selection leaves behind artifacts. So do a full invalidate // every 1 second. if (this.selectedPath.PointCount > 10 && (DateTime.Now - lastFullInvalidate > new TimeSpan(0, 0, 0, 1, 0))) { fullInvalidate = true; } // if we're moving to a simpler selection region ... if (this.selectedPath == null)// || this.selectedPath.PointCount == 0) { // then invalidate everything fullInvalidate = true; } else { // otherwise, be intelligent about it and only redraw the 'new' area PdnRegion xorMe = new PdnRegion(this.selectedPath); selectionRedrawInterior.Xor(xorMe); xorMe.Dispose(); } float ratio = 1.0f / (float)OwnerList.ScaleFactor.Ratio; int ratioInt = (int)Math.Ceiling(ratio); if (this.Visible && (this.EnableSelectionOutline || this.EnableSelectionTinting)) { using (PdnRegion simplified = Utility.SimplifyAndInflateRegion(selectionRedrawInterior, Utility.DefaultSimplificationFactor, 2 * ratioInt)) { Invalidate(simplified); } } if (fullInvalidate) { Rectangle rect = Rectangle.Inflate(Rectangle.Truncate(selectionRedrawOutline.GetBounds2()), 1, 1); Invalidate(rect); lastFullInvalidate = DateTime.Now; } this.selectionRedrawInterior.Dispose(); this.selectionRedrawInterior = null; if (this.zoomInSelectedPath != null) { this.zoomInSelectedPath.Dispose(); this.zoomInSelectedPath = null; } this.simplifiedRegionForTimer = null; // prepare for next call if (this.selectedPath != null && !this.selectedPath.IsEmpty) { this.selectionRedrawOutline = (PdnGraphicsPath)this.selectedPath.Clone(); this.selectionRedrawInterior = new PdnRegion(this.selectedPath); } else { if (invertedTinting) { this.selectionRedrawInterior = new PdnRegion(new Rectangle(0, 0, this.SourceSize.Width, this.SourceSize.Height)); } else { this.selectionRedrawInterior = new PdnRegion(); this.selectionRedrawInterior.MakeEmpty(); } Invalidate(); this.selectionRedrawOutline = new PdnGraphicsPath(); } }