public static final int bufferedImageType = BufferedImage.TYPE_4BYTE_ABGR;
- public final BufferedImage bufferedImage;
+ final BufferedImage bufferedImage;
public final Graphics2D graphics;
- public final byte[] bytes;
+ public final byte[] pixels;
public final int width;
public final int height;
*/
public boolean doRender = true; // TODO: make use of the variable
+ /**
+ * Mouse click. During rendering we can detect which item user clicked on.
+ */
public MouseClick mouseClick;
+ /**
+ * Item that user clicked on.
+ */
public MouseInteractionController clickedItem;
- public RenderingContext(final int width, final int height,
- final RenderingContext oldContext) {
-
+ public RenderingContext(final int width, final int height) {
this.width = width;
this.height = height;
final WritableRaster raster = bufferedImage.getRaster();
final DataBufferByte dbi = (DataBufferByte) raster.getDataBuffer();
- bytes = dbi.getData();
+ pixels = dbi.getData();
graphics = (Graphics2D) bufferedImage.getGraphics();
graphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
-
- if (oldContext != null) {
- mouseClick = oldContext.mouseClick;
- clickedItem = oldContext.clickedItem;
- }
}
}
long lastUpdateMillis = 0;
private Timer canvasUpdateTimer;
private ViewUpdateTimerTask canvasUpdateTimerTask;
- private RenderingContext renderingContext = new RenderingContext(1, 1, null);
+ private RenderingContext renderingContext = null;
private MouseInteractionController currentMouseOverComponent;
/**
* Currently target FPS for this view. It might change at runtime.
if ((renderingContext == null)
|| (renderingContext.width != getWidth())
|| (renderingContext.height != getHeight()))
- renderingContext = new RenderingContext(getWidth(), getHeight(),
- renderingContext);
+ renderingContext = new RenderingContext(getWidth(), getHeight());
// clear drawing area
{
* graphics is needed.
*/
public void updateView() {
- renderingContext.mouseClick = null;
- renderingContext.clickedItem = null;
+ if (renderingContext != null){
+ renderingContext.mouseClick = null;
+ renderingContext.clickedItem = null;
+ }
// compute time passed since last view update
final long currentTime = System.currentTimeMillis();
public class ForwardOrientedTexture extends AbstractCoordinateShape {
- public static final double SIZE_MULTIPLIER = 0.005;
+ private static final double SIZE_MULTIPLIER = 0.005;
public Texture texture;
private double scale;
if (xEnd > targetRenderingArea.width)
xEnd = targetRenderingArea.width;
- final byte[] targetRenderingAreaBytes = targetRenderingArea.bytes;
+ final byte[] targetRenderingAreaBytes = targetRenderingArea.pixels;
final int textureWidth = textureBitmap.width;
public Line(final Line parentLine) {
this(parentLine.coordinates[0].coordinate.clone(),
- parentLine.coordinates[1].coordinate.clone(), new Color(
- parentLine.color), parentLine.width);
+ parentLine.coordinates[1].coordinate.clone(),
+ new Color(parentLine.color), parentLine.width);
}
public Line(final Point3D point1, final Point3D point2, final Color color,
}
- public void drawHorizontalLine(final LineInterpolator line1,
- final LineInterpolator line2, final int y,
- final RenderingContext renderBuffer) {
+ private void drawHorizontalLine(final LineInterpolator line1,
+ final LineInterpolator line2, final int y,
+ final RenderingContext renderBuffer) {
int x1 = line1.getX(y);
int x2 = line2.getX(y);
final int drawnWidth = x2 - x1;
int offset = ((y * renderBuffer.width) + x1) * 4;
- final byte[] offSreenBufferBytes = renderBuffer.bytes;
+ final byte[] offSreenBufferBytes = renderBuffer.pixels;
final int lineAlpha = color.a;
}
- public void drawSinglePixelHorizontalLine(final RenderingContext buffer,
- final int alpha) {
+ private void drawSinglePixelHorizontalLine(final RenderingContext buffer,
+ final int alpha) {
final Point2D onScreenPoint1 = coordinates[0].onScreenCoordinate;
final Point2D onScreenPoint2 = coordinates[1].onScreenCoordinate;
if (lineWidth == 0)
return;
- final byte[] offSreenBufferBytes = buffer.bytes;
+ final byte[] offSreenBufferBytes = buffer.pixels;
final int backgroundAlpha = 255 - alpha;
final int blueWithAlpha = color.b * alpha;
}
- public void drawSinglePixelVerticalLine(final RenderingContext buffer,
- final int alpha) {
+ private void drawSinglePixelVerticalLine(final RenderingContext buffer,
+ final int alpha) {
final Point2D onScreenPoint1 = coordinates[0].onScreenCoordinate;
final Point2D onScreenPoint2 = coordinates[1].onScreenCoordinate;
if (lineHeight == 0)
return;
- final byte[] offSreenBufferBytes = buffer.bytes;
+ final byte[] offScreenBufferBytes = buffer.pixels;
final int backgroundAlpha = 255 - alpha;
final int blueWithAlpha = color.b * alpha;
- final int greenWithAplha = color.g * alpha;
+ final int greenWithAlpha = color.g * alpha;
final int redWithAlpha = color.r * alpha;
for (int relativeY = 0; relativeY <= lineHeight; relativeY++) {
if ((x >= 0) && (x < buffer.width)) {
int ramOffset = ((y * buffer.width) + x) * 4;
- offSreenBufferBytes[ramOffset] = (byte) 255;
+ offScreenBufferBytes[ramOffset] = (byte) 255;
ramOffset++;
- offSreenBufferBytes[ramOffset] = (byte) ((((offSreenBufferBytes[ramOffset] & 0xff) * backgroundAlpha) + blueWithAlpha) / 256);
+ offScreenBufferBytes[ramOffset] = (byte) ((((offScreenBufferBytes[ramOffset] & 0xff) * backgroundAlpha) + blueWithAlpha) / 256);
ramOffset++;
- offSreenBufferBytes[ramOffset] = (byte) ((((offSreenBufferBytes[ramOffset] & 0xff) * backgroundAlpha) + greenWithAplha) / 256);
+ offScreenBufferBytes[ramOffset] = (byte) ((((offScreenBufferBytes[ramOffset] & 0xff) * backgroundAlpha) + greenWithAlpha) / 256);
ramOffset++;
- offSreenBufferBytes[ramOffset] = (byte) ((((offSreenBufferBytes[ramOffset] & 0xff) * backgroundAlpha) + redWithAlpha) / 256);
+ offScreenBufferBytes[ramOffset] = (byte) ((((offScreenBufferBytes[ramOffset] & 0xff) * backgroundAlpha) + redWithAlpha) / 256);
}
}
}
}
- public int getLineInterpolator(final int startPointer, final int y) {
+ private int getLineInterpolator(final int startPointer, final int y) {
for (int i = startPointer; i < li.length; i++)
if (li[i].containsY(y))
public class SolidPolygon extends AbstractCoordinateShape {
- final static LineInterpolator polygonBoundary1 = new LineInterpolator();
- final static LineInterpolator polygonBoundary2 = new LineInterpolator();
- final static LineInterpolator polygonBoundary3 = new LineInterpolator();
+ private final static LineInterpolator polygonBoundary1 = new LineInterpolator();
+ private final static LineInterpolator polygonBoundary2 = new LineInterpolator();
+ private final static LineInterpolator polygonBoundary3 = new LineInterpolator();
private Color color;
public SolidPolygon(final Point3D point1, final Point3D point2,
final int width = x2 - x1;
int offset = ((y * renderBuffer.width) + x1) * 4;
- final byte[] offSreenBufferBytes = renderBuffer.bytes;
+ final byte[] offSreenBufferBytes = renderBuffer.pixels;
final int polygonAlpha = color.a;
final int b = color.b;
x2 = renderBuffer.width - 1;
int renderBufferOffset = ((y * renderBuffer.width) + x1) * 4;
- final byte[] renderBufferBytes = renderBuffer.bytes;
+ final byte[] renderBufferBytes = renderBuffer.pixels;
final double twidth = tx2 - tx1;
final double theight = ty2 - ty1;