From b5603648a4c88585764ac70db9614504b9b57515 Mon Sep 17 00:00:00 2001 From: Arne Dußin Date: Mon, 2 Nov 2020 11:51:18 +0100 Subject: Combine zooming in and zooming out into one function There was a lot of duplicate and hacky code in the zooming functions, so I made them cleaner while hopefully staying true to the idea. --- src/main.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index f116561..f3838a5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -26,11 +26,14 @@ fn main() { transform.move_by_px((rl.get_mouse_position() - last_mouse_pos).into()); } - // Handle scrolling of the canvas - if rl.get_mouse_wheel_move() > 0 { - transform.try_zoom_in(rl.get_mouse_position().into()); - } else if rl.get_mouse_wheel_move() < 0 { - transform.try_zoom_out(rl.get_mouse_position().into()); + let mouse_wheel_move = rl.get_mouse_wheel_move(); + if mouse_wheel_move != 0 { + // Zoom in for positive and zoom out for negative mouse wheel rotations. + let factor = if mouse_wheel_move > 0 { 1.2 } else { 1. / 1.2 }; + transform.try_zoom( + rl.get_mouse_position().into(), + mouse_wheel_move.abs() as f32 * factor, + ); } editor.update(&rl, &transform); -- cgit v1.2.3-70-g09d2