Zooming in on mouse
This commit is contained in:
parent
9614049610
commit
ef350183e2
2 changed files with 12 additions and 3 deletions
|
|
@ -38,6 +38,15 @@ grid_world_to_grid_matrix :: proc(zoom, offset: v2) -> mat3 {
|
||||||
return matrix3_translate2(offset) * matrix3_scale2(zoom_amount)
|
return matrix3_translate2(offset) * matrix3_scale2(zoom_amount)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
grid_zoom_in_on :: proc(grid: ^Grid, world_area: rect2, position: v2, amount: f32) {
|
||||||
|
area_size := rect_get_br(world_area)
|
||||||
|
mouse_screen_fraction := linalg.clamp(rl.GetMousePosition(), v2(0), area_size) / area_size
|
||||||
|
previous := matrix3_transform_xy(grid_world_to_grid_matrix(program.grid.zoom, program.grid.offset), area_size)
|
||||||
|
program.grid.zoom -= amount
|
||||||
|
current := matrix3_transform_xy(grid_world_to_grid_matrix(program.grid.zoom, program.grid.offset), area_size)
|
||||||
|
program.grid.offset -= (current - previous) * mouse_screen_fraction
|
||||||
|
}
|
||||||
|
|
||||||
draw_grid :: proc(grid: Grid, area, text_draw, text_clip: rect2, color: rl.Color) {
|
draw_grid :: proc(grid: Grid, area, text_draw, text_clip: rect2, color: rl.Color) {
|
||||||
world_to_grid_matrix := grid_world_to_grid_matrix(grid.zoom, grid.offset)
|
world_to_grid_matrix := grid_world_to_grid_matrix(grid.zoom, grid.offset)
|
||||||
grid_to_world_matrix := linalg.inverse(world_to_grid_matrix)
|
grid_to_world_matrix := linalg.inverse(world_to_grid_matrix)
|
||||||
|
|
|
||||||
|
|
@ -905,9 +905,9 @@ program_handle_mouse :: proc(mouse_state: MouseState, top_bar_container, matrix_
|
||||||
mouse_state = .DraggingGrid
|
mouse_state = .DraggingGrid
|
||||||
break state_label
|
break state_label
|
||||||
}
|
}
|
||||||
program.grid.zoom_previous = program.grid.zoom
|
screen_size := v2(program_screen_size())
|
||||||
grid_zoom_dimension_lock := v2{1.0 - f32(int(program.grid_zoom_y_only)), 1.0 - f32(int(program.grid_zoom_x_only))}
|
grid_zoom_in_on(&program.grid, {0, 0, screen_size.x, screen_size.y}, rl.GetMousePosition(), mouse_wheel.y * 0.1 * program.grid_zoom_speed)
|
||||||
program.grid.zoom -= grid_zoom_dimension_lock * mouse_wheel.y * 0.2 * program.grid_zoom_speed
|
|
||||||
case .DraggingDraggable:
|
case .DraggingDraggable:
|
||||||
if !rl.IsMouseButtonDown(.LEFT) {
|
if !rl.IsMouseButtonDown(.LEFT) {
|
||||||
mouse_state = .Hover
|
mouse_state = .Hover
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue