mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
feat: add line shape (#371)
* feat: add line shape * fix: align line tool * fix: hitbox bug sw to ne * fix: add stroke width n sloppiness for line * fix: center line inside a panel box * fix: use color as a unique key
This commit is contained in:
parent
42968ef44d
commit
8db8827c6f
8 changed files with 61 additions and 5 deletions
|
@ -1,6 +1,10 @@
|
|||
import { ExcalidrawElement } from "../element/types";
|
||||
import { isTextElement } from "../element/typeChecks";
|
||||
import { getDiamondPoints, getArrowPoints } from "../element/bounds";
|
||||
import {
|
||||
getDiamondPoints,
|
||||
getArrowPoints,
|
||||
getLinePoints
|
||||
} from "../element/bounds";
|
||||
import { RoughCanvas } from "roughjs/bin/canvas";
|
||||
import { Drawable } from "roughjs/bin/core";
|
||||
|
||||
|
@ -118,6 +122,22 @@ export function renderElement(
|
|||
(element.shape as Drawable[]).forEach(shape => rc.draw(shape));
|
||||
context.globalAlpha = 1;
|
||||
return;
|
||||
} else if (element.type === "line") {
|
||||
const [x1, y1, x2, y2] = getLinePoints(element);
|
||||
const options = {
|
||||
stroke: element.strokeColor,
|
||||
strokeWidth: element.strokeWidth,
|
||||
roughness: element.roughness,
|
||||
seed: element.seed
|
||||
};
|
||||
|
||||
if (!element.shape) {
|
||||
element.shape = generator.line(x1, y1, x2, y2, options);
|
||||
}
|
||||
|
||||
context.globalAlpha = element.opacity / 100;
|
||||
rc.draw(element.shape as Drawable);
|
||||
context.globalAlpha = 1;
|
||||
} else if (isTextElement(element)) {
|
||||
context.globalAlpha = element.opacity / 100;
|
||||
const font = context.font;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue