Don't allow the user to zoom in so far that we run out of space in the glyph atlas

This commit is contained in:
Patrick Walton 2017-09-12 22:32:18 -07:00
parent f68da75c75
commit 65eecbf071
5 changed files with 13 additions and 5 deletions

View File

@ -130,7 +130,7 @@ class BenchmarkTestView extends PathfinderDemoView {
this.appController = appController; this.appController = appController;
this.camera = new OrthographicCamera(this.canvas); this.camera = new OrthographicCamera(this.canvas, false);
this.camera.onPan = () => this.setDirty(); this.camera.onPan = () => this.setDirty();
this.camera.onZoom = () => this.setDirty(); this.camera.onZoom = () => this.setDirty();
} }

View File

@ -18,6 +18,8 @@ const ORTHOGRAPHIC_ZOOM_SPEED: number = 1.0 / 100.0;
const ORTHOGRAPHIC_ZOOM_IN_FACTOR: number = 1.2; const ORTHOGRAPHIC_ZOOM_IN_FACTOR: number = 1.2;
const ORTHOGRAPHIC_ZOOM_OUT_FACTOR: number = 1.0 / ORTHOGRAPHIC_ZOOM_IN_FACTOR; const ORTHOGRAPHIC_ZOOM_OUT_FACTOR: number = 1.0 / ORTHOGRAPHIC_ZOOM_IN_FACTOR;
const ORTHOGRAPHIC_MAX_SCALE: number = 10.0;
const PERSPECTIVE_MOVEMENT_SPEED: number = 10.0; const PERSPECTIVE_MOVEMENT_SPEED: number = 10.0;
const PERSPECTIVE_ROTATION_SPEED: number = 1.0 / 300.0; const PERSPECTIVE_ROTATION_SPEED: number = 1.0 / 300.0;
@ -50,9 +52,11 @@ export abstract class Camera {
} }
export class OrthographicCamera extends Camera { export class OrthographicCamera extends Camera {
constructor(canvas: HTMLCanvasElement) { constructor(canvas: HTMLCanvasElement, limitedZoom: boolean) {
super(canvas); super(canvas);
this.limitedZoom = limitedZoom;
this.translation = glmatrix.vec2.create(); this.translation = glmatrix.vec2.create();
this.scale = 1.0; this.scale = 1.0;
@ -144,6 +148,8 @@ export class OrthographicCamera extends Camera {
glmatrix.vec2.scale(absoluteTranslation, absoluteTranslation, 1.0 / this.scale); glmatrix.vec2.scale(absoluteTranslation, absoluteTranslation, 1.0 / this.scale);
this.scale *= scale; this.scale *= scale;
if (this.limitedZoom && this.scale > ORTHOGRAPHIC_MAX_SCALE)
this.scale = ORTHOGRAPHIC_MAX_SCALE;
glmatrix.vec2.scale(absoluteTranslation, absoluteTranslation, this.scale); glmatrix.vec2.scale(absoluteTranslation, absoluteTranslation, this.scale);
glmatrix.vec2.add(this.translation, absoluteTranslation, point); glmatrix.vec2.add(this.translation, absoluteTranslation, point);
@ -171,6 +177,8 @@ export class OrthographicCamera extends Camera {
translation: glmatrix.vec2; translation: glmatrix.vec2;
scale: number; scale: number;
private readonly limitedZoom: boolean;
} }
export class PerspectiveCamera extends Camera { export class PerspectiveCamera extends Camera {

View File

@ -68,7 +68,7 @@ class MeshDebuggerView extends PathfinderView {
super(); super();
this.appController = appController; this.appController = appController;
this.camera = new OrthographicCamera(this.canvas); this.camera = new OrthographicCamera(this.canvas, false);
this.scale = 1.0; this.scale = 1.0;
} }

View File

@ -213,7 +213,7 @@ class SVGDemoView extends PathfinderDemoView {
this.appController = appController; this.appController = appController;
this.camera = new OrthographicCamera(this.canvas); this.camera = new OrthographicCamera(this.canvas, false);
this.camera.onPan = () => this.setDirty(); this.camera.onPan = () => this.setDirty();
this.camera.onZoom = () => this.setDirty(); this.camera.onZoom = () => this.setDirty();
} }

View File

@ -251,7 +251,7 @@ class TextDemoView extends MonochromePathfinderView {
this.appController = appController; this.appController = appController;
this.camera = new OrthographicCamera(this.canvas); this.camera = new OrthographicCamera(this.canvas, true);
this.camera.onPan = () => this.onPan(); this.camera.onPan = () => this.onPan();
this.camera.onZoom = () => this.onZoom(); this.camera.onZoom = () => this.onZoom();