本文整理汇总了Java中org.newdawn.slick.UnicodeFont类的典型用法代码示例。如果您正苦于以下问题:Java UnicodeFont类的具体用法?Java UnicodeFont怎么用?Java UnicodeFont使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
UnicodeFont类属于org.newdawn.slick包,在下文中一共展示了UnicodeFont类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: init
import org.newdawn.slick.UnicodeFont; //导入依赖的package包/类
/**
* @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
*/
public void init(GameContainer container) throws SlickException {
container.setShowFPS(false);
// unicodeFont = new UnicodeFont(Font.decode("Arial Unicode MS"), 25, false, false);
unicodeFont = new UnicodeFont("c:/windows/fonts/arial.ttf", 48, false, false);
// unicodeFont.setPaddingBottom(10);
// unicodeFont.setPaddingRight(10);
// unicodeFont.setPaddingAdvanceX(-10);
// unicodeFont.getEffects().add(new ShadowEffect(java.awt.Color.black, 5, 5, 0.5f));
unicodeFont.getEffects().add(new ColorEffect(java.awt.Color.white));
// unicodeFont = new UnicodeFont("Arial", 25, false, false);
// unicodeFont = new UnicodeFont("Everson Mono", 44, false, false);
// font.addGlyphs(0, 255);
// font.addGlyphs("[email protected]#$%^&*()");
container.getGraphics().setBackground(Color.darkGray);
}
示例2: init
import org.newdawn.slick.UnicodeFont; //导入依赖的package包/类
@Override
public void init(GameContainer container) throws SlickException {
this.container = container;
this.map = new TiledMap("/home/enzo/newmap.tmx");
SpriteSheet spriteSheet = new SpriteSheet("/home/enzo/SpriteSheetAnim.png", 64, 64);
this.animations[0] = loadAnimation(spriteSheet, 0, 1, 0);
this.animations[1] = loadAnimation(spriteSheet, 0, 1, 1);
this.animations[2] = loadAnimation(spriteSheet, 0, 1, 2);
this.animations[3] = loadAnimation(spriteSheet, 0, 1, 3);
this.animations[4] = loadAnimation(spriteSheet, 1, 9, 0);
this.animations[5] = loadAnimation(spriteSheet, 1, 9, 1);
this.animations[6] = loadAnimation(spriteSheet, 1, 9, 2);
this.animations[7] = loadAnimation(spriteSheet, 1, 9, 3);
Font font = new Font("Verdana", Font.BOLD, 20);
UnicodeFont uFont = new UnicodeFont(font, font.getSize(), font.isBold(), font.isItalic());
nameInput = new TextField(container, uFont, 150,20,500,35, new ComponentListener()
{
public void componentActivated(AbstractComponent source) {
message = "Entered1: "+nameInput.getText();
nameInput.setFocus(true);
}
});
// ComponentListener listener = new ComponentListener();
// TextField nameInput = new TextField(arg0, truetypefont, 150,20,500,35, listener);
//
// {
// public void componentActivated(AbstractComponent source) {
// System.out.println("Entered1: "+nameInput.getText());
// }
// });
}
示例3: init
import org.newdawn.slick.UnicodeFont; //导入依赖的package包/类
/**
* @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
*/
public void init(GameContainer container) throws SlickException {
container.setShowFPS(false);
// unicodeFont = new UnicodeFont(Font.decode("Arial Unicode MS"), 25, false, false);
unicodeFont = new UnicodeFont("testdata/font.ttf", 48, false, false);
// unicodeFont.setPaddingBottom(10);
// unicodeFont.setPaddingRight(10);
// unicodeFont.setPaddingAdvanceX(-10);
// unicodeFont.getEffects().add(new ShadowEffect(java.awt.Color.black, 5, 5, 0.5f));
unicodeFont.getEffects().add(new ColorEffect(java.awt.Color.white));
unicodeFont.setDisplayListCaching(true);
// unicodeFont = new UnicodeFont("Arial", 25, false, false);
// unicodeFont = new UnicodeFont("Everson Mono", 44, false, false);
// font.addGlyphs(0, 255);
// font.addGlyphs("[email protected]#$%^&*()");
container.getGraphics().setBackground(Color.darkGray);
}
示例4: render
import org.newdawn.slick.UnicodeFont; //导入依赖的package包/类
@Override
public void render(GameContainer gc, StateBasedGame game, Graphics g) throws SlickException {
g.resetTransform();
g.clear();
float lw = 400.0f;
float lh = 50.0f;
float lx = (Globals.WIDTH / 2) - (lw / 2);
float ly = (Globals.HEIGHT / 2) - (lh / 2);
float loadWidth = lw * percentLoaded;
g.setColor(new Color(0x808080));
g.fillRect(lx, ly, lw, lh);
g.setColor(new Color(0x9B2111));
g.fillRect(lx, ly, loadWidth, lh);
g.setColor(Color.white);
g.drawRect(lx, ly, lw, lh);
g.setColor(Color.white);
UnicodeFont uni = assets.getFont("PressStart2P-Regular_large");
if(uni != null) {
g.setFont(uni);
FontUtils.drawCenter(uni, "Loading...", ((Globals.WIDTH / 2) - 200), (int)(ly - uni.getLineHeight() - 10), (int)lw, g.getColor());
}
}
示例5: addFont
import org.newdawn.slick.UnicodeFont; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public void addFont(String key, String file, int size, boolean bold, boolean italic, Effect [] effects) throws SlickException {
try {
AssetManager.ASSETS_TO_LOAD++;
UnicodeFont uni = new UnicodeFont(file, size, bold, italic);
uni.addAsciiGlyphs();
uni.addGlyphs(400, 600);
uni.getEffects().add(new ColorEffect(Color.WHITE));
uni.getEffects().addAll(Arrays.asList(effects));
uni.loadGlyphs();
if((fonts != null) && (uni != null)) {
fonts.put(key, uni);
AssetManager.ASSETS_LOADED++;
System.out.println(String.format("Font Loaded: %s", key));
}
} catch(Exception ex) {
ex.printStackTrace();
System.out.printf("ERROR: Font \"%s\" could not be loaded!\n", file);
}
}
示例6: init
import org.newdawn.slick.UnicodeFont; //导入依赖的package包/类
/**
* Initializes all fonts.
* @throws SlickException if ASCII glyphs could not be loaded
* @throws FontFormatException if any font stream data does not contain the required font tables
* @throws IOException if a font stream cannot be completely read
*/
public static void init() throws SlickException, FontFormatException, IOException {
float fontBase = 12f * GameImage.getUIscale();
Font javaFont = Font.createFont(Font.TRUETYPE_FONT, ResourceLoader.getResourceAsStream(Constants.FONT_NAME));
Font font = javaFont.deriveFont(Font.PLAIN, (int) (fontBase * 4 / 3));
DEFAULT = new UnicodeFont(font);
BOLD = new UnicodeFont(font.deriveFont(Font.BOLD));
XLARGE = new UnicodeFont(font.deriveFont(fontBase * 3));
LARGE = new UnicodeFont(font.deriveFont(fontBase * 2));
MEDIUM = new UnicodeFont(font.deriveFont(fontBase * 3 / 2));
MEDIUMBOLD = new UnicodeFont(font.deriveFont(Font.BOLD, fontBase * 3 / 2));
SMALL = new UnicodeFont(font.deriveFont(fontBase));
SMALLBOLD = new UnicodeFont(font.deriveFont(Font.BOLD, fontBase));
ColorEffect colorEffect = new ColorEffect();
loadFont(DEFAULT, colorEffect);
loadFont(BOLD, colorEffect);
loadFont(XLARGE, colorEffect);
loadFont(LARGE, colorEffect);
loadFont(MEDIUM, colorEffect);
loadFont(MEDIUMBOLD, colorEffect);
loadFont(SMALL, colorEffect);
loadFont(SMALLBOLD, colorEffect);
}
示例7: loadGlyphs
import org.newdawn.slick.UnicodeFont; //导入依赖的package包/类
/**
* Adds and loads glyphs for a font.
* @param font the font to add the glyphs to
* @param s the string containing the glyphs to load
*/
public static void loadGlyphs(UnicodeFont font, String s) {
if (s == null || s.isEmpty())
return;
// get set of added strings
HashSet<String> set = loadedGlyphs.get(font);
if (set == null) {
set = new HashSet<String>();
loadedGlyphs.put(font, set);
} else if (set.contains(s))
return; // string already in set
// load glyphs
font.addGlyphs(s);
set.add(s);
try {
font.loadGlyphs();
} catch (SlickException e) {
Log.warn(String.format("Failed to load glyphs for string '%s'.", s), e);
}
}
示例8: UnicodeFontRenderer
import org.newdawn.slick.UnicodeFont; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public UnicodeFontRenderer(Font awtFont) {
super(Minecraft.getMinecraft().gameSettings, new ResourceLocation("textures/font/ascii.png"),
Minecraft.getMinecraft().getTextureManager(), false);
font = new UnicodeFont(awtFont);
font.addAsciiGlyphs();
font.getEffects().add(new ColorEffect(Color.WHITE));
try {
font.loadGlyphs();
} catch (SlickException exception) {
throw new RuntimeException(exception);
}
String alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789";
FONT_HEIGHT = font.getHeight(alphabet) / 4;
}
示例9: draw
import org.newdawn.slick.UnicodeFont; //导入依赖的package包/类
/**
* @see org.newdawn.slick.font.effects.Effect#draw(java.awt.image.BufferedImage, java.awt.Graphics2D, org.newdawn.slick.UnicodeFont, org.newdawn.slick.font.Glyph)
*/
public void draw(BufferedImage image, Graphics2D g, UnicodeFont unicodeFont, Glyph glyph) {
g = (Graphics2D)g.create();
g.translate(xDistance, yDistance);
g.setColor(new Color(color.getRed(), color.getGreen(), color.getBlue(), Math.round(opacity * 255)));
g.fill(glyph.getShape());
// Also shadow the outline, if one exists.
for (Iterator iter = unicodeFont.getEffects().iterator(); iter.hasNext();) {
Effect effect = (Effect)iter.next();
if (effect instanceof OutlineEffect) {
Composite composite = g.getComposite();
g.setComposite(AlphaComposite.Src); // Prevent shadow and outline shadow alpha from combining.
g.setStroke(((OutlineEffect)effect).getStroke());
g.draw(glyph.getShape());
g.setComposite(composite);
break;
}
}
g.dispose();
if (blurKernelSize > 1 && blurKernelSize < NUM_KERNELS && blurPasses > 0) blur(image);
}
示例10: getWidth
import org.newdawn.slick.UnicodeFont; //导入依赖的package包/类
public static float getWidth(String s, double dScale)
{
UnicodeFont unicodeFont = null;// = fontStyleList.get(0).get(4);
int iFontIndex = 0;
//grab the font that is closest to the scale we are drawing.
for(int i = 0; i < fontSizes.length; i++)
{
if(iStandardSize * dScale * resolutionScale <= fontSizes[i])
{
unicodeFont = currentFont.get(i);
iFontIndex = i;
break;
}
}
float fFontScale = (float) (((float)iStandardSize * dScale * resolutionScale) / fontSizes[iFontIndex] );
return (float) (unicodeFont.getWidth(s) * fFontScale);
}
示例11: getHeight
import org.newdawn.slick.UnicodeFont; //导入依赖的package包/类
public static float getHeight(String s, double dScale)
{
String sFontName = inputFontList[iCurrentFontNum];
if(sFontName.equals("fonts/Base6.ttf"))
dScale *= .75f;
UnicodeFont unicodeFont = null;// = fontStyleList.get(0).get(4);
int iFontIndex = 0;
//grab the font that is closest to the scale we are drawing.
for(int i = 0; i < fontSizes.length; i++)
{
if(iStandardSize * dScale * resolutionScale <= fontSizes[i])
{
unicodeFont = currentFont.get(i);
iFontIndex = i;
break;
}
}
float fFontScale = (float) (((float)iStandardSize * dScale * resolutionScale) / fontSizes[iFontIndex] );
return (float) (unicodeFont.getHeight(s) * fFontScale);
}
示例12: init
import org.newdawn.slick.UnicodeFont; //导入依赖的package包/类
/**
* @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
*/
public void init(GameContainer container) throws SlickException {
container.setShowFPS(false);
// unicodeFont = new UnicodeFont(Font.decode("Arial Unicode MS"), 25, false, false);
unicodeFont = new UnicodeFont("testdata/Lato-Thin.ttf", 48, false, false);
// unicodeFont.setPaddingBottom(10);
// unicodeFont.setPaddingRight(10);
// unicodeFont.setPaddingAdvanceX(-10);
// unicodeFont.getEffects().add(new ShadowEffect(java.awt.Color.black, 5, 5, 0.5f));
unicodeFont.getEffects().add(new ColorEffect(java.awt.Color.white));
// unicodeFont = new UnicodeFont("Arial", 25, false, false);
// unicodeFont = new UnicodeFont("Everson Mono", 44, false, false);
// font.addGlyphs(0, 255);
// font.addGlyphs("[email protected]#$%^&*()");
container.getGraphics().setBackground(Color.darkGray);
}
示例13: draw
import org.newdawn.slick.UnicodeFont; //导入依赖的package包/类
/**
* @see org.newdawn.slick.font.effects.Effect#draw(java.awt.image.BufferedImage, java.awt.Graphics2D, org.newdawn.slick.UnicodeFont, org.newdawn.slick.font.Glyph)
*/
public void draw(BufferedImage image, Graphics2D g, UnicodeFont unicodeFont, Glyph glyph) {
int ascent = unicodeFont.getAscent();
float height = (ascent) * scale;
float top = -glyph.getYOffset() + unicodeFont.getDescent() + offset + ascent / 2 - height / 2;
g.setPaint(new GradientPaint(0, top, topColor, 0, top + height, bottomColor, cyclic));
g.fill(glyph.getShape());
}
示例14: Glyph
import org.newdawn.slick.UnicodeFont; //导入依赖的package包/类
/**
* Create a new glyph
*
* @param codePoint The code point in which this glyph can be found
* @param bounds The bounds that this glrph can fill
* @param vector The vector this glyph is part of
* @param index The index of this glyph within the vector
* @param unicodeFont The font this glyph forms part of
*/
public Glyph(int codePoint, Rectangle bounds, GlyphVector vector, int index, UnicodeFont unicodeFont) {
this.codePoint = codePoint;
GlyphMetrics metrics = vector.getGlyphMetrics(index);
int lsb = (int)metrics.getLSB();
if (lsb > 0) lsb = 0;
int rsb = (int)metrics.getRSB();
if (rsb > 0) rsb = 0;
int glyphWidth = bounds.width - lsb - rsb;
int glyphHeight = bounds.height;
if (glyphWidth > 0 && glyphHeight > 0) {
int padTop = unicodeFont.getPaddingTop();
int padRight = unicodeFont.getPaddingRight();
int padBottom = unicodeFont.getPaddingBottom();
int padLeft = unicodeFont.getPaddingLeft();
int glyphSpacing = 1; // Needed to prevent filtering problems.
width = (short)(glyphWidth + padLeft + padRight + glyphSpacing);
height = (short)(glyphHeight + padTop + padBottom + glyphSpacing);
yOffset = (short)(unicodeFont.getAscent() + bounds.y - padTop);
}
shape = vector.getGlyphOutline(index, -bounds.x + unicodeFont.getPaddingLeft(), -bounds.y + unicodeFont.getPaddingTop());
isMissing = !unicodeFont.getFont().canDisplay((char)codePoint);
}
示例15: render
import org.newdawn.slick.UnicodeFont; //导入依赖的package包/类
public void render(Graphics g) {
Image img = AssetManager.getManager().getImage(image);
if(img == null) {
// Draw the text representing the button.
UnicodeFont fnt = AssetManager.getManager().getFont(FONT_NAME);
Color color = mouseOver() ? DEFAULT_HOVER : DEFAULT_TEXT;
g.setColor(color);
g.setFont(fnt);
g.drawString(text, position.x, position.y);
} else g.drawImage(img, position.x, position.y);
}