From 78813313f9f1946afad202acfc537c7d0d465de4 Mon Sep 17 00:00:00 2001 From: MacDue Date: Sat, 20 Aug 2022 18:09:20 +0100 Subject: 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. --- Userland/Applications/PixelPaint/Tools/EllipseTool.cpp | 1 + Userland/Applications/PixelPaint/Tools/LineTool.cpp | 1 + Userland/Applications/PixelPaint/Tools/RectangleTool.cpp | 1 + Userland/Applications/PixelPaint/Tools/Tool.cpp | 6 ++++++ Userland/Applications/PixelPaint/Tools/Tool.h | 2 ++ 5 files changed, 11 insertions(+) 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(); auto preview_end = m_editor->content_to_frame_position(m_ellipse_end_position).to_type(); 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 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(); +} + 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 m_editor; RefPtr 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; } -- cgit v1.2.3