Example #1
0
        public static PdnRegion WrapRegion(Region region)
        {
            PdnRegion pdnRegion = new PdnRegion(false);

            pdnRegion.gdiRegion = region;
            return(pdnRegion);
        }
Example #2
0
 public void Exclude(PdnRegion region2)
 {
     lock (SyncRoot)
     {
         gdiRegion.Exclude(region2.gdiRegion);
     }
 }
Example #3
0
        /// <summary>
        /// Renders only the portions of the document that have changed (been Invalidated) since
        /// the last call to this function.
        /// </summary>
        /// <param name="args">Contains information used to control where rendering occurs.</param>
        /// <returns>true if any rendering was done (the update list was non-empty), false otherwise</returns>
        public bool Update(RenderArgs dst)
        {
            if (disposed)
            {
                throw new ObjectDisposedException("Document");
            }

            Rectangle[] updateRects;
            int         updateRectsLength;

            updateRegion.GetArrayReadOnly(out updateRects, out updateRectsLength);

            if (updateRectsLength == 0)
            {
                return(false);
            }

            PdnRegion region = Utility.RectanglesToRegion(updateRects, 0, updateRectsLength);

            Rectangle[] rectsOriginal = region.GetRegionScansReadOnlyInt();
            Rectangle[] rectsToUse;

            // Special case where we're drawing 1 big rectangle: split it up!
            // This case happens quite frequently, but we don't want to spend a lot of
            // time analyzing any other case that is more complicated.
            if (rectsOriginal.Length == 1 && rectsOriginal[0].Height > 1)
            {
                Rectangle[] rectsNew = new Rectangle[Processor.LogicalCpuCount];
                Utility.SplitRectangle(rectsOriginal[0], rectsNew);
                rectsToUse = rectsNew;
            }
            else
            {
                rectsToUse = rectsOriginal;
            }

            int cpuCount = Processor.LogicalCpuCount;

            for (int i = 0; i < cpuCount; ++i)
            {
                int start = (i * rectsToUse.Length) / cpuCount;
                int end   = ((i + 1) * rectsToUse.Length) / cpuCount;

                UpdateScansContext usc = new UpdateScansContext(this, dst, rectsToUse, start, end - start);

                if (i == cpuCount - 1)
                {
                    // Reuse this thread for the last job -- no sense creating a new thread.
                    usc.UpdateScans(usc);
                }
                else
                {
                    threadPool.QueueUserWorkItem(new WaitCallback(usc.UpdateScans), usc);
                }
            }

            this.threadPool.Drain();
            Validate();
            return(true);
        }
Example #4
0
        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;
            }
        }
Example #5
0
        private void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (this.surface != null)
                {
                    this.surface.Dispose();
                    this.surface = null;
                }

                if (this.region != null)
                {
                    this.region.Dispose();
                    this.region = null;
                }

                if (this.path != null)
                {
                    this.path.Dispose();
                    this.path = null;
                }

                if (this.shadowPath != null)
                {
                    this.shadowPath.Dispose();
                    this.shadowPath = null;
                }
            }

            this.disposed = true;
        }
Example #6
0
 public void Set(PdnRegion region, bool newValue)
 {
     foreach (Rectangle rect in region.GetRegionScansReadOnlyInt())
     {
         Set(rect, newValue);
     }
 }
Example #7
0
        private void Activate()
        {
            Debug.Assert(this.active != true, "already active!");
            this.active = true;

            this.handCursor          = new Cursor(PdnResources.GetResourceStream("Cursors.PanToolCursor.cur"));
            this.handCursorMouseDown = new Cursor(PdnResources.GetResourceStream("Cursors.PanToolCursorMouseDown.cur"));
            this.handCursorInvalid   = new Cursor(PdnResources.GetResourceStream("Cursors.PanToolCursorInvalid.cur"));

            this.panTracking = false;
            this.panMode     = false;
            this.mouseDown   = 0;
            this.savedTiles  = null;
            this.saveRegion  = null;

            this.scratchSurface = DocumentWorkspace.BorrowScratchSurface(this.GetType().Name + ": Tool.Activate()");
#if DEBUG
            this.haveClearedScratch = false;
#endif

            Selection.Changing += new EventHandler(SelectionChangingHandler);
            Selection.Changed  += new EventHandler(SelectionChangedHandler);
            HistoryStack.ExecutingHistoryMemento += new ExecutingHistoryMementoEventHandler(ExecutingHistoryMemento);
            HistoryStack.ExecutedHistoryMemento  += new ExecutedHistoryMementoEventHandler(ExecutedHistoryMemento);
            HistoryStack.FinishedStepGroup       += new EventHandler(FinishedHistoryStepGroup);

            this.trackingNub         = new MoveNubRenderer(this.RendererList);
            this.trackingNub.Visible = false;
            this.trackingNub.Size    = new SizeF(10, 10);
            this.trackingNub.Shape   = MoveNubShape.Compass;
            this.RendererList.Add(this.trackingNub, false);

            OnActivate();
        }
