5bfdee6105b229074c08c09976c21652a3e60e61
[sixth-3d.git] /
1 /*
2  * Sixth 3D engine. Author: Svjatoslav Agejenko. 
3  * This project is released under Creative Commons Zero (CC0) license.
4  *
5 *
6  */
7
8 package eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite;
9
10 import eu.svjatoslav.sixth.e3d.geometry.Point3D;
11 import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.basic.ForwardOrientedTexture;
12 import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.textcanvas.TextCanvas;
13 import eu.svjatoslav.sixth.e3d.renderer.raster.texture.Texture;
14
15 public class ForwardOrientedTextBlock extends ForwardOrientedTexture {
16
17     public ForwardOrientedTextBlock(final Point3D point, final double scale,
18                                     final int maxUpscaleFactor, final String text,
19                                     final eu.svjatoslav.sixth.e3d.renderer.raster.Color textColor) {
20         super(point, scale, getTexture(text, maxUpscaleFactor, textColor));
21
22     }
23
24     public static Texture getTexture(final String text,
25                                      final int maxUpscaleFactor,
26                                      final eu.svjatoslav.sixth.e3d.renderer.raster.Color textColor) {
27
28         final Texture texture = new Texture(text.length()
29                 * TextCanvas.FONT_CHAR_WIDTH_PIXELS, TextCanvas.FONT_CHAR_HEIGHT_PIXELS,
30                 maxUpscaleFactor);
31
32         // texture.graphics.setColor(Color.BLUE);
33         // texture.graphics.fillRect(0, 0, texture.primaryBitmap.width,
34         // texture.primaryBitmap.width);
35
36         texture.graphics.setFont(TextCanvas.FONT);
37         texture.graphics.setColor(textColor.toAwtColor());
38
39         for (int c = 0; c < text.length(); c++)
40             texture.graphics.drawChars(new char[]{text.charAt(c),}, 0, 1,
41                     (c * TextCanvas.FONT_CHAR_WIDTH_PIXELS) - 0,
42                     (0 * TextCanvas.FONT_CHAR_HEIGHT_PIXELS) + 11);
43
44         return texture;
45     }
46 }