Added ctx to draw methods

This commit is contained in:
2023-12-16 13:41:56 +02:00
parent cad9fdbb40
commit 3663cc43f5
2 changed files with 29 additions and 1 deletions

View File

@ -2200,6 +2200,34 @@ export class UserAPI {
ctx.clearRect(0, 0, canvas.width, canvas.height);
}
public width = (): number => {
/**
* Returns the width of the canvas.
* @returns The width of the canvas
*/
const canvas: HTMLCanvasElement = this.app.interface.drawings as HTMLCanvasElement;
return canvas.width;
}
public height = (): number => {
/**
* Returns the height of the canvas.
* @returns The height of the canvas
*/
const canvas: HTMLCanvasElement = this.app.interface.drawings as HTMLCanvasElement;
return canvas.height;
}
public draw = (func: Function): void => {
/**
* Draws on the canvas.
* @param func - The function to execute
*/
const canvas: HTMLCanvasElement = this.app.interface.drawings as HTMLCanvasElement;
const ctx = canvas.getContext("2d")!;
func(ctx);
}
public circle = (
x: number,
y: number,

View File

@ -464,7 +464,7 @@ export abstract class AudibleEvent extends AbstractEvent {
}
public draw = (lambda: Function) => {
lambda(this.values);
lambda(this.values, (this.app.interface.drawings as HTMLCanvasElement).getContext("2d"));
return this;
}