示例#1
0
        public void Draw(ImageSurface dst)
        {
            if (disposed)
            {
                throw new ObjectDisposedException("PlacedSurface");
            }

            using (Cairo.Context g = new Cairo.Context(dst)) {
                g.Save();

                Rectangle r = what.GetBounds().ToCairoRectangle();

                // We need to use the source operator to fully replace the old
                // data.  Or else we may paint transparent on top of it and
                // it will still be visible.  [Bug #670411]
                using (Path p = g.CreateRectanglePath(new Rectangle(where.X, where.Y, r.Width, r.Height))) {
                    g.AppendPath(p);
                    g.Clip();
                    g.Operator = Operator.Source;
                    g.DrawPixbuf(what.ToPixbuf(), new Cairo.Point(where.X, where.Y));
                }

                g.Restore();
            }
        }
示例#2
0
        public override void Redo()
        {
            Document doc = PintaCore.Workspace.ActiveDocument;

            // Copy the paste to the temp layer
            doc.CreateSelectionLayer();
            doc.ShowSelectionLayer = true;

            using (Cairo.Context g = new Cairo.Context(doc.SelectionLayer.Surface)) {
                g.DrawPixbuf(paste_image, new Cairo.Point(0, 0));
            }

            Swap();

            PintaCore.Workspace.Invalidate();
            PintaCore.Tools.SetCurrentTool(Catalog.GetString("Move Selected Pixels"));
        }
示例#3
0
		public override void Redo ()
		{
			Document doc = PintaCore.Workspace.ActiveDocument;

			// Copy the paste to the temp layer
			doc.CreateSelectionLayer ();
			doc.ShowSelectionLayer = true;

			using (Cairo.Context g = new Cairo.Context (doc.SelectionLayer.Surface)) {
				g.DrawPixbuf (paste_image, new Cairo.Point (0, 0));
			}

			Swap ();

			PintaCore.Workspace.Invalidate ();
			PintaCore.Tools.SetCurrentTool (Catalog.GetString ("Move Selected Pixels"));
		}
        public void Render(Cairo.Context c, MonoReports.Model.Controls.Control control)
        {
            Image     image = control as Image;
            Rectangle borderRect;

            c.Save();
            borderRect = new Rectangle(image.Location.X, image.Location.Y, image.Width, image.Height);
            c.ClipRectangle(borderRect);
            borderRect = new Rectangle(image.Location.X, image.Location.Y, image.Width, image.Height);
            c.FillRectangle(borderRect, image.BackgroundColor.ToCairoColor());
            if (PixbufRepository.ContainsKey(image.ImageKey))
            {
                var pixbuf = PixbufRepository[image.ImageKey];
                c.DrawPixbuf(pixbuf, image.Location.ToCairoPointD(), image.Offset.ToCairoPointD());
            }
            c.DrawInsideBorder(borderRect, image.Border, true);
            c.Restore();
        }
示例#5
0
        private void HandlerPintaCoreActionsEditPasteActivated(object sender, EventArgs e)
        {
            Document doc = PintaCore.Workspace.ActiveDocument;

            PintaCore.Tools.Commit ();

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

            Path p;

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

            if (image == null)
                return;

            // Copy the paste to the temp layer
            doc.CreateSelectionLayer ();
            doc.ShowSelectionLayer = true;

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

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

            Path old_path = doc.SelectionPath;
            bool old_show_selection = doc.ShowSelection;

            doc.SelectionPath = p;
            doc.ShowSelection = true;

            doc.Workspace.Invalidate ();

            doc.History.PushNewItem (new PasteHistoryItem (image, old_path, old_show_selection));
        }
示例#6
0
        private void HandlerPintaCoreActionsEditPasteIntoNewLayerActivated(object sender, EventArgs e)
        {
            PintaCore.Layers.FinishSelection ();

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

            // TODO: Message window saying no image on clipboard
            if (image == null)
                return;

            Layer l = PintaCore.Layers.AddNewLayer (string.Empty);

            using (Cairo.Context g = new Cairo.Context (l.Surface))
                g.DrawPixbuf (image, new Cairo.Point (0, 0));

            // Make new layer the current layer
            PintaCore.Layers.SetCurrentLayer (l);

            PintaCore.Workspace.Invalidate ();

            // TODO: Need paste icon
            AddLayerHistoryItem hist = new AddLayerHistoryItem ("Menu.Edit.EraseSelection.png", Mono.Unix.Catalog.GetString ("Paste Into New Layer"), PintaCore.Layers.IndexOf (l));
            PintaCore.History.PushNewItem (hist);
        }
