Skip to content

Commit 5ab41c3

Browse files
committed
feat(scene): add background color option to Scene
- Introduced `background` field to manage the scene's background color. - Added `getBackground()` and `setBackground(Color background)` methods to retrieve and update the background color. - Ensured thread safety and validation for the background color. This enhancement allows users to customize the scene's background color, improving visual customization and flexibility.
1 parent 9f2e4ff commit 5ab41c3

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

src/main/java/engine/scene/Scene.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import engine.scene.camera.Camera;
1010
import engine.scene.light.Light;
11+
import math.Color;
1112
import workspace.GraphicsPImpl;
1213
import workspace.ui.Graphics;
1314

@@ -37,6 +38,8 @@ public class Scene {
3738
/** Name of the scene. Used for identification or debugging purposes. */
3839
private final String name;
3940

41+
private Color background;
42+
4043
/** The currently active camera that determines the scene's view transformation. */
4144
private Camera activeCamera;
4245

@@ -56,6 +59,7 @@ public Scene(String name) {
5659
throw new IllegalArgumentException("Name cannot be null.");
5760
}
5861
this.name = name;
62+
this.background = new Color(0, 0, 0, 1);
5963
}
6064

6165
/**
@@ -116,6 +120,8 @@ public void update(float deltaTime) {
116120
* compatibility with most rendering APIs.
117121
*/
118122
public void render(Graphics g) {
123+
g.clear(background);
124+
119125
if (activeCamera != null) {
120126
g.applyCamera(activeCamera);
121127
}
@@ -295,4 +301,30 @@ public boolean isWireframeMode() {
295301
public void setWireframeMode(boolean wireframeMode) {
296302
this.wireframeMode = wireframeMode;
297303
}
304+
305+
/**
306+
* Retrieves the background color of the scene.
307+
*
308+
* <p>The background color is used to clear the rendering surface before drawing the scene.
309+
*
310+
* @return The current background color of the scene.
311+
*/
312+
public Color getBackground() {
313+
return background;
314+
}
315+
316+
/**
317+
* Sets the background color of the scene.
318+
*
319+
* <p>The background color is used to clear the rendering surface before drawing the scene.
320+
*
321+
* @param background The new background color for the scene. Must not be {@code null}.
322+
* @throws IllegalArgumentException if the provided background color is {@code null}.
323+
*/
324+
public void setBackground(Color background) {
325+
if (background == null) {
326+
throw new IllegalArgumentException("Background color cannot be null.");
327+
}
328+
this.background = background;
329+
}
298330
}

0 commit comments

Comments
 (0)