Created
March 21, 2025 19:07
-
-
Save trikitrok/327294beaa213fce49b70e32299d44dd to your computer and use it in GitHub Desktop.
Step 4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Step 4 | |
export class GDIBrush implements PointRenderer { | |
colorId: number; | |
public draw(renderingRoots: Point[], colors: ColorMatrix, selection: Point[]): void { | |
const renderer = new Renderer(this, renderingRoots, colors, selection); | |
renderer.draw(); // !!! -> we call the method object | |
} | |
drawPoint(x: number, y: number, color: Color): void { | |
// some code to draw a point... | |
} | |
} | |
export interface PointRenderer { | |
readonly colorId: number; | |
drawPoint(x: number, y: number, color: Color): void; | |
} | |
export class Renderer { | |
private readonly pointRenderer: PointRenderer; | |
private readonly renderingRoots: Point[]; | |
private readonly colors: ColorMatrix; | |
private readonly selection: Point[]; | |
constructor( | |
pointRenderer: PointRenderer, | |
renderingRoots: Point[], | |
colors: ColorMatrix, | |
selection: Point[] | |
) { | |
this.pointRenderer = pointRenderer; | |
this.renderingRoots = renderingRoots; | |
this.colors = colors; | |
this.selection = selection; | |
} | |
public draw(): void { | |
// some more code in the method | |
for (const point of this.renderingRoots) { | |
// a lot more code in the loop | |
this.pointRenderer.drawPoint(point.x, point.y, this.colors.getColor(this.pointRenderer.colorId)); | |
} | |
// a lot more code in the method | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment