/*
- * Sixth 3D engine. Copyright ©2012-2020, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 3 of the GNU Lesser General Public License
- * or later as published by the Free Software Foundation.
- *
+ * Sixth 3D engine. Author: Svjatoslav Agejenko.
+ * This project is released under Creative Commons Zero (CC0) license.
*/
-
package eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.textcanvas;
import eu.svjatoslav.sixth.e3d.geometry.Point2D;
import java.awt.*;
+import static java.lang.String.valueOf;
+
+/**
+ * Represents a single character on the text canvas.
+ */
public class CanvasCharacter extends AbstractCoordinateShape {
private static final int MAX_FONT_SIZE = 500;
+
+ /**
+ * Cached fonts.
+ */
private static final Font[] fonts = new Font[MAX_FONT_SIZE];
- private String value;
+
+ /**
+ * The character to be rendered.
+ */
+ private char value;
private eu.svjatoslav.sixth.e3d.renderer.raster.Color foregroundColor;
- private Color foregroundAwtColor;
private eu.svjatoslav.sixth.e3d.renderer.raster.Color backgroundColor;
super(5);
coordinates[0].coordinate = point;
- value = String.valueOf(character);
+ value = character;
this.foregroundColor = foregroundColor;
- foregroundAwtColor = foregroundColor.toAwtColor();
this.backgroundColor = backgroundColor;
// set corner coordinates (for drawing background)
{
- final double widthHalf = TextCanvas.FONT_CHAR_WIDTH_PIXELS / 2d;
- final double heightHalf = TextCanvas.FONT_CHAR_HEIGHT_PIXELS / 2d;
+ final double widthHalf = TextCanvas.FONT_CHAR_WIDTH / 2d;
+ final double heightHalf = TextCanvas.FONT_CHAR_HEIGHT / 2d;
// upper left
coordinates[1].coordinate = point.clone().translateX(-widthHalf)
}
}
+ /**
+ * Returns a font of the specified size.
+ * <p>
+ * If the font of the specified size is already cached, it will be
+ * returned. Otherwise, a new font will be created, cached and returned.
+ *
+ *
+ * @param size the size of the font
+ * @return the font
+ */
public static Font getFont(final int size) {
if (fonts[size] != null)
return fonts[size];
return font;
}
+ /**
+ * Returns color of the background.
+ */
public eu.svjatoslav.sixth.e3d.renderer.raster.Color getBackgroundColor() {
return backgroundColor;
}
+ /**
+ * Sets color of the background.
+ */
public void setBackgroundColor(
final eu.svjatoslav.sixth.e3d.renderer.raster.Color backgroundColor) {
this.backgroundColor = backgroundColor;
}
+ /**
+ * Returns color of the foreground.
+ * @return the color
+ */
public eu.svjatoslav.sixth.e3d.renderer.raster.Color getForegroundColor() {
return foregroundColor;
}
+ /**
+ * Sets color of the foreground.
+ * @param foregroundColor the color
+ */
public void setForegroundColor(
final eu.svjatoslav.sixth.e3d.renderer.raster.Color foregroundColor) {
this.foregroundColor = foregroundColor;
- foregroundAwtColor = foregroundColor.toAwtColor();
}
@Override
return;
renderingContext.graphics.setFont(getFont(size));
- renderingContext.graphics.setColor(foregroundAwtColor);
+ renderingContext.graphics.setColor(foregroundColor.toAwtColor());
renderingContext.graphics.drawString(
- value,
+ valueOf(value),
(int) onScreenLocation.x - (int) (size / 3.2),
(int) onScreenLocation.y + (int) (size / 2.5));
}
public void setValue(final char value) {
- this.value = String.valueOf(value);
+ this.value = value;
}
}