mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 09:38:11 +00:00
PixelPaint: Fix Line/Rectangle second paint alignment with pixels
The problem was a bit more complex than originally anticipated, and the root of the problem is that the "coordinates" of a pixel are actually the top left of the pixel, and when we're really zoomed in, the difference in editor coordinates of the top-left and the center of the pixel is significant. So, we need to offset the "start" point when we are painting on the editor to account for this, based on the current scale. This patch adds a `editor_stroke_position` in `Tool` which can be used to compute what point (in editor coords) we should use for a given pixel and it's corresponding stroke thickness. Note that this doesn't really work well with the ellipse, since that is drawn with a different mechanism. Using this new method with the `EllipseTool` seems to give the same (or slightly worse) results, so I have not changed anything there for now.
This commit is contained in:
parent
9097f86e51
commit
1d47d41c01
4 changed files with 14 additions and 4 deletions
|
@ -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<int>();
|
||||
auto end_position = m_editor->layer_position_to_editor_position(*layer, m_rectangle_end_position).to_type<int>();
|
||||
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));
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue