public override void Redo () { // Store the layer for "undo" layer = PintaCore.Layers[layer_index]; PintaCore.Layers.DeleteLayer (layer_index, false); }
/// <summary> /// A history item for when shapes are finalized. /// </summary> /// <param name="passedEE">The EditEngine being used.</param> /// <param name="icon">The history item's icon.</param> /// <param name="text">The history item's title.</param> /// <param name="passedUserSurface">The stored UserLayer surface.</param> /// <param name="passedUserLayer">The UserLayer being modified.</param> /// <param name="passedSelectedPointIndex">The selected point's index.</param> /// <param name="passedSelectedShapeIndex">The selected point's shape index.</param> /// <param name="passedRedrawEverything">Whether every shape should be redrawn when undoing (e.g. finalization).</param> public ShapesHistoryItem(BaseEditEngine passedEE, string icon, string text, ImageSurface passedUserSurface, UserLayer passedUserLayer, int passedSelectedPointIndex, int passedSelectedShapeIndex, bool passedRedrawEverything) : base(icon, text) { ee = passedEE; userLayer = passedUserLayer; userSurfaceDiff = SurfaceDiff.Create(passedUserSurface, userLayer.Surface, true); if (userSurfaceDiff == null) { userSurface = passedUserSurface; } else { (passedUserSurface as IDisposable).Dispose(); } sEngines = BaseEditEngine.SEngines.PartialClone(); selectedPointIndex = passedSelectedPointIndex; selectedShapeIndex = passedSelectedShapeIndex; redrawEverything = passedRedrawEverything; }
/// <summary> /// A history item for when text is created, edited, and/or finalized. /// </summary> /// <param name="icon">The history item's icon.</param> /// <param name="text">The history item's title.</param> /// <param name="passedTextSurface">The stored TextLayer surface.</param> /// <param name="passedUserSurface">The stored UserLayer surface.</param> /// <param name="passedTextEngine">The text engine being used.</param> /// <param name="passedUserLayer">The UserLayer being modified.</param> public TextHistoryItem(string icon, string text, ImageSurface passedTextSurface, ImageSurface passedUserSurface, TextEngine passedTextEngine, UserLayer passedUserLayer) : base(icon, text) { userLayer = passedUserLayer; text_surface_diff = SurfaceDiff.Create(passedTextSurface, userLayer.TextLayer.Layer.Surface, true); if (text_surface_diff == null) { textSurface = passedTextSurface; } else { (passedTextSurface as IDisposable).Dispose(); } user_surface_diff = SurfaceDiff.Create(passedUserSurface, userLayer.Surface, true); if (user_surface_diff == null) { userSurface = passedUserSurface; } else { (passedUserSurface as IDisposable).Dispose(); } tEngine = passedTextEngine; textBounds = new Gdk.Rectangle(userLayer.textBounds.X, userLayer.textBounds.Y, userLayer.textBounds.Width, userLayer.textBounds.Height); }
/// <summary> /// Create a new RoundedLineEngine. /// </summary> /// <param name="parent_layer">The parent UserLayer for the re-editable DrawingLayer.</param> /// <param name="drawing_layer">An existing ReEditableLayer to reuse. This is for cloning only. If not cloning, pass in null.</param> /// <param name="passedRadius">The radius of the corners.</param> /// <param name="antialiasing">Whether or not antialiasing is enabled.</param> /// <param name="outline_color">The outline color for the shape.</param> /// <param name="fill_color">The fill color for the shape.</param> /// <param name="brush_width">The width of the outline of the shape.</param> public RoundedLineEngine(UserLayer parentLayer, ReEditableLayer passedDrawingLayer, double passedRadius, bool passedAA, Color passedOutlineColor, Color passedFillColor, int passedBrushWidth) : base(parentLayer, passedDrawingLayer, BaseEditEngine.ShapeTypes.RoundedLineSeries, passedAA, true, passedOutlineColor, passedFillColor, passedBrushWidth) { Radius = passedRadius; }
/// <summary> /// Create a new EllipseEngine. /// </summary> /// <param name="parent_layer">The parent UserLayer for the re-editable DrawingLayer.</param> /// <param name="drawing_layer">An existing ReEditableLayer to reuse. This is for cloning only. If not cloning, pass in null.</param> /// <param name="antialiasing">Whether or not antialiasing is enabled.</param> /// <param name="outline_color">The outline color for the shape.</param> /// <param name="fill_color">The fill color for the shape.</param> /// <param name="brush_width">The width of the outline of the shape.</param> public EllipseEngine (UserLayer parent_layer, ReEditableLayer drawing_layer, bool antialiasing, Color outline_color, Color fill_color, int brush_width) : base (parent_layer, drawing_layer, BaseEditEngine.ShapeTypes.Ellipse, antialiasing, true, outline_color, fill_color, brush_width) { }
public override void Undo () { PintaCore.Layers.Insert (layer, layer_index); // Make new layer the current layer PintaCore.Layers.SetCurrentLayer (layer); layer = null; }
public UserLayer CreateLayer(string name, int width, int height) { Cairo.ImageSurface surface = new Cairo.ImageSurface(Cairo.Format.ARGB32, width, height); UserLayer layer = new UserLayer(surface) { Name = name }; return(layer); }
// Adds a new layer above the current one public void Insert(UserLayer layer, int index) { UserLayers.Insert(index, layer); if (UserLayers.Count == 1) { current_layer = 0; } layer.PropertyChanged += RaiseLayerPropertyChangedEvent; PintaCore.Layers.OnLayerAdded(); }
private void HandlePintaCoreActionsLayersAddNewLayerActivated(object sender, EventArgs e) { Document doc = PintaCore.Workspace.ActiveDocument; PintaCore.Tools.Commit(); UserLayer l = doc.AddNewLayer(string.Empty); // Make new layer the current layer doc.SetCurrentUserLayer(l); AddLayerHistoryItem hist = new AddLayerHistoryItem("Menu.Layers.AddNewLayer.png", Catalog.GetString("Add New Layer"), doc.UserLayers.IndexOf(l)); doc.History.PushNewItem(hist); }
private void HandlePintaCoreActionsLayersDuplicateLayerActivated(object sender, EventArgs e) { Document doc = PintaCore.Workspace.ActiveDocument; PintaCore.Tools.Commit(); UserLayer l = doc.Layers.DuplicateCurrentLayer(); // Make new layer the current layer doc.Layers.SetCurrentUserLayer(l); AddLayerHistoryItem hist = new AddLayerHistoryItem(Resources.Icons.LayerDuplicate, Translations.GetString("Duplicate Layer"), doc.Layers.IndexOf(l)); doc.History.PushNewItem(hist); }
// Move current layer up public void MoveCurrentLayerUp() { if (current_layer == UserLayers.Count) { throw new InvalidOperationException("Cannot move layer up because current layer is the top layer."); } UserLayer layer = CurrentUserLayer; UserLayers.RemoveAt(current_layer); UserLayers.Insert(++current_layer, layer); PintaCore.Layers.OnSelectedLayerChanged(); Workspace.Invalidate(); }
// Move current layer down public void MoveCurrentLayerDown() { if (current_layer == 0) { throw new InvalidOperationException("Cannot move layer down because current layer is the bottom layer."); } UserLayer layer = CurrentUserLayer; UserLayers.RemoveAt(current_layer); UserLayers.Insert(--current_layer, layer); PintaCore.Layers.OnSelectedLayerChanged(); Workspace.Invalidate(); }
private void Swap() { int selected = PintaCore.Layers.CurrentLayerIndex; int l1 = Math.Min(layer_index_1, layer_index_2); int l2 = Math.Max(layer_index_1, layer_index_2); UserLayer layer1 = PintaCore.Layers[l1]; UserLayer layer2 = PintaCore.Layers[l2]; PintaCore.Layers.DeleteLayer(l1, false); PintaCore.Layers.DeleteLayer(l2 - 1, false); PintaCore.Layers.Insert(layer2, l1); PintaCore.Layers.Insert(layer1, l2); PintaCore.Layers.SetCurrentLayer(selected); }
private void HandlePintaCoreActionsLayersImportFromFileActivated(object sender, EventArgs e) { Document doc = PintaCore.Workspace.ActiveDocument; PintaCore.Tools.Commit(); var fcd = new Gtk.FileChooserDialog(Catalog.GetString("Open Image File"), PintaCore.Chrome.MainWindow, FileChooserAction.Open, Stock.Cancel, ResponseType.Cancel, Stock.Open, ResponseType.Ok); fcd.SetCurrentFolder(PintaCore.System.GetDialogDirectory()); fcd.AlternativeButtonOrder = new int[] { (int)ResponseType.Ok, (int)ResponseType.Cancel }; fcd.AddImagePreview(); int response = fcd.Run(); if (response == (int)Gtk.ResponseType.Ok) { string file = fcd.Filename; PintaCore.System.LastDialogDirectory = fcd.CurrentFolder; // Open the image and add it to the layers UserLayer layer = doc.AddNewLayer(System.IO.Path.GetFileName(file)); using (var fs = new FileStream(file, FileMode.Open)) using (Pixbuf bg = new Pixbuf(fs)) using (Cairo.Context g = new Cairo.Context(layer.Surface)) { CairoHelper.SetSourcePixbuf(g, bg, 0, 0); g.Paint(); } doc.SetCurrentUserLayer(layer); AddLayerHistoryItem hist = new AddLayerHistoryItem("Menu.Layers.ImportFromFile.png", Catalog.GetString("Import From File"), doc.UserLayers.IndexOf(layer)); doc.History.PushNewItem(hist); doc.Workspace.Invalidate(); } fcd.Destroy(); }
private void Swap() { var doc = PintaCore.Workspace.ActiveDocument; int selected = doc.Layers.CurrentUserLayerIndex; int l1 = Math.Min(layer_index_1, layer_index_2); int l2 = Math.Max(layer_index_1, layer_index_2); UserLayer layer1 = doc.Layers[l1]; UserLayer layer2 = doc.Layers[l2]; doc.Layers.DeleteLayer(l1, false); doc.Layers.DeleteLayer(l2 - 1, false); doc.Layers.Insert(layer2, l1); doc.Layers.Insert(layer1, l2); doc.Layers.SetCurrentUserLayer(selected); }
// Duplicate current layer public UserLayer DuplicateCurrentLayer() { UserLayer source = CurrentUserLayer; UserLayer layer = CreateLayer(string.Format("{0} {1}", source.Name, Catalog.GetString("copy"))); using (Cairo.Context g = new Cairo.Context(layer.Surface)) { g.SetSource(source.Surface); g.Paint(); } layer.Hidden = source.Hidden; layer.Opacity = source.Opacity; layer.Tiled = source.Tiled; UserLayers.Insert(++current_layer, layer); layer.PropertyChanged += RaiseLayerPropertyChangedEvent; PintaCore.Layers.OnLayerAdded(); return(layer); }
// Adds a new layer above the current one public void Insert(UserLayer layer, int index) { PintaCore.Workspace.ActiveDocument.Insert(layer, index); }
public int IndexOf(UserLayer layer) { return(PintaCore.Workspace.ActiveDocument.IndexOf(layer)); }
public void Import(string fileName, Gtk.Window parent) { ZipFile file = new ZipFile(fileName); XmlDocument stackXml = new XmlDocument(); stackXml.Load(file.GetInputStream(file.GetEntry("stack.xml"))); XmlElement imageElement = stackXml.DocumentElement; int width = int.Parse(imageElement.GetAttribute("w")); int height = int.Parse(imageElement.GetAttribute("h")); Size imagesize = new Size(width, height); Document doc = PintaCore.Workspace.CreateAndActivateDocument(fileName, imagesize); doc.HasFile = true; XmlElement stackElement = (XmlElement)stackXml.GetElementsByTagName("stack")[0]; XmlNodeList layerElements = stackElement.GetElementsByTagName("layer"); if (layerElements.Count == 0) { throw new XmlException("No layers found in OpenRaster file"); } doc.ImageSize = imagesize; doc.Workspace.CanvasSize = imagesize; for (int i = 0; i < layerElements.Count; i++) { XmlElement layerElement = (XmlElement)layerElements[i]; int x = int.Parse(GetAttribute(layerElement, "x", "0")); int y = int.Parse(GetAttribute(layerElement, "y", "0")); string name = GetAttribute(layerElement, "name", string.Format("Layer {0}", i)); try { // Write the file to a temporary file first // Fixes a bug when running on .Net ZipEntry zf = file.GetEntry(layerElement.GetAttribute("src")); Stream s = file.GetInputStream(zf); string tmp_file = System.IO.Path.GetTempFileName(); using (Stream stream_out = File.Open(tmp_file, FileMode.OpenOrCreate)) { byte[] buffer = new byte[2048]; while (true) { int len = s.Read(buffer, 0, buffer.Length); if (len > 0) { stream_out.Write(buffer, 0, len); } else { break; } } } UserLayer layer = doc.CreateLayer(name); doc.Insert(layer, 0); layer.Opacity = double.Parse(GetAttribute(layerElement, "opacity", "1"), GetFormat()); layer.BlendMode = StandardToBlendMode(GetAttribute(layerElement, "composite-op", "svg:src-over")); using (var fs = new FileStream(tmp_file, FileMode.Open)) using (Pixbuf pb = new Pixbuf(fs)) { using (Context g = new Context(layer.Surface)) { CairoHelper.SetSourcePixbuf(g, pb, x, y); g.Paint(); } } try { File.Delete(tmp_file); } catch { } } catch { MessageDialog md = new MessageDialog(parent, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, "Could not import layer \"{0}\" from {0}", name, file); md.Title = "Error"; md.Run(); md.Destroy(); } } file.Close(); }
public void SetCurrentLayer(UserLayer layer) { PintaCore.Workspace.ActiveDocument.SetCurrentUserLayer(layer); }
public void SetCurrentLayer(UserLayer layer) { PintaCore.Workspace.ActiveDocument.SetCurrentUserLayer (layer); }
/// <summary> /// Creates a new ReEditableLayer for drawing and editing on separately from the rest of the image. /// </summary> /// <param name="passedParent">The parent UserLayer that the ReEditableLayer will be associated with.</param> public ReEditableLayer(UserLayer passedParent) { parent = passedParent; TryAddLayer(); }
public int IndexOf(UserLayer layer) { return(UserLayers.IndexOf(layer)); }
private void SetLayerVisibility(UserLayer layer, bool visibility) { if (layer != null) layer.Hidden = !visibility; var initial = new LayerProperties(layer.Name, visibility, layer.Opacity, layer.BlendMode); var updated = new LayerProperties(layer.Name, !visibility, layer.Opacity, layer.BlendMode); var historyItem = new UpdateLayerPropertiesHistoryItem ( "Menu.Layers.LayerProperties.png", (visibility) ? Catalog.GetString ("Layer Shown") : Catalog.GetString ("Layer Hidden"), PintaCore.Layers.IndexOf (layer), initial, updated); PintaCore.History.PushNewItem (historyItem); //TODO Call this automatically when the layer visibility changes. PintaCore.Workspace.Invalidate (); }
/// <summary> /// A history item for when text is created, edited, and/or finalized. /// </summary> /// <param name="icon">The history item's icon.</param> /// <param name="text">The history item's title.</param> /// <param name="passedTextSurface">The stored TextLayer surface.</param> /// <param name="passedUserSurface">The stored UserLayer surface.</param> /// <param name="passedUserLayer">The UserLayer being modified.</param> public TextHistoryItem(string icon, string text, ImageSurface passedTextSurface, ImageSurface passedUserSurface, TextEngine passedTextEngine, UserLayer passedUserLayer) : base(icon, text) { userLayer = passedUserLayer; text_surface_diff = SurfaceDiff.Create(passedTextSurface, userLayer.TextLayer.Surface, true); if (text_surface_diff == null) { textSurface = passedTextSurface; } else { (passedTextSurface as IDisposable).Dispose(); } user_surface_diff = SurfaceDiff.Create(passedUserSurface, userLayer.Surface, true); if (user_surface_diff == null) { userSurface = passedUserSurface; } else { (passedUserSurface as IDisposable).Dispose(); } tEngine = passedTextEngine; textBounds = new Gdk.Rectangle(userLayer.textBounds.X, userLayer.textBounds.Y, userLayer.textBounds.Width, userLayer.textBounds.Height); }
public UserLayer CreateLayer(string name, int width, int height) { Cairo.ImageSurface surface = new Cairo.ImageSurface (Cairo.Format.ARGB32, width, height); UserLayer layer = new UserLayer(surface) { Name = name }; return layer; }
public int IndexOf(UserLayer layer) { return PintaCore.Workspace.ActiveDocument.IndexOf (layer); }
public void SetCurrentUserLayer(UserLayer layer) { SetCurrentUserLayer(UserLayers.IndexOf(layer)); }
/// <summary> /// Create a new LineCurveSeriesEngine. /// </summary> /// <param name="parent_layer">The parent UserLayer for the re-editable DrawingLayer.</param> /// <param name="drawing_layer">An existing ReEditableLayer to reuse. This is for cloning only. If not cloning, pass in null.</param> /// <param name="shape_type">The owner EditEngine.</param> /// <param name="antialiasing">Whether or not antialiasing is enabled.</param> /// <param name="closed">Whether or not the shape is closed (first and last points are connected).</param> /// <param name="outline_color">The outline color for the shape.</param> /// <param name="fill_color">The fill color for the shape.</param> /// <param name="brush_width">The width of the outline of the shape.</param> public LineCurveSeriesEngine(UserLayer parentLayer, ReEditableLayer passedDrawingLayer, BaseEditEngine.ShapeTypes passedShapeType, bool passedAA, bool passedClosed, Color passedOutlineColor, Color passedFillColor, int passedBrushWidth) : base(parentLayer, passedDrawingLayer, passedShapeType, passedAA, passedClosed, passedOutlineColor, passedFillColor, passedBrushWidth) { }
public void TakeSnapshotOfLayer(UserLayer layer) { layer_index = PintaCore.Layers.IndexOf(layer); old_surface = layer.Surface.Clone(); }
public DeleteLayerHistoryItem(string icon, string text, UserLayer layer, int layerIndex) : base(icon, text) { layer_index = layerIndex; this.layer = layer; }
public void TakeSnapshotOfLayer(UserLayer layer) { layer_index = PintaCore.Layers.IndexOf (layer); old_surface = layer.Surface.Clone (); }
/// <summary> /// Creates a new ReEditableLayer for drawing and editing on separately from the rest of the image. /// </summary> /// <param name="passedParent">The parent UserLayer that the ReEditableLayer will be associated with.</param> public ReEditableLayer(UserLayer passedParent) { parent = passedParent; TryAddLayer(); }
private void HandlePintaCoreActionsLayersImportFromFileActivated(object sender, EventArgs e) { Document doc = PintaCore.Workspace.ActiveDocument; PintaCore.Tools.Commit(); using var fcd = new FileChooserNative( Translations.GetString("Open Image File"), PintaCore.Chrome.MainWindow, FileChooserAction.Open, Translations.GetString("Open"), Translations.GetString("Cancel")); fcd.SetCurrentFolder(PintaCore.System.GetDialogDirectory()); // Add image files filter var ff = new FileFilter(); foreach (var format in PintaCore.System.ImageFormats.Formats) { if (!format.IsWriteOnly()) { foreach (var ext in format.Extensions) { ff.AddPattern(string.Format("*.{0}", ext)); } } } ff.Name = Translations.GetString("Image files"); fcd.AddFilter(ff); var response = (ResponseType)fcd.Run(); if (response == ResponseType.Accept) { string file = fcd.Filename; string?directory = Path.GetDirectoryName(file); if (directory is not null) { PintaCore.System.LastDialogDirectory = directory; } // Open the image and add it to the layers UserLayer layer = doc.Layers.AddNewLayer(System.IO.Path.GetFileName(file)); using (var fs = new FileStream(file, FileMode.Open)) using (var bg = new Pixbuf(fs)) using (var g = new Cairo.Context(layer.Surface)) { Gdk.CairoHelper.SetSourcePixbuf(g, bg, 0, 0); g.Paint(); } doc.Layers.SetCurrentUserLayer(layer); AddLayerHistoryItem hist = new AddLayerHistoryItem(Resources.Icons.LayerImport, Translations.GetString("Import From File"), doc.Layers.IndexOf(layer)); doc.History.PushNewItem(hist); doc.Workspace.Invalidate(); } }
// Adds a new layer above the current one public void Insert(UserLayer layer, int index) { PintaCore.Workspace.ActiveDocument.Insert (layer, index); }
// Adds a new layer above the current one public void Insert(UserLayer layer, int index) { UserLayers.Insert (index, layer); if (UserLayers.Count == 1) current_layer = 0; layer.PropertyChanged += RaiseLayerPropertyChangedEvent; PintaCore.Layers.OnLayerAdded (); }
public void SetCurrentUserLayer(UserLayer layer) { SetCurrentUserLayer (UserLayers.IndexOf (layer)); }
public int IndexOf(UserLayer layer) { return UserLayers.IndexOf (layer); }
public ReEditableLayer(UserLayer passedParent) { parent = passedParent; }
/// <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 DeleteLayerHistoryItem(string icon, string text, UserLayer layer, int layerIndex) : base(icon, text) { layer_index = layerIndex; this.layer = layer; }