public static PdnGraphicsPath Combine(PdnGraphicsPath subjectPath, CombineMode combineMode, PdnGraphicsPath clipPath) { switch (combineMode) { case CombineMode.Complement: return(Combine(clipPath, CombineMode.Exclude, subjectPath)); case CombineMode.Replace: return(clipPath.Clone()); case CombineMode.Xor: case CombineMode.Intersect: case CombineMode.Union: case CombineMode.Exclude: if (subjectPath.IsEmpty && clipPath.IsEmpty) { return(new PdnGraphicsPath()); // empty path } else if (subjectPath.IsEmpty) { switch (combineMode) { case CombineMode.Xor: case CombineMode.Union: return(clipPath.Clone()); case CombineMode.Intersect: case CombineMode.Exclude: return(new PdnGraphicsPath()); default: throw new InvalidEnumArgumentException(); } } else if (clipPath.IsEmpty) { switch (combineMode) { case CombineMode.Exclude: case CombineMode.Xor: case CombineMode.Union: return(subjectPath.Clone()); case CombineMode.Intersect: return(new PdnGraphicsPath()); default: throw new InvalidEnumArgumentException(); } } else { GraphicsPath resultPath = PdnGraphics.ClipPath(subjectPath, combineMode, clipPath); return(new PdnGraphicsPath(resultPath)); } default: throw new InvalidEnumArgumentException(); } }
public MaskedSurface(Surface source, PdnGraphicsPath path) { RectangleF boundsF = path.GetBounds(); Rectangle bounds = Utility.RoundRectangle(boundsF); Rectangle boundsClipped = Rectangle.Intersect(bounds, source.Bounds); Rectangle boundsRead; if (bounds != boundsClipped) { PdnRegion region = new PdnRegion(path); region.Intersect(source.Bounds); SetPathField(PdnGraphicsPath.FromRegion(region)); this.region = region; boundsRead = region.GetBoundsInt(); } else { SetPathField(path.Clone()); this.region = new PdnRegion(this.path); boundsRead = boundsClipped; } if (boundsRead.Width > 0 && boundsRead.Height > 0) { this.surface = new Surface(boundsRead.Size); this.surface.CopySurface(source, boundsRead); } else { this.surface = null; } }
private void DrawSelection(Graphics gdiG, PdnGraphicsPath outline) { if (outline == null) { return; } float ratio = (float)OwnerList.ScaleFactor.Ratio; gdiG.ScaleTransform(ratio, ratio); if (EnableSelectionTinting) { PdnGraphicsPath outline2; if (invertedTinting) { outline2 = (PdnGraphicsPath)outline.Clone(); outline2.AddRectangle(new Rectangle(-1, -1, this.SourceSize.Width + 1, this.SourceSize.Height + 1)); outline2.CloseAllFigures(); } else { outline2 = outline; } DrawSelectionTinting(gdiG, outline2); if (invertedTinting) { outline2.Dispose(); } } if (EnableSelectionOutline) { DrawSelectionOutline(gdiG, outline); } gdiG.ScaleTransform(1 / ratio, 1 / ratio); }
private void SetPathField(PdnGraphicsPath newPath) { this.path = newPath; this.shadowPath = newPath.Clone(); }
private void SelectionTimer_Tick(object sender, System.EventArgs e) { if (this.IsDisposed || this.ownerControl.IsDisposed) { return; } if (this.selectedPath == null || this.selectedPath.IsEmpty) { this.selectionTimer.Enabled = false; return; } if (!this.enableOutlineAnimation) { return; } if (this.timer.GetTickCountDouble() < this.coolOffTimeTickCount) { return; } if (this.ownerControl != null && this.ownerControl.IsMouseCaptured()) { return; } int presentTickMod = (int)((Utility.GetTimeMs() / dancingAntsInterval) % 2); if (presentTickMod != lastTickMod) { lastTickMod = presentTickMod; dancingAntsT = unchecked (dancingAntsT + 1); if (this.simplifiedRegionForTimer == null) { using (PdnGraphicsPath invalidPath = (PdnGraphicsPath)selectedPath.Clone()) { invalidPath.CloseAllFigures(); float ratio = 1.0f / (float)OwnerList.ScaleFactor.Ratio; int inflateAmount = (int)Math.Ceiling(ratio); this.simplifiedRegionForTimer = Utility.SimplifyTrace(invalidPath, 50); Utility.InflateRectanglesInPlace(this.simplifiedRegionForTimer, inflateAmount); } } try { foreach (Rectangle rect in this.simplifiedRegionForTimer) { Invalidate(rect); } } catch (ObjectDisposedException) { try { this.selectionTimer.Enabled = false; } catch (Exception) { // Ignore error } } if (this.ownerControl == null || (this.ownerControl != null && !this.ownerControl.IsMouseCaptured())) { whiteOpacity = Math.Min(whiteOpacity + 16, 255); } } // If it takes "too long" to render the dancing ants, then we institute // a cooling-off period during which we will not render the ants. // This will curb the CPU usage by a few percent, which will avoid us // monopolizing the CPU. double maxRenderTime = (double)dancingAntsInterval * maxCpuTime; if (renderTime > maxRenderTime) { double coolOffTime = renderTime / maxRenderTime; this.coolOffTimeTickCount = timer.GetTickCountDouble() + coolOffTime; } this.renderTime = 0.0; }
public static PdnGraphicsPath Combine(PdnGraphicsPath subjectPath, CombineMode combineMode, PdnGraphicsPath clipPath) { switch (combineMode) { case CombineMode.Complement: return Combine(clipPath, CombineMode.Exclude, subjectPath); case CombineMode.Replace: return clipPath.Clone(); case CombineMode.Xor: case CombineMode.Intersect: case CombineMode.Union: case CombineMode.Exclude: if (subjectPath.IsEmpty && clipPath.IsEmpty) { return new PdnGraphicsPath(); // empty path } else if (subjectPath.IsEmpty) { switch (combineMode) { case CombineMode.Xor: case CombineMode.Union: return clipPath.Clone(); case CombineMode.Intersect: case CombineMode.Exclude: return new PdnGraphicsPath(); default: throw new InvalidEnumArgumentException(); } } else if (clipPath.IsEmpty) { switch (combineMode) { case CombineMode.Exclude: case CombineMode.Xor: case CombineMode.Union: return subjectPath.Clone(); case CombineMode.Intersect: return new PdnGraphicsPath(); default: throw new InvalidEnumArgumentException(); } } else { GraphicsPath resultPath = PdnGraphics.ClipPath(subjectPath, combineMode, clipPath); return new PdnGraphicsPath(resultPath); } default: throw new InvalidEnumArgumentException(); } }