center zooming on mouse
This commit is contained in:
parent
7a1de9d871
commit
e1e4dfb650
1 changed files with 9 additions and 2 deletions
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue