AddNewLayer() public method

public AddNewLayer ( string name ) : Pinta.Core.UserLayer
name string
return Pinta.Core.UserLayer
Example #1
0
        public void Import(string fileName, Gtk.Window parent)
        {
            Pixbuf bg;

            // Handle any EXIF orientation flags
            using (var fs = new FileStream(fileName, FileMode.Open, FileAccess.Read))
                bg = new Pixbuf(fs);

            bg = bg.ApplyEmbeddedOrientation();

            Size imagesize = new Size(bg.Width, bg.Height);

            Document doc = PintaCore.Workspace.CreateAndActivateDocument(fileName, imagesize);

            doc.HasFile              = true;
            doc.ImageSize            = imagesize;
            doc.Workspace.CanvasSize = imagesize;

            Layer layer = doc.AddNewLayer(Path.GetFileName(fileName));

            using (Cairo.Context g = new Cairo.Context(layer.Surface)) {
                CairoHelper.SetSourcePixbuf(g, bg, 0, 0);
                g.Paint();
            }

            bg.Dispose();
        }
Example #2
0
        public Document NewDocument(Gdk.Size imageSize, Color backgroundColor)
        {
            Document doc = CreateAndActivateDocument(null, imageSize);

            doc.Workspace.CanvasSize = imageSize;

            // Start with an empty white layer
            Layer background = doc.AddNewLayer(Catalog.GetString("Background"));

            if (backgroundColor.A != 0)
            {
                using (Cairo.Context g = new Cairo.Context(background.Surface)) {
                    g.SetSourceColor(backgroundColor);
                    g.Paint();
                }
            }

            doc.Workspace.History.PushNewItem(new BaseHistoryItem(Stock.New, Catalog.GetString("New Image")));
            doc.Workspace.History.SetClean();

            // This ensures these are called after the window is done being created and sized.
            // Without it, we sometimes try to zoom when the window has a size of (0, 0).
            Gtk.Application.Invoke(delegate {
                PintaCore.Actions.View.ActualSize.Activate();
            });

            return(doc);
        }
Example #3
0
        private void HandlePintaCoreActionsLayersAddNewLayerActivated(object sender, EventArgs e)
        {
            Document doc = PintaCore.Workspace.ActiveDocument;

            PintaCore.Tools.Commit();

            Layer l = doc.AddNewLayer(string.Empty);

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

            AddLayerHistoryItem hist = new AddLayerHistoryItem("Menu.Layers.AddNewLayer.png", Catalog.GetString("Add New Layer"), doc.Layers.IndexOf(l));

            doc.History.PushNewItem(hist);
        }
Example #4
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
                Layer 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.SetCurrentLayer(layer);

                AddLayerHistoryItem hist = new AddLayerHistoryItem("Menu.Layers.ImportFromFile.png", Catalog.GetString("Import From File"), doc.Layers.IndexOf(layer));
                doc.History.PushNewItem(hist);

                doc.Workspace.Invalidate();
            }

            fcd.Destroy();
        }
Example #5
0
        public Document NewDocument(Gdk.Size imageSize, Color backgroundColor)
        {
            Document doc = CreateAndActivateDocument(null, imageSize);

            doc.Workspace.CanvasSize = imageSize;

            // Start with an empty white layer
            Layer background = doc.AddNewLayer(Catalog.GetString("Background"));

            if (backgroundColor.A != 0)
            {
                using (Cairo.Context g = new Cairo.Context(background.Surface)) {
                    g.SetSourceColor(backgroundColor);
                    g.Paint();
                }
            }

            doc.Workspace.History.PushNewItem(new BaseHistoryItem(Stock.New, Catalog.GetString("New Image")));
            doc.IsDirty = false;

            PintaCore.Actions.View.ZoomToWindow.Activate();

            return(doc);
        }