mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 06:47:35 +00:00
PixelPaint: Use move semantics around Layer construction and accessors
This commit is contained in:
parent
a612c22278
commit
c7f7c1f7f0
3 changed files with 19 additions and 17 deletions
|
@ -98,7 +98,9 @@ RefPtr<Image> Image::try_create_from_pixel_paint_file(String const& file_path)
|
||||||
auto bitmap_base64_encoded = json_layer_object.get("bitmap").as_string();
|
auto bitmap_base64_encoded = json_layer_object.get("bitmap").as_string();
|
||||||
auto bitmap_data = decode_base64(bitmap_base64_encoded);
|
auto bitmap_data = decode_base64(bitmap_base64_encoded);
|
||||||
auto image_decoder = Gfx::ImageDecoder::create(bitmap_data);
|
auto image_decoder = Gfx::ImageDecoder::create(bitmap_data);
|
||||||
layer->set_bitmap(*image_decoder->bitmap());
|
auto bitmap = image_decoder->bitmap();
|
||||||
|
VERIFY(bitmap);
|
||||||
|
layer->set_bitmap(bitmap.release_nonnull());
|
||||||
image->add_layer(*layer);
|
image->add_layer(*layer);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
namespace PixelPaint {
|
namespace PixelPaint {
|
||||||
|
|
||||||
RefPtr<Layer> Layer::try_create_with_size(Image& image, Gfx::IntSize const& size, String const& name)
|
RefPtr<Layer> Layer::try_create_with_size(Image& image, Gfx::IntSize const& size, String name)
|
||||||
{
|
{
|
||||||
if (size.is_empty())
|
if (size.is_empty())
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
@ -18,10 +18,10 @@ RefPtr<Layer> Layer::try_create_with_size(Image& image, Gfx::IntSize const& size
|
||||||
if (size.width() > 16384 || size.height() > 16384)
|
if (size.width() > 16384 || size.height() > 16384)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
return adopt_ref(*new Layer(image, size, name));
|
return adopt_ref(*new Layer(image, size, move(name)));
|
||||||
}
|
}
|
||||||
|
|
||||||
RefPtr<Layer> Layer::try_create_with_bitmap(Image& image, Gfx::Bitmap const& bitmap, String const& name)
|
RefPtr<Layer> Layer::try_create_with_bitmap(Image& image, Gfx::Bitmap const& bitmap, String name)
|
||||||
{
|
{
|
||||||
if (bitmap.size().is_empty())
|
if (bitmap.size().is_empty())
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
@ -29,7 +29,7 @@ RefPtr<Layer> Layer::try_create_with_bitmap(Image& image, Gfx::Bitmap const& bit
|
||||||
if (bitmap.size().width() > 16384 || bitmap.size().height() > 16384)
|
if (bitmap.size().width() > 16384 || bitmap.size().height() > 16384)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
return adopt_ref(*new Layer(image, bitmap, name));
|
return adopt_ref(*new Layer(image, bitmap, move(name)));
|
||||||
}
|
}
|
||||||
|
|
||||||
RefPtr<Layer> Layer::try_create_snapshot(Image& image, Layer const& layer)
|
RefPtr<Layer> Layer::try_create_snapshot(Image& image, Layer const& layer)
|
||||||
|
@ -49,16 +49,16 @@ RefPtr<Layer> Layer::try_create_snapshot(Image& image, Layer const& layer)
|
||||||
return snapshot;
|
return snapshot;
|
||||||
}
|
}
|
||||||
|
|
||||||
Layer::Layer(Image& image, Gfx::IntSize const& size, String const& name)
|
Layer::Layer(Image& image, Gfx::IntSize const& size, String name)
|
||||||
: m_image(image)
|
: m_image(image)
|
||||||
, m_name(name)
|
, m_name(move(name))
|
||||||
{
|
{
|
||||||
m_bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::BGRA8888, size);
|
m_bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::BGRA8888, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
Layer::Layer(Image& image, Gfx::Bitmap const& bitmap, String const& name)
|
Layer::Layer(Image& image, Gfx::Bitmap const& bitmap, String name)
|
||||||
: m_image(image)
|
: m_image(image)
|
||||||
, m_name(name)
|
, m_name(move(name))
|
||||||
, m_bitmap(bitmap)
|
, m_bitmap(bitmap)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -84,11 +84,11 @@ void Layer::set_opacity_percent(int opacity_percent)
|
||||||
m_image.layer_did_modify_properties({}, *this);
|
m_image.layer_did_modify_properties({}, *this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Layer::set_name(String const& name)
|
void Layer::set_name(String name)
|
||||||
{
|
{
|
||||||
if (m_name == name)
|
if (m_name == name)
|
||||||
return;
|
return;
|
||||||
m_name = name;
|
m_name = move(name);
|
||||||
m_image.layer_did_modify_properties({}, *this);
|
m_image.layer_did_modify_properties({}, *this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,8 +24,8 @@ class Layer
|
||||||
AK_MAKE_NONMOVABLE(Layer);
|
AK_MAKE_NONMOVABLE(Layer);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static RefPtr<Layer> try_create_with_size(Image&, Gfx::IntSize const&, String const& name);
|
static RefPtr<Layer> try_create_with_size(Image&, Gfx::IntSize const&, String name);
|
||||||
static RefPtr<Layer> try_create_with_bitmap(Image&, Gfx::Bitmap const&, String const& name);
|
static RefPtr<Layer> try_create_with_bitmap(Image&, Gfx::Bitmap const&, String name);
|
||||||
static RefPtr<Layer> try_create_snapshot(Image&, Layer const&);
|
static RefPtr<Layer> try_create_snapshot(Image&, Layer const&);
|
||||||
|
|
||||||
~Layer() { }
|
~Layer() { }
|
||||||
|
@ -41,9 +41,9 @@ public:
|
||||||
Gfx::IntRect rect() const { return { {}, size() }; }
|
Gfx::IntRect rect() const { return { {}, size() }; }
|
||||||
|
|
||||||
String const& name() const { return m_name; }
|
String const& name() const { return m_name; }
|
||||||
void set_name(String const&);
|
void set_name(String);
|
||||||
|
|
||||||
void set_bitmap(Gfx::Bitmap& bitmap) { m_bitmap = bitmap; }
|
void set_bitmap(NonnullRefPtr<Gfx::Bitmap> bitmap) { m_bitmap = move(bitmap); }
|
||||||
|
|
||||||
void did_modify_bitmap(Image&);
|
void did_modify_bitmap(Image&);
|
||||||
|
|
||||||
|
@ -57,8 +57,8 @@ public:
|
||||||
void set_opacity_percent(int);
|
void set_opacity_percent(int);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Layer(Image&, Gfx::IntSize const&, String const& name);
|
Layer(Image&, Gfx::IntSize const&, String name);
|
||||||
Layer(Image&, Gfx::Bitmap const&, String const& name);
|
Layer(Image&, Gfx::Bitmap const&, String name);
|
||||||
|
|
||||||
Image& m_image;
|
Image& m_image;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue