218 lines
12 KiB
Java
218 lines
12 KiB
Java
package projectzombie.text;
|
|
|
|
import projectzombie.Main;
|
|
import projectzombie.init.Textures;
|
|
import projectzombie.util.gl.GlHelpers;
|
|
import projectzombie.util.gl.texture.TextureReference;
|
|
import projectzombie.util.math.vec.Vec2d;
|
|
|
|
public class Text
|
|
{
|
|
public static final TextureReference CHAR_A = Textures.texmap.getTextureReference(5, 6, 0, 1);
|
|
public static final TextureReference CHAR_B = Textures.texmap.getTextureReference(6, 7, 0, 1);
|
|
public static final TextureReference CHAR_C = Textures.texmap.getTextureReference(7, 8, 0, 1);
|
|
public static final TextureReference CHAR_D = Textures.texmap.getTextureReference(8, 9, 0, 1);
|
|
public static final TextureReference CHAR_E = Textures.texmap.getTextureReference(9, 10, 0, 1);
|
|
public static final TextureReference CHAR_F = Textures.texmap.getTextureReference(10, 11, 0, 1);
|
|
public static final TextureReference CHAR_G = Textures.texmap.getTextureReference(11, 12, 0, 1);
|
|
public static final TextureReference CHAR_H = Textures.texmap.getTextureReference(12, 13, 0, 1);
|
|
public static final TextureReference CHAR_I = Textures.texmap.getTextureReference(13, 14, 0, 1);
|
|
public static final TextureReference CHAR_J = Textures.texmap.getTextureReference(14, 15, 0, 1);
|
|
public static final TextureReference CHAR_K = Textures.texmap.getTextureReference(15, 16, 0, 1);
|
|
public static final TextureReference CHAR_L = Textures.texmap.getTextureReference(5, 6, 1, 2);
|
|
public static final TextureReference CHAR_M = Textures.texmap.getTextureReference(6, 7, 1, 2);
|
|
public static final TextureReference CHAR_N = Textures.texmap.getTextureReference(7, 8, 1, 2);
|
|
public static final TextureReference CHAR_O = Textures.texmap.getTextureReference(8, 9, 1, 2);
|
|
public static final TextureReference CHAR_P = Textures.texmap.getTextureReference(9, 10, 1, 2);
|
|
public static final TextureReference CHAR_Q = Textures.texmap.getTextureReference(10, 11, 1, 2);
|
|
public static final TextureReference CHAR_R = Textures.texmap.getTextureReference(11, 12, 1, 2);
|
|
public static final TextureReference CHAR_S = Textures.texmap.getTextureReference(12, 13, 1, 2);
|
|
public static final TextureReference CHAR_T = Textures.texmap.getTextureReference(13, 14, 1, 2);
|
|
public static final TextureReference CHAR_U = Textures.texmap.getTextureReference(14, 15, 1, 2);
|
|
public static final TextureReference CHAR_V = Textures.texmap.getTextureReference(15, 16, 1, 2);
|
|
public static final TextureReference CHAR_W = Textures.texmap.getTextureReference(5, 6, 2, 3);
|
|
public static final TextureReference CHAR_X = Textures.texmap.getTextureReference(6, 7, 2, 3);
|
|
public static final TextureReference CHAR_Y = Textures.texmap.getTextureReference(7, 8, 2, 3);
|
|
public static final TextureReference CHAR_Z = Textures.texmap.getTextureReference(8, 9, 2, 3);
|
|
public static final TextureReference CHAR_a = Textures.texmap.getTextureReference(9, 10, 2, 3);
|
|
public static final TextureReference CHAR_b = Textures.texmap.getTextureReference(10, 11, 2, 3);
|
|
public static final TextureReference CHAR_c = Textures.texmap.getTextureReference(11, 12, 2, 3);
|
|
public static final TextureReference CHAR_d = Textures.texmap.getTextureReference(12, 13, 2, 3);
|
|
public static final TextureReference CHAR_e = Textures.texmap.getTextureReference(13, 14, 2, 3);
|
|
public static final TextureReference CHAR_f = Textures.texmap.getTextureReference(14, 15, 2, 3);
|
|
public static final TextureReference CHAR_g = Textures.texmap.getTextureReference(15, 16, 2, 3);
|
|
public static final TextureReference CHAR_h = Textures.texmap.getTextureReference(5, 6, 3, 4);
|
|
public static final TextureReference CHAR_i = Textures.texmap.getTextureReference(6, 7, 3, 4);
|
|
public static final TextureReference CHAR_j = Textures.texmap.getTextureReference(7, 8, 3, 4);
|
|
public static final TextureReference CHAR_k = Textures.texmap.getTextureReference(8, 9, 3, 4);
|
|
public static final TextureReference CHAR_l = Textures.texmap.getTextureReference(9, 10, 3, 4);
|
|
public static final TextureReference CHAR_m = Textures.texmap.getTextureReference(10, 11, 3, 4);
|
|
public static final TextureReference CHAR_n = Textures.texmap.getTextureReference(11, 12, 3, 4);
|
|
public static final TextureReference CHAR_o = Textures.texmap.getTextureReference(12, 13, 3, 4);
|
|
public static final TextureReference CHAR_p = Textures.texmap.getTextureReference(13, 14, 3, 4);
|
|
public static final TextureReference CHAR_q = Textures.texmap.getTextureReference(14, 15, 3, 4);
|
|
public static final TextureReference CHAR_r = Textures.texmap.getTextureReference(15, 16, 3, 4);
|
|
public static final TextureReference CHAR_s = Textures.texmap.getTextureReference(5, 6, 4, 5);
|
|
public static final TextureReference CHAR_t = Textures.texmap.getTextureReference(6, 7, 4, 5);
|
|
public static final TextureReference CHAR_u = Textures.texmap.getTextureReference(7, 8, 4, 5);
|
|
public static final TextureReference CHAR_v = Textures.texmap.getTextureReference(8, 9, 4, 5);
|
|
public static final TextureReference CHAR_w = Textures.texmap.getTextureReference(9, 10, 4, 5);
|
|
public static final TextureReference CHAR_x = Textures.texmap.getTextureReference(10, 11, 4, 5);
|
|
public static final TextureReference CHAR_y = Textures.texmap.getTextureReference(11, 12, 4, 5);
|
|
public static final TextureReference CHAR_z = Textures.texmap.getTextureReference(12, 13, 4, 5);
|
|
public static final TextureReference CHAR_0 = Textures.texmap.getTextureReference(13, 14, 4, 5);
|
|
public static final TextureReference CHAR_1 = Textures.texmap.getTextureReference(14, 15, 4, 5);
|
|
public static final TextureReference CHAR_2 = Textures.texmap.getTextureReference(15, 16, 4, 5);
|
|
public static final TextureReference CHAR_3 = Textures.texmap.getTextureReference(5, 6, 5, 6);
|
|
public static final TextureReference CHAR_4 = Textures.texmap.getTextureReference(6, 7, 5, 6);
|
|
public static final TextureReference CHAR_5 = Textures.texmap.getTextureReference(7, 8, 5, 6);
|
|
public static final TextureReference CHAR_6 = Textures.texmap.getTextureReference(8, 9, 5, 6);
|
|
public static final TextureReference CHAR_7 = Textures.texmap.getTextureReference(9, 10, 5, 6);
|
|
public static final TextureReference CHAR_8 = Textures.texmap.getTextureReference(10, 11, 5, 6);
|
|
public static final TextureReference CHAR_9 = Textures.texmap.getTextureReference(11, 12, 5, 6);
|
|
public static final TextureReference CHAR_PEROID = Textures.texmap.getTextureReference(12, 13, 5, 6);
|
|
public static final TextureReference CHAR_COLON = Textures.texmap.getTextureReference(13, 14, 5, 6);
|
|
public static final TextureReference CHAR_COMMA = Textures.texmap.getTextureReference(14, 15, 5, 6);
|
|
public static final TextureReference CHAR_EXMARK = Textures.texmap.getTextureReference(15, 16, 5, 6);
|
|
public static final TextureReference CHAR_MINUS = Textures.texmap.getTextureReference(0, 1, 10, 11);
|
|
public static final TextureReference CHAR_PLUS = Textures.texmap.getTextureReference(1, 2, 10, 11);
|
|
public static final TextureReference CHAR_FSLASH = Textures.texmap.getTextureReference(2, 3, 10, 11);
|
|
public static final TextureReference CHAR_BSLASH = Textures.texmap.getTextureReference(3, 4, 10, 11);
|
|
public static final TextureReference CHAR_EQUALS = Textures.texmap.getTextureReference(4, 5, 10, 11);
|
|
public static final TextureReference CHAR_USCORE = Textures.texmap.getTextureReference(5, 6, 10, 11);
|
|
public static final TextureReference CHAR_NULL = Textures.texmap.getTextureReference(6, 7, 10, 11);
|
|
public static final TextureReference CHAR_BRACKET_O = Textures.texmap.getTextureReference(7, 8, 10, 11);
|
|
public static final TextureReference CHAR_BRACKET_C = Textures.texmap.getTextureReference(8, 9, 10, 11);
|
|
public static final TextureReference CHAR_PERCENT = Textures.texmap.getTextureReference(9, 10, 10, 11);
|
|
public static final TextureReference CHAR_VBAR = Textures.texmap.getTextureReference(10, 11, 10, 11);
|
|
public static final TextureReference CHAR_QMARK = Textures.texmap.getTextureReference(11, 12, 10, 11);
|
|
public static final TextureReference CHAR_DOLLAR = Textures.texmap.getTextureReference(12, 13, 10, 11);
|
|
public static final TextureReference CHAR_HASHTAG = Textures.texmap.getTextureReference(13, 14, 10, 11);
|
|
public static final TextureReference CHAR_L_THEN = Textures.texmap.getTextureReference(14, 15, 10, 11);
|
|
public static final TextureReference CHAR_G_THEN = Textures.texmap.getTextureReference(15, 16, 10, 11);
|
|
|
|
public static void renderCenter(String text, Vec2d size) {
|
|
int w = Main.window.getWidth();
|
|
int h = Main.window.getHeight();
|
|
double aspect_ratio = ((double)w) / ((double)h);
|
|
GlHelpers.translate2(0 - (text.length() * size.x / 2 / aspect_ratio), 0);
|
|
Text.render(text, size);
|
|
}
|
|
|
|
public static void render(String text, Vec2d size)
|
|
{
|
|
// Get the bytes from the string
|
|
byte[] text_b = text.getBytes();
|
|
|
|
double sx = size.x;
|
|
double sy = size.y;
|
|
|
|
// Begin quads
|
|
GlHelpers.begin();
|
|
|
|
// Loop over the bytes
|
|
for(int i=0;i<text_b.length;i++)
|
|
{
|
|
// Get the character from the string
|
|
TextureReference l = CHAR_NULL;
|
|
switch(text_b[i]) {
|
|
case(' '): l = null; break;
|
|
case('Q'): l = CHAR_Q; break;
|
|
case('W'): l = CHAR_W; break;
|
|
case('E'): l = CHAR_E; break;
|
|
case('R'): l = CHAR_R; break;
|
|
case('T'): l = CHAR_T; break;
|
|
case('Y'): l = CHAR_Y; break;
|
|
case('U'): l = CHAR_U; break;
|
|
case('I'): l = CHAR_I; break;
|
|
case('O'): l = CHAR_O; break;
|
|
case('P'): l = CHAR_P; break;
|
|
case('A'): l = CHAR_A; break;
|
|
case('S'): l = CHAR_S; break;
|
|
case('D'): l = CHAR_D; break;
|
|
case('F'): l = CHAR_F; break;
|
|
case('G'): l = CHAR_G; break;
|
|
case('H'): l = CHAR_H; break;
|
|
case('J'): l = CHAR_J; break;
|
|
case('K'): l = CHAR_K; break;
|
|
case('L'): l = CHAR_L; break;
|
|
case('Z'): l = CHAR_Z; break;
|
|
case('X'): l = CHAR_X; break;
|
|
case('C'): l = CHAR_C; break;
|
|
case('V'): l = CHAR_V; break;
|
|
case('B'): l = CHAR_B; break;
|
|
case('N'): l = CHAR_N; break;
|
|
case('M'): l = CHAR_M; break;
|
|
case('q'): l = CHAR_q; break;
|
|
case('w'): l = CHAR_w; break;
|
|
case('e'): l = CHAR_e; break;
|
|
case('r'): l = CHAR_r; break;
|
|
case('t'): l = CHAR_t; break;
|
|
case('y'): l = CHAR_y; break;
|
|
case('u'): l = CHAR_u; break;
|
|
case('i'): l = CHAR_i; break;
|
|
case('o'): l = CHAR_o; break;
|
|
case('p'): l = CHAR_p; break;
|
|
case('a'): l = CHAR_a; break;
|
|
case('s'): l = CHAR_s; break;
|
|
case('d'): l = CHAR_d; break;
|
|
case('f'): l = CHAR_f; break;
|
|
case('g'): l = CHAR_g; break;
|
|
case('h'): l = CHAR_h; break;
|
|
case('j'): l = CHAR_j; break;
|
|
case('k'): l = CHAR_k; break;
|
|
case('l'): l = CHAR_l; break;
|
|
case('z'): l = CHAR_z; break;
|
|
case('x'): l = CHAR_x; break;
|
|
case('c'): l = CHAR_c; break;
|
|
case('v'): l = CHAR_v; break;
|
|
case('b'): l = CHAR_b; break;
|
|
case('n'): l = CHAR_n; break;
|
|
case('m'): l = CHAR_m; break;
|
|
case('0'): l = CHAR_0; break;
|
|
case('1'): l = CHAR_1; break;
|
|
case('2'): l = CHAR_2; break;
|
|
case('3'): l = CHAR_3; break;
|
|
case('4'): l = CHAR_4; break;
|
|
case('5'): l = CHAR_5; break;
|
|
case('6'): l = CHAR_6; break;
|
|
case('7'): l = CHAR_7; break;
|
|
case('8'): l = CHAR_8; break;
|
|
case('9'): l = CHAR_9; break;
|
|
case(':'): l = CHAR_COLON; break;
|
|
case(','): l = CHAR_COMMA; break;
|
|
case('.'): l = CHAR_PEROID; break;
|
|
case('!'): l = CHAR_EXMARK; break;
|
|
case('-'): l = CHAR_MINUS; break;
|
|
case('+'): l = CHAR_PLUS; break;
|
|
case('/'): l = CHAR_FSLASH; break;
|
|
case('\\'): l = CHAR_BSLASH; break;
|
|
case('='): l = CHAR_EQUALS; break;
|
|
case('_'): l = CHAR_USCORE; break;
|
|
case('('): l = CHAR_BRACKET_O; break;
|
|
case(')'): l = CHAR_BRACKET_C; break;
|
|
case('%'): l = CHAR_PERCENT; break;
|
|
case('|'): l = CHAR_VBAR; break;
|
|
case('?'): l = CHAR_QMARK; break;
|
|
case('$'): l = CHAR_DOLLAR; break;
|
|
case('#'): l = CHAR_HASHTAG; break;
|
|
case('>'): l = CHAR_G_THEN; break;
|
|
case('<'): l = CHAR_L_THEN; break;
|
|
}
|
|
|
|
// Is the letter not null
|
|
if(l != null)
|
|
{
|
|
// Render the character
|
|
l.texCoord(0, 1); GlHelpers.vertex2(sy*i, 0 );
|
|
l.texCoord(0, 0); GlHelpers.vertex2(sy*i, sx);
|
|
l.texCoord(1, 0); GlHelpers.vertex2(sy*(i+1), sx);
|
|
l.texCoord(1, 1); GlHelpers.vertex2(sy*(i+1), 0 );
|
|
}
|
|
}
|
|
|
|
// Stop drawing quads
|
|
GlHelpers.end();
|
|
}
|
|
}
|