Example #8
0
        public PdnGraphicsPath(SerializationInfo info, StreamingContext context)
        {
            int ptCount = info.GetInt32("ptCount");

            PointF[] pts;
            byte[]   types;

            if (ptCount == 0)
            {
                pts   = new PointF[0];
                types = new byte[0];
            }
            else
            {
                pts   = (PointF[])info.GetValue("pts", typeof(PointF[]));
                types = (byte[])info.GetValue("types", typeof(byte[]));
            }

            FillMode fillMode = (FillMode)info.GetValue("fillMode", typeof(FillMode));

            Changed();

            if (ptCount == 0)
            {
                gdiPath = new GraphicsPath();
            }
            else
            {
                gdiPath = new GraphicsPath(pts, types, fillMode);
            }

            this.tooComplex  = false;
            this.regionCache = null;
        }
Example #9
0
        public static PdnRegion CreateEmpty()
        {
            PdnRegion region = new PdnRegion();

            region.MakeEmpty();
            return(region);
        }
Example #10
0
 public void Invalidate(PdnRegion region)
 {
     foreach (Rectangle rect in region.GetRegionScansReadOnlyInt())
     {
         Invalidate(rect);
     }
 }
Example #11
0
 public void Complement(PdnRegion region2)
 {
     lock (SyncRoot)
     {
         Changed();
         gdiRegion.Complement(region2.gdiRegion);
     }
 }
Example #12
0
 public void ClearSavedRegion()
 {
     if (this.saveRegion != null)
     {
         this.saveRegion.Dispose();
         this.saveRegion = null;
     }
 }
Example #13
0
 public void Union(PdnRegion region2)
 {
     lock (SyncRoot)
     {
         Changed();
         gdiRegion.Union(region2.gdiRegion);
     }
 }
Example #14
0
 public void Xor(PdnRegion region2)
 {
     lock (SyncRoot)
     {
         Changed();
         gdiRegion.Xor(region2.gdiRegion);
     }
 }
Example #15
0
 public void Intersect(PdnRegion region2)
 {
     lock (SyncRoot)
     {
         Changed();
         gdiRegion.Intersect(region2.gdiRegion);
     }
 }
Example #16
0
        internal PdnRegion GetRegionCache()
        {
            if (regionCache == null)
            {
                regionCache = new PdnRegion(this.gdiPath);
            }

            return(regionCache);
        }
Example #17
0
 public void RestoreRegion(PdnRegion region)
 {
     if (region != null)
     {
         BitmapLayer activeLayer = (BitmapLayer)ActiveLayer;
         activeLayer.Surface.CopySurface(this.ScratchSurface, region);
         activeLayer.Invalidate(region);
     }
 }
Example #18
0
        public SurfaceForClipboard(MaskedSurface maskedSurface)
        {
            using (PdnRegion region = maskedSurface.CreateRegion())
            {
                this.Bounds = region.GetBoundsInt();
            }

            this.MaskedSurface = maskedSurface;
        }
Example #19
0
        private PdnRegion GetRegion()
        {
            if (this.region == null)
            {
                this.region = new PdnRegion(this.shadowPath);
            }

            return(this.region);
        }
Example #20
0
 public void RestoreSavedRegion()
 {
     if (this.saveRegion != null)
     {
         BitmapLayer activeLayer = (BitmapLayer)ActiveLayer;
         activeLayer.Surface.CopySurface(this.ScratchSurface, this.saveRegion);
         activeLayer.Invalidate(this.saveRegion);
         this.saveRegion.Dispose();
         this.saveRegion = null;
     }
 }
Example #21
0
        private IrregularSurface(IrregularSurface cloneMe)
        {
            this.placedSurfaces = new ArrayList(cloneMe.placedSurfaces.Count);

            foreach (PlacedSurface ps in cloneMe.placedSurfaces)
            {
                this.placedSurfaces.Add(ps.Clone());
            }

            this.region = (PdnRegion)cloneMe.Region.Clone();
        }
Example #22
0
 private void Changed()
 {
     if (regionCache != null)
     {
         lock (regionCache.SyncRoot)
         {
             regionCache.Dispose();
             regionCache = null;
         }
     }
 }
