mirror of
https://github.com/sbrl/Nibriboard.git
synced 2018-01-10 21:33:49 +00:00
Clamp the zoom to avoid crashes.
This commit is contained in:
parent
441cb5a283
commit
1845e38613
2 changed files with 19 additions and 3 deletions
|
@ -10,7 +10,7 @@ import RippleLink from './RippleLink';
|
|||
import CursorSyncer from './CursorSyncer';
|
||||
import OtherClient from './OtherClient';
|
||||
import Pencil from './Pencil';
|
||||
import { get } from './Utilities';
|
||||
import { get, clamp } from './Utilities';
|
||||
import Keyboard from './Utilities/Keyboard';
|
||||
import Interface from './Interface';
|
||||
import ChunkCache from './ChunkCache';
|
||||
|
@ -72,7 +72,7 @@ class BoardWindow extends EventEmitter
|
|||
zoomLevel: 1,
|
||||
|
||||
toString() {
|
||||
return `${+this.width.toFixed(2)}x${+this.height.toFixed(2)} @ (${+this.x.toFixed(2)}, ${+this.y.toFixed(2)}) @ ${+this.zoomLevel.toFixed(2)}`
|
||||
return `${+this.width.toFixed(2)}x${+this.height.toFixed(2)} @ (${+this.x.toFixed(2)}, ${+this.y.toFixed(2)}) @ ${+this.zoomLevel.toFixed(2)}x`
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -369,6 +369,7 @@ class BoardWindow extends EventEmitter
|
|||
this.viewport.x -= event.dx * 1/this.viewport.zoomLevel;
|
||||
this.viewport.y -= event.dy * 1/this.viewport.zoomLevel;
|
||||
this.viewport.zoomLevel += event.dz / 1000;
|
||||
this.viewport.zoomLevel = clamp(this.viewport.zoomLevel, 0.1, 10000);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -2,6 +2,21 @@
|
|||
|
||||
function get(u){return new Promise(function(r,t,a){a=new XMLHttpRequest();a.onload=function(b,c){b=a.status;c=a.response;if(b>199&&b<300){r(c)}else{t(c)}};a.open("GET",u,true);a.send(null)})}
|
||||
|
||||
/**
|
||||
* Clamps x to be between min and max.
|
||||
* @param {number} x The number to clamp.
|
||||
* @param {number} min The minimum allowed value.
|
||||
* @param {number} max The maximum allowed value.
|
||||
* @return {number} The clamped number.
|
||||
*/
|
||||
function clamp(x, min, max)
|
||||
{
|
||||
if(x < min) return min;
|
||||
if(x > max) return max;
|
||||
return x;
|
||||
}
|
||||
|
||||
export {
|
||||
get
|
||||
get,
|
||||
clamp
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue