Skip to content

Commit adab129

Browse files
committed
Add clear method to Graphics2D interface for viewport clearing
Introduced a clear(math.Color color) method in the Graphics2D interface. The method allows clearing the entire viewport with a specified color, resetting the drawing surface. Useful for initializing or refreshing the rendering context during updates.
1 parent 5ab41c3 commit adab129

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/main/java/workspace/GraphicsPImpl.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,4 +550,9 @@ public void drawImage(Image image, float x, float y, float width, float height)
550550
throw new IllegalArgumentException("Unsupported image backend.");
551551
}
552552
}
553+
554+
@Override
555+
public void clear(math.Color color) {
556+
g.background(color.getRedInt(), color.getGreenInt(), color.getBlueInt(), color.getAlphaInt());
557+
}
553558
}

src/main/java/workspace/ui/Graphics2D.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,17 @@ public interface Graphics2D {
226226
*/
227227
void text(String text, float x, float y);
228228

229+
/**
230+
* Clears the rendering context with the specified color.
231+
*
232+
* <p>This method fills the entire viewport with the provided color, effectively resetting the
233+
* drawing surface to a blank state. Any previously drawn content is overwritten.
234+
*
235+
* @param color The {@link math.Color} to use for clearing the viewport. The color is applied
236+
* uniformly across the entire rendering surface.
237+
*/
238+
void clear(math.Color color);
239+
229240
void drawImage(Image image, float x, float y);
230241

231242
void drawImage(Image image, float x, float y, float width, float height);

0 commit comments

Comments
 (0)