mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 13:47:35 +00:00
PixelPaint: Add Copy Merged
action
This allows the user to copy the merged bitmap (all visible layers).
This commit is contained in:
parent
65d52467f4
commit
6910cbc075
3 changed files with 32 additions and 0 deletions
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
#include "Image.h"
|
#include "Image.h"
|
||||||
#include "Layer.h"
|
#include "Layer.h"
|
||||||
|
#include "Selection.h"
|
||||||
#include <AK/Base64.h>
|
#include <AK/Base64.h>
|
||||||
#include <AK/JsonObject.h>
|
#include <AK/JsonObject.h>
|
||||||
#include <AK/JsonObjectSerializer.h>
|
#include <AK/JsonObjectSerializer.h>
|
||||||
|
@ -173,6 +174,20 @@ RefPtr<Gfx::Bitmap> Image::try_compose_bitmap(Gfx::BitmapFormat format) const
|
||||||
return bitmap;
|
return bitmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RefPtr<Gfx::Bitmap> Image::try_copy_bitmap(Selection const& selection) const
|
||||||
|
{
|
||||||
|
if (selection.is_empty())
|
||||||
|
return {};
|
||||||
|
auto selection_rect = selection.bounding_rect();
|
||||||
|
|
||||||
|
// FIXME: Add a way to only compose a certain part of the image
|
||||||
|
auto full_bitmap = try_compose_bitmap(Gfx::BitmapFormat::BGRA8888);
|
||||||
|
if (!full_bitmap)
|
||||||
|
return {};
|
||||||
|
|
||||||
|
return full_bitmap->cropped(selection_rect);
|
||||||
|
}
|
||||||
|
|
||||||
Result<void, String> Image::export_bmp_to_fd_and_close(int fd, bool preserve_alpha_channel)
|
Result<void, String> Image::export_bmp_to_fd_and_close(int fd, bool preserve_alpha_channel)
|
||||||
{
|
{
|
||||||
auto file = Core::File::construct();
|
auto file = Core::File::construct();
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
namespace PixelPaint {
|
namespace PixelPaint {
|
||||||
|
|
||||||
class Layer;
|
class Layer;
|
||||||
|
class Selection;
|
||||||
|
|
||||||
class ImageClient {
|
class ImageClient {
|
||||||
public:
|
public:
|
||||||
|
@ -53,6 +54,7 @@ public:
|
||||||
|
|
||||||
// This generates a new Bitmap with the final image (all layers composed according to their attributes.)
|
// This generates a new Bitmap with the final image (all layers composed according to their attributes.)
|
||||||
RefPtr<Gfx::Bitmap> try_compose_bitmap(Gfx::BitmapFormat format) const;
|
RefPtr<Gfx::Bitmap> try_compose_bitmap(Gfx::BitmapFormat format) const;
|
||||||
|
RefPtr<Gfx::Bitmap> try_copy_bitmap(Selection const&) const;
|
||||||
|
|
||||||
size_t layer_count() const { return m_layers.size(); }
|
size_t layer_count() const { return m_layers.size(); }
|
||||||
Layer const& layer(size_t index) const { return m_layers.at(index); }
|
Layer const& layer(size_t index) const { return m_layers.at(index); }
|
||||||
|
|
|
@ -256,6 +256,20 @@ int main(int argc, char** argv)
|
||||||
}
|
}
|
||||||
GUI::Clipboard::the().set_bitmap(*bitmap);
|
GUI::Clipboard::the().set_bitmap(*bitmap);
|
||||||
});
|
});
|
||||||
|
auto copy_merged_action = GUI::Action::create(
|
||||||
|
"Copy &Merged", { Mod_Ctrl | Mod_Shift, Key_C }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/edit-copy.png"),
|
||||||
|
[&](auto&) {
|
||||||
|
auto* editor = current_image_editor();
|
||||||
|
if (!editor)
|
||||||
|
return;
|
||||||
|
auto bitmap = editor->image().try_copy_bitmap(editor->selection());
|
||||||
|
if (!bitmap) {
|
||||||
|
dbgln("try_copy_bitmap() from Image failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
GUI::Clipboard::the().set_bitmap(*bitmap);
|
||||||
|
},
|
||||||
|
window);
|
||||||
|
|
||||||
auto paste_action = GUI::CommonActions::make_paste_action([&](auto&) {
|
auto paste_action = GUI::CommonActions::make_paste_action([&](auto&) {
|
||||||
auto* editor = current_image_editor();
|
auto* editor = current_image_editor();
|
||||||
|
@ -277,6 +291,7 @@ int main(int argc, char** argv)
|
||||||
paste_action->set_enabled(GUI::Clipboard::the().mime_type() == "image/x-serenityos");
|
paste_action->set_enabled(GUI::Clipboard::the().mime_type() == "image/x-serenityos");
|
||||||
|
|
||||||
edit_menu.add_action(copy_action);
|
edit_menu.add_action(copy_action);
|
||||||
|
edit_menu.add_action(copy_merged_action);
|
||||||
edit_menu.add_action(paste_action);
|
edit_menu.add_action(paste_action);
|
||||||
|
|
||||||
auto undo_action = GUI::CommonActions::make_undo_action([&](auto&) {
|
auto undo_action = GUI::CommonActions::make_undo_action([&](auto&) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue