mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 22:37:35 +00:00
PixelPaint: Ensure the selection is always within image bounds
This commit is contained in:
parent
fc137a7827
commit
f132751fae
8 changed files with 97 additions and 55 deletions
|
@ -21,14 +21,18 @@
|
|||
|
||||
namespace PixelPaint {
|
||||
|
||||
static void set_flood_selection(Gfx::Bitmap& bitmap, Image& image, Gfx::IntPoint start_position, Gfx::IntPoint selection_offset, int threshold, Selection::MergeMode merge_mode)
|
||||
static void set_flood_selection(Gfx::Bitmap& bitmap, Image& image, Gfx::IntPoint start_position, Gfx::IntRect layer_rect, int threshold, Selection::MergeMode merge_mode)
|
||||
{
|
||||
VERIFY(bitmap.bpp() == 32);
|
||||
|
||||
auto selection_mask = Mask::empty({ selection_offset, bitmap.size() });
|
||||
auto image_rect = image.rect();
|
||||
auto mask_rect = layer_rect.intersected(image_rect);
|
||||
auto selection_mask = Mask::empty(mask_rect);
|
||||
|
||||
auto pixel_reached = [&](Gfx::IntPoint location) {
|
||||
selection_mask.set(selection_offset.x() + location.x(), selection_offset.y() + location.y(), 0xFF);
|
||||
auto point_to_set = layer_rect.top_left() + location;
|
||||
if (selection_mask.bounding_rect().contains(point_to_set))
|
||||
selection_mask.set(point_to_set, 0xFF);
|
||||
};
|
||||
|
||||
bitmap.flood_visit_from_point(start_position, threshold, move(pixel_reached));
|
||||
|
@ -55,10 +59,8 @@ void WandSelectTool::on_mousedown(Layer* layer, MouseEvent& event)
|
|||
if (!layer->rect().contains(layer_event.position()))
|
||||
return;
|
||||
|
||||
auto selection_offset = layer->relative_rect().top_left();
|
||||
|
||||
m_editor->image().selection().begin_interactive_selection();
|
||||
set_flood_selection(layer->currently_edited_bitmap(), m_editor->image(), layer_event.position(), selection_offset, m_threshold, m_merge_mode);
|
||||
set_flood_selection(layer->currently_edited_bitmap(), m_editor->image(), layer_event.position(), layer->relative_rect(), m_threshold, m_merge_mode);
|
||||
m_editor->image().selection().end_interactive_selection();
|
||||
m_editor->update();
|
||||
m_editor->did_complete_action(tool_name());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue