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

PixelPaint: Allow bigger Brush-Tool sizes

This patch allows a bigger brush tool size of 250 pixels and limits the
cursor bitmap to a reasonable size so that its not much bigger than the
image editor size. If the cursor is bigger as the editor it is rended
with a red edge to indicate that the actual cursor is bigger than
displayed. This change mitigates the OOM conditions when the cursor
gets unusual big.
This commit is contained in:
Torstennator 2023-07-18 14:25:33 +02:00 committed by Sam Atkins
parent 55edfe5c3c
commit 31ee20e179
4 changed files with 46 additions and 22 deletions

View file

@ -69,7 +69,7 @@ ErrorOr<GUI::Widget*> EraseTool::get_properties_widget()
size_label->set_fixed_size(80, 20);
auto size_slider = TRY(size_container->try_add<GUI::ValueSlider>(Orientation::Horizontal, "px"_string));
size_slider->set_range(1, 100);
size_slider->set_range(1, 250);
size_slider->set_value(size());
size_slider->on_change = [this, size_slider](int value) {
@ -144,20 +144,28 @@ NonnullRefPtr<Gfx::Bitmap> EraseTool::build_cursor()
return BrushTool::build_cursor();
m_scale_last_created_cursor = m_editor ? m_editor->scale() : 1;
int scaled_size = size() * m_scale_last_created_cursor;
int cursor_size = AK::clamp(preferred_cursor_size(), 1, max_allowed_cursor_size());
NonnullRefPtr<Gfx::Bitmap> new_cursor = Gfx::Bitmap::create(Gfx::BitmapFormat::BGRA8888, Gfx::IntSize(scaled_size, scaled_size)).release_value_but_fixme_should_propagate_errors();
NonnullRefPtr<Gfx::Bitmap> new_cursor = Gfx::Bitmap::create(Gfx::BitmapFormat::BGRA8888, Gfx::IntSize(cursor_size, cursor_size)).release_value_but_fixme_should_propagate_errors();
Gfx::IntRect rect { 0, 0, scaled_size, scaled_size };
Gfx::Painter painter { new_cursor };
painter.draw_rect(rect, Color::LightGray);
painter.draw_line({ scaled_size / 2 - 5, scaled_size / 2 }, { scaled_size / 2 + 5, scaled_size / 2 }, Color::LightGray, 3);
painter.draw_line({ scaled_size / 2, scaled_size / 2 - 5 }, { scaled_size / 2, scaled_size / 2 + 5 }, Color::LightGray, 3);
painter.draw_line({ scaled_size / 2 - 5, scaled_size / 2 }, { scaled_size / 2 + 5, scaled_size / 2 }, Color::MidGray, 1);
painter.draw_line({ scaled_size / 2, scaled_size / 2 - 5 }, { scaled_size / 2, scaled_size / 2 + 5 }, Color::MidGray, 1);
if (preferred_cursor_size() > max_allowed_cursor_size()) {
painter.draw_rect({ 0, 0, cursor_size, cursor_size }, Color::Red);
painter.draw_rect({ 3, 3, cursor_size - 6, cursor_size - 6 }, Color::LightGray);
} else {
painter.draw_rect({ 0, 0, cursor_size, cursor_size }, Color::LightGray);
}
painter.draw_line({ cursor_size / 2 - 5, cursor_size / 2 }, { cursor_size / 2 + 5, cursor_size / 2 }, Color::LightGray, 3);
painter.draw_line({ cursor_size / 2, cursor_size / 2 - 5 }, { cursor_size / 2, cursor_size / 2 + 5 }, Color::LightGray, 3);
painter.draw_line({ cursor_size / 2 - 5, cursor_size / 2 }, { cursor_size / 2 + 5, cursor_size / 2 }, Color::MidGray, 1);
painter.draw_line({ cursor_size / 2, cursor_size / 2 - 5 }, { cursor_size / 2, cursor_size / 2 + 5 }, Color::MidGray, 1);
return new_cursor;
}
float EraseTool::preferred_cursor_size()
{
return size() * (m_editor ? m_editor->scale() : 1);
}
}