PixelPaint: Draw polygonal select tool lines with two colors

This stops lines from disappearing when entering a dark area of the
image.
This commit is contained in:
Tim Ledbetter 2023-01-06 00:53:54 +00:00 committed by Linus Groh
parent 2f6c71c829
commit 0cf29f6c45
Notes: sideshowbarker 2024-07-17 10:05:47 +09:00

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, the SerenityOS developers.
* Copyright (c) 2022-2023, the SerenityOS developers.
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -139,15 +139,20 @@ void PolygonalSelectTool::on_second_paint(Layer const* layer, GUI::PaintEvent& e
painter.translate(editor_layer_location(*layer));
for (size_t i = 0; i < m_polygon_points.size() - 1; i++) {
auto preview_start = editor_stroke_position(m_polygon_points.at(i), 1);
auto preview_end = editor_stroke_position(m_polygon_points.at(i + 1), 1);
painter.draw_line(preview_start, preview_end, Color::Black, 1);
}
auto draw_preview_lines = [&](auto color, auto thickness) {
for (size_t i = 0; i < m_polygon_points.size() - 1; i++) {
auto preview_start = editor_stroke_position(m_polygon_points.at(i), 1);
auto preview_end = editor_stroke_position(m_polygon_points.at(i + 1), 1);
painter.draw_line(preview_start, preview_end, color, thickness);
}
auto last_line_start = editor_stroke_position(m_polygon_points.at(m_polygon_points.size() - 1), 1);
auto last_line_stop = editor_stroke_position(m_last_selecting_cursor_position, 1);
painter.draw_line(last_line_start, last_line_stop, Color::Black, 1);
auto last_line_start = editor_stroke_position(m_polygon_points.at(m_polygon_points.size() - 1), 1);
auto last_line_stop = editor_stroke_position(m_last_selecting_cursor_position, 1);
painter.draw_line(last_line_start, last_line_stop, color, thickness);
};
draw_preview_lines(Gfx::Color::Black, 3);
draw_preview_lines(Gfx::Color::White, 1);
}
bool PolygonalSelectTool::on_keydown(GUI::KeyEvent& key_event)