diff options
author | MacDue <macdue@dueutil.tech> | 2022-08-20 18:09:20 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-08-21 14:13:08 +0200 |
commit | 78813313f9f1946afad202acfc537c7d0d465de4 (patch) | |
tree | 01cdb440c9f58aea15f3c95f0fa111b19a6250d2 /Userland/Applications/PixelPaint | |
parent | 973771f8f431cb9c5faaa87f9c66cfcf480a83c4 (diff) | |
download | serenity-78813313f9f1946afad202acfc537c7d0d465de4.zip |
PixelPaint: Fix tool preview positions after moving a layer
Previously the tool previews did not account for the position of
the layer, so would be drawn in the wrong location if the layer was
not at 0,0.
Diffstat (limited to 'Userland/Applications/PixelPaint')
5 files changed, 11 insertions, 0 deletions
diff --git a/Userland/Applications/PixelPaint/Tools/EllipseTool.cpp b/Userland/Applications/PixelPaint/Tools/EllipseTool.cpp index c45bec5884..cd709bc090 100644 --- a/Userland/Applications/PixelPaint/Tools/EllipseTool.cpp +++ b/Userland/Applications/PixelPaint/Tools/EllipseTool.cpp @@ -116,6 +116,7 @@ void EllipseTool::on_second_paint(Layer const* layer, GUI::PaintEvent& event) GUI::Painter painter(*m_editor); painter.add_clip_rect(event.rect()); + painter.translate(editor_layer_location(*layer)); auto preview_start = m_editor->content_to_frame_position(m_ellipse_start_position).to_type<int>(); auto preview_end = m_editor->content_to_frame_position(m_ellipse_end_position).to_type<int>(); draw_using(painter, preview_start, preview_end, AK::max(m_thickness * m_editor->scale(), 1)); diff --git a/Userland/Applications/PixelPaint/Tools/LineTool.cpp b/Userland/Applications/PixelPaint/Tools/LineTool.cpp index bbe7f50e47..a394494b0e 100644 --- a/Userland/Applications/PixelPaint/Tools/LineTool.cpp +++ b/Userland/Applications/PixelPaint/Tools/LineTool.cpp @@ -117,6 +117,7 @@ void LineTool::on_second_paint(Layer const* layer, GUI::PaintEvent& event) GUI::Painter painter(*m_editor); painter.add_clip_rect(event.rect()); + painter.translate(editor_layer_location(*layer)); auto preview_start = editor_stroke_position(m_line_start_position, m_thickness); auto preview_end = editor_stroke_position(m_line_end_position, m_thickness); draw_using(painter, preview_start, preview_end, m_editor->color_for(m_drawing_button), AK::max(m_thickness * m_editor->scale(), 1)); diff --git a/Userland/Applications/PixelPaint/Tools/RectangleTool.cpp b/Userland/Applications/PixelPaint/Tools/RectangleTool.cpp index efe9ee0058..5ec0f35122 100644 --- a/Userland/Applications/PixelPaint/Tools/RectangleTool.cpp +++ b/Userland/Applications/PixelPaint/Tools/RectangleTool.cpp @@ -123,6 +123,7 @@ void RectangleTool::on_second_paint(Layer const* layer, GUI::PaintEvent& event) GUI::Painter painter(*m_editor); painter.add_clip_rect(event.rect()); + painter.translate(editor_layer_location(*layer)); auto start_position = editor_stroke_position(m_rectangle_start_position, m_thickness); auto end_position = editor_stroke_position(m_rectangle_end_position, m_thickness); draw_using(painter, start_position, end_position, AK::max(m_thickness * m_editor->scale(), 1), m_corner_radius * m_editor->scale()); diff --git a/Userland/Applications/PixelPaint/Tools/Tool.cpp b/Userland/Applications/PixelPaint/Tools/Tool.cpp index 4c647b1d5b..86ea2160a9 100644 --- a/Userland/Applications/PixelPaint/Tools/Tool.cpp +++ b/Userland/Applications/PixelPaint/Tools/Tool.cpp @@ -8,6 +8,7 @@ #include "Tool.h" #include "../ImageEditor.h" +#include "../Layer.h" #include <LibGUI/Action.h> namespace PixelPaint { @@ -46,6 +47,11 @@ void Tool::on_keydown(GUI::KeyEvent& event) } } +Gfx::IntPoint Tool::editor_layer_location(Layer const& layer) const +{ + return (Gfx::FloatPoint { layer.location() } * m_editor->scale()).to_rounded<int>(); +} + Gfx::IntPoint Tool::editor_stroke_position(Gfx::IntPoint const& pixel_coords, int stroke_thickness) const { auto position = m_editor->content_to_frame_position(pixel_coords); diff --git a/Userland/Applications/PixelPaint/Tools/Tool.h b/Userland/Applications/PixelPaint/Tools/Tool.h index 14a9ed935c..379513a4af 100644 --- a/Userland/Applications/PixelPaint/Tools/Tool.h +++ b/Userland/Applications/PixelPaint/Tools/Tool.h @@ -79,6 +79,8 @@ protected: WeakPtr<ImageEditor> m_editor; RefPtr<GUI::Action> m_action; + Gfx::IntPoint editor_layer_location(Layer const& layer) const; + virtual Gfx::IntPoint editor_stroke_position(Gfx::IntPoint const& pixel_coords, int stroke_thickness) const; void set_primary_slider(GUI::ValueSlider* primary) { m_primary_slider = primary; } |