sprotty
Version:
A next-gen framework for graphical views
82 lines • 3.04 kB
JavaScript
"use strict";
/********************************************************************************
* Copyright (c) 2017-2018 TypeFox and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the Eclipse
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
* with the GNU Classpath Exception which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/
Object.defineProperty(exports, "__esModule", { value: true });
exports.ViewportRootElementImpl = void 0;
const geometry_1 = require("sprotty-protocol/lib/utils/geometry");
const smodel_1 = require("../../base/model/smodel");
const model_1 = require("./model");
const model_2 = require("../export/model");
/**
* Model root element that defines a viewport, so it transforms the coordinate system with
* a `scroll` translation and a `zoom` scaling.
*/
class ViewportRootElementImpl extends smodel_1.SModelRootImpl {
constructor(index) {
super(index);
this.scroll = { x: 0, y: 0 };
this.zoom = 1;
this.position = geometry_1.Point.ORIGIN;
this.size = geometry_1.Dimension.EMPTY;
}
get bounds() {
return {
x: this.position.x,
y: this.position.y,
width: this.size.width,
height: this.size.height
};
}
set bounds(newBounds) {
this.position = {
x: newBounds.x,
y: newBounds.y
};
this.size = {
width: newBounds.width,
height: newBounds.height
};
}
localToParent(point) {
const result = {
x: (point.x - this.scroll.x) * this.zoom,
y: (point.y - this.scroll.y) * this.zoom,
width: -1,
height: -1
};
if ((0, geometry_1.isBounds)(point)) {
result.width = point.width * this.zoom;
result.height = point.height * this.zoom;
}
return result;
}
parentToLocal(point) {
const result = {
x: (point.x / this.zoom) + this.scroll.x,
y: (point.y / this.zoom) + this.scroll.y,
width: -1,
height: -1
};
if ((0, geometry_1.isBounds)(point) && geometry_1.Dimension.isValid(point)) {
result.width = point.width / this.zoom;
result.height = point.height / this.zoom;
}
return result;
}
}
exports.ViewportRootElementImpl = ViewportRootElementImpl;
ViewportRootElementImpl.DEFAULT_FEATURES = [model_1.viewportFeature, model_2.exportFeature];
//# sourceMappingURL=viewport-root.js.map