@wcardinal/wcardinal-geditor
Version:
WebGL-based graphic editor, tester and viewer for supervisory systems
145 lines • 5.38 kB
JavaScript
import { __extends } from "tslib";
import { DApplications, EShapeAcceptorEdgeType, EShapeCircle, EShapeContainer, EShapeDefaults, EShapeLockPart } from "@wcardinal/wcardinal-ui";
var EToolShapeAcceptorEdgeRenderer = /** @class */ (function (_super) {
__extends(EToolShapeAcceptorEdgeRenderer, _super);
function EToolShapeAcceptorEdgeRenderer(edge) {
var _this = _super.call(this) || this;
_this._edge = edge;
_this._circles = _this.newCircles();
_this._foundEdges = [];
_this._radius = EShapeDefaults.SIZE_X * 2;
_this._scaleBound = 1;
_this._scaleBoundInverse = 1;
_this._type = EShapeAcceptorEdgeType.TAIL;
_this._x = 0;
_this._y = 0;
_this._ox = 0;
_this._oy = 0;
_this._isDirty = false;
_this._isBegan = false;
_this._doUpdateBound = function () {
_this._timeout = null;
if (_this._isDirty) {
_this._isDirty = false;
if (_this._isBegan) {
_this.visible = true;
_this.doUpdate();
}
}
};
return _this;
}
EToolShapeAcceptorEdgeRenderer.prototype.newCircles = function () {
var result = [];
var color = EShapeDefaults.STROKE_COLOR;
var alpha = EShapeDefaults.STROKE_ALPHA;
for (var i = 0, imax = 64; i < imax; ++i) {
var shape = new EShapeCircle();
shape.stroke.set(false);
shape.fill.set(true, color, alpha);
shape.visible = false;
shape.attach(this);
result.push(shape);
}
return result;
};
EToolShapeAcceptorEdgeRenderer.prototype.begin = function (canvas) {
canvas.addChild(this);
var layer = canvas.layer.active;
if (layer != null) {
var position = layer.transform.position;
this._ox = position.x;
this._oy = position.y;
}
else {
this._ox = 0;
this._oy = 0;
}
this.visible = false;
this._isBegan = true;
};
EToolShapeAcceptorEdgeRenderer.prototype.end = function () {
var parent = this.parent;
if (parent != null) {
parent.removeChild(this);
}
this.visible = false;
this._isBegan = false;
};
EToolShapeAcceptorEdgeRenderer.prototype.onPrerender = function () {
var scale0 = this.getParentScale();
var scale1 = this._scaleBound;
if (0.001 < Math.abs(scale0 - scale1)) {
this._scaleBound = scale0;
this._scaleBoundInverse = 1 / scale0;
var size = this.getCircleSize();
var circles = this._circles;
for (var i = 0, imax = circles.length; i < imax; ++i) {
circles[i].size.set(size, size);
}
}
};
EToolShapeAcceptorEdgeRenderer.prototype.render = function (renderer) {
if (!this.visible || this.worldAlpha <= 0 || !this.renderable) {
return;
}
this.onPrerender();
_super.prototype.render.call(this, renderer);
};
EToolShapeAcceptorEdgeRenderer.prototype.getParentScale = function () {
var parent = this.parent;
if (parent != null) {
return parent.scale.y;
}
return 1;
};
EToolShapeAcceptorEdgeRenderer.prototype.getCircleSize = function () {
return 10 * Math.min(1, this._scaleBoundInverse);
};
EToolShapeAcceptorEdgeRenderer.prototype.update = function (type, x, y) {
if (this._isBegan) {
this._type = type;
this._x = x;
this._y = y;
if (this._timeout == null) {
this.visible = true;
this.doUpdate();
this._timeout = window.setTimeout(this._doUpdateBound, 100);
}
else {
this._isDirty = true;
}
}
};
EToolShapeAcceptorEdgeRenderer.prototype.doUpdate = function () {
var radius = this._radius;
var circles = this._circles;
var circlesLength = circles.length;
var edges = this._foundEdges;
this._edge.findAll(this._type, this._x, this._y, radius, circlesLength, edges);
var edgesLength = edges.length;
var ox = this._ox;
var oy = this._oy;
var size = this.getCircleSize();
var isize = Math.min(circlesLength, edgesLength);
var distance = radius * radius;
for (var i = 0; i < isize; ++i) {
var edge = edges[i];
var edgeCenter = edge.center;
var circle = circles[i];
circle.lock(EShapeLockPart.UPLOADED);
circle.transform.position.set(ox + edgeCenter.x, oy + edgeCenter.y);
circle.size.set(size, size);
circle.fill.alpha = 0.5 * Math.max(0, 1 - edge.distance / distance);
circle.visible = true;
circle.unlock(EShapeLockPart.UPLOADED, true);
}
for (var i = isize; i < circlesLength; ++i) {
circles[i].visible = false;
}
DApplications.update(this);
};
return EToolShapeAcceptorEdgeRenderer;
}(EShapeContainer));
export { EToolShapeAcceptorEdgeRenderer };
//# sourceMappingURL=e-tool-shape-acceptor-edge-renderer.js.map