示例#7
0
        private void HandlerPintaCoreActionsEditPasteActivated(object sender, EventArgs e)
        {
            PintaCore.Layers.FinishSelection ();

            Cairo.ImageSurface old = PintaCore.Layers.CurrentLayer.Surface.Clone ();

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

            if (image == null)
                return;

            Path p;

            using (Cairo.Context g = new Cairo.Context (PintaCore.Layers.CurrentLayer.Surface)) {
                g.DrawPixbuf (image, new Cairo.Point (0, 0));
                p = g.CreateRectanglePath (new Rectangle (0, 0, image.Width, image.Height));
            }

            PintaCore.Layers.SelectionPath = p;
            PintaCore.Layers.ShowSelection = true;

            PintaCore.Workspace.Invalidate ();

            // TODO: Need paste icon
            PintaCore.History.PushNewItem (new SimpleHistoryItem ("Menu.Edit.EraseSelection.png", Mono.Unix.Catalog.GetString ("Paste"), old, PintaCore.Layers.CurrentLayerIndex));
        }
示例#8
0
        private void HandlerPintaCoreActionsEditPasteActivated(object sender, EventArgs e)
        {
            Document doc = PintaCore.Workspace.ActiveDocument;

            PintaCore.Tools.Commit ();

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

            Path p;

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

            if (image == null)
                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 (image.Width > canvas_size.Width || image.Height > canvas_size.Height)
            {
                string message = Catalog.GetString ("The image being pasted is larger than the canvas size. What would you like to do?");

                var enlarge_dialog = new MessageDialog (PintaCore.Chrome.MainWindow, DialogFlags.Modal, MessageType.Question, ButtonsType.None, message);
                enlarge_dialog.AddButton (Catalog.GetString ("Expand canvas"), ResponseType.Accept);
                enlarge_dialog.AddButton (Catalog.GetString ("Don't change canvas size"), ResponseType.Reject);
                enlarge_dialog.AddButton (Stock.Cancel, ResponseType.Cancel);
                enlarge_dialog.DefaultResponse = ResponseType.Accept;

                ResponseType response = (ResponseType)enlarge_dialog.Run ();
                enlarge_dialog.Destroy ();

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

            // Copy the paste to the temp layer
            doc.CreateSelectionLayer ();
            doc.ShowSelectionLayer = true;

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

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

            Path old_path = doc.SelectionPath;
            bool old_show_selection = doc.ShowSelection;

            doc.SelectionPath = p;
            doc.ShowSelection = true;

            doc.Workspace.Invalidate ();

            doc.History.PushNewItem (new PasteHistoryItem (image, old_path, old_show_selection));
        }
示例#9
0
        private void HandlerPintaCoreActionsEditPasteActivated(object sender, EventArgs e)
        {
            Document doc = PintaCore.Workspace.ActiveDocument;

            PintaCore.Tools.Commit();

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

            Path p;

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

            if (image == null)
            {
                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 (image.Width > canvas_size.Width || image.Height > canvas_size.Height)
            {
                string message = Catalog.GetString("The image being pasted is larger than the canvas size. What would you like to do?");

                var enlarge_dialog = new MessageDialog(PintaCore.Chrome.MainWindow, DialogFlags.Modal, MessageType.Question, ButtonsType.None, message);
                enlarge_dialog.AddButton(Catalog.GetString("Expand canvas"), ResponseType.Accept);
                enlarge_dialog.AddButton(Catalog.GetString("Don't change canvas size"), ResponseType.Reject);
                enlarge_dialog.AddButton(Stock.Cancel, ResponseType.Cancel);
                enlarge_dialog.DefaultResponse = ResponseType.Accept;

                ResponseType response = (ResponseType)enlarge_dialog.Run();
                enlarge_dialog.Destroy();

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

            // Copy the paste to the temp layer
            doc.CreateSelectionLayer();
            doc.ShowSelectionLayer = true;

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

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

            Path old_path           = doc.SelectionPath;
            bool old_show_selection = doc.ShowSelection;

            doc.SelectionPath = p;
            doc.ShowSelection = true;

            doc.Workspace.Invalidate();

            doc.History.PushNewItem(new PasteHistoryItem(image, old_path, old_show_selection));
        }
示例#10
0
文件: Document.cs 项目: msiyer/Pinta
		/// <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 ();

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

			if (cb.WaitIsImageAvailable ()) {
				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));
			}

			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.CreateRectangleSelection (new Cairo.Rectangle (x, y, cbImage.Width, cbImage.Height));
			ShowSelection = true;

			Workspace.Invalidate ();

			paste_action.Push (new PasteHistoryItem (cbImage, old_selection, old_show_selection));
			History.PushNewItem (paste_action);
		}
