diff options
author | Tobias Christiansen <tobyase@serenityos.org> | 2022-03-07 23:14:52 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-03-08 22:07:12 +0100 |
commit | 4b1c31bb36f43721f4a66c1d430414c28d3fc615 (patch) | |
tree | 97adfb767a78c961b11529961bbb9aeccf86af6f /Userland | |
parent | 57772f9708d88e76cb35b9c77cbf9a15bbe7180c (diff) | |
download | serenity-4b1c31bb36f43721f4a66c1d430414c28d3fc615.zip |
PixelPaint: Change EditMode of Layer when double clicking on thumbnail
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Applications/PixelPaint/LayerListWidget.cpp | 42 | ||||
-rw-r--r-- | Userland/Applications/PixelPaint/LayerListWidget.h | 1 |
2 files changed, 43 insertions, 0 deletions
diff --git a/Userland/Applications/PixelPaint/LayerListWidget.cpp b/Userland/Applications/PixelPaint/LayerListWidget.cpp index 61cc6e0853..f5e167029c 100644 --- a/Userland/Applications/PixelPaint/LayerListWidget.cpp +++ b/Userland/Applications/PixelPaint/LayerListWidget.cpp @@ -180,6 +180,48 @@ Optional<size_t> LayerListWidget::gadget_at(Gfx::IntPoint const& position) return {}; } +void LayerListWidget::doubleclick_event(GUI::MouseEvent& event) +{ + if (!m_image) + return; + if (event.button() != GUI::MouseButton::Primary) + return; + + Gfx::IntPoint translated_event_point = { 0, vertical_scrollbar().value() + event.y() }; + + auto maybe_gadget_index = gadget_at(translated_event_point); + if (!maybe_gadget_index.has_value()) + return; + auto gadget_index = maybe_gadget_index.value(); + + // FIXME: Allow for a double click to change the selected gadget + if (m_selected_gadget_index != gadget_index) + return; + + auto& gadget = m_gadgets[gadget_index]; + auto& layer = m_image->layer(to_layer_index(gadget_index)); + + auto is_masked = layer.is_masked(); + + if (!is_masked) + return; + + Gfx::IntRect adjusted_rect; + Gfx::IntRect outer_thumbnail_rect; + Gfx::IntRect inner_thumbnail_rect; + Gfx::IntRect outer_mask_thumbnail_rect; + Gfx::IntRect inner_mask_thumbnail_rect; + Gfx::IntRect text_rect; + get_gadget_rects(gadget, is_masked, adjusted_rect, outer_thumbnail_rect, inner_thumbnail_rect, outer_mask_thumbnail_rect, inner_mask_thumbnail_rect, text_rect); + + if (outer_thumbnail_rect.contains(event.position())) + layer.set_edit_mode(Layer::EditMode::Content); + else if (outer_mask_thumbnail_rect.contains(event.position())) + layer.set_edit_mode(Layer::EditMode::Mask); + + update(); +} + void LayerListWidget::mousedown_event(GUI::MouseEvent& event) { if (!m_image) diff --git a/Userland/Applications/PixelPaint/LayerListWidget.h b/Userland/Applications/PixelPaint/LayerListWidget.h index fea40fdcee..15132f6e38 100644 --- a/Userland/Applications/PixelPaint/LayerListWidget.h +++ b/Userland/Applications/PixelPaint/LayerListWidget.h @@ -39,6 +39,7 @@ private: virtual void mouseup_event(GUI::MouseEvent&) override; virtual void context_menu_event(GUI::ContextMenuEvent&) override; virtual void resize_event(GUI::ResizeEvent&) override; + virtual void doubleclick_event(GUI::MouseEvent&) override; virtual void image_did_add_layer(size_t) override; virtual void image_did_remove_layer(size_t) override; |