mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-26 22:38:51 +00:00
LibDraw: Add Rect::from_two_points(Point, Point)
This returns the rectangle between two given Points. Thanks Owlinator for suggesting this much easier way of doing it :^)
This commit is contained in:
parent
32ff660aa5
commit
6685be36a0
Notes:
sideshowbarker
2024-07-19 11:10:53 +09:00
Author: https://github.com/awesomekling
Commit: 6685be36a0
2 changed files with 7 additions and 16 deletions
|
@ -142,25 +142,11 @@ void CursorTool::set_rubber_band_position(const Point& position)
|
|||
m_editor.form_widget().update();
|
||||
}
|
||||
|
||||
static Rect rect_from_two_points(const Point& a, const Point& b)
|
||||
{
|
||||
if (a.x() <= b.x()) {
|
||||
if (a.y() <= b.y())
|
||||
return { a, { b.x() - a.x(), b.y() - a.y() } };
|
||||
int height = a.y() - b.y();
|
||||
return { a.x(), a.y() - height, b.x() - a.x(), height };
|
||||
}
|
||||
if (a.y() >= b.y())
|
||||
return { b, { a.x() - b.x(), a.y() - b.y() } };
|
||||
int height = b.y() - a.y();
|
||||
return { b.x(), b.y() - height, a.x() - b.x(), height };
|
||||
}
|
||||
|
||||
Rect CursorTool::rubber_band_rect() const
|
||||
{
|
||||
if (!m_rubber_banding)
|
||||
return {};
|
||||
return rect_from_two_points(m_rubber_band_origin, m_rubber_band_position);
|
||||
return Rect::from_two_points(m_rubber_band_origin, m_rubber_band_position);
|
||||
}
|
||||
|
||||
void CursorTool::on_second_paint(GPainter& painter, GPaintEvent&)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue