|
|
@ -58,10 +58,13 @@ function debug_panel_init(state, context) { |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
document.getElementById('debug-begin-benchmark').addEventListener('click', (e) => { |
|
|
|
document.getElementById('debug-begin-benchmark').addEventListener('click', (e) => { |
|
|
|
state.canvas.zoom = config.benchmark.zoom; |
|
|
|
state.canvas.zoom_level = config.benchmark.zoom_level; |
|
|
|
state.canvas.offset.x = config.benchmark.offset.x; |
|
|
|
state.canvas.offset.x = config.benchmark.offset.x; |
|
|
|
state.canvas.offset.y = config.benchmark.offset.y; |
|
|
|
state.canvas.offset.y = config.benchmark.offset.y; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const dz = (state.canvas.zoom_level > 0 ? config.zoom_delta : -config.zoom_delta); |
|
|
|
|
|
|
|
state.canvas.zoom = Math.pow(1.0 + dz, Math.abs(state.canvas.zoom_level)) |
|
|
|
|
|
|
|
|
|
|
|
state.debug.benchmark_mode = true; |
|
|
|
state.debug.benchmark_mode = true; |
|
|
|
|
|
|
|
|
|
|
|
const origin_x = state.canvas.offset.x; |
|
|
|
const origin_x = state.canvas.offset.x; |
|
|
@ -328,31 +331,29 @@ function wheel(e, state, context) { |
|
|
|
const screenp = {'x': window.devicePixelRatio * e.clientX, 'y': window.devicePixelRatio * e.clientY}; |
|
|
|
const screenp = {'x': window.devicePixelRatio * e.clientX, 'y': window.devicePixelRatio * e.clientY}; |
|
|
|
const canvasp = screen_to_canvas(state, screenp); |
|
|
|
const canvasp = screen_to_canvas(state, screenp); |
|
|
|
|
|
|
|
|
|
|
|
const dz = (e.deltaY < 0 ? 0.1 : -0.1); |
|
|
|
const zooming_in = e.deltaY < 0; |
|
|
|
const old_zoom = state.canvas.zoom; |
|
|
|
const zoom_level = zooming_in ? state.canvas.zoom_level + 1 : state.canvas.zoom_level - 1; |
|
|
|
|
|
|
|
|
|
|
|
state.canvas.zoom *= (1.0 + dz); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (state.canvas.zoom > config.max_zoom) { |
|
|
|
if (zoom_level < config.min_zoom_level || zoom_level > config.max_zoom_level) { |
|
|
|
state.canvas.zoom = old_zoom; |
|
|
|
|
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (state.canvas.zoom < config.min_zoom) { |
|
|
|
state.canvas.zoom_level = zoom_level; |
|
|
|
state.canvas.zoom = old_zoom; |
|
|
|
|
|
|
|
return; |
|
|
|
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)) |
|
|
|
|
|
|
|
|
|
|
|
// If we are moving our canvas, we don't need to follow anymore
|
|
|
|
// If we are moving our canvas, we don't need to follow anymore
|
|
|
|
if (state.following_player !== null) { |
|
|
|
if (state.following_player !== null) { |
|
|
|
toggle_follow_player(state, state.following_player); |
|
|
|
toggle_follow_player(state, state.following_player); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const zoom_offset_x = Math.round((dz * old_zoom) * canvasp.x); |
|
|
|
|
|
|
|
const zoom_offset_y = Math.round((dz * old_zoom) * canvasp.y); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
state.canvas.offset.x -= zoom_offset_x; |
|
|
|
// https://gist.github.com/aolo2/a373363419bd5a9283977ab9f8841f78
|
|
|
|
state.canvas.offset.y -= zoom_offset_y; |
|
|
|
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; |
|
|
|
|
|
|
|
|
|
|
|
fire_event(state, movecanvas_event(state)); |
|
|
|
fire_event(state, movecanvas_event(state)); |
|
|
|
|
|
|
|
|
|
|
|