diff options
| author | Arne Dußin | 2020-11-02 11:51:18 +0100 |
|---|---|---|
| committer | Arne Dußin | 2020-11-02 11:51:18 +0100 |
| commit | b5603648a4c88585764ac70db9614504b9b57515 (patch) | |
| tree | b67f96ccb06c079f93d2cb871dcb15d2689e9a41 /src/main.rs | |
| parent | d2bd3e0e20f269c35dc74486af0578958fe21315 (diff) | |
| download | graf_karto-b5603648a4c88585764ac70db9614504b9b57515.tar.gz graf_karto-b5603648a4c88585764ac70db9614504b9b57515.zip | |
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.
Diffstat (limited to 'src/main.rs')
| -rw-r--r-- | src/main.rs | 13 |
1 files changed, 8 insertions, 5 deletions
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); |
