Exemplo n.º 1
0
        public void RenderMask(ISurface <ColorAlpha8> dstMask, PointInt32 renderOffset)
        {
            RectInt32 sourceRect = new RectInt32(renderOffset, dstMask.Size <ColorAlpha8>());

            if (Interlocked.Exchange(ref this.haveFetchedStamp, 1) == 0)
            {
                this.lazyStampMaskDevBitmap.EnsureEvaluated();
            }
            foreach (PointInt32 num2 in this.tileMathHelper.EnumerateTileOffsets(sourceRect))
            {
                TileData               tileData       = this.GetTileData(num2);
                RectInt32              tileSourceRect = this.tileMathHelper.GetTileSourceRect(num2);
                RectInt32              num4           = RectInt32.Intersect(tileSourceRect, sourceRect);
                PointInt32             num5           = new PointInt32(num4.X - tileSourceRect.X, num4.Y - tileSourceRect.Y);
                RectInt32              bounds         = new RectInt32(num4.X - sourceRect.X, num4.Y - sourceRect.Y, num4.Width, num4.Height);
                ISurface <ColorAlpha8> surface        = dstMask.CreateWindow <ColorAlpha8>(bounds);
                object sync = tileData.Sync;
                lock (sync)
                {
                    this.UpdateTileWhileLocked(tileData);
                    if (tileData.Mask == null)
                    {
                        surface.Clear();
                    }
                    else
                    {
                        tileData.Mask.Render(surface, num5);
                    }
                }
            }
        }
        private BitmapLayerToolLayerOverlay <TTool, TChanges> CreateLayerOverlay(BitmapLayer layer, TChanges changes)
        {
            IRenderer <ColorAlpha8> renderer;
            RectInt32 num;

            this.tool.VerifyAccess <TTool>();
            if (this.autoClipToSelection)
            {
                this.GetDefaultContentClip(changes, out num, out renderer);
            }
            else
            {
                this.tool.GetContentClip(changes, out num, out renderer);
            }
            ContentBlendMode blendMode = this.tool.GetBlendMode(changes);
            IEnumerable <IMaskedRenderer <ColorBgra, ColorAlpha8> > contentRenderers = this.tool.CreateContentRenderers(layer, changes);

            if (contentRenderers == null)
            {
                ExceptionUtil.ThrowInternalErrorException("OnCreateContentRenderer() returned null");
            }
            RectInt32 maxRenderBounds = changes.GetMaxRenderBounds();

            return(new BitmapLayerToolLayerOverlay <TTool, TChanges>(layer, RectInt32.Intersect(layer.Bounds(), RectInt32.Intersect(num, maxRenderBounds)), changes, blendMode, contentRenderers, renderer));
        }
Exemplo n.º 3
0
        private static unsafe void LoadOrSaveSurfaceRegion(Stream stream, Surface surface, RectInt32[] scans, bool trueForSave)
        {
            int length = scans.Length;

            if (length != 0)
            {
                void *[]  voidPtrArray;
                ulong[]   numArray;
                RectInt32 b      = surface.Bounds <ColorBgra>();
                RectInt32 bounds = RectInt32.Intersect(scans.Bounds(), b);
                int       num5   = 0;
                long      num6   = (bounds.Width * bounds.Height) * 4L;
                if (((length == 1) && (num6 <= 0xffffffffL)) && surface.IsContiguousMemoryRegion(bounds))
                {
                    voidPtrArray = new void *[] { surface.GetPointAddressUnchecked(bounds.Location.ToGdipPoint()) };
                    numArray     = new ulong[] { num6 };
                }
                else
                {
                    for (int i = 0; i < length; i++)
                    {
                        RectInt32 num9 = RectInt32.Intersect(scans[i], b);
                        if ((num9.Width != 0) && (num9.Height != 0))
                        {
                            num5 += num9.Height;
                        }
                    }
                    int index = 0;
                    voidPtrArray = new void *[num5];
                    numArray     = new ulong[num5];
                    for (int j = 0; j < length; j++)
                    {
                        RectInt32 num11 = RectInt32.Intersect(scans[j], b);
                        if ((num11.Width != 0) && (num11.Height != 0))
                        {
                            for (int k = num11.Y; k < (num11.Y + num11.Height); k++)
                            {
                                voidPtrArray[index] = (void *)surface.GetPointAddress(num11.X, k);
                                numArray[index]     = (ulong)(num11.Width * 4L);
                                index++;
                            }
                        }
                    }
                }
                if (trueForSave)
                {
                    WriteToStreamGather(stream, voidPtrArray, numArray);
                }
                else
                {
                    ReadFromStreamScatter(stream, voidPtrArray, numArray);
                }
            }
        }
