Last active
September 5, 2024 19:15
-
-
Save trikitrok/b4126f1be9ba337df7b5af4e4e83c03b to your computer and use it in GitHub Desktop.
Step 4
This file contains 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 | |
class GDIBrush implements PointRenderer { | |
private int colorId; | |
public void draw(List<Point> renderingRoots, | |
ColorMatrix colors, | |
List<Point> selection) { | |
Renderer renderer = new Renderer(this, renderingRoots, colors, selection); | |
renderer.draw(); // !!! -> we call the method object | |
} | |
@Override | |
public void drawPoint(int x, int y, Color color) { | |
// some code to draw a point... | |
} | |
@Override | |
public int getColorId() { | |
return colorId; | |
} | |
} | |
interface PointRenderer { | |
int getColorId(); | |
void drawPoint(int x, int y, Color color); | |
} | |
class Renderer { | |
private final PointRenderer pointRenderer; | |
private final List<Point> renderingRoots; | |
private final ColorMatrix colors; | |
private final List<Point> selection; | |
public Renderer(PointRenderer pointRenderer, List<Point> renderingRoots, ColorMatrix colors, List<Point> selection) { | |
this.pointRenderer = pointRenderer; | |
this.renderingRoots = renderingRoots; | |
this.colors = colors; | |
this.selection = selection; | |
} | |
public void draw() { | |
// some more code in the method | |
for (Point point : renderingRoots) { | |
// a lot more code in the loop | |
pointRenderer.drawPoint(point.x(), point.y(), colors.getColor(pointRenderer.getColorId())); | |
} | |
// 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