diff --git a/Userland/Applications/PixelPaint/ImageEditor.cpp b/Userland/Applications/PixelPaint/ImageEditor.cpp index 23096e2b6e..70626e150f 100644 --- a/Userland/Applications/PixelPaint/ImageEditor.cpp +++ b/Userland/Applications/PixelPaint/ImageEditor.cpp @@ -372,10 +372,9 @@ void ImageEditor::mousedown_event(GUI::MouseEvent& event) if (!m_active_tool) return; - if (is(*m_active_tool)) { - if (auto* other_layer = layer_at_editor_position(event.position())) { - set_active_layer(other_layer); - } + if (auto* tool = dynamic_cast(m_active_tool); tool && tool->layer_selection_mode() == MoveTool::LayerSelectionMode::ForegroundLayer) { + if (auto* foreground_layer = layer_at_editor_position(event.position())) + set_active_layer(foreground_layer); } auto layer_event = m_active_layer ? event_adjusted_for_layer(event, *m_active_layer) : event; diff --git a/Userland/Applications/PixelPaint/Tools/MoveTool.cpp b/Userland/Applications/PixelPaint/Tools/MoveTool.cpp index 1559b93f96..d2b46a8388 100644 --- a/Userland/Applications/PixelPaint/Tools/MoveTool.cpp +++ b/Userland/Applications/PixelPaint/Tools/MoveTool.cpp @@ -11,6 +11,8 @@ #include "../Layer.h" #include #include +#include +#include #include #include #include @@ -138,6 +140,9 @@ bool MoveTool::on_keydown(GUI::KeyEvent& event) if (event.key() == Key_Shift) m_keep_aspect_ratio = true; + if (event.key() == Key_Alt) + toggle_selection_mode(); + if (m_scaling) return true; @@ -176,6 +181,9 @@ void MoveTool::on_keyup(GUI::KeyEvent& event) { if (event.key() == Key_Shift) m_keep_aspect_ratio = false; + + if (event.key() == Key_Alt) + toggle_selection_mode(); } void MoveTool::on_second_paint(Layer const* layer, GUI::PaintEvent& event) @@ -243,4 +251,44 @@ Variant> MoveTool::cursor() return Gfx::StandardCursor::Move; } +GUI::Widget* MoveTool::get_properties_widget() +{ + if (!m_properties_widget) { + m_properties_widget = GUI::Widget::construct(); + m_properties_widget->set_layout(); + + auto& selection_mode_container = m_properties_widget->add(); + selection_mode_container.set_layout(); + selection_mode_container.set_fixed_height(46); + auto& selection_mode_label = selection_mode_container.add("Selection Mode:"); + selection_mode_label.set_text_alignment(Gfx::TextAlignment::CenterLeft); + selection_mode_label.set_fixed_size(80, 40); + + auto& mode_radio_container = selection_mode_container.add(); + mode_radio_container.set_layout(); + m_selection_mode_foreground = mode_radio_container.add("Foreground"); + + m_selection_mode_active = mode_radio_container.add("Active Layer"); + + m_selection_mode_foreground->on_checked = [&](bool) { + m_layer_selection_mode = LayerSelectionMode::ForegroundLayer; + }; + m_selection_mode_active->on_checked = [&](bool) { + m_layer_selection_mode = LayerSelectionMode::ActiveLayer; + }; + + m_selection_mode_foreground->set_checked(true); + } + + return m_properties_widget.ptr(); +} + +void MoveTool::toggle_selection_mode() +{ + if (m_selection_mode_foreground->is_checked()) + m_selection_mode_active->set_checked(true); + else + m_selection_mode_foreground->set_checked(true); +} + } diff --git a/Userland/Applications/PixelPaint/Tools/MoveTool.h b/Userland/Applications/PixelPaint/Tools/MoveTool.h index 6c668a281b..cfce91b839 100644 --- a/Userland/Applications/PixelPaint/Tools/MoveTool.h +++ b/Userland/Applications/PixelPaint/Tools/MoveTool.h @@ -1,6 +1,6 @@ /* * Copyright (c) 2020, Andreas Kling - * Copyright (c) 2022, the SerenityOS developers. + * Copyright (c) 2022-2023, the SerenityOS developers. * * SPDX-License-Identifier: BSD-2-Clause */ @@ -9,6 +9,7 @@ #include "../Layer.h" #include "Tool.h" +#include namespace PixelPaint { @@ -23,19 +24,29 @@ public: MoveTool() = default; virtual ~MoveTool() override = default; + enum class LayerSelectionMode { + ForegroundLayer, + ActiveLayer, + }; + virtual void on_mousedown(Layer*, MouseEvent&) override; virtual void on_mousemove(Layer*, MouseEvent&) override; virtual void on_mouseup(Layer*, MouseEvent&) override; virtual bool on_keydown(GUI::KeyEvent&) override; virtual void on_keyup(GUI::KeyEvent&) override; virtual void on_second_paint(Layer const*, GUI::PaintEvent&) override; + virtual GUI::Widget* get_properties_widget() override; virtual Variant> cursor() override; + virtual bool is_overriding_alt() override { return true; } + LayerSelectionMode layer_selection_mode() const { return m_layer_selection_mode; } private: virtual StringView tool_name() const override { return "Move Tool"sv; } ErrorOr update_cached_preview_bitmap(Layer const* layer); Optional resize_anchor_location_from_cursor_position(Layer const*, MouseEvent&); + void toggle_selection_mode(); + LayerSelectionMode m_layer_selection_mode { LayerSelectionMode::ForegroundLayer }; RefPtr m_layer_being_moved; Gfx::IntPoint m_event_origin; Gfx::IntPoint m_layer_origin; @@ -43,6 +54,9 @@ private: bool m_scaling { false }; Optional m_resize_anchor_location {}; bool m_keep_aspect_ratio { false }; + RefPtr m_properties_widget; + RefPtr m_selection_mode_foreground; + RefPtr m_selection_mode_active; RefPtr m_cached_preview_bitmap { nullptr }; };