From 3663cc43f5bc571d4173462374b63f64d0c144af Mon Sep 17 00:00:00 2001 From: Miika Alonen Date: Sat, 16 Dec 2023 13:41:56 +0200 Subject: [PATCH] Added ctx to draw methods --- src/API.ts | 28 ++++++++++++++++++++++++++++ src/classes/AbstractEvents.ts | 2 +- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/API.ts b/src/API.ts index 0e38307..e194498 100644 --- a/src/API.ts +++ b/src/API.ts @@ -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, diff --git a/src/classes/AbstractEvents.ts b/src/classes/AbstractEvents.ts index 4d34d44..a419a97 100644 --- a/src/classes/AbstractEvents.ts +++ b/src/classes/AbstractEvents.ts @@ -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; }