X-Git-Url: http://www2.svjatoslav.eu/gitweb/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Feu%2Fsvjatoslav%2Fsixth%2Fe3d%2Frenderer%2Fraster%2Fshapes%2Fcomposite%2Ftextcanvas%2FTextCanvas.java;h=dfb6e45d4db17308b6cb85c2e4047db0d3eecb66;hb=2ba2ce636354885e669e9e3fbb97226025e5af45;hp=5c594f20335afb478c50c9a903f3cad9ef8d4bb4;hpb=6213716671ccab6b7256de41838e1f5401ce173c;p=sixth-3d.git diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/composite/textcanvas/TextCanvas.java b/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/composite/textcanvas/TextCanvas.java index 5c594f2..dfb6e45 100644 --- a/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/composite/textcanvas/TextCanvas.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/composite/textcanvas/TextCanvas.java @@ -1,19 +1,19 @@ /* - * Sixth - System for data storage, computation, exploration and interaction. - * Copyright ©2012-2016, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu - * + * 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. + * */ package eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.textcanvas; import eu.svjatoslav.sixth.e3d.geometry.Point3D; -import eu.svjatoslav.sixth.e3d.geometry.Transform; -import eu.svjatoslav.sixth.e3d.geometry.TransformPipe; import eu.svjatoslav.sixth.e3d.gui.RenderingContext; import eu.svjatoslav.sixth.e3d.gui.TextPointer; +import eu.svjatoslav.sixth.e3d.math.Transform; +import eu.svjatoslav.sixth.e3d.math.TransformPipe; import eu.svjatoslav.sixth.e3d.renderer.raster.Color; import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.TexturedRectangle; @@ -22,10 +22,13 @@ import java.io.BufferedReader; import java.io.IOException; import java.io.StringReader; +import static eu.svjatoslav.sixth.e3d.renderer.raster.Color.BLACK; +import static eu.svjatoslav.sixth.e3d.renderer.raster.Color.WHITE; + public class TextCanvas extends TexturedRectangle { - public static final int FONT_CHAR_WIDTH = 8; - public static final int FONT_CHAR_HEIGHT = 16; + public static final int FONT_CHAR_WIDTH_PIXELS = 8; + public static final int FONT_CHAR_HEIGHT_PIXELS = 16; public static final Font FONT = CanvasCharacter.getFont(15); private static final String GROUP_TEXTURE = "texture"; private static final String GROUP_CHARACTERS = "characters"; @@ -33,13 +36,11 @@ public class TextCanvas extends TexturedRectangle { private final TextPointer cursorLocation = new TextPointer(); CanvasCharacter lines[][]; private RenderMode renderMode = null; - private Color backgroundColor = Color.BLACK; - - private Color foregroundColor = Color.WHITE; + private Color backgroundColor = BLACK; + private Color foregroundColor = WHITE; public TextCanvas(final Transform location, final String text, - final Color foregroundColor, final Color backgroundColor) - throws IOException { + final Color foregroundColor, final Color backgroundColor) { this(location, getTextDimensions(text), foregroundColor, backgroundColor); setText(text); @@ -58,7 +59,7 @@ public class TextCanvas extends TexturedRectangle { this.foregroundColor = foregroundColor; // initialize underlying textured rectangle - initialize(columns * FONT_CHAR_WIDTH, rows * FONT_CHAR_HEIGHT, 0); + initialize(columns * FONT_CHAR_WIDTH_PIXELS, rows * FONT_CHAR_HEIGHT_PIXELS, 0); getTexture().primaryBitmap.fillColor(backgroundColor); getTexture().resetResampledBitmapCache(); @@ -86,8 +87,7 @@ public class TextCanvas extends TexturedRectangle { setRenderMode(RenderMode.TEXTURE); } - public static TextPointer getTextDimensions(final String text) - throws IOException { + public static TextPointer getTextDimensions(final String text) { final BufferedReader reader = new BufferedReader(new StringReader(text)); @@ -95,7 +95,12 @@ public class TextCanvas extends TexturedRectangle { int columns = 0; while (true) { - final String line = reader.readLine(); + final String line; + try { + line = reader.readLine(); + } catch (IOException e) { + throw new RuntimeException(e); + } if (line == null) return new TextPointer(rows, columns); @@ -147,18 +152,18 @@ public class TextCanvas extends TexturedRectangle { } private void drawCharToTexture(final int row, final int column, - final char character, final Color background, final Color foreground) { + final char character, final Color foreground) { final Graphics2D graphics = getTexture().graphics; - getTexture().primaryBitmap.drawRectangle(column * FONT_CHAR_WIDTH, row - * FONT_CHAR_HEIGHT, (column * FONT_CHAR_WIDTH) - + FONT_CHAR_WIDTH, (row * FONT_CHAR_HEIGHT) + FONT_CHAR_HEIGHT, + getTexture().primaryBitmap.drawRectangle(column * FONT_CHAR_WIDTH_PIXELS, row + * FONT_CHAR_HEIGHT_PIXELS, (column * FONT_CHAR_WIDTH_PIXELS) + + FONT_CHAR_WIDTH_PIXELS, (row * FONT_CHAR_HEIGHT_PIXELS) + FONT_CHAR_HEIGHT_PIXELS, backgroundColor); graphics.setFont(FONT); graphics.setColor(foreground.toAwtColor()); graphics.drawChars(new char[]{character,}, 0, 1, - (column * FONT_CHAR_WIDTH) - 0, (row * FONT_CHAR_HEIGHT) + 13); + (column * FONT_CHAR_WIDTH_PIXELS) - 0, (row * FONT_CHAR_HEIGHT_PIXELS) + 13); getTexture().resetResampledBitmapCache(); } @@ -166,11 +171,11 @@ public class TextCanvas extends TexturedRectangle { public Point3D getCharLocation(final int row, final int column) { final Point3D coordinate = topLeft.clone(); - coordinate.translateY((row * FONT_CHAR_HEIGHT) - + ((FONT_CHAR_HEIGHT / 2) - 3)); + coordinate.translateY((row * FONT_CHAR_HEIGHT_PIXELS) + + ((FONT_CHAR_HEIGHT_PIXELS / 2) - 3)); - coordinate.translateX((column * FONT_CHAR_WIDTH) - + (FONT_CHAR_WIDTH / 2)); + coordinate.translateX((column * FONT_CHAR_WIDTH_PIXELS) + + (FONT_CHAR_WIDTH_PIXELS / 2)); return coordinate; } @@ -212,7 +217,7 @@ public class TextCanvas extends TexturedRectangle { canvasCharacter.setValue(character); canvasCharacter.setBackgroundColor(backgroundColor); canvasCharacter.setForegroundColor(foregroundColor); - drawCharToTexture(row, column, character, backgroundColor, + drawCharToTexture(row, column, character, foregroundColor); } @@ -248,13 +253,18 @@ public class TextCanvas extends TexturedRectangle { renderMode = mode; } - public void setText(final String text) throws IOException { + public void setText(final String text) { final BufferedReader reader = new BufferedReader(new StringReader(text)); int row = 0; while (true) { - final String line = reader.readLine(); + final String line; + try { + line = reader.readLine(); + } catch (IOException e) { + throw new RuntimeException(e); + } if (line == null) return;