Files
game-cards-poker-design/frontend/node_modules/fabric/dist-extensions/aligning_guidelines/util/draw.mjs
Poker Design Developer 5dbcebf7a2 Fix frontend blank page issues
- Fix router import path in main.js
- Handle Django REST Framework pagination format in API calls
- Add getTemplates function to project API
- Restart frontend development server
2026-05-31 18:40:56 +08:00

72 lines
2.1 KiB
JavaScript

import { Point } from "fabric";
//#region extensions/aligning_guidelines/util/draw.ts
function drawLine(origin, target) {
const ctx = this.canvas.getTopContext();
const viewportTransform = this.canvas.viewportTransform;
const zoom = this.canvas.getZoom();
ctx.save();
ctx.transform(...viewportTransform);
ctx.lineWidth = this.width / zoom;
if (this.lineDash) ctx.setLineDash(this.lineDash);
ctx.strokeStyle = this.color;
ctx.beginPath();
ctx.moveTo(origin.x, origin.y);
ctx.lineTo(target.x, target.y);
ctx.stroke();
if (this.lineDash) ctx.setLineDash([]);
this.drawX(origin, -1);
this.drawX(target, 1);
ctx.restore();
}
function drawX(point, _) {
const ctx = this.canvas.getTopContext();
const zoom = this.canvas.getZoom();
const size = this.xSize / zoom;
ctx.save();
ctx.translate(point.x, point.y);
ctx.beginPath();
ctx.moveTo(-size, -size);
ctx.lineTo(size, size);
ctx.moveTo(size, -size);
ctx.lineTo(-size, size);
ctx.stroke();
ctx.restore();
}
function drawPoint(arr) {
const ctx = this.canvas.getTopContext();
const viewportTransform = this.canvas.viewportTransform;
const zoom = this.canvas.getZoom();
ctx.save();
ctx.transform(...viewportTransform);
ctx.lineWidth = this.width / zoom;
ctx.strokeStyle = this.color;
for (const item of arr) this.drawX(item, 0);
ctx.restore();
}
function drawPointList() {
const list = [];
if (!this.closeVLine) for (const v of this.verticalLines) list.push(JSON.parse(v));
if (!this.closeHLine) for (const h of this.horizontalLines) list.push(JSON.parse(h));
const arr = list.map((item) => item.target);
drawPoint.call(this, arr);
}
function drawVerticalLine() {
if (this.closeVLine) return;
for (const v of this.verticalLines) {
const { origin, target } = JSON.parse(v);
const o = new Point(target.x, origin.y);
this.drawLine(o, target);
}
}
function drawHorizontalLine() {
if (this.closeHLine) return;
for (const v of this.horizontalLines) {
const { origin, target } = JSON.parse(v);
const o = new Point(origin.x, target.y);
this.drawLine(o, target);
}
}
//#endregion
export { drawHorizontalLine, drawLine, drawPointList, drawVerticalLine, drawX };
//# sourceMappingURL=draw.mjs.map