Ejemplo n.º 1
0
		public override void Redo ()
		{
			// Store the layer for "undo"
			layer = PintaCore.Layers[layer_index];
			
			PintaCore.Layers.DeleteLayer (layer_index, false);
		}
Ejemplo n.º 2
0
		/// <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;
		}
Ejemplo n.º 3
0
		/// <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);
		}
Ejemplo n.º 4
0
        /// <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;
        }
Ejemplo n.º 5
0
		/// <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)
		{
			
		}
Ejemplo n.º 6
0
		public override void Undo ()
		{
			PintaCore.Layers.Insert (layer, layer_index);

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

			layer = null;
		}
Ejemplo n.º 7
0
        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);
        }
Ejemplo n.º 8
0
        // 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();
        }
Ejemplo n.º 9
0
        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);
        }
Ejemplo n.º 10
0
        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);
        }
Ejemplo n.º 11
0
        // 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();
        }
Ejemplo n.º 12
0
        // 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();
        }
Ejemplo n.º 13
0
        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);
        }
Ejemplo n.º 14
0
        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();
        }
Ejemplo n.º 15
0
        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);
        }
Ejemplo n.º 16
0
        // 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);
        }
Ejemplo n.º 17
0
 // Adds a new layer above the current one
 public void Insert(UserLayer layer, int index)
 {
     PintaCore.Workspace.ActiveDocument.Insert(layer, index);
 }
Ejemplo n.º 18
0
 public int IndexOf(UserLayer layer)
 {
     return(PintaCore.Workspace.ActiveDocument.IndexOf(layer));
 }
Ejemplo n.º 19
0
        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();
        }
Ejemplo n.º 20
0
 public void SetCurrentLayer(UserLayer layer)
 {
     PintaCore.Workspace.ActiveDocument.SetCurrentUserLayer(layer);
 }
Ejemplo n.º 21
0
 public void SetCurrentLayer(UserLayer layer)
 {
     PintaCore.Workspace.ActiveDocument.SetCurrentUserLayer (layer);
 }
Ejemplo n.º 22
0
		/// <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();
		}
Ejemplo n.º 23
0
 public int IndexOf(UserLayer layer)
 {
     return(UserLayers.IndexOf(layer));
 }
Ejemplo n.º 24
0
        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 ();
        }
Ejemplo n.º 25
0
        /// <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);
        }
Ejemplo n.º 26
0
		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;
		}
Ejemplo n.º 27
0
 public int IndexOf(UserLayer layer)
 {
     return PintaCore.Workspace.ActiveDocument.IndexOf (layer);
 }
Ejemplo n.º 28
0
 public void SetCurrentUserLayer(UserLayer layer)
 {
     SetCurrentUserLayer(UserLayers.IndexOf(layer));
 }
Ejemplo n.º 29
0
		/// <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)
		{
			
		}
Ejemplo n.º 30
0
 public void TakeSnapshotOfLayer(UserLayer layer)
 {
     layer_index = PintaCore.Layers.IndexOf(layer);
     old_surface = layer.Surface.Clone();
 }
Ejemplo n.º 31
0
		public DeleteLayerHistoryItem(string icon, string text, UserLayer layer, int layerIndex) : base(icon, text)
		{
			layer_index = layerIndex;
			this.layer = layer;
		}
Ejemplo n.º 32
0
		public void TakeSnapshotOfLayer(UserLayer layer)
		{
			layer_index = PintaCore.Layers.IndexOf (layer);
			old_surface = layer.Surface.Clone ();
		}
Ejemplo n.º 33
0
        /// <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();
        }
Ejemplo n.º 34
0
        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();
            }
        }
Ejemplo n.º 35
0
 // Adds a new layer above the current one
 public void Insert(UserLayer layer, int index)
 {
     PintaCore.Workspace.ActiveDocument.Insert (layer, index);
 }
Ejemplo n.º 36
0
		// 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 ();
		}
Ejemplo n.º 37
0
		public void SetCurrentUserLayer(UserLayer layer)
		{
			SetCurrentUserLayer (UserLayers.IndexOf (layer));
		}
Ejemplo n.º 38
0
		public int IndexOf(UserLayer layer)
		{
			return UserLayers.IndexOf (layer);
		}
Ejemplo n.º 39
0
 public ReEditableLayer(UserLayer passedParent)
 {
     parent = passedParent;
 }
Ejemplo n.º 40
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);
        }
Ejemplo n.º 41
0
 public DeleteLayerHistoryItem(string icon, string text, UserLayer layer, int layerIndex) : base(icon, text)
 {
     layer_index = layerIndex;
     this.layer  = layer;
 }