Exemplo n.º 4
0
        public override HistoryMemento OnExecute(IHistoryWorkspace historyWorkspace)
        {
            GeometryList cachedClippingMask = historyWorkspace.Selection.GetCachedClippingMask();

            if (historyWorkspace.Selection.IsEmpty || (cachedClippingMask.Bounds.Area < 1.0))
            {
                return(null);
            }
            Document document = historyWorkspace.Document;
            List <HistoryMemento> mementos   = new List <HistoryMemento>(document.Layers.Count);
            RectInt32             b          = cachedClippingMask.Bounds.GetInt32Bound(1E-05);
            RectInt32             sourceRect = RectInt32.Intersect(document.Bounds(), b);
            Document document2 = new Document(sourceRect.Width, sourceRect.Height);

            document2.ReplaceMetadataFrom(document);
            RectInt32 rect = new RectInt32(0, 0, sourceRect.Width, sourceRect.Height);
            IRenderer <ColorAlpha8> cachedClippingMaskRenderer = historyWorkspace.Selection.GetCachedClippingMaskRenderer(historyWorkspace.ToolSettings.Selection.RenderingQuality.Value);
            IRenderer <ColorAlpha8> newClipMaskRenderer        = new ClippedRenderer <ColorAlpha8>(cachedClippingMaskRenderer, sourceRect);
            SelectionHistoryMemento item = new SelectionHistoryMemento(null, null, historyWorkspace);

            mementos.Add(item);
            base.EnterCriticalRegion();
            int count = document.Layers.Count;

            while (document.Layers.Count > 0)
            {
                BitmapLayer layer          = (BitmapLayer)document.Layers[0];
                Surface     croppedSurface = layer.Surface.CreateWindow(sourceRect);
                BitmapLayer newLayer       = RetryManager.RunMemorySensitiveOperation <BitmapLayer>(() => new BitmapLayer(croppedSurface));
                newLayer.LoadProperties(layer.SaveProperties());
                HistoryMemento deleteLayerMemento = new DeleteLayerFunction(0).Execute(historyWorkspace);
                mementos.Add(deleteLayerMemento);
                Task task = Task.Factory.StartNew(delegate {
                    deleteLayerMemento.Flush();
                }, TaskCreationOptions.LongRunning);
                Parallel.ForEach <RectInt32>(rect.GetTiles(TilingStrategy.Tiles, 7), delegate(RectInt32 newTileRect) {
                    ISurface <ColorBgra> surface = newLayer.Surface.CreateWindow(newTileRect);
                    IRenderer <ColorAlpha8> mask = new ClippedRenderer <ColorAlpha8>(newClipMaskRenderer, newTileRect);
                    surface.MultiplyAlphaChannel(mask);
                });
                document2.Layers.Add(newLayer);
                task.Wait();
                if (document2.Layers.Count > count)
                {
                    ExceptionUtil.ThrowInternalErrorException("newDocument.Layers.Count > oldLayerCount");
                }
            }
            ReplaceDocumentHistoryMemento memento2 = new ReplaceDocumentHistoryMemento(null, null, historyWorkspace);

            mementos.Add(memento2);
            historyWorkspace.Document = document2;
            return(HistoryMemento.Combine(HistoryMementoName, HistoryMementoImage, mementos));
        }
        public void BeforeRender(RectFloat clipRect)
        {
            if ((!this.afterRenderCalled || this.beforeRenderCalled) || this.renderCalled)
            {
                throw new PaintDotNet.InternalErrorException();
            }
            this.afterRenderCalled  = false;
            this.beforeRenderCalled = true;
            bool flag = this.canvasView.RenderTarget.IsSupported(RenderTargetType.Software, null, null, null);

            if (flag || this.IsActive)
            {
                this.renderStopwatch.Restart();
                RectInt32 num2  = RectInt32.Intersect(clipRect.Int32Bound, this.owner.Document.Bounds());
                bool      flag2 = false;
                if (num2.HasPositiveArea)
                {
                    PointInt32   num7;
                    PointInt32[] array = this.nonCurrentTileOffsets.ToArrayEx <PointInt32>();
                    this.nonCurrentTileOffsets.Clear();
                    PointInt32 sourcePt  = PointDouble.Round(this.owner.Owner.MouseLocation, MidpointRounding.AwayFromZero);
                    PointInt32 comparand = this.tileMathHelper.ConvertSourcePointToTileOffset(sourcePt);
                    CompareTileOffsetsByDistance comparer = new CompareTileOffsetsByDistance(comparand);
                    ListUtil.Sort <PointInt32, ArrayStruct <PointInt32>, CompareTileOffsetsByDistance>(array.AsStruct <PointInt32>(), comparer);
                    DequeSet <PointInt32> set = new DequeSet <PointInt32>(array);
                    int count = set.Count;
                    while (set.TryDequeue(out num7))
                    {
                        if (!this.isDeviceBitmapCurrent[num7.Y][num7.X])
                        {
                            if (flag2)
                            {
                                this.nonCurrentTileOffsets.TryEnqueue(num7);
                            }
                            else
                            {
                                if (!this.TryUpdateDeviceBitmap(num7))
                                {
                                    this.nonCurrentTileOffsets.TryEnqueue(num7);
                                    flag2 = true;
                                }
                                if ((!flag2 && !flag) && (this.renderStopwatch.ElapsedMilliseconds > 0x7fffffffffffffffL))
                                {
                                    flag2 = true;
                                }
                            }
                        }
                    }
                }
            }
        }
        internal void NotifyTileCacheInvalidated(DocumentCanvasTileCache tileCache, RectInt32 sourceRect)
        {
            int mipLevel = tileCache.MipLevel;

            this.mipLayers[mipLevel].NotifyTileCacheInvalidated(sourceRect);
            if (this.mipLayers[mipLevel].IsActive)
            {
                RectInt32 num4 = RectInt32.Intersect(this.canvasView.GetVisibleCanvasBounds().Int32Bound, sourceRect);
                if (num4.HasPositiveArea)
                {
                    this.tileCaches[mipLevel].QueueInvalidTilesForRendering(num4, true);
                }
            }
        }
Exemplo n.º 7
0
        private ColorBgra SampleCurrentLayer(int x, int y)
        {
            Surface surface = ((BitmapLayer)base.ActiveLayer).Surface;

            if (this.currentSampleSize == 1)
            {
                return(surface[x, y]);
            }
            int       num        = (this.currentSampleSize - 1) / 2;
            RectInt32 sampleArea = new RectInt32(x - num, y - num, this.currentSampleSize, this.currentSampleSize);
            Rectangle bounds     = surface.Bounds;

            sampleArea.Intersect(new RectInt32(bounds.X, bounds.Y, bounds.Width, bounds.Height));
            return(SampleArea(surface, sampleArea));
        }
Exemplo n.º 8
0
        private ColorBgra SampleAllLayers(int x, int y)
        {
            if (this.currentSampleSize == 1)
            {
                this.allLayersDocumentRenderer.Render(this.allLayersRenderSurface, new PointInt32(x, y));
                return(this.allLayersRenderSurface[0, 0]);
            }
            int       num    = (this.currentSampleSize - 1) / 2;
            RectInt32 num2   = new RectInt32(x - num, y - num, this.currentSampleSize, this.currentSampleSize);
            Rectangle bounds = base.Document.Bounds;

            num2.Intersect(new RectInt32(bounds.X, bounds.Y, bounds.Width, bounds.Height));
            PointInt32 location = num2.Location;

            this.allLayersDocumentRenderer.Render(this.allLayersRenderSurface, location);
            return(SampleArea(this.allLayersRenderSurface, new RectInt32(PointInt32.Zero, num2.Size)));
        }
 public void GetDefaultContentClip(TChanges changes, out RectInt32 clipRect, out IRenderer <ColorAlpha8> clipMaskRenderer)
 {
     if (this.tool.Selection.IsEmpty)
     {
         clipMaskRenderer = null;
         clipRect         = this.tool.Document.Bounds();
     }
     else
     {
         GeometryList cachedClippingMask = this.tool.Selection.GetCachedClippingMask();
         clipRect = RectInt32.Intersect(cachedClippingMask.Bounds.Int32Bound, this.tool.Document.Bounds());
         SelectionRenderingQuality         drawingSettingValue            = changes.GetDrawingSettingValue <SelectionRenderingQuality>(this.tool.ToolSettings.Selection.RenderingQuality);
         Result <IRenderer <ColorAlpha8> > cachedLazyClippingMaskRenderer = this.tool.Selection.GetCachedLazyClippingMaskRenderer(drawingSettingValue);
         SizeInt32 size = this.tool.Document.Size();
         clipMaskRenderer = LazyRenderer.Create <ColorAlpha8>(size, cachedLazyClippingMaskRenderer);
     }
 }
        public void Render(IDrawingContext dc, RectFloat clipRect, float opacity, BitmapInterpolationMode interpolationMode)
        {
            if (!this.beforeRenderCalled || this.afterRenderCalled)
            {
                throw new PaintDotNet.InternalErrorException();
            }
            this.renderCalled = true;
            if (this.isRendering)
            {
                throw new InvalidOperationException("Render() is not reentrant");
            }
            RectInt32 sourceRect = RectInt32.Intersect(clipRect.Int32Bound, this.owner.Document.Bounds());

            if (sourceRect.HasPositiveArea)
            {
                this.isRendering = true;
                try
                {
                    bool flag = dc.IsSupported(RenderTargetType.Software, null, null, null);
                    foreach (PointInt32 num3 in this.tileMathHelper.EnumerateTileOffsets(sourceRect))
                    {
                        if (flag)
                        {
                            IBitmap <ColorPbgra32> bitmap2 = this.tileBuffers[num3.Y][num3.X];
                            if ((bitmap2 != null) && bitmap2.IsDisposed)
                            {
                                continue;
                            }
                        }
                        IDeviceBitmap bitmap = this.deviceBitmaps[num3.Y][num3.X];
                        if (bitmap != null)
                        {
                            RectInt32 tileSourceRect = this.tileMathHelper.GetTileSourceRect(num3.X, num3.Y);
                            RectFloat?srcRect        = null;
                            dc.DrawBitmap(bitmap, new RectFloat?(tileSourceRect), opacity, interpolationMode, srcRect);
                        }
                    }
                }
                finally
                {
                    this.isRendering = false;
                }
            }
        }
