Skip to content

Commit

Permalink
refactor(rendering): check primitive type
Browse files Browse the repository at this point in the history
  • Loading branch information
ruggero-visintin committed Dec 4, 2023
1 parent d6e3425 commit 0383256
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/renderer/RenderCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,19 @@ export interface RenderCommand {
execute(ctx: CanvasRenderingContext2D, device: CanvasDevice): void;
}

/**
* Draws a primitive (Rectangle)
*/
export class DrawPrimitiveCommand implements RenderCommand {
public readonly renderCommandID: RenderCommandID = RenderCommandID.RC_DrawPrimitive;

/**
* @param primitiveType - the type of the Primitive
* @param position - the position of the Primitive (x, y)
* @param size - the size of the Primitive (width, height)
* @param fill - if the Primitive should be filled. Default is true
* @param color - the color of the primitive. Default is #d16cd8
*/
constructor(
public readonly primitiveType: PrimitiveType,
public readonly position: [number, number],
Expand All @@ -25,7 +35,8 @@ export class DrawPrimitiveCommand implements RenderCommand {
) { }

public execute(ctx: CanvasRenderingContext2D, device: CanvasDevice): void {
device.drawRect(ctx, this.position[0], this.position[1], this.size[0], this.size[1]);
this.primitiveType === PrimitiveType.Rectangle
&& device.drawRect(ctx, this.position[0], this.position[1], this.size[0], this.size[1]);

if (this.fill) {
device.fill(ctx, this.color);
Expand Down

0 comments on commit 0383256

Please sign in to comment.