Sfoglia il codice sorgente

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.
MacDue 2 anni fa
parent
commit
78813313f9

+ 1 - 0
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));

+ 1 - 0
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));

+ 1 - 0
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());

+ 6 - 0
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);

+ 2 - 0
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; }