Exemplo n.º 11
0
        private static ISurface <ColorAlpha8> UseTileOrToSurfaceWithEdgePadding(IRenderer <ColorAlpha8> source, RectInt32 bounds, ColorAlpha8 padding)
        {
            if (source.Bounds <ColorAlpha8>().Contains(bounds))
            {
                return(source.UseTileOrToSurface(bounds));
            }
            ISurface <ColorAlpha8> surface = SurfaceAllocator.Alpha8.Allocate <ColorAlpha8>(bounds.Size, AllocationOptions.ZeroFillNotRequired);

            surface.Clear(padding);
            RectInt32  num2     = RectInt32.Intersect(source.Bounds <ColorAlpha8>(), bounds);
            PointInt32 location = new PointInt32(num2.Location.X - bounds.Location.X, num2.Location.Y - bounds.Location.Y);
            RectInt32  num4     = new RectInt32(location, num2.Size);

            using (ISurfaceWindow <ColorAlpha8> window = surface.CreateWindow <ColorAlpha8>(num4))
            {
                source.Render(window, num2.Location);
            }
            return(surface);
        }
Exemplo n.º 12
0
        protected override void OnMouseMove(MouseEventArgsF e)
        {
            base.OnMouseMove(e);
            PointInt32 b = new PointInt32(e.X, e.Y);

            if (this.moveOffsetMode)
            {
                VectorInt32 num2 = (VectorInt32)(b - this.lastPt);
                this.downPt.X += num2.X;
                this.downPt.Y += num2.Y;
            }
            if ((e.Button == MouseButtons.Left) && (this.mouseDown == MouseButtons.Left))
            {
                VectorDouble num3 = (VectorDouble)(b - this.downPt);
                if (num3.Length >= 10.0)
                {
                    goto Label_00B1;
                }
            }
            if (!this.rect.HasPositiveArea)
            {
                if ((e.Button == MouseButtons.Middle) && (this.mouseDown == MouseButtons.Middle))
                {
                    PointDouble documentScrollPosition = base.DocumentWorkspace.DocumentScrollPosition;
                    documentScrollPosition.X += b.X - this.lastPt.X;
                    documentScrollPosition.Y += b.Y - this.lastPt.Y;
                    base.DocumentWorkspace.DocumentScrollPosition = documentScrollPosition;
                    base.Update();
                }
                else
                {
                    this.rect = RectInt32.Zero;
                }
                goto Label_0173;
            }
Label_00B1:
            this.rect = RectInt32Util.FromPixelPoints(this.downPt, b);
            this.rect = RectInt32.Intersect(this.rect, base.ActiveLayer.Bounds());
            this.UpdateDrawnRect();
Label_0173:
            this.lastPt = b;
        }
Exemplo n.º 13
0
 private void ProcessInvalidationQueue()
 {
     if (!base.IsDisposed)
     {
         RectInt32 num2;
         base.VerifyAccess();
         int       count    = this.invalidationQueue.Count;
         RectInt32?nullable = null;
         while ((count > 0) && this.invalidationQueue.TryDequeue(out num2))
         {
             nullable = new RectInt32?(RectInt32Util.Union(nullable, num2));
             count--;
         }
         if (nullable.HasValue)
         {
             RectInt32 invalidRect = RectInt32.Intersect(this.Document.Bounds(), nullable.Value);
             this.InvalidateCore(invalidRect);
         }
     }
 }
Exemplo n.º 14
0
        public RectInt32 GetMaxRenderBounds()
        {
            RectInt32?cachedMaxRenderBounds;

            lock (changes)
            {
                cachedMaxRenderBounds = this.cachedMaxRenderBounds;
            }
            RectInt32?nullable2 = cachedMaxRenderBounds;
            RectInt32 num       = nullable2.HasValue ? nullable2.GetValueOrDefault() : this.OnGetMaxRenderBounds();

            lock (changes2)
            {
                this.cachedMaxRenderBounds = new RectInt32?(num);
            }
            if (num.IsEmpty)
            {
                return(TransactedToolChanges.MaxMaxRenderBounds);
            }
            return(RectInt32.Intersect(num, TransactedToolChanges.MaxMaxRenderBounds));
        }
Exemplo n.º 15
0
        public void RenderMask(ISurface <ColorAlpha8> dstMask, PointInt32 renderOffset, ICancellationToken cancelToken)
        {
            Validate.Begin().IsNotNull <ISurface <ColorAlpha8> >(dstMask, "dstMask").IsNotNull <ICancellationToken>(cancelToken, "cancelToken").Check();
            cancelToken.ThrowIfCancellationRequested <ICancellationToken>();
            RectInt32 sourceRect = new RectInt32(renderOffset, dstMask.Size <ColorAlpha8>());

            if (Interlocked.Exchange(ref this.haveFetchedStamp, 1) == 0)
            {
                cancelToken.ThrowIfCancellationRequested <ICancellationToken>();
                this.lazyStampMaskDevBitmap.EnsureEvaluated();
            }
            foreach (PointInt32 num2 in this.tileMathHelper.EnumerateTileOffsets(sourceRect))
            {
                cancelToken.ThrowIfCancellationRequested <ICancellationToken>();
                TileData               tileData       = this.GetTileData(num2);
                RectInt32              tileSourceRect = this.tileMathHelper.GetTileSourceRect(num2);
                RectInt32              num4           = RectInt32.Intersect(tileSourceRect, sourceRect);
                PointInt32             num5           = new PointInt32(num4.X - tileSourceRect.X, num4.Y - tileSourceRect.Y);
                RectInt32              bounds         = new RectInt32(num4.X - sourceRect.X, num4.Y - sourceRect.Y, num4.Width, num4.Height);
                ISurface <ColorAlpha8> surface        = dstMask.CreateWindow <ColorAlpha8>(bounds);
                object sync = tileData.Sync;
                lock (sync)
                {
                    cancelToken.ThrowIfCancellationRequested <ICancellationToken>();
                    this.UpdateTileWhileLocked(tileData, cancelToken);
                    cancelToken.ThrowIfCancellationRequested <ICancellationToken>();
                    if (tileData.Mask == null)
                    {
                        surface.Clear();
                    }
                    else
                    {
                        tileData.Mask.Render(surface, num5);
                    }
                }
                cancelToken.ThrowIfCancellationRequested <ICancellationToken>();
            }
        }
