Code refactoring
[sixth-3d.git] / src / main / java / eu / svjatoslav / sixth / e3d / renderer / raster / shapes / composite / textcanvas / TextCanvas.java
index 845fdc5..dfb6e45 100644 (file)
@@ -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,9 +36,8 @@ 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) {
@@ -57,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();
@@ -153,15 +155,15 @@ public class TextCanvas extends TexturedRectangle {
                                    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();
     }
@@ -169,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;
     }