improved zooming

This commit is contained in:
MaxRobinsonTheGreat
2024-07-20 14:35:10 -05:00
parent f59caf4086
commit 2207eed78b

View File

@@ -18,18 +18,18 @@ class EnvironmentController extends CanvasController{
defineZoomControls() {
var scale = 1;
var zoom_speed = 0.5;
var zoom_speed = 0.7;
const el = document.querySelector('#env-canvas');
el.onwheel = function zoom(event) {
event.preventDefault();
var sign = Math.sign(event.deltaY);
// Update the scale by multiplying it with the zoom speed raised to the power of the scroll direction (positive or negative)
scale *= Math.pow(zoom_speed, sign);
// Make sure the scale doesn't go below a minimum value or above a maximum value
scale = Math.min(64, Math.max(Math.pow(2, -10), scale));
const MAX = 32;
const MIN = Math.pow(2, -3);
scale = Math.min(MAX, Math.max(MIN, scale));
var cur_top = parseInt($('#env-canvas').css('top'));
var cur_left = parseInt($('#env-canvas').css('left'));
@@ -157,8 +157,8 @@ class EnvironmentController extends CanvasController{
}
dragScreen() {
var cur_top = parseInt($('#env-canvas').css('top'), 10);
var cur_left = parseInt($('#env-canvas').css('left'), 10);
var cur_top = parseInt($('#env-canvas').css('top'));
var cur_left = parseInt($('#env-canvas').css('left'));
var new_top = cur_top + ((this.mouse_y - this.start_y)*this.scale);
var new_left = cur_left + ((this.mouse_x - this.start_x)*this.scale);
$('#env-canvas').css('top', new_top+'px');