diff --git a/Userland/Applications/PixelPaint/LineTool.cpp b/Userland/Applications/PixelPaint/LineTool.cpp index fa47a00170..c6171be741 100644 --- a/Userland/Applications/PixelPaint/LineTool.cpp +++ b/Userland/Applications/PixelPaint/LineTool.cpp @@ -108,8 +108,8 @@ void LineTool::on_second_paint(Layer const* layer, GUI::PaintEvent& event) GUI::Painter painter(*m_editor); painter.add_clip_rect(event.rect()); - auto preview_start = m_editor->layer_position_to_editor_position(*layer, m_line_start_position).to_type(); - auto preview_end = m_editor->layer_position_to_editor_position(*layer, m_line_end_position).to_type(); + auto preview_start = editor_stroke_position(m_line_start_position, m_thickness); + auto preview_end = editor_stroke_position(m_line_end_position, m_thickness); painter.draw_line(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/RectangleTool.cpp b/Userland/Applications/PixelPaint/RectangleTool.cpp index f19b123e31..9b0821afdf 100644 --- a/Userland/Applications/PixelPaint/RectangleTool.cpp +++ b/Userland/Applications/PixelPaint/RectangleTool.cpp @@ -106,8 +106,8 @@ void RectangleTool::on_second_paint(Layer const* layer, GUI::PaintEvent& event) GUI::Painter painter(*m_editor); painter.add_clip_rect(event.rect()); - auto start_position = m_editor->layer_position_to_editor_position(*layer, m_rectangle_start_position).to_type(); - auto end_position = m_editor->layer_position_to_editor_position(*layer, m_rectangle_end_position).to_type(); + 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)); } diff --git a/Userland/Applications/PixelPaint/Tool.cpp b/Userland/Applications/PixelPaint/Tool.cpp index 0d747807b0..5c2255d2ce 100644 --- a/Userland/Applications/PixelPaint/Tool.cpp +++ b/Userland/Applications/PixelPaint/Tool.cpp @@ -53,4 +53,12 @@ void Tool::on_keydown(GUI::KeyEvent& event) } } +Gfx::IntPoint Tool::editor_stroke_position(Gfx::IntPoint const& pixel_coords, int stroke_thickness) const +{ + auto position = m_editor->image_position_to_editor_position(pixel_coords); + auto offset = (stroke_thickness % 2 == 0) ? m_editor->scale() : m_editor->scale() / 2; + position = position.translated(offset, offset); + return position.to_type(); +} + } diff --git a/Userland/Applications/PixelPaint/Tool.h b/Userland/Applications/PixelPaint/Tool.h index be2d783166..4e65271956 100644 --- a/Userland/Applications/PixelPaint/Tool.h +++ b/Userland/Applications/PixelPaint/Tool.h @@ -76,6 +76,8 @@ protected: WeakPtr m_editor; RefPtr m_action; + 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; } void set_secondary_slider(GUI::ValueSlider* secondary) { m_secondary_slider = secondary; }