Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge pull request #52 from don-mccomb/bug1094444

[Fixes bug #1094444] Fix to paste to displayed top-left corner in scrolled window
  • Loading branch information...
commit 4c17f43e32c7cff5a72d9e7c26d70857e5291488 2 parents 8dfb196 + 4896709
Cameron White cameronwhite authored
42 Pinta.Core/Classes/Document.cs
@@ -733,7 +733,18 @@ public void SetCurrentUserLayer(UserLayer layer)
733 733 SetCurrentUserLayer (UserLayers.IndexOf (layer));
734 734 }
735 735
736   - public void Paste (bool toNewLayer)
  736 + /// <summary>
  737 + /// Pastes an image from the clipboard.
  738 + /// </summary>
  739 + /// <param name="toNewLayer">Set to TRUE to paste into a
  740 + /// new layer. Otherwise, will paste to the current layer.</param>
  741 + /// <param name="x">Optional. Location within image to paste to.
  742 + /// Position will be adjusted if pasted image would hang
  743 + /// over right or bottom edges of canvas.</param>
  744 + /// <param name="y">Optional. Location within image to paste to.
  745 + /// Position will be adjusted if pasted image would hang
  746 + /// over right or bottom edges of canvas.</param>
  747 + public void Paste (bool toNewLayer, int x = 0, int y = 0)
737 748 {
738 749 // Create a compound history item for recording several
739 750 // operations so that they can all be undone/redone together.
@@ -762,9 +773,9 @@ public void Paste (bool toNewLayer)
762 773 Path p;
763 774
764 775 // Don't dispose this, as we're going to give it to the history
765   - Gdk.Pixbuf image = cb.WaitForImage ();
  776 + Gdk.Pixbuf cbImage = cb.WaitForImage ();
766 777
767   - if (image == null)
  778 + if (cbImage == null)
768 779 {
769 780 ShowClipboardEmptyDialog();
770 781 return;
@@ -773,13 +784,13 @@ public void Paste (bool toNewLayer)
773 784 Gdk.Size canvas_size = PintaCore.Workspace.ImageSize;
774 785
775 786 // If the image being pasted is larger than the canvas size, allow the user to optionally resize the canvas
776   - if (image.Width > canvas_size.Width || image.Height > canvas_size.Height)
  787 + if (cbImage.Width > canvas_size.Width || cbImage.Height > canvas_size.Height)
777 788 {
778 789 ResponseType response = ShowExpandCanvasDialog ();
779 790
780 791 if (response == ResponseType.Accept)
781 792 {
782   - PintaCore.Workspace.ResizeCanvas (image.Width, image.Height,
  793 + PintaCore.Workspace.ResizeCanvas (cbImage.Width, cbImage.Height,
783 794 Pinta.Core.Anchor.Center, paste_action);
784 795 PintaCore.Actions.View.UpdateCanvasScale ();
785 796 }
@@ -789,6 +800,11 @@ public void Paste (bool toNewLayer)
789 800 }
790 801 }
791 802
  803 + // If the pasted image would fall off bottom- or right-
  804 + // side of image, adjust paste position
  805 + x = Math.Max (0, Math.Min (x, canvas_size.Width - cbImage.Width));
  806 + y = Math.Max (0, Math.Min (y, canvas_size.Height - cbImage.Height));
  807 +
792 808 // If requested, create a new layer, make it the current
793 809 // layer and record it's creation in the history
794 810 if (toNewLayer)
@@ -799,16 +815,20 @@ public void Paste (bool toNewLayer)
799 815 }
800 816
801 817 // Copy the paste to the temp layer, which should be at least the size of this document.
802   - CreateSelectionLayer (Math.Max(ImageSize.Width, image.Width),
803   - Math.Max(ImageSize.Height, image.Height));
  818 + CreateSelectionLayer (Math.Max(ImageSize.Width, cbImage.Width),
  819 + Math.Max(ImageSize.Height, cbImage.Height));
804 820 ShowSelectionLayer = true;
805 821
806 822 using (Cairo.Context g = new Cairo.Context (SelectionLayer.Surface))
807 823 {
808   - g.DrawPixbuf (image, new Cairo.Point (0, 0));
809   - p = g.CreateRectanglePath (new Cairo.Rectangle (0, 0, image.Width, image.Height));
  824 +
  825 + g.DrawPixbuf (cbImage, new Cairo.Point (0, 0));
  826 + p = g.CreateRectanglePath (new Cairo.Rectangle (x, y, cbImage.Width, cbImage.Height));
810 827 }
811   -
  828 +
  829 + SelectionLayer.Transform.InitIdentity();
  830 + SelectionLayer.Transform.Translate (x, y);
  831 +
812 832 PintaCore.Tools.SetCurrentTool (Catalog.GetString ("Move Selected Pixels"));
813 833
814 834 DocumentSelection old_selection = Selection.Clone();
@@ -820,7 +840,7 @@ public void Paste (bool toNewLayer)
820 840
821 841 Workspace.Invalidate ();
822 842
823   - paste_action.Push (new PasteHistoryItem (image, old_selection, old_show_selection));
  843 + paste_action.Push (new PasteHistoryItem (cbImage, old_selection, old_show_selection));
824 844 History.PushNewItem (paste_action);
825 845 }
826 846
11 Pinta/Actions/Edit/PasteAction.cs
@@ -55,10 +55,19 @@ private void Activated (object sender, EventArgs e)
55 55 return;
56 56 }
57 57
  58 + // Get the scroll position in canvas co-ordinates
  59 + Gtk.Viewport view = (Gtk.Viewport)PintaCore.Chrome.Canvas.Parent;
  60 + Cairo.PointD canvasPos = PintaCore.Workspace.ActiveWorkspace.WindowPointToCanvas (
  61 + view.Hadjustment.Value,
  62 + view.Vadjustment.Value);
  63 +
58 64 // Paste into the active document.
59 65 // The 'false' argument indicates that paste should be
60 66 // performed into the current (not a new) layer.
61   - PintaCore.Workspace.ActiveDocument.Paste (false);
  67 + PintaCore.Workspace.ActiveDocument.Paste (
  68 + false,
  69 + (int) canvasPos.X,
  70 + (int) canvasPos.Y);
62 71 }
63 72 }
64 73 }
11 Pinta/Actions/Edit/PasteIntoNewLayerAction.cs
@@ -55,10 +55,19 @@ private void Activated (object sender, EventArgs e)
55 55 return;
56 56 }
57 57
  58 + // Get the scroll position in canvas co-ordinates
  59 + Gtk.Viewport view = (Gtk.Viewport)PintaCore.Chrome.Canvas.Parent;
  60 + Cairo.PointD canvasPos = PintaCore.Workspace.ActiveWorkspace.WindowPointToCanvas (
  61 + view.Hadjustment.Value,
  62 + view.Vadjustment.Value);
  63 +
58 64 // Paste into the active document.
59 65 // The 'true' argument indicates that paste should be
60 66 // performed into a new layer.
61   - PintaCore.Workspace.ActiveDocument.Paste (true);
  67 + PintaCore.Workspace.ActiveDocument.Paste (
  68 + true,
  69 + (int) canvasPos.X,
  70 + (int) canvasPos.Y);
62 71 }
63 72 }
64 73 }

0 comments on commit 4c17f43

Please sign in to comment.
Something went wrong with that request. Please try again.