800c6bd54a99c21457d19005e1e9fb4830bfdc29
[sixth-3d.git] /
1 /*
2  * Sixth 3D engine. Copyright ©2012-2020, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of version 3 of the GNU Lesser General Public License
6  * or later as published by the Free Software Foundation.
7  *
8  */
9
10 package eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite;
11
12 import eu.svjatoslav.sixth.e3d.geometry.Point3D;
13 import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.basic.ForwardOrientedTexture;
14 import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.textcanvas.TextCanvas;
15 import eu.svjatoslav.sixth.e3d.renderer.raster.texture.Texture;
16
17 public class ForwardOrientedTextBlock extends ForwardOrientedTexture {
18
19     public ForwardOrientedTextBlock(final Point3D point, final double scale,
20                                     final int maxUpscaleFactor, final String text,
21                                     final eu.svjatoslav.sixth.e3d.renderer.raster.Color textColor) {
22         super(point, scale, getTexture(text, maxUpscaleFactor, textColor));
23
24     }
25
26     public static Texture getTexture(final String text,
27                                      final int maxUpscaleFactor,
28                                      final eu.svjatoslav.sixth.e3d.renderer.raster.Color textColor) {
29
30         final Texture texture = new Texture(text.length()
31                 * TextCanvas.FONT_CHAR_WIDTH_PIXELS, TextCanvas.FONT_CHAR_HEIGHT_PIXELS,
32                 maxUpscaleFactor);
33
34         // texture.graphics.setColor(Color.BLUE);
35         // texture.graphics.fillRect(0, 0, texture.primaryBitmap.width,
36         // texture.primaryBitmap.width);
37
38         texture.graphics.setFont(TextCanvas.FONT);
39         texture.graphics.setColor(textColor.toAwtColor());
40
41         for (int c = 0; c < text.length(); c++)
42             texture.graphics.drawChars(new char[]{text.charAt(c),}, 0, 1,
43                     (c * TextCanvas.FONT_CHAR_WIDTH_PIXELS) - 0,
44                     (0 * TextCanvas.FONT_CHAR_HEIGHT_PIXELS) + 11);
45
46         return texture;
47     }
48 }