diff options
author | MacDue <macdue@dueutil.tech> | 2022-11-27 14:17:38 +0000 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-11-27 20:35:22 +0100 |
commit | 458ca83d8cd71c971df6b62b5cf4c8cfb98cbad0 (patch) | |
tree | d56551a03b46fb76db872a8096ddca7c019b3147 | |
parent | fccda26ef9997f8401b9c4d6efe0f2d3f1c03781 (diff) | |
download | serenity-458ca83d8cd71c971df6b62b5cf4c8cfb98cbad0.zip |
PixelPaint: Fix lasso tool preview when zoomed in
Previously only part of the preview would be visible when zoomed in,
with less visible the more you zoomed. This also now doesn't scale
the preview line thickness, similar to other image editing programs.
-rw-r--r-- | Userland/Applications/PixelPaint/Tools/LassoSelectTool.cpp | 25 | ||||
-rw-r--r-- | Userland/Applications/PixelPaint/Tools/LassoSelectTool.h | 3 |
2 files changed, 9 insertions, 19 deletions
diff --git a/Userland/Applications/PixelPaint/Tools/LassoSelectTool.cpp b/Userland/Applications/PixelPaint/Tools/LassoSelectTool.cpp index d945c0c621..aeed055af7 100644 --- a/Userland/Applications/PixelPaint/Tools/LassoSelectTool.cpp +++ b/Userland/Applications/PixelPaint/Tools/LassoSelectTool.cpp @@ -16,7 +16,6 @@ #include <LibGUI/Model.h> #include <LibGUI/Painter.h> #include <LibGUI/ValueSlider.h> -#include <LibGfx/BitmapMixer.h> namespace PixelPaint { @@ -33,17 +32,13 @@ void LassoSelectTool::on_mousedown(Layer* layer, MouseEvent& event) if (selection_bitmap_result.is_error()) return; - auto preview_bitmap_result = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRA8888, layer->content_bitmap().size()); - if (preview_bitmap_result.is_error()) - return; - m_selection_bitmap = selection_bitmap_result.release_value(); - m_preview_bitmap = preview_bitmap_result.release_value(); m_start_position = layer_event.position(); m_most_recent_position = layer_event.position(); m_top_left = m_start_position; m_bottom_right = m_start_position; - + m_preview_path.clear(); + m_preview_path.move_to(editor_stroke_position(m_most_recent_position, 1).to_type<float>()); m_selection_bitmap->set_pixel(m_most_recent_position, Gfx::Color::Black); m_selecting = true; @@ -74,10 +69,8 @@ void LassoSelectTool::on_mousemove(Layer* layer, MouseEvent& event) if (new_position.y() > m_bottom_right.y()) m_bottom_right.set_y(new_position.y()); - auto preview_painter = Gfx::Painter(*m_preview_bitmap); - auto preview_start = editor_stroke_position(m_most_recent_position, 1); auto preview_end = editor_stroke_position(new_position, 1); - preview_painter.draw_line(preview_start, preview_end, Gfx::Color::Black, AK::max(1 * m_editor->scale(), 1)); + m_preview_path.line_to(preview_end.to_type<float>()); auto selection_painter = Gfx::Painter(*m_selection_bitmap); selection_painter.draw_line(m_most_recent_position, new_position, Gfx::Color::Black); @@ -145,17 +138,13 @@ void LassoSelectTool::flood_lasso_selection(Gfx::Bitmap& lasso_bitmap, Gfx::IntP void LassoSelectTool::on_second_paint(Layer const* layer, GUI::PaintEvent& event) { - if (!m_selecting) return; - - if (m_preview_bitmap.is_null()) - return; - GUI::Painter painter(*m_editor); painter.add_clip_rect(event.rect()); - - painter.blit(layer->location(), *m_preview_bitmap, m_preview_bitmap->rect()); + if (layer) + painter.translate(editor_layer_location(*layer)); + painter.stroke_path(m_preview_path, Gfx::Color::Black, 1); } bool LassoSelectTool::on_keydown(GUI::KeyEvent const& key_event) @@ -165,7 +154,7 @@ bool LassoSelectTool::on_keydown(GUI::KeyEvent const& key_event) if (m_selecting) { m_selecting = false; m_selection_bitmap.clear(); - m_preview_bitmap.clear(); + m_preview_path.clear(); return true; } } diff --git a/Userland/Applications/PixelPaint/Tools/LassoSelectTool.h b/Userland/Applications/PixelPaint/Tools/LassoSelectTool.h index af2730571f..621134fd40 100644 --- a/Userland/Applications/PixelPaint/Tools/LassoSelectTool.h +++ b/Userland/Applications/PixelPaint/Tools/LassoSelectTool.h @@ -11,6 +11,7 @@ #include <AK/Vector.h> #include <LibGUI/Widget.h> +#include <LibGfx/Path.h> namespace PixelPaint { @@ -36,7 +37,7 @@ private: Gfx::IntPoint m_start_position; Gfx::IntPoint m_most_recent_position; RefPtr<Gfx::Bitmap> m_selection_bitmap; - RefPtr<Gfx::Bitmap> m_preview_bitmap; + Gfx::Path m_preview_path; Gfx::IntPoint m_top_left; Gfx::IntPoint m_bottom_right; |