Files
AFFiNE-Mirror/blocksuite/affine/gfx/shape/src/overlay/rounded-rect.ts
T
2025-03-21 06:13:11 +00:00

33 lines
954 B
TypeScript

import type { RoughCanvas } from '@blocksuite/affine-block-surface';
import { Shape } from './shape';
import { drawGeneralShape } from './utils';
export class RoundedRectShape extends Shape {
draw(ctx: CanvasRenderingContext2D, rc: RoughCanvas): void {
if (this.shapeStyle === 'Scribbled') {
const [x, y, w, h] = this.xywh;
const radius = 0.1;
const r = Math.min(w * radius, h * radius);
const x0 = x + r;
const x1 = x + w - r;
const y0 = y + r;
const y1 = y + h - r;
const path = `
M${x0},${y} L${x1},${y}
A${r},${r} 0 0 1 ${x1},${y0}
L${x1},${y1}
A${r},${r} 0 0 1 ${x1 - r},${y1}
L${x0 + r},${y1}
A${r},${r} 0 0 1 ${x0},${y1 - r}
L${x0},${y0}
A${r},${r} 0 0 1 ${x0 + r},${y}
`;
rc.path(path, this.options);
} else {
drawGeneralShape(ctx, 'roundedRect', this.xywh, this.options);
}
}
}