File tree Expand file tree Collapse file tree 1 file changed +9
-1
lines changed
Userland/Demos/Mandelbrot Expand file tree Collapse file tree 1 file changed +9
-1
lines changed Original file line number Diff line number Diff line change @@ -152,7 +152,15 @@ void Mandelbrot::mousedown_event(GUI::MouseEvent& event)
152
152
void Mandelbrot::mousemove_event (GUI::MouseEvent& event)
153
153
{
154
154
if (m_dragging) {
155
- m_selection_end = event.position ();
155
+ // Maintain aspect ratio
156
+ int selection_width = event.position ().x () - m_selection_start.x ();
157
+ int selection_height = event.position ().y () - m_selection_start.y ();
158
+ int aspect_corrected_selection_width = selection_height * width () / height ();
159
+ int aspect_corrected_selection_height = selection_width * height () / width ();
160
+ if (selection_width * aspect_corrected_selection_height > aspect_corrected_selection_width * selection_height)
161
+ m_selection_end = { event.position ().x (), m_selection_start.y () + abs (aspect_corrected_selection_height) * ((selection_height < 0 ) ? -1 : 1 ) };
162
+ else
163
+ m_selection_end = { m_selection_start.x () + abs (aspect_corrected_selection_width) * ((selection_width < 0 ) ? -1 : 1 ), event.position ().y () };
156
164
update ();
157
165
}
158
166
You can’t perform that action at this time.
0 commit comments