mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 16:07:47 +00:00
PixelPaint: Allow pasting a copied bitmap as a new layer :^)
This commit is contained in:
parent
00bdb74c84
commit
6aa7f59608
4 changed files with 35 additions and 2 deletions
|
@ -71,6 +71,8 @@ void Image::add_layer(NonnullRefPtr<Layer> layer)
|
||||||
|
|
||||||
for (auto* client : m_clients)
|
for (auto* client : m_clients)
|
||||||
client->image_did_add_layer(m_layers.size() - 1);
|
client->image_did_add_layer(m_layers.size() - 1);
|
||||||
|
|
||||||
|
did_modify_layer_stack();
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Image::index_of(const Layer& layer) const
|
size_t Image::index_of(const Layer& layer) const
|
||||||
|
|
|
@ -41,6 +41,17 @@ RefPtr<Layer> Layer::create_with_size(Image& image, const Gfx::IntSize& size, co
|
||||||
return adopt(*new Layer(image, size, name));
|
return adopt(*new Layer(image, size, name));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RefPtr<Layer> Layer::create_with_bitmap(Image& image, const Gfx::Bitmap& bitmap, const String& name)
|
||||||
|
{
|
||||||
|
if (bitmap.size().is_empty())
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
if (bitmap.size().width() > 16384 || bitmap.size().height() > 16384)
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
return adopt(*new Layer(image, bitmap, name));
|
||||||
|
}
|
||||||
|
|
||||||
Layer::Layer(Image& image, const Gfx::IntSize& size, const String& name)
|
Layer::Layer(Image& image, const Gfx::IntSize& size, const String& name)
|
||||||
: m_image(image)
|
: m_image(image)
|
||||||
, m_name(name)
|
, m_name(name)
|
||||||
|
@ -48,6 +59,13 @@ Layer::Layer(Image& image, const Gfx::IntSize& size, const String& name)
|
||||||
m_bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::RGBA32, size);
|
m_bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::RGBA32, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Layer::Layer(Image& image, const Gfx::Bitmap& bitmap, const String& name)
|
||||||
|
: m_image(image)
|
||||||
|
, m_name(name)
|
||||||
|
, m_bitmap(bitmap)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
void Layer::did_modify_bitmap(Image& image)
|
void Layer::did_modify_bitmap(Image& image)
|
||||||
{
|
{
|
||||||
image.layer_did_modify_bitmap({}, *this);
|
image.layer_did_modify_bitmap({}, *this);
|
||||||
|
|
|
@ -45,6 +45,7 @@ class Layer
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static RefPtr<Layer> create_with_size(Image&, const Gfx::IntSize&, const String& name);
|
static RefPtr<Layer> create_with_size(Image&, const Gfx::IntSize&, const String& name);
|
||||||
|
static RefPtr<Layer> create_with_bitmap(Image&, const Gfx::Bitmap&, const String& name);
|
||||||
|
|
||||||
~Layer() { }
|
~Layer() { }
|
||||||
|
|
||||||
|
@ -75,7 +76,8 @@ public:
|
||||||
void set_opacity_percent(int);
|
void set_opacity_percent(int);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit Layer(Image&, const Gfx::IntSize&, const String& name);
|
Layer(Image&, const Gfx::IntSize&, const String& name);
|
||||||
|
Layer(Image&, const Gfx::Bitmap&, const String& name);
|
||||||
|
|
||||||
Image& m_image;
|
Image& m_image;
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,7 @@
|
||||||
#include <LibGUI/Action.h>
|
#include <LibGUI/Action.h>
|
||||||
#include <LibGUI/Application.h>
|
#include <LibGUI/Application.h>
|
||||||
#include <LibGUI/BoxLayout.h>
|
#include <LibGUI/BoxLayout.h>
|
||||||
|
#include <LibGUI/Clipboard.h>
|
||||||
#include <LibGUI/FilePicker.h>
|
#include <LibGUI/FilePicker.h>
|
||||||
#include <LibGUI/Icon.h>
|
#include <LibGUI/Icon.h>
|
||||||
#include <LibGUI/Menu.h>
|
#include <LibGUI/Menu.h>
|
||||||
|
@ -126,7 +127,17 @@ int main(int argc, char** argv)
|
||||||
return;
|
return;
|
||||||
}));
|
}));
|
||||||
|
|
||||||
menubar->add_menu("Edit");
|
auto& edit_menu = menubar->add_menu("Edit");
|
||||||
|
edit_menu.add_action(GUI::CommonActions::make_paste_action([&](auto&) {
|
||||||
|
|
||||||
|
ASSERT(image_editor.image());
|
||||||
|
auto bitmap = GUI::Clipboard::the().bitmap();
|
||||||
|
if (!bitmap)
|
||||||
|
return;
|
||||||
|
|
||||||
|
auto layer = PixelPaint::Layer::create_with_bitmap(*image_editor.image(), *bitmap, "Pasted layer");
|
||||||
|
image_editor.image()->add_layer(layer.release_nonnull());
|
||||||
|
}));
|
||||||
|
|
||||||
auto& tool_menu = menubar->add_menu("Tool");
|
auto& tool_menu = menubar->add_menu("Tool");
|
||||||
toolbox.for_each_tool([&](auto& tool) {
|
toolbox.for_each_tool([&](auto& tool) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue