2 * Sixth 3D engine. Copyright ©2012-2018, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of version 3 of the GNU Lesser General Public License
6 * or later as published by the Free Software Foundation.
10 package eu.svjatoslav.sixth.e3d.gui;
12 import eu.svjatoslav.sixth.e3d.gui.humaninput.MouseClick;
13 import eu.svjatoslav.sixth.e3d.gui.humaninput.MouseInteractionController;
16 import java.awt.image.BufferedImage;
17 import java.awt.image.DataBufferByte;
18 import java.awt.image.WritableRaster;
20 public class RenderingContext {
22 public static final int bufferedImageType = BufferedImage.TYPE_4BYTE_ABGR;
24 final BufferedImage bufferedImage;
26 public final Graphics2D graphics;
28 public final byte[] pixels;
30 public final int width;
31 public final int height;
33 public final int xCenter;
34 public final int yCenter;
36 public final double zoom;
38 public int frameNumber = 0;
41 * Used to signal that actual rendering should be performed. It is useful to
42 * skip rendering when we only want to detect mouse clicks intersections
43 * without actually updating rendered frame.
45 public boolean doRender = true; // TODO: make use of the variable
48 * Mouse click. During rendering we can detect which item user clicked on.
50 public MouseClick mouseClick;
53 * Item that user clicked on.
55 public MouseInteractionController clickedItem;
57 public RenderingContext(final int width, final int height) {
61 this.xCenter = width / 2;
62 this.yCenter = height / 2;
64 this.zoom = width / 3d;
66 bufferedImage = new BufferedImage(width, height, bufferedImageType);
68 final WritableRaster raster = bufferedImage.getRaster();
69 final DataBufferByte dbi = (DataBufferByte) raster.getDataBuffer();
70 pixels = dbi.getData();
72 graphics = (Graphics2D) bufferedImage.getGraphics();
73 graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
74 graphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);