mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
Mandelbrot: Maintain aspect ratio when selecting a region
This makes sure the aspect ratio of the widget and the selection match. Otherwise you'd end up with distorted images when zooming in.
This commit is contained in:
parent
198a4e2a3c
commit
c961616e6d
Notes:
sideshowbarker
2024-07-18 17:52:16 +09:00
Author: https://github.com/gunnarbeutner Commit: https://github.com/SerenityOS/serenity/commit/c961616e6df Pull-request: https://github.com/SerenityOS/serenity/pull/7214 Reviewed-by: https://github.com/bgianfo ✅
1 changed files with 9 additions and 1 deletions
|
@ -152,7 +152,15 @@ void Mandelbrot::mousedown_event(GUI::MouseEvent& event)
|
|||
void Mandelbrot::mousemove_event(GUI::MouseEvent& event)
|
||||
{
|
||||
if (m_dragging) {
|
||||
m_selection_end = event.position();
|
||||
// Maintain aspect ratio
|
||||
int selection_width = event.position().x() - m_selection_start.x();
|
||||
int selection_height = event.position().y() - m_selection_start.y();
|
||||
int aspect_corrected_selection_width = selection_height * width() / height();
|
||||
int aspect_corrected_selection_height = selection_width * height() / width();
|
||||
if (selection_width * aspect_corrected_selection_height > aspect_corrected_selection_width * selection_height)
|
||||
m_selection_end = { event.position().x(), m_selection_start.y() + abs(aspect_corrected_selection_height) * ((selection_height < 0) ? -1 : 1) };
|
||||
else
|
||||
m_selection_end = { m_selection_start.x() + abs(aspect_corrected_selection_width) * ((selection_width < 0) ? -1 : 1), event.position().y() };
|
||||
update();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue