@aurigma/design-atoms
Version:
Design Atoms is a part of Customer's Canvas SDK which allows for manipulating individual design elements through your code.
74 lines • 2.8 kB
JavaScript
import { LineItemHandler } from "./LineItemHandler";
import { Graphics } from "../Graphics";
export class DashedLineItemHandler extends LineItemHandler {
constructor(item, textWhizz = null, colorPreviewService) {
super(item, textWhizz, colorPreviewService);
}
get item() {
return this._getItem();
}
get dashWidth() {
return this.item.dashWidth;
}
set dashWidth(value) {
this.item.dashWidth = value;
}
get altDashWidth() {
return this.item.altDashWidth;
}
set altDashWidth(value) {
this.item.altDashWidth = value;
}
get altColor() {
return this.item.altColor;
}
set altColor(value) {
this.item.altColor = value;
}
drawItemHandler(itemHandlerCtx) {
const width = this._getActualWidth();
if (itemHandlerCtx == null || width <= 0) {
return;
}
if (!this._isReadyToDraw) {
this.canvas.drawWaitClock(itemHandlerCtx, this.rectangle.center);
return;
}
const { colorPreview, altColorPreview } = this._getItemColorPreviews();
const startPoint = this.point0;
const endPoint = this.point1;
let dashWidth = this.dashWidth;
let altDashWidth = this.altDashWidth;
if (this.fixedWidth) {
const zoom = this.canvas.zoom;
dashWidth /= zoom;
altDashWidth /= zoom;
}
Graphics.drawDashedLine(itemHandlerCtx, startPoint.x, startPoint.y, endPoint.x, endPoint.y, width, colorPreview === null || colorPreview === void 0 ? void 0 : colorPreview.toString(), altColorPreview === null || altColorPreview === void 0 ? void 0 : altColorPreview.toString(), dashWidth, altDashWidth, this.item.opacity);
}
_getColors() {
return [this.color, this.altColor, ...super._getColors()];
}
_getItemColorPreviews() {
const { colorPreview } = super._getItemColorPreviews();
const altColorPreview = this._colorPreviewService.getPreview(this.item.altColor);
if (this.item.altColor != null && altColorPreview == null) {
this._colorPreviewService.subscribeToPreviewLoaded(this.item.altColor, this._onColorPreviewLoaded);
}
return {
colorPreview: colorPreview,
altColorPreview: altColorPreview
};
}
_onItemPropertyChanged(sender, propertyName) {
switch (propertyName) {
case "altColor":
case "dashWidth":
case "altDashWidth":
this.canvas.redraw();
break;
}
super._onItemPropertyChanged(sender, propertyName);
}
}
//# sourceMappingURL=DashedLineItemHandler.js.map