mirror of
https://github.com/RGBCube/serenity
synced 2025-06-25 18:32:10 +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
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)
|
void Mandelbrot::mousemove_event(GUI::MouseEvent& event)
|
||||||
{
|
{
|
||||||
if (m_dragging) {
|
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();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue