diff --git a/showimage.odin b/showimage.odin index b3c5463..16c8c35 100644 --- a/showimage.odin +++ b/showimage.odin @@ -26,9 +26,9 @@ main :: proc() { for !rl.WindowShouldClose() { scroll := rl.GetMouseWheelMove() if scroll > 0 { - zoom *= 2 + change_zoom(zoom) } else if scroll < 0 { - zoom /= 2 + change_zoom(-zoom / 2) } if rl.IsMouseButtonDown(rl.MouseButton.LEFT) { offset += rl.GetMouseDelta() @@ -47,6 +47,13 @@ main :: proc() { rl.CloseWindow() } +change_zoom :: proc(delta: f32) { + mouse_pos := rl.GetMousePosition() + zoom_pos := (mouse_pos - offset) / zoom + zoom += delta + offset = mouse_pos - zoom_pos * zoom +} + zoom_to_power :: proc(size: i32, max: i32) -> i32 { fit: i32 = 2 for fit * size < max {