godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.12k stars 69 forks source link

Add the ability to copy images to clipboard #8769

Closed yamikukki closed 8 months ago

yamikukki commented 8 months ago

Describe the project you are working on

A texture editing tool that requires a lot of copying/pasting for the work-in-progress texture between the tool and an external image editor (for example Krita) in order to apply some complex filters / tools that are impossible to add to Krita via scripting. Generally useful for any kind of image editing tools.

Some other tools that are limited by this include basically any sprite editor plugins / standalone tools, for example Pixelorama (https://www.oramainteractive.com/Pixelorama-Docs/user_manual/selecting/#copy-paste-cut-and-delete)

Describe the problem or limitation you are having in your project

Currently, the class DisplayServer has clipboard_get() to get text, clipboard_set() to set text and clipboard_get_image() to get the image data from the clipboard, but doesn't have clipboard_set_image() for setting the image data to the clipboard. This prevents me from implementing the ability to quickly copy the image data from my tool to paste it in some other tool.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

Add clipboard_set_image() method to DisplayServer class to enable the ability to implement image copy/paste functionality. If some platform doesn't support this functionality, then do nothing / print a warning.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

clipboard_set_image(Image) should accept Image data as the only parameter (the same type as the result type in the clipboard_get_image() method)

If this enhancement will not be used often, can it be worked around with a few lines of script?

I haven't tested this method yet, but if it's possible, the only workaround is to create a C++ Dll / GDExtension, pass DisplayServer.WindowGetNativeHandle(DisplayServer.HandleType.WindowHandle) into it together with the image bytes, dimensions and encoding, and then implement the desired functionality with the help of WinAPI's winuser.h. If this doesn't work, then the only option is to save the WIP texture into a file, then reload this file in the image editing app, then copy-paste it to your actual .psd project to work on it there. It's doable this way, but I expect my tool's users to transfer the WIP texture back and forth at least a few dozens to a few hundred times, so having the ability to directly copy/paste images would save them a lot of time and mental energy.

Is there a reason why this should be core and not an add-on in the asset library?

In my opinion it's only natural to have DisplayServer.clipboard_set_image(Image) method, as we already have clipboard_get_image() to match it, just as clipboard_get has its matching clipboard_set

KoBeWi commented 8 months ago

Thanks for the proposal! Consolidating in https://github.com/godotengine/godot-proposals/issues/7899. The feature is already planned and had implementation attempts: https://github.com/godotengine/godot/pull/79561