示例#11
0
        private void Activated(object sender, EventArgs e)
        {
            Gtk.Clipboard cb = Gtk.Clipboard.Get (Gdk.Atom.Intern ("CLIPBOARD", false));
            if (PintaCore.Tools.CurrentTool.TryHandlePaste (cb))
                return;

            Document doc = PintaCore.Workspace.ActiveDocument;

            PintaCore.Tools.Commit ();

            Path p;

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

            if (image == null)
            {
                Dialogs.ClipboardEmptyDialog.Show ();
                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 (image.Width > canvas_size.Width || image.Height > canvas_size.Height)
            {
                ResponseType response = ShowExpandCanvasDialog ();

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

            // Copy the paste to the temp layer
            doc.CreateSelectionLayer ();
            doc.ShowSelectionLayer = true;

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

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

            Path old_path = doc.SelectionPath;
            bool old_show_selection = doc.ShowSelection;

            doc.SelectionPath = p;
            doc.ShowSelection = true;

            doc.Workspace.Invalidate ();

            doc.History.PushNewItem (new PasteHistoryItem (image, old_path, old_show_selection));
        }
示例#12
0
        private void Activated(object sender, EventArgs e)
        {
            Gtk.Clipboard cb = Gtk.Clipboard.Get(Gdk.Atom.Intern("CLIPBOARD", false));
            if (PintaCore.Tools.CurrentTool.TryHandlePaste(cb))
            {
                return;
            }

            Document doc = PintaCore.Workspace.ActiveDocument;

            PintaCore.Tools.Commit();

            Path p;

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

            if (image == null)
            {
                Dialogs.ClipboardEmptyDialog.Show();
                return;
            }

            Gdk.Size canvas_size = PintaCore.Workspace.ImageSize;

            // Merge the (optional) canvas resize and the pasted image into a single history item.
            var paste_action = new CompoundHistoryItem(Stock.Paste, Catalog.GetString("Paste"));

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

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

            // Copy the paste to the temp layer
            doc.CreateSelectionLayer();
            doc.ShowSelectionLayer = true;

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

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

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

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

            doc.Workspace.Invalidate();

            paste_action.Push(new PasteHistoryItem(image, old_selection, old_show_selection));
            doc.History.PushNewItem(paste_action);
        }
示例#13
0
        private void HandlerPintaCoreActionsEditPasteIntoNewLayerActivated(object sender, EventArgs e)
        {
            Gtk.Clipboard cb = Gtk.Clipboard.Get(Gdk.Atom.Intern("CLIPBOARD", false));

            if (cb.WaitIsImageAvailable())
            {
                PintaCore.Layers.FinishSelection();

                Gdk.Pixbuf image = cb.WaitForImage();

                Layer l = PintaCore.Layers.AddNewLayer(string.Empty);

                using (Cairo.Context g = new Cairo.Context(l.Surface))
                    g.DrawPixbuf(image, new Cairo.Point(0, 0));

                // Make new layer the current layer
                PintaCore.Layers.SetCurrentLayer(l);

                PintaCore.Workspace.Invalidate();

                AddLayerHistoryItem hist = new AddLayerHistoryItem(Stock.Paste, Catalog.GetString("Paste Into New Layer"), PintaCore.Layers.IndexOf(l));
                PintaCore.History.PushNewItem(hist);
            }
            else
            {
                ClipboardEmptyError();
            }
        }
示例#14
0
        private void HandlerPintaCoreActionsEditPasteIntoNewImageActivated(object sender, EventArgs e)
        {
            Gtk.Clipboard cb = Gtk.Clipboard.Get(Gdk.Atom.Intern("CLIPBOARD", false));

            if (cb.WaitIsImageAvailable())
            {
                bool canceled = false;

                Gdk.Pixbuf image = cb.WaitForImage();

                Gdk.Size size = new Gdk.Size(image.Width, image.Height);

                if (PintaCore.Workspace.IsDirty)
                {
                    var primary = Catalog.GetString("Save the changes to image \"{0}\" before creating a new image?");
                    var secondary = Catalog.GetString("If you don't save, all changes will be permanently lost.");
                    var markup = "<span weight=\"bold\" size=\"larger\">{0}</span>\n\n{1}\n";
                    markup = string.Format(markup, primary, secondary);

                    var md = new MessageDialog(PintaCore.Chrome.MainWindow, DialogFlags.Modal,
                                                MessageType.Question, ButtonsType.None, true,
                                                markup,
                                                System.IO.Path.GetFileName(PintaCore.Workspace.Filename));

                    md.AddButton(Catalog.GetString("Close without saving"), ResponseType.No);
                    md.AddButton(Stock.Cancel, ResponseType.Cancel);
                    md.AddButton(Stock.Save, ResponseType.Yes);

                    // so that user won't accidentally overwrite
                    md.DefaultResponse = ResponseType.Cancel;

                    ResponseType response = (ResponseType)md.Run();
                    md.Destroy();

                    if (response == ResponseType.Yes)
                    {
                        PintaCore.Actions.File.Save.Activate();
                    }
                    else
                    {
                        canceled = response == ResponseType.Cancel;
                    }

                    PintaCore.Actions.File.NewFile(size);
                }
                else
                {
                    PintaCore.Workspace.ResizeImage(image.Width, image.Height);
                }

                PintaCore.Layers.FinishSelection();

                Cairo.ImageSurface old = PintaCore.Layers.CurrentLayer.Surface.Clone();

                Path p;

                using (Cairo.Context g = new Cairo.Context(PintaCore.Layers.CurrentLayer.Surface))
                {
                    g.DrawPixbuf(image, new Cairo.Point(0, 0));
                    p = g.CreateRectanglePath(new Rectangle(0, 0, image.Width, image.Height));
                }

                PintaCore.Workspace.Invalidate();

                PintaCore.History.PushNewItem(new SimpleHistoryItem(Stock.Paste, Catalog.GetString("Paste into new image"), old, PintaCore.Layers.CurrentLayerIndex));
            }
            else
            {
                ClipboardEmptyError();
            }
        }
示例#15
0
        private void HandlerPintaCoreActionsEditPasteActivated(object sender, EventArgs e)
        {
            Gtk.Clipboard cb = Gtk.Clipboard.Get(Gdk.Atom.Intern("CLIPBOARD", false));

            if (cb.WaitIsImageAvailable())
            {
                PintaCore.Layers.FinishSelection();

                Cairo.ImageSurface old = PintaCore.Layers.CurrentLayer.Surface.Clone();

                Gdk.Pixbuf image = cb.WaitForImage();

                Path p;

                using (Cairo.Context g = new Cairo.Context(PintaCore.Layers.CurrentLayer.Surface))
                {
                    g.DrawPixbuf(image, new Cairo.Point(0, 0));
                    p = g.CreateRectanglePath(new Rectangle(0, 0, image.Width, image.Height));
                }

                PintaCore.Layers.SelectionPath = p;
                PintaCore.Layers.ShowSelection = true;

                PintaCore.Workspace.Invalidate();

                PintaCore.History.PushNewItem(new SimpleHistoryItem(Stock.Paste, Catalog.GetString("Paste"), old, PintaCore.Layers.CurrentLayerIndex));
            }
            else
            {
                ClipboardEmptyError();
            }
        }
示例#16
0
 public static void DrawImage(this Cairo.Context s, Gtk.Widget widget, Gdk.Pixbuf image, double x, double y)
 {
     s.DrawPixbuf(image, x, y);
 }
示例#17
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);
        }
示例#18
0
        public void Draw(ImageSurface dst)
        {
            if (disposed)
                throw new ObjectDisposedException ("PlacedSurface");

            using (Cairo.Context g = new Cairo.Context (dst)) {
                g.Save ();

                Rectangle r = what.GetBounds ().ToCairoRectangle ();

                // We need to use the source operator to fully replace the old
                // data.  Or else we may paint transparent on top of it and
                // it will still be visible.  [Bug #670411]
                using (Path p = g.CreateRectanglePath (new Rectangle (where.X, where.Y, r.Width, r.Height))) {
                    g.AppendPath (p);
                    g.Clip ();
                    g.Operator = Operator.Source;
                    g.DrawPixbuf (what.ToPixbuf (), new Cairo.Point (where.X, where.Y));
                }

                g.Restore ();
            }
        }