Example #23
0
 private PdnRegion(PdnRegion pdnRegion)
 {
     lock (pdnRegion.SyncRoot)
     {
         this.gdiRegion    = pdnRegion.gdiRegion.Clone();
         this.changed      = pdnRegion.changed;
         this.cachedArea   = pdnRegion.cachedArea;
         this.cachedRectsF = pdnRegion.cachedRectsF;
         this.cachedRects  = pdnRegion.cachedRects;
     }
 }
Example #24
0
        public void Union(RectangleF[] rectsF)
        {
            lock (SyncRoot)
            {
                Changed();

                using (PdnRegion tempRegion = Utility.RectanglesToRegion(rectsF))
                {
                    this.Union(tempRegion);
                }
            }
        }
Example #25
0
 public PdnGraphicsPath CreatePixelatedPath()
 {
     using (PdnGraphicsPath path = CreatePath())
     //PdnGraphicsPath path = GetPathReadOnly();
     {
         using (PdnRegion region = new PdnRegion(path))
         {
             PdnGraphicsPath pixellatedPath = PdnGraphicsPath.FromRegion(region);
             return(pixellatedPath);
         }
     }
 }
Example #26
0
        /// <summary>
        /// Causes the layer to render a given region of interest (roi) to the given destination surface.
        /// </summary>
        /// <param name="args">Contains information about which objects to use for rendering</param>
        /// <param name="roi">The region to be rendered.</param>
        public void Render(RenderArgs args, PdnRegion roi)
        {
            Rectangle roiBounds = roi.GetBoundsInt();

            if (!IsInBounds(roiBounds))
            {
                throw new ArgumentOutOfRangeException("roi");
            }

            Rectangle[] rects = roi.GetRegionScansReadOnlyInt();
            RenderImpl(args, rects);
        }
Example #27
0
        public void OnDeserialization(object sender)
        {
            region = PdnRegion.CreateEmpty();

            Rectangle[] rects = new Rectangle[placedSurfaces.Count];

            for (int i = 0; i < placedSurfaces.Count; ++i)
            {
                rects[i] = ((PlacedSurface)placedSurfaces[i]).Bounds;
            }

            region = Utility.RectanglesToRegion(rects);
        }
Example #28
0
        protected virtual void Dispose(bool disposing)
        {
            Debug.Assert(!this.active, "Tool is still active!");

            if (disposing)
            {
                if (this.saveRegion != null)
                {
                    this.saveRegion.Dispose();
                    this.saveRegion = null;
                }

                OnDisposed();
            }
        }
Example #29
0
        private void Deactivate()
        {
            Debug.Assert(this.active != false, "not active!");

            this.active = false;

            Selection.Changing -= new EventHandler(SelectionChangingHandler);
            Selection.Changed  -= new EventHandler(SelectionChangedHandler);

            HistoryStack.ExecutingHistoryMemento -= new ExecutingHistoryMementoEventHandler(ExecutingHistoryMemento);
            HistoryStack.ExecutedHistoryMemento  -= new ExecutedHistoryMementoEventHandler(ExecutedHistoryMemento);
            HistoryStack.FinishedStepGroup       -= new EventHandler(FinishedHistoryStepGroup);

            OnDeactivate();

            this.RendererList.Remove(this.trackingNub);
            this.trackingNub.Dispose();
            this.trackingNub = null;

            DocumentWorkspace.ReturnScratchSurface(this.scratchSurface);
            this.scratchSurface = null;

            if (this.saveRegion != null)
            {
                this.saveRegion.Dispose();
                this.saveRegion = null;
            }

            this.savedTiles = null;

            if (this.handCursor != null)
            {
                this.handCursor.Dispose();
                this.handCursor = null;
            }

            if (this.handCursorMouseDown != null)
            {
                this.handCursorMouseDown.Dispose();
                this.handCursorMouseDown = null;
            }

            if (this.handCursorInvalid != null)
            {
                this.handCursorInvalid.Dispose();
                this.handCursorInvalid = null;
            }
        }
Example #30
0
        /// <summary>
        /// Constructs an IrregularSurface by copying the given region-of-interest from an Image.
        /// </summary>
        /// <param name="source">The Surface to copy pixels from.</param>
        /// <param name="roi">Defines the Region from which to copy pixels from the Image.</param>
        public IrregularSurface(Surface source, PdnRegion roi)
        {
            PdnRegion roiClipped = (PdnRegion)roi.Clone();

            roiClipped.Intersect(source.Bounds);

            Rectangle[] rects = roiClipped.GetRegionScansReadOnlyInt();
            this.placedSurfaces = new ArrayList(rects.Length);

            foreach (Rectangle rect in rects)
            {
                this.placedSurfaces.Add(new PlacedSurface(source, rect));
            }

            this.region = roiClipped;
        }