|
|
|
@ -393,8 +393,6 @@ function update_cursor(state) {
@@ -393,8 +393,6 @@ function update_cursor(state) {
|
|
|
|
|
|
|
|
|
|
function wheel(e, state, context) { |
|
|
|
|
const screenp = {'x': window.devicePixelRatio * e.clientX, 'y': window.devicePixelRatio * e.clientY}; |
|
|
|
|
const canvasp = screen_to_canvas(state, screenp); |
|
|
|
|
|
|
|
|
|
const zooming_in = e.deltaY < 0; |
|
|
|
|
const zoom_level = zooming_in ? state.canvas.zoom_level + 1 : state.canvas.zoom_level - 1; |
|
|
|
|
|
|
|
|
@ -402,24 +400,16 @@ function wheel(e, state, context) {
@@ -402,24 +400,16 @@ function wheel(e, state, context) {
|
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
state.canvas.zoom_level = zoom_level; |
|
|
|
|
|
|
|
|
|
const dz = (zoom_level > 0 ? config.zoom_delta : -config.zoom_delta); |
|
|
|
|
const old_zoom = state.canvas.zoom; |
|
|
|
|
const new_zoom = Math.pow(1.0 + dz, Math.abs(zoom_level)) |
|
|
|
|
state.canvas.zoom_level = zoom_level; |
|
|
|
|
state.canvas.target_zoom = Math.pow(1.0 + dz, Math.abs(zoom_level)) |
|
|
|
|
state.canvas.zoom_screenp = screenp; |
|
|
|
|
|
|
|
|
|
// If we are moving our canvas, we don't need to follow anymore
|
|
|
|
|
if (state.following_player !== null) { |
|
|
|
|
toggle_follow_player(state, state.following_player); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// https://gist.github.com/aolo2/a373363419bd5a9283977ab9f8841f78
|
|
|
|
|
state.canvas.offset.x = screenp.x - (screenp.x - state.canvas.offset.x) * new_zoom / old_zoom; |
|
|
|
|
state.canvas.offset.y = screenp.y - (screenp.y - state.canvas.offset.y) * new_zoom / old_zoom; |
|
|
|
|
|
|
|
|
|
state.canvas.zoom = new_zoom; |
|
|
|
|
|
|
|
|
|
update_cursor(state); |
|
|
|
|
fire_event(state, movecanvas_event(state)); |
|
|
|
|
schedule_draw(state, context); |
|
|
|
|
} |
|
|
|
|