Exemplo n.º 16
0
            public void DrawScansBilinear(int cpuNumber)
            {
                int       logicalCpuCount = Processor.LogicalCpuCount;
                RectInt32 b = this.dst.Bounds <ColorBgra>();

                for (int i = cpuNumber; i < this.dstScans.Length; i += logicalCpuCount)
                {
                    RectInt32   num4 = RectInt32.Intersect(this.dstScans[i], b);
                    PointDouble pt   = new PointDouble((double)num4.X, (double)num4.Y);
                    pt.X += 0.5;
                    pt.Y += 0.5;
                    pt    = this.inverse.Transform(pt);
                    pt.X -= this.boundsX;
                    pt.Y -= this.boundsY;
                    pt.X -= 0.5;
                    pt.Y -= 0.5;
                    PointDouble num6 = pt;
                    for (int j = num4.Y; j < (num4.Y + num4.Height); j++)
                    {
                        PointDouble num8 = num6;
                        if (j >= 0)
                        {
                            for (int k = num4.X; k < (num4.X + num4.Width); k++)
                            {
                                float     x = (float)num8.X;
                                float     y = (float)num8.Y;
                                ColorBgra bilinearSampleClamped = this.src.GetBilinearSampleClamped(x, y);
                                *(this.dst.GetPointAddressUnchecked(k, j)) = bilinearSampleClamped;
                                num8.X += this.dsxddx;
                                num8.Y += this.dsyddx;
                            }
                        }
                        num6.X += this.dsxddy;
                        num6.Y += this.dsyddy;
                    }
                }
            }
Exemplo n.º 17
0
        public override HistoryMemento OnExecute(IHistoryWorkspace historyWorkspace)
        {
            if (historyWorkspace.Selection.IsEmpty)
            {
                return(null);
            }
            SelectionHistoryMemento             memento      = new SelectionHistoryMemento(StaticName, StaticImage, historyWorkspace);
            GeometryList                        selectedPath = historyWorkspace.Selection.GetCachedGeometryList();
            SelectionRenderingQuality           selectionRenderingQuality = historyWorkspace.ToolSettings.Selection.RenderingQuality.Value;
            Result <IReadOnlyList <RectInt32> > selectedPathScansLazy     = historyWorkspace.Selection.GetCachedLazyClippingMaskScans();
            RectInt32           documentBounds = historyWorkspace.Document.Bounds();
            Func <GeometryList> invertedPathFn = delegate {
                if ((selectionRenderingQuality == SelectionRenderingQuality.Aliased) || selectedPath.IsPixelated)
                {
                    GeometryList list2 = GeometryList.FromNonOverlappingSortedScans(selectedPathScansLazy.Value);
                    list2.AddRect(documentBounds);
                    SegmentedList <RectInt32> scans = new SegmentedList <RectInt32>();
                    foreach (RectInt32 num in list2.EnumerateInteriorScans())
                    {
                        if (documentBounds.Contains(num))
                        {
                            scans.Add(num);
                        }
                        else if (documentBounds.IntersectsWith(num))
                        {
                            scans.Add(RectInt32.Intersect(documentBounds, num));
                        }
                    }
                    return(GeometryList.FromNonOverlappingScans(scans));
                }
                GeometryList lhs = documentBounds.Contains(selectedPath.Bounds) ? selectedPath : GeometryList.ClipToRect(selectedPath, documentBounds);
                return(GeometryList.Combine(lhs, GeometryCombineMode.Xor, documentBounds));
            };
            ThreadTask <GeometryList> task = historyWorkspace.TaskManager.StartNewThreadTask <GeometryList>(task => invertedPathFn(), ApartmentState.MTA);
            ManualResetEvent          taskFinishedEvent = new ManualResetEvent(false);

            task.ResultAsync <GeometryList>().Receive(delegate(Result <GeometryList> r) {
                taskFinishedEvent.Set();
            }).Observe();
            if (!taskFinishedEvent.WaitOne(0x3e8))
            {
                using (TaskProgressDialog dialog = new TaskProgressDialog())
                {
                    dialog.Task       = task;
                    dialog.Text       = StaticName;
                    dialog.Icon       = StaticImage.Reference.ToIcon();
                    dialog.HeaderText = PdnResources.GetString("SaveConfigDialog.Finishing.Text");
                    dialog.ShowDialog(historyWorkspace.Window);
                }
            }
            Result <GeometryList> taskResult = task.TaskResult;

            if (taskResult.IsError)
            {
                if (taskResult.Error is OutOfMemoryException)
                {
                    throw new OutOfMemoryException(null, taskResult.Error);
                }
                throw new AggregateException(null, taskResult.Error);
            }
            GeometryList geometry = task.TaskResult.Value;

            base.EnterCriticalRegion();
            using (historyWorkspace.Selection.UseChangeScope())
            {
                historyWorkspace.Selection.Reset();
                geometry.Freeze();
                historyWorkspace.Selection.SetContinuation(geometry, SelectionCombineMode.Replace);
                historyWorkspace.Selection.CommitContinuation();
            }
            return(memento);
        }
Exemplo n.º 18
0
        public override HistoryMemento OnExecute(IHistoryWorkspace historyWorkspace)
        {
            GeometryList cachedClippingMask = historyWorkspace.Selection.GetCachedClippingMask();

            if (historyWorkspace.Selection.IsEmpty || (cachedClippingMask.Bounds.Area < 1.0))
            {
                return(null);
            }
            Document  oldDocument   = historyWorkspace.Document;
            RectInt32 b             = cachedClippingMask.Bounds.GetInt32Bound(1E-05);
            RectInt32 oldClipBounds = RectInt32.Intersect(oldDocument.Bounds(), b);
            Document  document      = new Document(oldClipBounds.Width, oldClipBounds.Height);

            document.ReplaceMetadataFrom(oldDocument);
            RectInt32 newClipBounds = new RectInt32(0, 0, oldClipBounds.Width, oldClipBounds.Height);
            SelectionRenderingQuality                   quality = historyWorkspace.ToolSettings.Selection.RenderingQuality.Value;
            Result <IRenderer <ColorAlpha8> >           oldClipMaskRendererLazy = historyWorkspace.Selection.GetCachedLazyClippingMaskRenderer(quality);
            LazyResult <ClippedRenderer <ColorAlpha8> > newClipMaskRendererLazy = LazyResult.New <ClippedRenderer <ColorAlpha8> >(() => new ClippedRenderer <ColorAlpha8>(oldClipMaskRendererLazy.Value, oldClipBounds), LazyThreadSafetyMode.ExecutionAndPublication, new VistaCriticalSection(0));
            SelectionData selectionData = historyWorkspace.Selection.Save();

            System.Threading.Tasks.Task <SelectionHistoryMemento>       task  = System.Threading.Tasks.Task.Factory.StartNew <SelectionHistoryMemento>(() => new SelectionHistoryMemento(null, null, historyWorkspace, selectionData));
            System.Threading.Tasks.Task <ReplaceDocumentHistoryMemento> task2 = System.Threading.Tasks.Task.Factory.StartNew <ReplaceDocumentHistoryMemento>(() => new ReplaceDocumentHistoryMemento(null, null, historyWorkspace, oldDocument), TaskCreationOptions.LongRunning);
            int count = oldDocument.Layers.Count;

            System.Threading.Tasks.Task <BitmapLayer>[] items = new System.Threading.Tasks.Task <BitmapLayer> [count];
            for (int i = 0; i < count; i++)
            {
                int iP = i;
                items[iP] = System.Threading.Tasks.Task.Factory.StartNew <BitmapLayer>(delegate {
                    if (iP == 0)
                    {
                        newClipMaskRendererLazy.EnsureEvaluated();
                    }
                    BitmapLayer layer      = (BitmapLayer)oldDocument.Layers[iP];
                    Surface croppedSurface = layer.Surface.CreateWindow(oldClipBounds);
                    BitmapLayer newLayer   = RetryManager.RunMemorySensitiveOperation <BitmapLayer>(() => new BitmapLayer(croppedSurface));
                    newLayer.LoadProperties(layer.SaveProperties());
                    Parallel.ForEach <RectInt32>(newClipBounds.GetTiles(TilingStrategy.Tiles, 7), delegate(RectInt32 newTileRect) {
                        ISurface <ColorBgra> surface = newLayer.Surface.CreateWindow(newTileRect);
                        IRenderer <ColorAlpha8> mask = new ClippedRenderer <ColorAlpha8>(newClipMaskRendererLazy.Value, newTileRect);
                        surface.MultiplyAlphaChannel(mask);
                    });
                    return(newLayer);
                });
            }
            List <TupleStruct <System.Threading.Tasks.Task, double> > collection = new List <TupleStruct <System.Threading.Tasks.Task, double> >();

            collection.AddTuple <System.Threading.Tasks.Task, double>(task, 0.1);
            collection.AddTuple <System.Threading.Tasks.Task, double>(task2, 1.0);
            for (int j = 0; j < items.Length; j++)
            {
                collection.AddTuple <System.Threading.Tasks.Task, double>(items[j], 0.1);
            }
            PaintDotNet.Threading.Tasks.Task <Unit> task3 = historyWorkspace.TaskManager.CreateFrameworkTasksWrapper(collection);
            historyWorkspace.WaitWithProgress(task3, HistoryMementoImage, HistoryMementoName, PdnResources.GetString("Effects.ApplyingDialog.Description"));
            document.Layers.AddRange <Layer>(items.Select <System.Threading.Tasks.Task <BitmapLayer>, BitmapLayer>(t => t.Result));
            SelectionHistoryMemento       result   = task.Result;
            ReplaceDocumentHistoryMemento memento2 = task2.Result;

            base.EnterCriticalRegion();
            historyWorkspace.Document = document;
            HistoryMemento[] mementos = new HistoryMemento[] { result, memento2 };
            return(HistoryMemento.Combine(HistoryMementoName, HistoryMementoImage, mementos));
        }
 private void UpdateLayerOverlay()
 {
     this.tool.VerifyAccess <TTool>();
     using (this.updateLayerOverlayRegion.UseEnterScope())
     {
         TChanges  local;
         RectInt32?nullable;
         RectInt32?nullable2;
         RectInt32?nullable3;
         RectInt32?nullable4;
         BitmapLayerToolLayerOverlay <TTool, TChanges> overlay2;
         RectInt32 differentialMaxBounds;
         RectInt32 num3;
         BitmapLayerToolLayerOverlay <TTool, TChanges> layerOverlay = this.layerOverlay;
         if (layerOverlay == null)
         {
             local     = default(TChanges);
             nullable  = null;
             nullable2 = null;
         }
         else
         {
             local     = layerOverlay.Changes;
             nullable  = new RectInt32?(local.GetMaxRenderBounds());
             nullable2 = new RectInt32?(layerOverlay.AffectedBounds);
         }
         TChanges changes = this.tool.Changes;
         if (changes == null)
         {
             nullable3 = null;
             nullable4 = null;
             overlay2  = null;
         }
         else
         {
             nullable3 = new RectInt32?(changes.GetMaxRenderBounds());
             overlay2  = this.CreateLayerOverlay(this.tool.ActiveLayer, changes);
             if (overlay2 == null)
             {
                 ExceptionUtil.ThrowInternalErrorException("CreateLayerOverlay() -> null");
             }
             nullable4 = new RectInt32?(overlay2.AffectedBounds);
         }
         RectInt32 num = this.tool.Document.Bounds();
         if ((local == null) && (changes != null))
         {
             differentialMaxBounds = nullable3.Value;
             num3 = nullable4.Value;
         }
         else if ((local != null) && (changes == null))
         {
             differentialMaxBounds = nullable.Value;
             num3 = nullable2.Value;
         }
         else
         {
             differentialMaxBounds = this.tool.GetDifferentialMaxBounds(local, changes);
             num3 = RectInt32.Union(nullable2.Value, nullable4.Value);
         }
         RectInt32 num4 = RectInt32.Intersect(differentialMaxBounds, num3);
         this.layerOverlay = overlay2;
         this.tool.DocumentCanvas.ReplaceLayerOverlay(this.tool.ActiveLayer, layerOverlay, overlay2, new RectInt32?(num4));
     }
 }
Exemplo n.º 20
0
 protected override void OnRender(IDrawingContext dc, RectFloat clipRect)
 {
     if (this.historyStack != null)
     {
         dc.Clear(new ColorRgba128Float?(this.BackColor));
         using (dc.UseTranslateTransform(0f, (float)-this.scrollOffset, MatrixMultiplyOrder.Prepend))
         {
             int                 num7;
             int                 num8;
             int                 num11;
             int                 num12;
             RectDouble?         nullable;
             TextLayoutAlgorithm?nullable2;
             int                 num  = UIUtil.ScaleWidth(1);
             int                 num2 = (this.itemHeight - this.imageHeight) / 2;
             int                 num3 = UIUtil.ScaleWidth(2);
             RectInt32           a    = this.ClientRectangleToViewRectangle(base.ClientRectangle.ToRectInt32());
             RectInt32           undoViewRectangle = this.UndoViewRectangle;
             dc.FillRectangle(undoViewRectangle, PaintDotNet.UI.Media.SystemBrushes.Window);
             RectInt32 num6 = RectInt32.Intersect(a, undoViewRectangle);
             if ((num6.Width > 0) && (num6.Height > 0))
             {
                 ItemType type;
                 this.ViewPointToStackIndex(num6.Location, out type, out num7);
                 this.ViewPointToStackIndex(new PointInt32(num6.Left, num6.Bottom - 1), out type, out num8);
             }
             else
             {
                 num7 = 0;
                 num8 = -1;
             }
             for (int i = num7; i <= num8; i++)
             {
                 DeviceBitmap   deviceBitmap;
                 int            imageHeight;
                 HighlightState hover;
                 ImageResource  image = this.historyStack.UndoStack[i].Image;
                 if (image != null)
                 {
                     deviceBitmap = ImageResourceUtil.GetDeviceBitmap(image);
                 }
                 else
                 {
                     deviceBitmap = null;
                 }
                 if (deviceBitmap != null)
                 {
                     imageHeight = (deviceBitmap.PixelSize.Width * this.imageHeight) / deviceBitmap.PixelSize.Height;
                 }
                 else
                 {
                     imageHeight = this.imageHeight;
                 }
                 if (i == (this.historyStack.UndoStack.Count - 1))
                 {
                     hover = HighlightState.Checked;
                 }
                 else if (i == this.undoItemHighlight)
                 {
                     hover = HighlightState.Hover;
                 }
                 else
                 {
                     hover = HighlightState.Default;
                 }
                 RectInt32 bounds = new RectInt32(0, i * this.itemHeight, this.ViewWidth, this.itemHeight);
                 this.selectionHighlightRenderer.HighlightState = hover;
                 this.selectionHighlightRenderer.RenderBackground(dc, bounds);
                 PaintDotNet.UI.Media.Brush embeddedTextBrush = this.selectionHighlightRenderer.EmbeddedTextBrush;
                 if (deviceBitmap != null)
                 {
                     nullable = null;
                     dc.DrawBitmap(deviceBitmap, new RectDouble?(new RectInt32(bounds.X + num, bounds.Y + num2, imageHeight, this.imageHeight)), 1.0, BitmapInterpolationMode.Linear, nullable);
                 }
                 int       x     = (num + num3) + imageHeight;
                 RectInt32 num17 = new RectInt32(x, bounds.Y, this.ViewWidth - x, this.itemHeight);
                 nullable2 = null;
                 TextLayout textLayout = UIText.CreateLayout(dc, this.historyStack.UndoStack[i].Name, this.Font, nullable2, HotkeyRenderMode.Hide, (double)num17.Width, (double)num17.Height);
                 textLayout.WordWrapping       = WordWrapping.Wrap;
                 textLayout.ParagraphAlignment = ParagraphAlignment.Center;
                 UIText.AdjustFontSizeToFitLayoutSize(dc, textLayout, (double)num17.Width, (double)num17.Height, 0.6);
                 dc.DrawTextLayout(num17.Location, textLayout, embeddedTextBrush, DrawTextOptions.None);
             }
             RectInt32 redoViewRectangle = this.RedoViewRectangle;
             dc.FillRectangle(redoViewRectangle, slateGrayBrush);
             RectInt32 num10 = RectInt32.Intersect(a, redoViewRectangle);
             if ((num10.Width > 0) && (num10.Height > 0))
             {
                 ItemType type2;
                 this.ViewPointToStackIndex(num10.Location, out type2, out num11);
                 this.ViewPointToStackIndex(new PointInt32(num10.Left, num10.Bottom - 1), out type2, out num12);
             }
             else
             {
                 num11 = 0;
                 num12 = -1;
             }
             for (int j = num11; j <= num12; j++)
             {
                 DeviceBitmap bitmap2;
                 int          num20;
                 PaintDotNet.UI.Media.Brush inactiveCaptionText;
                 ImageResource imageResource = this.historyStack.RedoStack[j].Image;
                 if (imageResource != null)
                 {
                     bitmap2 = ImageResourceUtil.GetDeviceBitmap(imageResource);
                 }
                 else
                 {
                     bitmap2 = null;
                 }
                 if (bitmap2 != null)
                 {
                     num20 = (bitmap2.PixelSize.Width * this.imageHeight) / bitmap2.PixelSize.Height;
                 }
                 else
                 {
                     num20 = this.imageHeight;
                 }
                 RectInt32 num21 = new RectInt32(0, redoViewRectangle.Top + (j * this.itemHeight), this.ViewWidth, this.itemHeight);
                 if (j == this.redoItemHighlight)
                 {
                     this.selectionHighlightRenderer.HighlightState = HighlightState.Hover;
                     this.selectionHighlightRenderer.RenderBackground(dc, num21);
                     inactiveCaptionText = this.selectionHighlightRenderer.EmbeddedTextBrush;
                 }
                 else
                 {
                     inactiveCaptionText = PaintDotNet.UI.Media.SystemBrushes.InactiveCaptionText;
                 }
                 if (bitmap2 != null)
                 {
                     nullable = null;
                     dc.DrawBitmap(bitmap2, new RectDouble?(new RectInt32(num21.X + num, num21.Y + num2, num20, this.imageHeight)), 1.0, BitmapInterpolationMode.Linear, nullable);
                 }
                 int       num22 = (num + num3) + num20;
                 RectInt32 num23 = new RectInt32(num22, num21.Y, this.ViewWidth - num22, this.itemHeight);
                 nullable2 = null;
                 TextLayout layout2 = UIText.CreateLayout(dc, this.historyStack.RedoStack[j].Name, this.Font, nullable2, HotkeyRenderMode.Hide, (double)num23.Width, (double)num23.Height);
                 layout2.WordWrapping       = WordWrapping.NoWrap;
                 layout2.ParagraphAlignment = ParagraphAlignment.Center;
                 layout2.FontStyle          = PaintDotNet.DirectWrite.FontStyle.Italic;
                 UIText.AdjustFontSizeToFitLayoutSize(dc, layout2, (double)num23.Width, (double)num23.Height, 0.6);
                 dc.DrawTextLayout(num23.Location, layout2, inactiveCaptionText, DrawTextOptions.None);
             }
         }
     }
     base.OnRender(dc, clipRect);
 }
Exemplo n.º 21
0
            public unsafe void DrawScansNearestNeighbor(int cpuNumber)
            {
                int       logicalCpuCount = Processor.LogicalCpuCount;
                void *    voidStar        = this.src.Scan0.VoidStar;
                int       stride          = this.src.Stride;
                RectInt32 b = this.dst.Bounds <ColorBgra>();

                for (int i = cpuNumber; i < this.dstScans.Length; i += logicalCpuCount)
                {
                    RectInt32 num5 = RectInt32.Intersect(this.dstScans[i], b);
                    if ((num5.Width != 0) && (num5.Height != 0))
                    {
                        PointDouble pt = new PointDouble((double)num5.X, (double)num5.Y);
                        pt.X += 0.5;
                        pt.Y += 0.5;
                        pt    = this.inverse.Transform(pt);
                        pt.X -= this.boundsX;
                        pt.Y -= this.boundsY;
                        pt.X -= 0.5;
                        pt.Y -= 0.5;
                        int num7 = (int)(pt.X * 16384.0);
                        int num8 = (int)(pt.Y * 16384.0);
                        for (int j = num5.Y; j < (num5.Y + num5.Height); j++)
                        {
                            int num10 = num7;
                            int num11 = num8;
                            num7 += this.fp_dsxddy;
                            num8 += this.fp_dsyddy;
                            if (j >= 0)
                            {
                                int        x            = num5.X;
                                ColorBgra *pointAddress = this.dst.GetPointAddress(x, j);
                                ColorBgra *bgraPtr2     = pointAddress + num5.Width;
                                int        num13        = num10 + (this.fp_dsxddx * (num5.Width - 1));
                                int        num14        = num11 + (this.fp_dsyddx * (num5.Width - 1));
                                while (pointAddress < bgraPtr2)
                                {
                                    int num15 = (num10 + 0x1fff) >> 14;
                                    int num16 = (num11 + 0x1fff) >> 14;
                                    int num17 = Int32Util.Clamp(num15, 0, this.src.Width - 1);
                                    int y     = Int32Util.Clamp(num16, 0, this.src.Height - 1);
                                    pointAddress[0] = this.src.GetPointUnchecked(num17, y);
                                    pointAddress++;
                                    num10 += this.fp_dsxddx;
                                    num11 += this.fp_dsyddx;
                                    if ((num17 == num15) && (y == num16))
                                    {
                                        break;
                                    }
                                }
                                ColorBgra *bgraPtr3 = pointAddress;
                                pointAddress = bgraPtr2 - 1;
                                while (pointAddress >= bgraPtr3)
                                {
                                    int num19 = (num13 + 0x1fff) >> 14;
                                    int num20 = (num14 + 0x1fff) >> 14;
                                    int num21 = Int32Util.Clamp(num19, 0, this.src.Width - 1);
                                    int num22 = Int32Util.Clamp(num20, 0, this.src.Height - 1);
                                    pointAddress[0] = this.src.GetPointUnchecked(num21, num22);
                                    if ((num21 == num19) && (num22 == num20))
                                    {
                                        break;
                                    }
                                    pointAddress--;
                                    num13 -= this.fp_dsxddx;
                                    num14 -= this.fp_dsyddx;
                                }
                                ColorBgra *bgraPtr4 = pointAddress;
                                while (bgraPtr3 < bgraPtr4)
                                {
                                    int num23 = (num10 + 0x1fff) >> 14;
                                    int num24 = (num11 + 0x1fff) >> 14;
                                    bgraPtr3->Bgra = (((IntPtr)(num23 * sizeof(ColorBgra))) + (voidStar + (num24 * stride))).Bgra;
                                    bgraPtr3++;
                                    num10 += this.fp_dsxddx;
                                    num11 += this.fp_dsyddx;
                                }
                            }
                        }
                    }
                }
            }
Exemplo n.º 22
0
        private bool PerformActionImpl()
        {
            PointInt32 num2;
            RectInt32  num3;

            if (this.clipData == null)
            {
                try
                {
                    using (new WaitCursorChanger(this.documentWorkspace))
                    {
                        CleanupManager.RequestCleanup();
                        this.clipData = PdnClipboard.GetDataObject();
                    }
                }
                catch (OutOfMemoryException exception)
                {
                    ExceptionDialog.ShowErrorDialog(this.documentWorkspace, PdnResources.GetString("PasteAction.Error.OutOfMemory"), exception);
                    return(false);
                }
                catch (Exception exception2)
                {
                    ExceptionDialog.ShowErrorDialog(this.documentWorkspace, PdnResources.GetString("PasteAction.Error.TransferFromClipboard"), exception2);
                    return(false);
                }
            }
            bool handled = false;

            if (this.documentWorkspace.Tool != null)
            {
                this.documentWorkspace.Tool.PerformPaste(this.clipData, out handled);
            }
            if (handled)
            {
                return(true);
            }
            if (this.maskedSurface == null)
            {
                try
                {
                    using (new WaitCursorChanger(this.documentWorkspace))
                    {
                        this.maskedSurface = ClipboardUtil.GetClipboardImage(this.documentWorkspace, this.clipData);
                    }
                }
                catch (OutOfMemoryException exception3)
                {
                    ExceptionDialog.ShowErrorDialog(this.documentWorkspace, PdnResources.GetString("PasteAction.Error.OutOfMemory"), exception3);
                    return(false);
                }
                catch (Exception exception4)
                {
                    ExceptionDialog.ShowErrorDialog(this.documentWorkspace, PdnResources.GetString("PasteAction.Error.TransferFromClipboard"), exception4);
                    return(false);
                }
            }
            if (this.maskedSurface == null)
            {
                MessageBoxUtil.ErrorBox(this.documentWorkspace, PdnResources.GetString("PasteAction.Error.NoImage"));
                return(false);
            }
            RectInt32 cachedGeometryMaskScansBounds = this.maskedSurface.GetCachedGeometryMaskScansBounds();

            if ((cachedGeometryMaskScansBounds.Width > this.documentWorkspace.Document.Width) || (cachedGeometryMaskScansBounds.Height > this.documentWorkspace.Document.Height))
            {
                Surface surface;
                try
                {
                    using (new WaitCursorChanger(this.documentWorkspace))
                    {
                        surface = CreateThumbnail(this.maskedSurface);
                    }
                }
                catch (OutOfMemoryException)
                {
                    surface = null;
                }
                DialogResult result           = ShowExpandCanvasTaskDialog(this.documentWorkspace, surface);
                int          activeLayerIndex = this.documentWorkspace.ActiveLayerIndex;
                ColorBgra    background       = this.documentWorkspace.ToolSettings.SecondaryColor.Value;
                if (result != DialogResult.Cancel)
                {
                    if (result != DialogResult.Yes)
                    {
                        if (result != DialogResult.No)
                        {
                            throw ExceptionUtil.InvalidEnumArgumentException <DialogResult>(result, "dr");
                        }
                        goto Label_031D;
                    }
                    using (new PushNullToolMode(this.documentWorkspace))
                    {
                        int      width    = Math.Max(cachedGeometryMaskScansBounds.Width, this.documentWorkspace.Document.Width);
                        Size     newSize  = new Size(width, Math.Max(cachedGeometryMaskScansBounds.Height, this.documentWorkspace.Document.Height));
                        Document document = CanvasSizeAction.ResizeDocument(this.documentWorkspace.Document, newSize, AnchorEdge.TopLeft, background);
                        if (document == null)
                        {
                            return(false);
                        }
                        SelectionHistoryMemento       memento  = new SelectionHistoryMemento(null, null, this.documentWorkspace);
                        ReplaceDocumentHistoryMemento memento2 = new ReplaceDocumentHistoryMemento(CanvasSizeAction.StaticName, CanvasSizeAction.StaticImage, this.documentWorkspace);
                        this.documentWorkspace.Document = document;
                        HistoryMemento[]       actions  = new HistoryMemento[] { memento, memento2 };
                        CompoundHistoryMemento memento3 = new CompoundHistoryMemento(CanvasSizeAction.StaticName, CanvasSizeAction.StaticImage, actions);
                        this.documentWorkspace.History.PushNewMemento(memento3);
                        this.documentWorkspace.ActiveLayer = (Layer)this.documentWorkspace.Document.Layers[activeLayerIndex];
                        goto Label_031D;
                    }
                }
                return(false);
            }
Label_031D:
            num3 = this.documentWorkspace.Document.Bounds();
            RectDouble visibleDocumentRect = this.documentWorkspace.VisibleDocumentRect;
            RectInt32? nullable            = visibleDocumentRect.Int32Inset();
            RectDouble num5 = nullable.HasValue ? ((RectDouble)nullable.Value) : visibleDocumentRect;
            RectInt32  num6 = num5.Int32Bound;

            if (num5.Contains(cachedGeometryMaskScansBounds))
            {
                num2 = new PointInt32(0, 0);
            }
            else
            {
                int num12;
                int num13;
                int num16;
                int num17;
                if (cachedGeometryMaskScansBounds.X < num5.Left)
                {
                    num12 = -cachedGeometryMaskScansBounds.X + num6.X;
                }
                else if (cachedGeometryMaskScansBounds.Right > num6.Right)
                {
                    num12 = (-cachedGeometryMaskScansBounds.X + num6.Right) - cachedGeometryMaskScansBounds.Width;
                }
                else
                {
                    num12 = 0;
                }
                if (cachedGeometryMaskScansBounds.Y < num5.Top)
                {
                    num13 = -cachedGeometryMaskScansBounds.Y + num6.Y;
                }
                else if (cachedGeometryMaskScansBounds.Bottom > num6.Bottom)
                {
                    num13 = (-cachedGeometryMaskScansBounds.Y + num6.Bottom) - cachedGeometryMaskScansBounds.Height;
                }
                else
                {
                    num13 = 0;
                }
                PointInt32 num14 = new PointInt32(num12, num13);
                RectInt32  num15 = new RectInt32(cachedGeometryMaskScansBounds.X + num14.X, cachedGeometryMaskScansBounds.Y + num14.Y, cachedGeometryMaskScansBounds.Width, cachedGeometryMaskScansBounds.Height);
                if (num15.X < 0)
                {
                    num16 = num12 - num15.X;
                }
                else
                {
                    num16 = num12;
                }
                if (num15.Y < 0)
                {
                    num17 = num13 - num15.Y;
                }
                else
                {
                    num17 = num13;
                }
                PointInt32 num18 = new PointInt32(num16, num17);
                RectInt32  rect  = new RectInt32(cachedGeometryMaskScansBounds.X + num18.X, cachedGeometryMaskScansBounds.Y + num18.Y, cachedGeometryMaskScansBounds.Width, cachedGeometryMaskScansBounds.Height);
                if (num3.Contains(rect))
                {
                    num2 = num18;
                }
                else
                {
                    PointInt32 num20 = num18;
                    if (rect.Right > num3.Right)
                    {
                        int num21 = rect.Right - num3.Right;
                        int num22 = Math.Min(num21, rect.Left);
                        num20.X -= num22;
                    }
                    if (rect.Bottom > num3.Bottom)
                    {
                        int num23 = rect.Bottom - num3.Bottom;
                        int num24 = Math.Min(num23, rect.Top);
                        num20.Y -= num24;
                    }
                    num2 = num20;
                }
            }
            RectInt32 b           = this.documentWorkspace.VisibleDocumentRect.Int32Bound;
            RectInt32 a           = new RectInt32(cachedGeometryMaskScansBounds.X + num2.X, cachedGeometryMaskScansBounds.Y + num2.Y, cachedGeometryMaskScansBounds.Width, cachedGeometryMaskScansBounds.Height);
            bool      hasZeroArea = RectInt32.Intersect(a, b).HasZeroArea;

            MoveTool.BeginPaste(this.documentWorkspace, PdnResources.GetString("CommonAction.Paste"), PdnResources.GetImageResource("Icons.MenuEditPasteIcon.png"), this.maskedSurface.SurfaceReadOnly, this.maskedSurface.GeometryMask, num2);
            if (hasZeroArea)
            {
                PointInt32  num25 = new PointInt32(b.Left + (b.Width / 2), b.Top + (b.Height / 2));
                PointInt32  num26 = new PointInt32(a.Left + (a.Width / 2), a.Top + (a.Height / 2));
                SizeInt32   num27 = new SizeInt32(num26.X - num25.X, num26.Y - num25.Y);
                PointDouble documentScrollPosition = this.documentWorkspace.DocumentScrollPosition;
                PointDouble num29 = new PointDouble(documentScrollPosition.X + num27.Width, documentScrollPosition.Y + num27.Height);
                this.documentWorkspace.DocumentScrollPosition = num29;
            }
            return(true);
        }
