1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 11:17:35 +00:00

PixelPaint: Rename Layer::resize() to Layer::scale()

This name more accurately describes the transform being performed.
This commit is contained in:
Tim Ledbetter 2023-03-13 23:58:55 +00:00 committed by Andreas Kling
parent 690f3ae43b
commit bdaad815a1
4 changed files with 13 additions and 13 deletions

View file

@ -664,8 +664,8 @@ ErrorOr<void> Image::resize(Gfx::IntSize new_size, Gfx::Painter::ScalingMode sca
}
if (scaling_mode != Gfx::Painter::ScalingMode::None) {
Vector<NonnullRefPtr<Layer>> resized_layers;
TRY(resized_layers.try_ensure_capacity(m_layers.size()));
Vector<NonnullRefPtr<Layer>> scaled_layers;
TRY(scaled_layers.try_ensure_capacity(m_layers.size()));
VERIFY(m_layers.size() > 0);
@ -681,12 +681,12 @@ ErrorOr<void> Image::resize(Gfx::IntSize new_size, Gfx::Painter::ScalingMode sca
auto scaled_top_left = layer_rect.top_left().scaled(scale_x, scale_y).to_rounded<int>();
auto scaled_bottom_right = layer_rect.bottom_right().translated(1).scaled(scale_x, scale_y).to_rounded<int>();
auto scaled_layer_rect = Gfx::IntRect::from_two_points(scaled_top_left, scaled_bottom_right);
TRY(new_layer->resize(scaled_layer_rect, scaling_mode, Layer::NotifyClients::No));
TRY(new_layer->scale(scaled_layer_rect, scaling_mode, Layer::NotifyClients::No));
resized_layers.unchecked_append(new_layer);
scaled_layers.unchecked_append(new_layer);
}
m_layers = move(resized_layers);
m_layers = move(scaled_layers);
for (auto& layer : m_layers)
layer->did_modify_bitmap({}, Layer::NotifyClients::Yes);

View file

@ -237,14 +237,14 @@ ErrorOr<void> Layer::crop(Gfx::IntRect const& rect, NotifyClients notify_clients
return {};
}
ErrorOr<void> Layer::resize(Gfx::IntRect const& new_rect, Gfx::Painter::ScalingMode scaling_mode, NotifyClients notify_clients)
ErrorOr<void> Layer::scale(Gfx::IntRect const& new_rect, Gfx::Painter::ScalingMode scaling_mode, NotifyClients notify_clients)
{
auto src_rect = Gfx::IntRect({}, size());
auto dst_rect = Gfx::IntRect({}, new_rect.size());
auto resized_content_bitmap = TRY(Gfx::Bitmap::create(Gfx::BitmapFormat::BGRA8888, new_rect.size()));
auto scaled_content_bitmap = TRY(Gfx::Bitmap::create(Gfx::BitmapFormat::BGRA8888, new_rect.size()));
{
Gfx::Painter painter(resized_content_bitmap);
Gfx::Painter painter(scaled_content_bitmap);
if (scaling_mode == Gfx::Painter::ScalingMode::None) {
painter.blit(src_rect.top_left(), *m_content_bitmap, src_rect, 1.0f);
@ -266,7 +266,7 @@ ErrorOr<void> Layer::resize(Gfx::IntRect const& new_rect, Gfx::Painter::ScalingM
m_mask_bitmap = move(dst);
}
m_content_bitmap = move(resized_content_bitmap);
m_content_bitmap = move(scaled_content_bitmap);
set_location(new_rect.location());
did_modify_bitmap({}, notify_clients);

View file

@ -67,7 +67,7 @@ public:
ErrorOr<void> flip(Gfx::Orientation orientation, NotifyClients notify_clients = NotifyClients::Yes);
ErrorOr<void> rotate(Gfx::RotationDirection direction, NotifyClients notify_clients = NotifyClients::Yes);
ErrorOr<void> crop(Gfx::IntRect const& rect, NotifyClients notify_clients = NotifyClients::Yes);
ErrorOr<void> resize(Gfx::IntRect const& new_rect, Gfx::Painter::ScalingMode scaling_mode, NotifyClients notify_clients = NotifyClients::Yes);
ErrorOr<void> scale(Gfx::IntRect const& new_rect, Gfx::Painter::ScalingMode scaling_mode, NotifyClients notify_clients = NotifyClients::Yes);
Optional<Gfx::IntRect> nonempty_content_bounding_rect() const;

View file

@ -124,9 +124,9 @@ void MoveTool::on_mouseup(Layer* layer, MouseEvent& event)
return;
if (m_scaling) {
auto resized_or_error = m_editor->active_layer()->resize(m_new_layer_rect, Gfx::Painter::ScalingMode::BilinearBlend);
if (resized_or_error.is_error())
GUI::MessageBox::show_error(m_editor->window(), MUST(String::formatted("Failed to resize layer: {}", resized_or_error.error().string_literal())));
auto scaled_layer_or_error = m_editor->active_layer()->scale(m_new_layer_rect, Gfx::Painter::ScalingMode::BilinearBlend);
if (scaled_layer_or_error.is_error())
GUI::MessageBox::show_error(m_editor->window(), MUST(String::formatted("Failed to resize layer: {}", scaled_layer_or_error.error().string_literal())));
else
m_editor->layers_did_change();
}