WIP
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { SquareStyle } from "../../types";
|
||||
import createGradient from "../fill/createGradient";
|
||||
import createPattern from "../fill/createPattern";
|
||||
import loadImage from "../loaders/loadImage";
|
||||
|
||||
const drawRectangle = async (
|
||||
ctx: CanvasRenderingContext2D,
|
||||
@@ -10,11 +10,15 @@ const drawRectangle = async (
|
||||
y: number,
|
||||
squareStyle: SquareStyle
|
||||
) => {
|
||||
if (squareStyle.type === "image") {
|
||||
const img = await loadImage(squareStyle.data.src);
|
||||
ctx.drawImage(img, x, y, width, height);
|
||||
return;
|
||||
}
|
||||
|
||||
const fill = await (squareStyle.type === "solid"
|
||||
? squareStyle.data.color
|
||||
: squareStyle.type === "gradient"
|
||||
? createGradient(ctx, squareStyle.data, width, height, x, y)
|
||||
: createPattern(ctx, squareStyle.data));
|
||||
: createGradient(ctx, squareStyle.data, width, height, x, y));
|
||||
|
||||
if (fill === null) {
|
||||
throw new Error("Cannot create canvas fill style");
|
||||
|
||||
Reference in New Issue
Block a user