Exemplo n.º 23
0
        public bool PerformAction()
        {
            bool flag = true;

            if (!this.QueryCanPerformAction())
            {
                return(false);
            }
            try
            {
                using (new WaitCursorChanger(this.documentWorkspace))
                {
                    IRenderer <ColorBgra>   source             = this.GetSource();
                    RectInt32               num                = source.Bounds <ColorBgra>();
                    GeometryList            cachedClippingMask = this.documentWorkspace.Selection.GetCachedClippingMask();
                    RectInt32               a = cachedClippingMask.Bounds.Int32Bound;
                    IRenderer <ColorAlpha8> cachedClippingMaskRenderer = this.documentWorkspace.Selection.GetCachedClippingMaskRenderer(this.documentWorkspace.ToolSettings.Selection.RenderingQuality.Value);
                    RectInt32               sourceRect = RectInt32.Intersect(a, source.Bounds <ColorBgra>());
                    IRenderer <ColorBgra>   renderer3  = new ClippedRenderer <ColorBgra>(source, sourceRect);
                    IRenderer <ColorAlpha8> alpha      = new ClippedRenderer <ColorAlpha8>(cachedClippingMaskRenderer, sourceRect);
                    IRenderer <ColorBgra>   sourceRHS  = new MultiplyAlphaChannelRendererBgra32(renderer3, alpha);
                    IRenderer <ColorBgra>   sourceLHS  = new SolidColorRendererBgra(sourceRHS.Width, sourceRHS.Height, ColorBgra.White);
                    IRenderer <ColorBgra>   renderer   = new BlendRendererBgra(sourceLHS, CompositionOps.Normal.Static, sourceRHS);
                    if ((a.Width > 0) && (a.Height > 0))
                    {
                        int num5 = 10;
                        while (num5 >= 0)
                        {
                            try
                            {
                                try
                                {
                                    using (Clipboard.Transaction transaction = Clipboard.Open(this.documentWorkspace))
                                    {
                                        transaction.Empty();
                                        using (MaskedSurface surface = MaskedSurface.CopyFrom(source, cachedClippingMask))
                                        {
                                            transaction.AddManagedData(surface);
                                            using (Surface surface2 = surface.Surface.CreateWindow(new Rectangle(0, 0, a.Width, a.Height)))
                                            {
                                                sourceRHS.Parallelize <ColorBgra>(TilingStrategy.Tiles, 7, WorkItemQueuePriority.Normal).Render <ColorBgra>(surface2);
                                                using (Bitmap copyBitmap = surface2.CreateAliasedBitmap(true))
                                                {
                                                    transaction.AddRawNativeData("PNG", delegate(Stream dstStream) {
                                                        copyBitmap.Save(dstStream, ImageFormat.Png);
                                                    });
                                                }
                                                renderer.Parallelize <ColorBgra>(TilingStrategy.Tiles, 7, WorkItemQueuePriority.Normal).Render <ColorBgra>(surface2);
                                                using (Bitmap bitmap = surface2.CreateAliasedBitmap(false))
                                                {
                                                    transaction.AddDibV5(bitmap);
                                                }
                                            }
                                            goto Label_0292;
                                        }
                                    }
                                }
                                catch (Exception exception)
                                {
                                    if (num5 == 0)
                                    {
                                        flag = false;
                                        ExceptionDialog.ShowErrorDialog(this.documentWorkspace, PdnResources.GetString("CopyAction.Error.TransferToClipboard"), exception.ToString());
                                    }
                                    else
                                    {
                                        CleanupManager.RequestCleanup();
                                        CleanupManager.WaitForPendingCleanup(50);
                                        Thread.Sleep(50);
                                    }
                                }
                                continue;
                            }
                            finally
                            {
                                num5--;
                            }
                        }
                    }
                }
            }
            catch (OutOfMemoryException exception2)
            {
                flag = false;
                ExceptionDialog.ShowErrorDialog(this.documentWorkspace, PdnResources.GetString("CopyAction.Error.OutOfMemory"), exception2.ToString());
            }
            catch (Exception exception3)
            {
                flag = false;
                ExceptionDialog.ShowErrorDialog(this.documentWorkspace, PdnResources.GetString("CopyAction.Error.Generic"), exception3.ToString());
            }
Label_0292:
            CleanupManager.RequestCleanup();
            return(flag);
        }