Configure location of imported layer / clipboard image

The feature would be useful for online teaching (see discussion).

When adding an image as a new layer (Ctrl+Alt+O), it will appear at the top left corner of the current layer. It can take some time to move this image to the bottom of the “blackboard” and then to merge layers.

  1. I’d like to paste an image from clipboard as a part of the existing layer (e.g., Ctrl+Shift+V). Specifically, I’d like it to appear at the top right corner of the current screen (another good option is “under the pointer”).

  2. If that’s not possible or this feature doesn’t look like one to be implemented, I’d like to be able to adjust the behavior of “Import Layers…” (Ctrl+Alt+O). For example, user can choose where to place the imported layer — top/bottom/middle & left/right/center of the existing layer or current screen.

I think this sounds very reasonable, and a good quality of life feature.

None of what you propose is particularly difficult to implement (changing the position of the pasted image to the position of the mouse pointer is a 1-line change) so it’s mostly a question of making things configurable so that:

  1. The old behaviour can be retained for those who want it.
  2. The new behaviour can be configured to be reasonably flexible (e.g. which corner/point of the pasted image should align with the reference corner/point).

Since the settings for this will involve a fair number of new strings, the full implementation might not make it for v2.1.0, but I will implement at least the paste-under-cursor part so that it’s part of the release. You would then activate the setting manually in the settings file.

If you are fine with just the paste-at-cursor functionality for the time being, you can edit /usr/lib/mypaint/gui/ (you need root access to do this) and change the line:

x, y, w, h = self.model.get_bbox()


x, y = map(int, self.tdw.display_to_model(*self.get_last_event_info(self.tdw)[1:]))

(with the same indentation)

1 Like

Thank you, it works, now Ctrl+V pastes an image under the cursor. Unfortunately, it still removes the existing layer. I’d like the image to be added to the existing layer (I repeat it just in case I was not clear). Anyway, thank you for your reply, I’m looking forward to have this feature in MyPaint!

IMO, the clipboard data should always be added to a new, seaparate layer, not directly to the current one. You otherwise lose a lot of flexibility that way (e.g. wanting to move it more precicely or changing opacity). After that you can easily merge the layer down with the shortcut if you want to. That is the standard in basically any image editor I know including Photoshop and Krita.

Also: What is the “Cursor position” if i paste clipboard data via the menu bar item? Should that always resort to the previous behaviour?

IMO, configuration of a paste position is overkill. It bloats the configuration and I can’t imagine many people actually configuring it. Instead I would just paste the clipboard data either under the cursor position or centered in the whole image.

What do you guys think?

I think you’re right about the first point. Maybe I’m too hesitant about changing existing behaviour. The configuration being bloated is a separate issue imo, but I agree that until setting discoverability is improved (probably by redesigning the preferences and adding a search field) new ones should be added sparingly.

As for pasting from the menu, we can just handle that differently (the “patch” provided in my previous post is not what will end up in the code. This is something that is already done for e.g. rotation actions in the toolbar.

As a default I would prefer: top left corner of the pasted image is positioned on the cursor position, unless pasting from the menu, in which case the image would be centered on the current canvas center, rather than the whole image (pros/cons?).

It was clear, but it’s not something I can change in one line of code.

1 Like

I just realized that you have already solved my issue and I can both: (1) keep an existing layer and (2) paste an image under the pointer. One needs first to create a new layer and then to paste an image from the clipboard (Ctrl+PgUp; Ctrl+V). It seems obvious but I was not familiar with layers and realized it just now. Thanks again, no more need to move the pasted image from the top!

1 Like

In the master branch, the default paste behavior is now similar to what toniw suggested. When pasting with a keyboard shortcut, the content is placed relative to the cursor, and when pasting from the menu it is centered in the viewport. Configurability could be added of course.

Edit: oh, and it always pastes to a new layer now.

That’s a great improvement @jpll!
Maybe I found a bug? Reproduced this way:

  • make a dot on layer 1
  • make another one on layer 2 (somewhere right to the first dot)
  • copy and paste layer 2 somewhere
  • the position seems shifted by the distance of the dots

… It looks like the size of all layers combined is copied to the clipboard instead of just the current layer.

That is definitely a bug, nice find!

The way it is implemented atm is actually intentional, though not compatible with the change in paste behaviour. The reason the bounding box of the copied content is set to the full document is so that the layer can be pasted to the same position, presumably in a different document (in the same document I see no reason that you wouldn’t just duplicate and move the layer instead).

I will add a setting to retain the old behavior for copy/pasting (not the paste-to-new-layer thing though) so that it can at least be changed in the settings file if someone really needs the old behavior for their workflow.

1 Like