X-Git-Url: http://www2.svjatoslav.eu/gitweb/?p=sixth-3d.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Feu%2Fsvjatoslav%2Fsixth%2Fe3d%2Frenderer%2Fraster%2Fshapes%2Fcomposite%2Ftextcanvas%2FCanvasCharacter.java;fp=src%2Fmain%2Fjava%2Feu%2Fsvjatoslav%2Fsixth%2Fe3d%2Frenderer%2Fraster%2Fshapes%2Fcomposite%2Ftextcanvas%2FCanvasCharacter.java;h=b1812265c6f4f2afee8c56e120083d5a27e0fe35;hp=b754faf1c10ea33c9841fb7aef2707a13ebd2b29;hb=324c5f8de858634643f8dd201cfcd99faa23af17;hpb=a2131986d65a769e3d589e4e0370d4af0ce10c38 diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/composite/textcanvas/CanvasCharacter.java b/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/composite/textcanvas/CanvasCharacter.java index b754faf..b181226 100644 --- a/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/composite/textcanvas/CanvasCharacter.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/composite/textcanvas/CanvasCharacter.java @@ -12,14 +12,26 @@ import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.basic.solidpolygon.SolidPo 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; @@ -30,10 +42,9 @@ public class CanvasCharacter extends AbstractCoordinateShape { super(5); coordinates[0].coordinate = point; - value = String.valueOf(character); + value = character; this.foregroundColor = foregroundColor; - foregroundAwtColor = foregroundColor.toAwtColor(); this.backgroundColor = backgroundColor; @@ -61,6 +72,16 @@ public class CanvasCharacter extends AbstractCoordinateShape { } } + /** + * Returns a font of the specified size. + *

+ * 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]; @@ -70,23 +91,36 @@ public class CanvasCharacter extends AbstractCoordinateShape { 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 @@ -124,16 +158,16 @@ public class CanvasCharacter extends AbstractCoordinateShape { 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; } }