diff options
author | Robin Burchell <robin+git@viroteck.net> | 2019-06-28 11:20:22 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-06-28 15:27:23 +0200 |
commit | 933cd3848f3f791e57fc788bac67dc92957e90e0 (patch) | |
tree | 432e9ee56cdee5e8f3b7e108c94ee70f7c1c54f0 | |
parent | 24ada6bd1f6f99ddc603bb48c60697efc7349d29 (diff) | |
download | serenity-933cd3848f3f791e57fc788bac67dc92957e90e0.zip |
PaintBrush: Add size context menu to SprayTool
-rw-r--r-- | Applications/PaintBrush/SprayTool.cpp | 26 | ||||
-rw-r--r-- | Applications/PaintBrush/SprayTool.h | 5 |
2 files changed, 30 insertions, 1 deletions
diff --git a/Applications/PaintBrush/SprayTool.cpp b/Applications/PaintBrush/SprayTool.cpp index 84888fb4f9..e574515354 100644 --- a/Applications/PaintBrush/SprayTool.cpp +++ b/Applications/PaintBrush/SprayTool.cpp @@ -3,6 +3,8 @@ #include <AK/Queue.h> #include <AK/SinglyLinkedList.h> #include <LibGUI/GPainter.h> +#include <LibGUI/GAction.h> +#include <LibGUI/GMenu.h> #include <SharedGraphics/GraphicsBitmap.h> #include <stdio.h> #include <LibM/math.h> @@ -30,7 +32,8 @@ void SprayTool::paint_it() auto& bitmap = m_widget->bitmap(); ASSERT(bitmap.bpp() == 32); m_widget->update(); - const double base_radius = 15; + const double minimal_radius = 10; + const double base_radius = minimal_radius * m_thickness; for (int i = 0; i < 100 + (nrand() * 800); i++) { double radius = base_radius * nrand(); double angle = 2 * M_PI * nrand(); @@ -68,3 +71,24 @@ void SprayTool::on_mouseup(GMouseEvent&) { m_timer.stop(); } + +void SprayTool::on_contextmenu(GContextMenuEvent& event) +{ + if (!m_context_menu) { + m_context_menu = make<GMenu>("SprayTool Context Menu"); + m_context_menu->add_action(GAction::create("1", [this](auto&) { + m_thickness = 1; + })); + m_context_menu->add_action(GAction::create("2", [this](auto&) { + m_thickness = 2; + })); + m_context_menu->add_action(GAction::create("3", [this](auto&) { + m_thickness = 3; + })); + m_context_menu->add_action(GAction::create("4", [this](auto&) { + m_thickness = 4; + })); + } + m_context_menu->popup(event.screen_position()); +} + diff --git a/Applications/PaintBrush/SprayTool.h b/Applications/PaintBrush/SprayTool.h index ac2e8322a5..2260990555 100644 --- a/Applications/PaintBrush/SprayTool.h +++ b/Applications/PaintBrush/SprayTool.h @@ -4,6 +4,8 @@ #include <LibGUI/GPainter.h> #include <LibCore/CTimer.h> +class GMenu; + class SprayTool final : public Tool { public: SprayTool(); @@ -12,6 +14,7 @@ public: virtual void on_mousedown(GMouseEvent&) override; virtual void on_mouseup(GMouseEvent&) override; virtual void on_mousemove(GMouseEvent&) override; + virtual void on_contextmenu(GContextMenuEvent&) override; private: virtual const char* class_name() const override { return "SprayTool"; } @@ -19,4 +22,6 @@ private: CTimer m_timer; Point m_last_pos; Color m_color; + OwnPtr<GMenu> m_context_menu; + int m_thickness { 1 }; }; |