aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/fr/umlv/java/wallj/viewer/ScreenManager.java
blob: be16067ddc45beaa520ac0c7e6569460a7770538 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package fr.umlv.java.wallj.viewer;

import fr.umlv.java.wallj.context.GraphicsContext;
import fr.umlv.zen5.ApplicationContext;
import fr.umlv.zen5.ScreenInfo;
import org.jbox2d.common.Vec2;

import java.awt.Graphics2D;
import java.util.Objects;

/**
 * Generates a clean GraphicsContext
 *
 * @author Adam NAILI
 */
public final class ScreenManager {
  private final ApplicationContext applicationContext;
  private final Graphics2D graphics2D;

  /**
   *
   * @param applicationContext the current application context
   * @param graphics2D the current graphics2D
   */
  public ScreenManager(ApplicationContext applicationContext, Graphics2D graphics2D) {
    this.applicationContext = Objects.requireNonNull(applicationContext);
    this.graphics2D = Objects.requireNonNull(graphics2D);
  }

  /**
   *
   * @return a graphic context
   */
  public GraphicsContext clearScreen() {
    ScreenInfo screenInfo = applicationContext.getScreenInfo();
    GraphicsContext graphicsContext = new GraphicsContext(graphics2D, screenInfo);
    graphicsContext.paintRectangle(graphics2D.getBackground(), new Vec2(0, 0), screenInfo.getWidth(), screenInfo.getHeight());
    return graphicsContext;
  }
}