Skip to content

Commit

Permalink
Abstract Display
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Creech committed Feb 12, 2024
1 parent c45e9a1 commit 1755471
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 7 deletions.
42 changes: 37 additions & 5 deletions src/display.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,42 @@
import { Point } from "./point.ts";

export class Display {
export interface Display {
readonly canvasSize: Point;

clearRect(corner: Point, size: Point): void;

strokeRect(corner: Point, size: Point): void;

translate(dist: Point): void;

scale(amount: Point): void;

restore(): void;

save(): void;

stroke(): void;

beginPath(): void;

closePath(): void;

moveTo(point: Point): void;

lineTo(point: Point): void;

fill(): void;

bezierCurveTo(cp1: Point, cp2: Point, ep: Point): void;

quadraticCurveTo(cp: Point, ep: Point): void;

set lineWidth(width: number);

set strokeStyle(style: string);
}

export class DisplayImpl implements Display {
constructor(
public readonly canvasSize: Point,
private readonly context: CanvasRenderingContext2D,
Expand All @@ -18,10 +54,6 @@ export class Display {
this.context.translate(dist.x, dist.y);
}

rotate(rads: number) {
this.context.rotate(rads);
}

scale(amount: Point) {
this.context.scale(amount.x, amount.y);
}
Expand Down
4 changes: 2 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Game } from "./game.ts";
import { Display } from "./display.ts";
import { DisplayImpl } from "./display.ts";
import { GameTextImpl } from "./gametext.ts";
import { KeyboardImpl } from "./keyboard.ts";
import { Point } from "./point.ts";
Expand All @@ -13,7 +13,7 @@ const canvas: HTMLCanvasElement = document.getElementById(
"canvas",
)! as HTMLCanvasElement;

const display = new Display(
const display = new DisplayImpl(
new Point(canvas.width, canvas.height),
canvas.getContext("2d")!,
);
Expand Down

0 comments on commit 1755471

Please sign in to comment.