private void HandlePintaCoreActionsLayersMergeLayerDownActivated(object sender, EventArgs e) { Document doc = PintaCore.Workspace.ActiveDocument; PintaCore.Tools.Commit(); CompoundHistoryItem hist = new CompoundHistoryItem("Menu.Layers.MergeLayerDown.png", Catalog.GetString("Merge Layer Down")); DeleteLayerHistoryItem h1 = new DeleteLayerHistoryItem(string.Empty, string.Empty, doc.CurrentLayer, doc.CurrentLayerIndex); SimpleHistoryItem h2 = new SimpleHistoryItem(string.Empty, string.Empty, doc.Layers[doc.CurrentLayerIndex - 1].Surface.Clone(), doc.CurrentLayerIndex - 1); hist.Push(h1); hist.Push(h2); doc.MergeCurrentLayerDown(); doc.History.PushNewItem(hist); }
private void HandlePintaCoreActionsImageFlattenActivated (object sender, EventArgs e) { Document doc = PintaCore.Workspace.ActiveDocument; PintaCore.Tools.Commit (); var oldBottomSurface = doc.UserLayers[0].Surface.Clone (); CompoundHistoryItem hist = new CompoundHistoryItem ("Menu.Image.Flatten.png", Catalog.GetString ("Flatten")); for (int i = doc.UserLayers.Count - 1; i >= 1; i--) hist.Push (new DeleteLayerHistoryItem (string.Empty, string.Empty, doc.UserLayers[i], i)); doc.FlattenImage (); hist.Push (new SimpleHistoryItem (string.Empty, string.Empty, oldBottomSurface, 0)); doc.History.PushNewItem (hist); }
/// <summary> /// Resizes the canvas. /// </summary> /// <param name='compoundAction'> /// Optionally, the history item for resizing the canvas can be added to /// a CompoundHistoryItem if it is part of a larger action (e.g. pasting an image). /// </param> public void ResizeCanvas(int width, int height, Anchor anchor, CompoundHistoryItem compoundAction) { double scale; if (ImageSize.Width == width && ImageSize.Height == height) { return; } PintaCore.Tools.Commit(); ResizeHistoryItem hist = new ResizeHistoryItem(ImageSize); hist.Icon = "Menu.Image.CanvasSize.png"; hist.Text = Catalog.GetString("Resize Canvas"); hist.StartSnapshotOfImage(); scale = Workspace.Scale; ImageSize = new Gdk.Size(width, height); foreach (var layer in UserLayers) { layer.ResizeCanvas(width, height, anchor); } hist.FinishSnapshotOfImage(); if (compoundAction != null) { compoundAction.Push(hist); } else { Workspace.History.PushNewItem(hist); } ResetSelectionPath(); Workspace.Scale = scale; }
private void HandlePintaCoreActionsLayersMergeLayerDownActivated(object sender, EventArgs e) { Document doc = PintaCore.Workspace.ActiveDocument; PintaCore.Tools.Commit(); int bottomLayerIndex = doc.Layers.CurrentUserLayerIndex - 1; var oldBottomSurface = doc.Layers.UserLayers[bottomLayerIndex].Surface.Clone(); CompoundHistoryItem hist = new CompoundHistoryItem(Resources.Icons.LayerMergeDown, Translations.GetString("Merge Layer Down")); DeleteLayerHistoryItem h1 = new DeleteLayerHistoryItem(string.Empty, string.Empty, doc.Layers.CurrentUserLayer, doc.Layers.CurrentUserLayerIndex); doc.Layers.MergeCurrentLayerDown(); SimpleHistoryItem h2 = new SimpleHistoryItem(string.Empty, string.Empty, oldBottomSurface, bottomLayerIndex); hist.Push(h1); hist.Push(h2); doc.History.PushNewItem(hist); }
private void HandlePintaCoreActionsImageFlattenActivated(object sender, EventArgs e) { Document doc = PintaCore.Workspace.ActiveDocument; PintaCore.Tools.Commit (); var oldBottomSurface = doc.UserLayers[0].Surface.Clone (); CompoundHistoryItem hist = new CompoundHistoryItem ("Menu.Image.Flatten.png", Catalog.GetString ("Flatten")); for (int i = doc.UserLayers.Count - 1; i >= 1; i--) hist.Push (new DeleteLayerHistoryItem (string.Empty, string.Empty, doc.UserLayers[i], i)); doc.FlattenImage (); hist.Push (new SimpleHistoryItem (string.Empty, string.Empty, oldBottomSurface, 0)); doc.History.PushNewItem (hist); }
/// <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); }
public void ResizeCanvas(int width, int height, Anchor anchor, CompoundHistoryItem compoundAction) { ActiveDocument.ResizeCanvas(width, height, anchor, compoundAction); }
private void HandlePintaCoreActionsImageFlattenActivated(object sender, EventArgs e) { PintaCore.Layers.FinishSelection (); CompoundHistoryItem hist = new CompoundHistoryItem ("Menu.Image.Flatten.png", Catalog.GetString ("Flatten")); SimpleHistoryItem h1 = new SimpleHistoryItem (string.Empty, string.Empty, PintaCore.Layers[0].Surface.Clone (), 0); hist.Push (h1); for (int i = 1; i < PintaCore.Layers.Count; i++) hist.Push (new DeleteLayerHistoryItem (string.Empty, string.Empty, PintaCore.Layers[i], i)); PintaCore.Layers.FlattenImage (); PintaCore.History.PushNewItem (hist); }
public void ResizeCanvas(int width, int height, Anchor anchor, CompoundHistoryItem compoundAction) { ActiveDocument.ResizeCanvas (width, height, anchor, compoundAction); }
protected void OnKeyPress(DrawingArea canvas, KeyPressEventArgs args) { switch (args.Event.Key) { case Gdk.Key.KP_Enter: case Gdk.Key.Return: if (tracking) { args.RetVal = true; } break; case Gdk.Key.Escape: if (tracking) { args.RetVal = true; } else { if (mode == EditingMode.Editing) { SaveHistoryMemento (); } else if (mode == EditingMode.EmptyEdit) { RedrawText (false); } if (mode != EditingMode.NotEditing) { args.RetVal = true; StopEditing (); } } break; } bool handled = false; if (args.RetVal != null && args.RetVal is bool) handled = (bool)args.RetVal; if (!handled && mode != EditingMode.NotEditing && !tracking) { args.RetVal = true; if (mode == EditingMode.EmptyEdit) { mode = EditingMode.Editing; CompoundHistoryItem cha = new CompoundHistoryItem (Icon, Name); this.currentHA = cha; PintaCore.History.PushNewItem (cha); } if ((args.Event.State & ModifierType.ControlMask) == 0 && args.Event.Key != Gdk.Key.Control_L && args.Event.Key != Gdk.Key.Control_R) { char ch = (char)args.Event.Key; InsertCharIntoString (ch); textPos++; RedrawText (true); } } //base.OnKeyPress (args.Event.Key, args.Event.State); }
private void SaveHistoryMemento() { pulseEnabled = false; RedrawText (false); if (saved != null) { Region hitTest = Region.Rectangle (PintaCore.Layers.SelectionPath.GetBounds ()); hitTest.Intersect (saved.Region); if (hitTest.Clipbox.Width != 0 && hitTest.Clipbox.Height != 0) { ClippedSurfaceHistoryItem bha = new ClippedSurfaceHistoryItem (Icon, Name, saved, PintaCore.Layers.CurrentLayerIndex); if (this.currentHA == null) { PintaCore.History.PushNewItem (bha); } else { this.currentHA.Push (bha); this.currentHA = null; } } hitTest.Dispose (); saved.Dispose (); saved = null; } }
private void HandlePintaCoreActionsLayersMergeLayerDownActivated(object sender, EventArgs e) { Document doc = PintaCore.Workspace.ActiveDocument; PintaCore.Tools.Commit (); CompoundHistoryItem hist = new CompoundHistoryItem ("Menu.Layers.MergeLayerDown.png", Catalog.GetString ("Merge Layer Down")); DeleteLayerHistoryItem h1 = new DeleteLayerHistoryItem (string.Empty, string.Empty, doc.CurrentLayer, doc.CurrentLayerIndex); SimpleHistoryItem h2 = new SimpleHistoryItem (string.Empty, string.Empty, doc.Layers[doc.CurrentLayerIndex - 1].Surface.Clone (), doc.CurrentLayerIndex - 1); hist.Push (h1); hist.Push (h2); doc.MergeCurrentLayerDown (); doc.History.PushNewItem (hist); }
/// <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); }
/// <summary> /// Resizes the canvas. /// </summary> /// <param name="width">The new width of the canvas.</param> /// <param name="height">The new height of the canvas.</param> /// <param name="anchor">Direction in which to adjust the canvas</param> /// <param name='compoundAction'> /// Optionally, the history item for resizing the canvas can be added to /// a CompoundHistoryItem if it is part of a larger action (e.g. pasting an image). /// </param> public void ResizeCanvas (int width, int height, Anchor anchor, CompoundHistoryItem compoundAction) { double scale; if (ImageSize.Width == width && ImageSize.Height == height) return; PintaCore.Tools.Commit (); ResizeHistoryItem hist = new ResizeHistoryItem (ImageSize); hist.Icon = "Menu.Image.CanvasSize.png"; hist.Text = Catalog.GetString ("Resize Canvas"); hist.StartSnapshotOfImage (); scale = Workspace.Scale; ImageSize = new Gdk.Size (width, height); foreach (var layer in UserLayers) layer.ResizeCanvas (width, height, anchor); hist.FinishSnapshotOfImage (); if (compoundAction != null) { compoundAction.Push (hist); } else { Workspace.History.PushNewItem (hist); } ResetSelectionPaths (); Workspace.Scale = scale; }
private void HandlePintaCoreActionsLayersMergeLayerDownActivated(object sender, EventArgs e) { PintaCore.Layers.FinishSelection (); CompoundHistoryItem hist = new CompoundHistoryItem ("Menu.Layers.MergeLayerDown.png", Mono.Unix.Catalog.GetString ("Merge Layer Down")); DeleteLayerHistoryItem h1 = new DeleteLayerHistoryItem (string.Empty, string.Empty, PintaCore.Layers.CurrentLayer, PintaCore.Layers.CurrentLayerIndex); SimpleHistoryItem h2 = new SimpleHistoryItem (string.Empty, string.Empty, PintaCore.Layers[PintaCore.Layers.CurrentLayerIndex - 1].Surface.Clone (), PintaCore.Layers.CurrentLayerIndex - 1); hist.Push (h1); hist.Push (h2); PintaCore.Layers.MergeCurrentLayerDown (); PintaCore.History.PushNewItem (hist); }
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); }