Exemple #1
0
        public override void Undo()
        {
            // maintain the current scaling setting after the operation
            double scale = PintaCore.Workspace.Scale;

            Size swap = PintaCore.Workspace.ImageSize;

            PintaCore.Workspace.ImageSize  = old_size;
            PintaCore.Workspace.CanvasSize = old_size;

            old_size = swap;

            base.Undo();

            if (RestoreSelection != null)
            {
                DocumentSelection old = PintaCore.Workspace.ActiveDocument.Selection;
                PintaCore.Workspace.ActiveDocument.Selection = RestoreSelection.Clone();

                if (old != null)
                {
                    old.DisposeSelection();
                }

                PintaCore.Layers.ShowSelection = true;
            }
            else
            {
                PintaCore.Layers.ResetSelectionPath();
            }

            PintaCore.Workspace.Invalidate();

            PintaCore.Workspace.Scale = scale;
        }
Exemple #2
0
        public override void Undo()
        {
            // maintain the current scaling setting after the operation
            double scale = PintaCore.Workspace.Scale;

            Size swap = PintaCore.Workspace.ImageSize;

            var window = PintaCore.Workspace.ActiveWorkspace.Canvas.GdkWindow;

            window.FreezeUpdates();

            PintaCore.Workspace.ImageSize  = old_size;
            PintaCore.Workspace.CanvasSize = old_size;

            old_size = swap;

            base.Undo();

            if (RestoreSelection != null)
            {
                DocumentSelection old = PintaCore.Workspace.ActiveDocument.Selection;
                PintaCore.Workspace.ActiveDocument.Selection = RestoreSelection.Clone();

                if (old != null)
                {
                    old.Dispose();
                }
            }
            else
            {
                PintaCore.Layers.ResetSelectionPath();
            }

            PintaCore.Workspace.Invalidate();

            PintaCore.Workspace.Scale = scale;
            PintaCore.Actions.View.UpdateCanvasScale();

            window.ThawUpdates();
        }
Exemple #3
0
        /// <summary>
        /// Pastes an image from the clipboard.
        /// </summary>
        /// <param name="toNewLayer">Set to TRUE to paste into a
        /// new layer.  Otherwise, will paste to the current layer.</param>
        /// <param name="x">Optional. Location within image to paste to.
        /// Position will be adjusted if pasted image would hang
        /// over right or bottom edges of canvas.</param>
        /// <param name="y">Optional. Location within image to paste to.
        /// Position will be adjusted if pasted image would hang
        /// over right or bottom edges of canvas.</param>
        public void Paste(bool toNewLayer, int x = 0, int y = 0)
        {
            // Create a compound history item for recording several
            // operations so that they can all be undone/redone together.
            CompoundHistoryItem paste_action;

            if (toNewLayer)
            {
                paste_action = new CompoundHistoryItem(Stock.Paste, Catalog.GetString("Paste Into New Layer"));
            }
            else
            {
                paste_action = new CompoundHistoryItem(Stock.Paste, Catalog.GetString("Paste"));
            }

            Gtk.Clipboard cb = Gtk.Clipboard.Get(Gdk.Atom.Intern("CLIPBOARD", false));

            // See if the current tool wants to handle the paste
            // operation (e.g., the text tool could paste text)
            if (!toNewLayer)
            {
                if (PintaCore.Tools.CurrentTool.TryHandlePaste(cb))
                {
                    return;
                }
            }

            PintaCore.Tools.Commit();

            Path p;

            // Don't dispose this, as we're going to give it to the history
            Gdk.Pixbuf cbImage = cb.WaitForImage();

            if (cbImage == null)
            {
                ShowClipboardEmptyDialog();
                return;
            }

            Gdk.Size canvas_size = PintaCore.Workspace.ImageSize;

            // If the image being pasted is larger than the canvas size, allow the user to optionally resize the canvas
            if (cbImage.Width > canvas_size.Width || cbImage.Height > canvas_size.Height)
            {
                ResponseType response = ShowExpandCanvasDialog();

                if (response == ResponseType.Accept)
                {
                    PintaCore.Workspace.ResizeCanvas(cbImage.Width, cbImage.Height,
                                                     Pinta.Core.Anchor.Center, paste_action);
                    PintaCore.Actions.View.UpdateCanvasScale();
                }
                else if (response == ResponseType.Cancel || response == ResponseType.DeleteEvent)
                {
                    return;
                }
            }

            // If the pasted image would fall off bottom- or right-
            // side of image, adjust paste position
            x = Math.Max(0, Math.Min(x, canvas_size.Width - cbImage.Width));
            y = Math.Max(0, Math.Min(y, canvas_size.Height - cbImage.Height));

            // If requested, create a new layer, make it the current
            // layer and record it's creation in the history
            if (toNewLayer)
            {
                UserLayer l = AddNewLayer(string.Empty);
                SetCurrentUserLayer(l);
                paste_action.Push(new AddLayerHistoryItem("Menu.Layers.AddNewLayer.png", Catalog.GetString("Add New Layer"), UserLayers.IndexOf(l)));
            }

            // Copy the paste to the temp layer, which should be at least the size of this document.
            CreateSelectionLayer(Math.Max(ImageSize.Width, cbImage.Width),
                                 Math.Max(ImageSize.Height, cbImage.Height));
            ShowSelectionLayer = true;

            using (Cairo.Context g = new Cairo.Context(SelectionLayer.Surface))
            {
                g.DrawPixbuf(cbImage, new Cairo.Point(0, 0));
                p = g.CreateRectanglePath(new Cairo.Rectangle(x, y, cbImage.Width, cbImage.Height));
            }

            SelectionLayer.Transform.InitIdentity();
            SelectionLayer.Transform.Translate(x, y);

            PintaCore.Tools.SetCurrentTool(Catalog.GetString("Move Selected Pixels"));

            DocumentSelection old_selection = Selection.Clone();
            bool old_show_selection         = ShowSelection;

            Selection.SelectionPath = p;
            Selection.SelectionPolygons.Clear();
            ShowSelection = true;

            Workspace.Invalidate();

            paste_action.Push(new PasteHistoryItem(cbImage, old_selection, old_show_selection));
            History.PushNewItem(paste_action);
        }