Formatting, classpath.

This commit is contained in:
Ondřej Hruška
2014-04-01 09:07:33 +02:00
parent 4a1a84fd87
commit 4bd18be9bb
106 changed files with 4802 additions and 4043 deletions
+2 -3
View File
@@ -1,13 +1,12 @@
package mightypork.rogue.fonts;
/**
* Alignment
*
* @author MightyPork
*/
public class Align {
public static final int LEFT = -1;
public static final int RIGHT = 1;
public static final int TOP = 1;
@@ -16,5 +15,5 @@ public class Align {
public static final int DOWN = -1;
public static final int CENTER = 0;
public static final int MIDDLE = 0;
}
+151 -132
View File
@@ -1,6 +1,5 @@
package mightypork.rogue.fonts;
import java.awt.Font;
import java.io.InputStream;
import java.util.HashMap;
@@ -18,16 +17,17 @@ import org.newdawn.slick.util.ResourceLoader;
* @author MightyPork
*/
public class FontManager {
private static final boolean DEBUG = Config.LOG_FONTS;
/**
* Glyph tables.
*
* @author MightyPork
*/
public static class Glyphs {
//@formatter:off
/** all glyphs */
public static final String all =
@@ -74,14 +74,14 @@ public class FontManager {
public static final String basic = alnum + signs;
//@formatter:on
}
/**
* Font style
*
* @author MightyPork
*/
public static enum Style
{
public static enum Style {
/** Normal */
NORMAL,
/** Italic */
@@ -111,98 +111,102 @@ public class FontManager {
/** Outline variant of normal */
OUTLINE;
}
// /**
// * Preloaded font identifier [name, size, style]
// *
// * @author MightyPork
// */
// public static class FontId {
//
// /** font size (pt) */
// public float size = 24;
// /** font name, registered with registerFile */
// public String name = "";
// /** font style. The given style must be in a file. */
// public Style style;
//
// /** Set of glyphs in this ID */
// public String glyphs = "";
//
// /** Index for faster comparision of glyph ids. */
// public int glyphset_id = 0;
//
//
// /**
// * Preloaded font identifier
// *
// * @param name font name (registerFile)
// * @param size font size (pt)
// * @param style font style
// * @param glyphs glyphs to load
// */
// public FontId(String name, double size, Style style, String glyphs) {
// this.name = name;
// this.size = (float) size;
// this.style = style;
//
// if (glyphs.equals(Glyphs.basic)) {
// glyphset_id = 1;
// } else if (glyphs.equals(Glyphs.alnum)) {
// glyphset_id = 2;
// } else if (glyphs.equals(Glyphs.basic_text)) {
// glyphset_id = 3;
// } else if (glyphs.equals(Glyphs.numbers)) {
// glyphset_id = 4;
// } else if (glyphs.equals(Glyphs.alpha)) {
// glyphset_id = 5;
// } else if (glyphs.equals(Glyphs.all)) {
// glyphset_id = 6;
// } else if (glyphs.equals(Glyphs.alnum_extra)) {
// glyphset_id = 7;
// } else if (glyphs.equals(Glyphs.signs)) {
// glyphset_id = 8;
// } else if (glyphs.equals(Glyphs.signs_extra)) {
// glyphset_id = 9;
// } else {
// this.glyphs = glyphs;
// }
// }
//
//
// @Override
// public boolean equals(Object obj)
// {
// if (obj == null) return false;
// if (!(obj.getClass().isAssignableFrom(getClass()))) return false;
// if (obj instanceof FontId) {
// if (obj == this) return true;
// FontId id2 = ((FontId) obj);
// boolean flag = true;
// flag &= id2.size == size;
// flag &= id2.name.equals(name);
// flag &= id2.style == style;
// flag &= ((id2.glyphset_id != -1 && id2.glyphset_id == glyphset_id) || id2.glyphs.equals(glyphs));
// return flag;
// }
// return false;
// }
//
//
// @Override
// public int hashCode()
// {
// return (new Float(size).hashCode()) ^ name.hashCode() ^ style.hashCode() ^ glyphset_id;
// }
//
//
// @Override
// public String toString()
// {
// return "[" + name + ", " + size + ", " + style + (glyphset_id > 0 ? ", g=" + glyphset_id : ", g=custom") + "]";
// }
// }
// /**
// * Preloaded font identifier [name, size, style]
// *
// * @author MightyPork
// */
// public static class FontId {
//
// /** font size (pt) */
// public float size = 24;
// /** font name, registered with registerFile */
// public String name = "";
// /** font style. The given style must be in a file. */
// public Style style;
//
// /** Set of glyphs in this ID */
// public String glyphs = "";
//
// /** Index for faster comparision of glyph ids. */
// public int glyphset_id = 0;
//
//
// /**
// * Preloaded font identifier
// *
// * @param name font name (registerFile)
// * @param size font size (pt)
// * @param style font style
// * @param glyphs glyphs to load
// */
// public FontId(String name, double size, Style style, String glyphs) {
// this.name = name;
// this.size = (float) size;
// this.style = style;
//
// if (glyphs.equals(Glyphs.basic)) {
// glyphset_id = 1;
// } else if (glyphs.equals(Glyphs.alnum)) {
// glyphset_id = 2;
// } else if (glyphs.equals(Glyphs.basic_text)) {
// glyphset_id = 3;
// } else if (glyphs.equals(Glyphs.numbers)) {
// glyphset_id = 4;
// } else if (glyphs.equals(Glyphs.alpha)) {
// glyphset_id = 5;
// } else if (glyphs.equals(Glyphs.all)) {
// glyphset_id = 6;
// } else if (glyphs.equals(Glyphs.alnum_extra)) {
// glyphset_id = 7;
// } else if (glyphs.equals(Glyphs.signs)) {
// glyphset_id = 8;
// } else if (glyphs.equals(Glyphs.signs_extra)) {
// glyphset_id = 9;
// } else {
// this.glyphs = glyphs;
// }
// }
//
//
// @Override
// public boolean equals(Object obj)
// {
// if (obj == null) return false;
// if (!(obj.getClass().isAssignableFrom(getClass()))) return false;
// if (obj instanceof FontId) {
// if (obj == this) return true;
// FontId id2 = ((FontId) obj);
// boolean flag = true;
// flag &= id2.size == size;
// flag &= id2.name.equals(name);
// flag &= id2.style == style;
// flag &= ((id2.glyphset_id != -1 && id2.glyphset_id == glyphset_id) ||
// id2.glyphs.equals(glyphs));
// return flag;
// }
// return false;
// }
//
//
// @Override
// public int hashCode()
// {
// return (new Float(size).hashCode()) ^ name.hashCode() ^ style.hashCode()
// ^ glyphset_id;
// }
//
//
// @Override
// public String toString()
// {
// return "[" + name + ", " + size + ", " + style + (glyphset_id > 0 ?
// ", g=" + glyphset_id : ", g=custom") + "]";
// }
// }
/**
* Group of styles of one font.
*
@@ -210,19 +214,22 @@ public class FontManager {
*/
public static class FontFamily extends HashMap<Style, String> {
}
/**
* Table of font files. name → {style:file,style:file,style:file...}
*/
private static HashMap<String, FontFamily> fontFiles = new HashMap<String, FontFamily>();
/**
* Register font file.
*
* @param path resource path (res/fonts/...)
* @param name font name (for binding)
* @param style font style in this file
* @param path
* resource path (res/fonts/...)
* @param name
* font name (for binding)
* @param style
* font style in this file
*/
public static void registerFile(String path, String name, Style style)
{
@@ -232,47 +239,59 @@ public class FontManager {
return;
}
}
// insert new table of styles to font name.
FontFamily family = new FontFamily();
family.put(style, path);
fontFiles.put(name, family);
}
/** Counter of loaded fonts */
public static int loadedFontCounter = 0;
/**
* Preload font if needed, get preloaded font.<br>
* If needed file is not available, throws runtime exception.
*
* @param name font name (registerFile)
* @param size font size (pt)
* @param style font style
* @param glyphs glyphs needed
* @param name
* font name (registerFile)
* @param size
* font size (pt)
* @param style
* font style
* @param glyphs
* glyphs needed
* @return the loaded font.
*/
public static LoadedFont loadFont(String name, double size, Style style, String glyphs)
{
return loadFont(name, size, style, glyphs, 9, 8, Coord.one(), 0, 0);
}
/**
* Preload font if needed, get preloaded font.<br>
* If needed file is not available, throws runtime exception.
*
* @param name font name (registerFile)
* @param size font size (pt)
* @param style font style
* @param glyphs glyphs needed
* @param correctLeft left horizontal correction
* @param correctRight right horizontal correction
* @param scale font scale (changing aspect ratio)
* @param clipTop top clip (0-1) - top part of the font to be cut off
* @param clipBottom bottom clip (0-1) - bottom part of the font to be cut
* off
* @param name
* font name (registerFile)
* @param size
* font size (pt)
* @param style
* font style
* @param glyphs
* glyphs needed
* @param correctLeft
* left horizontal correction
* @param correctRight
* right horizontal correction
* @param scale
* font scale (changing aspect ratio)
* @param clipTop
* top clip (0-1) - top part of the font to be cut off
* @param clipBottom
* bottom clip (0-1) - bottom part of the font to be cut off
* @return the loaded font.
*/
public static LoadedFont loadFont(String name, double size, Style style, String glyphs, int correctLeft, int correctRight, Coord scale, double clipTop, double clipBottom)
@@ -290,9 +309,9 @@ public class FontManager {
} catch (NullPointerException npe) {
throw new RuntimeException("Font loading failed: no font file registered for name \"" + name + "\".");
}
InputStream in = ResourceLoader.getResourceAsStream(resourcePath);
Font awtFont;
try {
awtFont = Font.createFont(Font.TRUETYPE_FONT, in);
@@ -300,18 +319,18 @@ public class FontManager {
Log.e("Loading of font " + resourcePath + " failed.", e);
throw new RuntimeException(e);
}
awtFont = awtFont.deriveFont((float) size); // set font size
LoadedFont font = new LoadedFont(awtFont, true, glyphs);
font.setCorrection(correctLeft, correctRight);
font.setClip(clipTop, clipBottom);
font.setScale(scale.x, scale.y);
loadedFontCounter++;
if (DEBUG) Log.f3("Font from file \"" + resourcePath + "\" preloaded.");
return font;
}
}
+11 -12
View File
@@ -1,6 +1,5 @@
package mightypork.rogue.fonts;
import static mightypork.rogue.fonts.FontManager.Style.*;
import mightypork.rogue.fonts.FontManager.Glyphs;
import mightypork.utils.logging.Log;
@@ -12,9 +11,9 @@ import mightypork.utils.logging.Log;
* @author Rapus
*/
public class Fonts {
public static LoadedFont splash_info;
public static LoadedFont tooltip;
public static LoadedFont gui;
public static LoadedFont gui_title;
@@ -22,26 +21,26 @@ public class Fonts {
public static LoadedFont menu_button;
public static LoadedFont menu_title;
public static LoadedFont tiny;
private static void registerFileNames()
{
FontManager.registerFile("res/fonts/4feb.ttf", "4feb", NORMAL);
}
/**
* Load fonts needed for splash.
*/
public static void loadForSplash()
{
registerFileNames();
gui = FontManager.loadFont("4feb", 24, NORMAL, Glyphs.basic).setCorrection(8, 7);
splash_info = FontManager.loadFont("4feb", 42, NORMAL, "Loading.");
}
/**
* Preload all fonts we will use in the game
*/
@@ -53,8 +52,8 @@ public class Fonts {
menu_title = FontManager.loadFont("4feb", 34, NORMAL, Glyphs.basic_text);
program_number = FontManager.loadFont("4feb", 28, NORMAL, Glyphs.numbers);
tiny = FontManager.loadFont("4feb", 20, NORMAL, Glyphs.basic_text);
Log.i("Fonts loaded = " + FontManager.loadedFontCounter);
}
}
+163 -153
View File
@@ -1,6 +1,5 @@
package mightypork.rogue.fonts;
import static mightypork.rogue.fonts.Align.*;
import static org.lwjgl.opengl.GL11.*;
@@ -39,82 +38,83 @@ import org.lwjgl.util.glu.GLU;
* @new version edited by MightyPork
*/
public class LoadedFont {
private static final boolean DEBUG = Config.LOG_FONTS;
/** Map of user defined font characters (Character <-> IntObject) */
private Map<Character, CharStorageEntry> chars = new HashMap<Character, CharStorageEntry>(100);
/** Boolean flag on whether AntiAliasing is enabled or not */
private boolean antiAlias;
/** Font's size */
private int fontSize = 0;
/** Font's height */
private int fontHeight = 0;
/** Texture used to cache the font 0-255 characters */
private int fontTextureID;
/** Default font texture width */
private int textureWidth = 2048;
/** Default font texture height */
private int textureHeight = 2048;
/** A reference to Java's AWT Font that we create our font texture from */
private Font font;
/** The font metrics for our Java AWT font */
private FontMetrics fontMetrics;
private int correctL = 9, correctR = 8;
private double defScaleX = 1, defScaleY = 1;
private double clipVerticalT = 0;
private double clipVerticalB = 0;
private class CharStorageEntry {
/** Character's width */
public int width;
/** Character's height */
public int height;
/** Character's stored x position */
public int texPosX;
/** Character's stored y position */
public int texPosY;
}
public LoadedFont(Font font, boolean antiAlias, String charsNeeded) {
this.font = font;
this.fontSize = font.getSize() + 3;
this.antiAlias = antiAlias;
createSet(charsNeeded.toCharArray());
fontHeight -= 1;
if (fontHeight <= 0) fontHeight = 1;
}
public void setCorrection(boolean on)
{
if (on) {
correctL = 9;//2
correctR = 8;//1
correctL = 9;// 2
correctR = 8;// 1
} else {
correctL = 0;
correctR = 0;
}
}
private BufferedImage getFontImage(char ch)
{
// Create a temporary image to extract the character's size
@@ -126,7 +126,7 @@ public class LoadedFont {
g.setFont(font);
fontMetrics = g.getFontMetrics();
int charwidth = fontMetrics.charWidth(ch) + 8;
if (charwidth <= 0) {
charwidth = 7;
}
@@ -134,7 +134,7 @@ public class LoadedFont {
if (charheight <= 0) {
charheight = fontSize;
}
// Create another image holding the character we are creating
BufferedImage fontImage;
fontImage = new BufferedImage(charwidth, charheight, BufferedImage.TYPE_INT_ARGB);
@@ -143,28 +143,28 @@ public class LoadedFont {
gt.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
}
gt.setFont(font);
gt.setColor(Color.WHITE);
int charx = 3;
int chary = 1;
gt.drawString(String.valueOf(ch), (charx), (chary) + fontMetrics.getAscent());
return fontImage;
}
private void createSet(char[] charsToLoad)
{
try {
class LoadedGlyph {
public char c;
public BufferedImage image;
public int width;
public int height;
public LoadedGlyph(char c, BufferedImage image) {
this.image = image;
this.c = c;
@@ -172,7 +172,7 @@ public class LoadedFont {
this.height = image.getHeight();
}
}
List<LoadedGlyph> glyphs = new ArrayList<LoadedGlyph>();
List<Character> loaded = new ArrayList<Character>();
for (char ch : charsToLoad) {
@@ -181,35 +181,35 @@ public class LoadedFont {
loaded.add(ch);
}
}
Coord canvas = new Coord(128, 128);
double lineHeight = 0;
Coord begin = new Coord(0, 0);
boolean needsLarger = false;
while (true) {
needsLarger = false;
for (LoadedGlyph glyph : glyphs) {
if (begin.x + glyph.width > canvas.x) {
begin.y += lineHeight;
lineHeight = 0;
begin.x = 0;
}
if (lineHeight < glyph.height) {
lineHeight = glyph.height;
}
if (begin.y + lineHeight > canvas.y) {
needsLarger = true;
break;
}
// draw.
begin.x += glyph.width;
}
if (needsLarger) {
canvas.x *= 2;
canvas.y *= 2;
@@ -220,62 +220,62 @@ public class LoadedFont {
break;
}
}
textureWidth = (int) canvas.x;
textureHeight = (int) canvas.y;
BufferedImage imgTemp = new BufferedImage(textureWidth, textureHeight, BufferedImage.TYPE_INT_ARGB);
Graphics2D g = (Graphics2D) imgTemp.getGraphics();
g.setColor(new Color(0, 0, 0, 1));
g.fillRect(0, 0, textureWidth, textureHeight);
int rowHeight = 0;
int positionX = 0;
int positionY = 0;
for (LoadedGlyph glyph : glyphs) {
CharStorageEntry storedChar = new CharStorageEntry();
storedChar.width = glyph.width;
storedChar.height = glyph.height;
if (positionX + storedChar.width >= textureWidth) {
positionX = 0;
positionY += rowHeight;
rowHeight = 0;
}
storedChar.texPosX = positionX;
storedChar.texPosY = positionY;
if (storedChar.height > fontHeight) {
fontHeight = storedChar.height;
}
if (storedChar.height > rowHeight) {
rowHeight = storedChar.height;
}
// Draw it here
g.drawImage(glyph.image, positionX, positionY, null);
positionX += storedChar.width;
chars.put(glyph.c, storedChar);
}
fontTextureID = loadImage(imgTemp);
imgTemp = null;
} catch (Exception e) {
System.err.println("Failed to create font.");
e.printStackTrace();
}
}
private void drawQuad(double drawX, double drawY, double drawX2, double drawY2, CharStorageEntry charObj)
{
double srcX = charObj.texPosX + charObj.width;
@@ -290,9 +290,9 @@ public class LoadedFont {
double SrcHeight = srcY2 - srcY;
double RenderWidth = (SrcWidth / textureWidth);
double RenderHeight = (SrcHeight / textureHeight);
drawY -= DrawHeight * clipVerticalB;
GL11.glTexCoord2d(TextureSrcX, TextureSrcY);
GL11.glVertex2d(drawX, drawY);
GL11.glTexCoord2d(TextureSrcX, TextureSrcY + RenderHeight);
@@ -302,8 +302,8 @@ public class LoadedFont {
GL11.glTexCoord2d(TextureSrcX + RenderWidth, TextureSrcY);
GL11.glVertex2d(drawX + DrawWidth, drawY);
}
public int getWidth(String whatchars)
{
if (whatchars == null) whatchars = "";
@@ -312,61 +312,61 @@ public class LoadedFont {
char currentChar = 0;
for (int i = 0; i < whatchars.length(); i++) {
currentChar = whatchars.charAt(i);
charStorage = chars.get(currentChar);
if (charStorage != null) {
totalwidth += charStorage.width - correctL;
}
}
return (int) (totalwidth * defScaleX);
}
public int getHeight()
{
return (int) (fontHeight * defScaleY * (1 - clipVerticalT - clipVerticalB));
}
public int getLineHeight()
{
return getHeight();
}
public void drawString(double x, double y, String text, double scaleX, double scaleY, RGB color)
{
drawString(x, y, text, 0, text.length() - 1, scaleX, scaleY, color, LEFT);
}
public void drawString(double x, double y, String text, double scaleX, double scaleY, RGB color, int align)
{
drawString(x, y, text, 0, text.length() - 1, scaleX, scaleY, color, align);
}
private void drawString(double x, double y, String text, int startIndex, int endIndex, double scaleX, double scaleY, RGB color, int align)
{
x = Math.round(x);
y = Math.round(y);
scaleX *= defScaleX;
scaleY *= defScaleY;
CharStorageEntry charStorage = null;
int charCurrent;
int totalwidth = 0;
int i = startIndex, d = 1, c = correctL;
float startY = 0;
switch (align) {
case RIGHT: {
d = -1;
c = correctR;
while (i < endIndex) {
if (text.charAt(i) == '\n') startY -= getHeight();
i++;
@@ -377,7 +377,7 @@ public class LoadedFont {
for (int l = startIndex; l <= endIndex; l++) {
charCurrent = text.charAt(l);
if (charCurrent == '\n') break;
charStorage = chars.get((char) charCurrent);
if (charStorage != null) {
totalwidth += charStorage.width - correctL;
@@ -392,20 +392,20 @@ public class LoadedFont {
c = correctL;
break;
}
}
GL11.glPushAttrib(GL_ENABLE_BIT);
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glBindTexture(GL11.GL_TEXTURE_2D, fontTextureID);
GL11.glColor4d(color.r, color.g, color.b, color.a);
GL11.glBegin(GL11.GL_QUADS);
while (i >= startIndex && i <= endIndex) {
charCurrent = text.charAt(i);
charStorage = chars.get(new Character((char) charCurrent));
if (charStorage != null) {
if (d < 0) totalwidth += (charStorage.width - c) * d;
if (charCurrent == '\n') {
@@ -415,14 +415,14 @@ public class LoadedFont {
for (int l = i + 1; l <= endIndex; l++) {
charCurrent = text.charAt(l);
if (charCurrent == '\n') break;
charStorage = chars.get((char) charCurrent);
totalwidth += charStorage.width - correctL;
}
totalwidth /= -2;
}
//if center get next lines total width/2;
// if center get next lines total width/2;
} else {
//@formatter:off
drawQuad(
@@ -432,25 +432,26 @@ public class LoadedFont {
charStorage
);
//@formatter:on
if (d > 0) totalwidth += (charStorage.width - c) * d;
}
}
i += d;
}
GL11.glEnd();
GL11.glPopAttrib();
}
public static int loadImage(BufferedImage bufferedImage)
{
try {
short width = (short) bufferedImage.getWidth();
short height = (short) bufferedImage.getHeight();
//textureLoader.bpp = bufferedImage.getColorModel().hasAlpha() ? (byte)32 : (byte)24;
// textureLoader.bpp = bufferedImage.getColorModel().hasAlpha() ?
// (byte)32 : (byte)24;
int bpp = (byte) bufferedImage.getColorModel().getPixelSize();
ByteBuffer byteBuffer;
DataBuffer db = bufferedImage.getData().getDataBuffer();
@@ -460,45 +461,45 @@ public class LoadedFont {
for (int i = 0; i < intI.length; i++) {
byte b[] = intToByteArray(intI[i]);
int newIndex = i * 4;
newI[newIndex] = b[1];
newI[newIndex + 1] = b[2];
newI[newIndex + 2] = b[3];
newI[newIndex + 3] = b[0];
}
byteBuffer = ByteBuffer.allocateDirect(width * height * (bpp / 8)).order(ByteOrder.nativeOrder()).put(newI);
} else {
byteBuffer = ByteBuffer.allocateDirect(width * height * (bpp / 8)).order(ByteOrder.nativeOrder()).put(((DataBufferByte) (bufferedImage.getData().getDataBuffer())).getData());
}
byteBuffer.flip();
int internalFormat = GL11.GL_RGBA8, format = GL11.GL_RGBA;
IntBuffer textureId = BufferUtils.createIntBuffer(1);
GL11.glGenTextures(textureId);
GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureId.get(0));
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_CLAMP);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
GL11.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_MODE, GL11.GL_MODULATE);
GLU.gluBuild2DMipmaps(GL11.GL_TEXTURE_2D, internalFormat, width, height, format, GL11.GL_UNSIGNED_BYTE, byteBuffer);
return textureId.get(0);
} catch (Exception e) {
e.printStackTrace();
System.exit(-1);
}
return -1;
}
public static boolean isSupported(String fontname)
{
Font font[] = getFonts();
@@ -507,14 +508,14 @@ public class LoadedFont {
}
return false;
}
public static Font[] getFonts()
{
return GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts();
}
public static Font getFont(String fontname, int style, float size)
{
Font result = null;
@@ -527,14 +528,14 @@ public class LoadedFont {
}
return result;
}
public static byte[] intToByteArray(int value)
{
return new byte[] { (byte) (value >>> 24), (byte) (value >>> 16), (byte) (value >>> 8), (byte) value };
}
public void destroy()
{
IntBuffer scratch = BufferUtils.createIntBuffer(1);
@@ -542,82 +543,91 @@ public class LoadedFont {
GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
GL11.glDeleteTextures(scratch);
}
public LoadedFont setScale(double x, double y)
{
defScaleX = x;
defScaleY = y;
return this;
}
public LoadedFont setClip(double clipRatioTop, double clipRatioBottom)
{
clipVerticalT = clipRatioTop;
clipVerticalB = clipRatioBottom;
return this;
}
public LoadedFont setCorrection(int correctionLeft, int correctionRight)
{
correctL = correctionLeft;
correctR = correctionRight;
return this;
}
/**
* Draw string with font.
*
* @param x x coord
* @param y y coord
* @param text text to draw
* @param color render color
* @param align (-1,0,1)
* @param x
* x coord
* @param y
* y coord
* @param text
* text to draw
* @param color
* render color
* @param align
* (-1,0,1)
*/
public void draw(double x, double y, String text, RGB color, int align)
{
drawString(x, y, text, 1, 1, color, align);
}
/**
* Draw string with font.
*
* @param pos coord
* @param text text to draw
* @param color render color
* @param align (-1,0,1)
* @param pos
* coord
* @param text
* text to draw
* @param color
* render color
* @param align
* (-1,0,1)
*/
public void draw(Coord pos, String text, RGB color, int align)
{
drawString(pos.x, pos.y, text, 1, 1, color, align);
}
public void drawFuzzy(Coord pos, String text, int align, RGB textColor, RGB blurColor, int blurSize)
{
drawFuzzy(pos, text, align, textColor, blurColor, blurSize, true);
}
public void drawFuzzy(Coord pos, String text, int align, RGB textColor, RGB blurColor, int blurSize, boolean smooth)
{
glPushMatrix();
glTranslated(pos.x, pos.y, pos.z);
//shadow
// shadow
int sh = blurSize;
int l = glGenLists(1);
glNewList(l, GL_COMPILE);
draw(0, 0, text, blurColor, align);
glEndList();
for (int xx = -sh; xx <= sh; xx += (smooth ? 1 : sh)) {
for (int yy = -sh; yy <= sh; yy += (smooth ? 1 : sh)) {
if (xx == 0 && yy == 0) continue;
@@ -627,12 +637,12 @@ public class LoadedFont {
glPopMatrix();
}
}
glDeleteLists(l, 1);
draw(0, 0, text, textColor, align);
glPopMatrix();
}
}