예제 #1
0
        public override HistoryMemento OnExecute(IHistoryWorkspace historyWorkspace)
        {
            if ((this.layerIndex < 1) || (this.layerIndex >= historyWorkspace.Document.Layers.Count))
            {
                object[] objArray1 = new object[] { "layerIndex must be greater than or equal to 1, and a valid layer index. layerIndex=", this.layerIndex, ", allowableRange=[0,", historyWorkspace.Document.Layers.Count, ")" };
                throw new ArgumentException(string.Concat(objArray1));
            }
            int          layerIndex = this.layerIndex - 1;
            RectInt32    rect       = historyWorkspace.Document.Bounds();
            GeometryList list       = new GeometryList();

            list.AddRect(rect);
            RectInt32[]          changedRegion = list.EnumerateInteriorScans().ToArrayEx <RectInt32>();
            BitmapHistoryMemento memento       = new BitmapHistoryMemento(null, null, historyWorkspace, layerIndex, changedRegion);
            BitmapLayer          layer         = (BitmapLayer)historyWorkspace.Document.Layers[this.layerIndex];
            BitmapLayer          layer2        = (BitmapLayer)historyWorkspace.Document.Layers[layerIndex];
            RenderArgs           args          = new RenderArgs(layer2.Surface);

            base.EnterCriticalRegion();
            foreach (RectInt32 num4 in changedRegion)
            {
                layer.Render(args, num4.ToGdipRectangle());
            }
            layer2.Invalidate();
            args.Dispose();
            args = null;
            list = null;
            HistoryMemento memento2 = new DeleteLayerFunction(this.layerIndex).Execute(historyWorkspace);

            return(new CompoundHistoryMemento(StaticName, StaticImage, new HistoryMemento[] { memento, memento2 }));
        }
예제 #2
0
        public override HistoryMemento OnExecute(IHistoryWorkspace historyWorkspace)
        {
            if (this.layerIndex < 1 || this.layerIndex >= historyWorkspace.Document.Layers.Count)
            {
                throw new ArgumentException("layerIndex must be greater than or equal to 1, and a valid layer index. layerIndex=" +
                                            layerIndex + ", allowableRange=[0," + historyWorkspace.Document.Layers.Count + ")");
            }

            int       bottomLayerIndex = this.layerIndex - 1;
            Rectangle bounds           = historyWorkspace.Document.Bounds;
            PdnRegion region           = new PdnRegion(bounds);

            BitmapHistoryMemento bhm = new BitmapHistoryMemento(
                null,
                null,
                historyWorkspace,
                bottomLayerIndex,
                region);

            BitmapLayer topLayer    = (BitmapLayer)historyWorkspace.Document.Layers[this.layerIndex];
            BitmapLayer bottomLayer = (BitmapLayer)historyWorkspace.Document.Layers[bottomLayerIndex];
            RenderArgs  bottomRA    = new RenderArgs(bottomLayer.Surface);

            EnterCriticalRegion();

            topLayer.Render(bottomRA, region);
            bottomLayer.Invalidate();

            bottomRA.Dispose();
            bottomRA = null;

            region.Dispose();
            region = null;

            DeleteLayerFunction dlf  = new DeleteLayerFunction(this.layerIndex);
            HistoryMemento      dlhm = dlf.Execute(historyWorkspace);

            CompoundHistoryMemento chm = new CompoundHistoryMemento(StaticName, StaticImage, new HistoryMemento[] { bhm, dlhm });

            return(chm);
        }