Example #1
0
        // Flatten image
        public void FlattenImage()
        {
            if (UserLayers.Count < 2)
            {
                throw new InvalidOperationException("Cannot flatten image because there is only one layer.");
            }

            // Find the "bottom" layer
            var bottom_layer = UserLayers[0];
            var old_surf     = bottom_layer.Surface;

            // Replace the bottom surface with the flattened image,
            // and dispose the old surface
            bottom_layer.Surface = GetFlattenedImage();
            (old_surf as IDisposable).Dispose();

            // Reset our layer pointer to the only remaining layer
            current_layer = 0;

            // Delete all other layers
            while (UserLayers.Count > 1)
            {
                UserLayers.RemoveAt(1);
            }

            PintaCore.Layers.OnLayerRemoved();
            Workspace.Invalidate();
        }
Example #2
0
        // Clean up any native resources we had
        public void Close()
        {
            // Dispose all of our layers
            while (UserLayers.Count > 0)
            {
                Layer l = UserLayers[UserLayers.Count - 1];
                UserLayers.RemoveAt(UserLayers.Count - 1);
                (l.Surface as IDisposable).Dispose();
            }

            current_layer = -1;

            if (tool_layer != null)
            {
                (tool_layer.Surface as IDisposable).Dispose();
            }

            if (selection_layer != null)
            {
                (selection_layer.Surface as IDisposable).Dispose();
            }

            Selection.DisposeSelection();

            Workspace.History.Clear();
        }
Example #3
0
        // Adds a new layer above the current one
        public UserLayer AddNewLayer(string name)
        {
            UserLayer layer;

            if (string.IsNullOrEmpty(name))
            {
                layer = CreateLayer();
            }
            else
            {
                layer = CreateLayer(name);
            }

            UserLayers.Insert(current_layer + 1, layer);

            if (UserLayers.Count == 1)
            {
                current_layer = 0;
            }

            layer.PropertyChanged += RaiseLayerPropertyChangedEvent;

            PintaCore.Layers.OnLayerAdded();
            return(layer);
        }
Example #4
0
        public async Task <IActionResult> PostUserLayers(string osmUserId, [FromBody] UserLayers userLayers)
        {
            if (string.IsNullOrWhiteSpace(osmUserId) || osmUserId != User.Identity.Name)
            {
                return(Unauthorized());
            }
            await _repository.UpdateUserLayers(User.Identity.Name, userLayers);

            return(Ok(userLayers));
        }
Example #5
0
        public void Clear()
        {
            while (UserLayers.Count > 0)
            {
                Layer l = UserLayers[UserLayers.Count - 1];
                UserLayers.RemoveAt(UserLayers.Count - 1);
                (l.Surface as IDisposable).Dispose();
            }

            current_layer = -1;
            PintaCore.Layers.OnLayerRemoved();
        }
Example #6
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();
        }
Example #7
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();
        }
Example #8
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();
        }
Example #9
0
        // Delete the current layer
        public void DeleteCurrentLayer()
        {
            Layer layer = CurrentUserLayer;

            UserLayers.RemoveAt(current_layer);

            // Only change this if this wasn't already the bottom layer
            if (current_layer > 0)
            {
                current_layer--;
            }

            layer.PropertyChanged -= RaiseLayerPropertyChangedEvent;

            PintaCore.Layers.OnLayerRemoved();
        }
Example #10
0
        public async Task UpdateUserLayers(string osmUserId, UserLayers newUserLayers)
        {
            var oldUserLayers = await GetUserLayers(osmUserId);

            if (oldUserLayers != null)
            {
                _dbContext.UsersLayers.Remove(oldUserLayers);
            }
            newUserLayers.Id        = 0;
            newUserLayers.OsmUserId = osmUserId;
            foreach (var newUserLayer in newUserLayers.Layers)
            {
                newUserLayer.Id      = 0;
                newUserLayer.Address = newUserLayer.Address.Trim();
                newUserLayer.Key     = newUserLayer.Key.Trim();
            }
            _dbContext.UsersLayers.Add(newUserLayers);
            await _dbContext.SaveChangesAsync().ConfigureAwait(false);
        }
Example #11
0
        public void GetLayers_ShouldGetThem()
        {
            var userLayers = new UserLayers {
                Layers = new List <UserLayerData> {
                    new UserLayerData()
                }
            };
            var osmUser = "******";

            _controller.SetupIdentity(osmUser);
            _israelHikingRepository.GetUserLayers(osmUser).Returns(userLayers);

            var result = _controller.GetUserLayers().Result as OkObjectResult;

            Assert.IsNotNull(result);
            var returnedUserLayers = result.Value as UserLayers;

            Assert.IsNotNull(returnedUserLayers);
            Assert.AreEqual(returnedUserLayers.Layers.Count, userLayers.Layers.Count);
        }
Example #12
0
        // Delete the layer
        public void DeleteLayer(int index, bool dispose)
        {
            Layer layer = UserLayers[index];

            UserLayers.RemoveAt(index);

            if (dispose)
            {
                (layer.Surface as IDisposable).Dispose();
            }

            // Only change this if this wasn't already the bottom layer
            if (current_layer > 0)
            {
                current_layer--;
            }

            layer.PropertyChanged -= RaiseLayerPropertyChangedEvent;

            PintaCore.Layers.OnLayerRemoved();
        }
Example #13
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);
        }
Example #14
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);
        }
Example #15
0
 public void SetCurrentUserLayer(UserLayer layer)
 {
     SetCurrentUserLayer(UserLayers.IndexOf(layer));
 }
Example #16
0
 public int IndexOf(UserLayer layer)
 {
     return(UserLayers.IndexOf(layer));
 }