diff --git a/src/grid.odin b/src/grid.odin index c8610c8..180e724 100644 --- a/src/grid.odin +++ b/src/grid.odin @@ -38,6 +38,15 @@ grid_world_to_grid_matrix :: proc(zoom, offset: v2) -> mat3 { 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) { world_to_grid_matrix := grid_world_to_grid_matrix(grid.zoom, grid.offset) grid_to_world_matrix := linalg.inverse(world_to_grid_matrix) diff --git a/src/program.odin b/src/program.odin index 5ef882e..1f9553e 100644 --- a/src/program.odin +++ b/src/program.odin @@ -905,9 +905,9 @@ program_handle_mouse :: proc(mouse_state: MouseState, top_bar_container, matrix_ mouse_state = .DraggingGrid break state_label } - program.grid.zoom_previous = program.grid.zoom - grid_zoom_dimension_lock := v2{1.0 - f32(int(program.grid_zoom_y_only)), 1.0 - f32(int(program.grid_zoom_x_only))} - program.grid.zoom -= grid_zoom_dimension_lock * mouse_wheel.y * 0.2 * program.grid_zoom_speed + screen_size := v2(program_screen_size()) + 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) + case .DraggingDraggable: if !rl.IsMouseButtonDown(.LEFT) { mouse_state = .Hover