RectangleSelectTool.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
  3. * Copyright (c) 2022, the SerenityOS developers.
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #pragma once
  8. #include "../Selection.h"
  9. #include "Tool.h"
  10. #include <AK/Vector.h>
  11. #include <LibGUI/Widget.h>
  12. namespace PixelPaint {
  13. class RectangleSelectTool final : public Tool {
  14. public:
  15. RectangleSelectTool() = default;
  16. virtual ~RectangleSelectTool() = default;
  17. virtual void on_mousedown(Layer*, MouseEvent& event) override;
  18. virtual void on_mousemove(Layer*, MouseEvent& event) override;
  19. virtual void on_mouseup(Layer*, MouseEvent& event) override;
  20. virtual bool on_keydown(GUI::KeyEvent&) override;
  21. virtual void on_keyup(GUI::KeyEvent&) override;
  22. virtual void on_second_paint(Layer const*, GUI::PaintEvent&) override;
  23. virtual NonnullRefPtr<GUI::Widget> get_properties_widget() override;
  24. virtual Variant<Gfx::StandardCursor, NonnullRefPtr<Gfx::Bitmap const>> cursor() override { return Gfx::StandardCursor::Crosshair; }
  25. virtual Gfx::IntPoint point_position_to_preferred_cell(Gfx::FloatPoint position) const override;
  26. private:
  27. virtual StringView tool_name() const override { return "Rectangle Select Tool"sv; }
  28. enum class MovingMode {
  29. MovingOrigin,
  30. AroundCenter,
  31. None,
  32. };
  33. RefPtr<GUI::Widget> m_properties_widget;
  34. Vector<DeprecatedString> m_merge_mode_names {};
  35. Selection::MergeMode m_merge_mode { Selection::MergeMode::Set };
  36. float m_edge_feathering { 0.0f };
  37. bool m_selecting { false };
  38. MovingMode m_moving_mode { MovingMode::None };
  39. Gfx::IntPoint m_selection_start;
  40. Gfx::IntPoint m_selection_end;
  41. Gfx::IntRect selection_rect() const;
  42. };
  43. }