org.newdawn.slick.font.effects.ColorEffect Java Examples

The following examples show how to use org.newdawn.slick.font.effects.ColorEffect. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Fonts.java    From opsu-dance with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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);
}
 
Example #2
Source File: UnicodeFontTest.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
	 * @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("~!@#$%^&*()");

		container.getGraphics().setBackground(Color.darkGray);
	}
 
Example #3
Source File: HyperiumFontRenderer.java    From Hyperium with GNU Lesser General Public License v3.0 5 votes vote down vote up
public HyperiumFontRenderer(String fontName, float fontSize) {
    name = fontName;
    size = fontSize;
    ScaledResolution resolution = new ScaledResolution(Minecraft.getMinecraft());

    try {
        prevScaleFactor = resolution.getScaleFactor();
        unicodeFont = new UnicodeFont(getFontByName(fontName).deriveFont(fontSize * prevScaleFactor / 2));
        unicodeFont.addAsciiGlyphs();
        unicodeFont.getEffects().add(new ColorEffect(java.awt.Color.WHITE));
        unicodeFont.loadGlyphs();
    } catch (FontFormatException | IOException | SlickException e) {
        e.printStackTrace();
    }

    this.antiAliasingFactor = resolution.getScaleFactor();
}
 
Example #4
Source File: Fonts.java    From opsu with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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 javaFontMain = Font.createFont(Font.TRUETYPE_FONT, ResourceLoader.getResourceAsStream(Options.FONT_MAIN));
	Font javaFontBold = Font.createFont(Font.TRUETYPE_FONT, ResourceLoader.getResourceAsStream(Options.FONT_BOLD));
	Font javaFontCJK = Font.createFont(Font.TRUETYPE_FONT, ResourceLoader.getResourceAsStream(Options.FONT_CJK));
	Font fontMain = javaFontMain.deriveFont(Font.PLAIN, (int) (fontBase * 4 / 3));
	Font fontBold = javaFontBold.deriveFont(Font.PLAIN, (int) (fontBase * 4 / 3));
	Font fontCJK = javaFontCJK.deriveFont(Font.PLAIN, (int) (fontBase * 4 / 3));
	DEFAULT = new UnicodeFont(fontMain);
	BOLD = new UnicodeFont(fontBold.deriveFont(Font.BOLD));
	XLARGE = new UnicodeFont(fontMain.deriveFont(fontBase * 3));
	LARGE = new UnicodeFont(fontMain.deriveFont(fontBase * 2));
	MEDIUM = new UnicodeFont(fontMain.deriveFont(fontBase * 3 / 2));
	MEDIUMBOLD = new UnicodeFont(fontBold.deriveFont(Font.BOLD, fontBase * 3 / 2));
	SMALL = new UnicodeFont(fontMain.deriveFont(fontBase));
	SMALLBOLD = new UnicodeFont(fontBold.deriveFont(Font.BOLD, fontBase));
	ColorEffect colorEffect = new ColorEffect();
	loadFont(DEFAULT, colorEffect, new UnicodeFont(fontCJK));
	loadFont(BOLD, colorEffect, new UnicodeFont(fontCJK.deriveFont(Font.BOLD)));
	loadFont(XLARGE, colorEffect, new UnicodeFont(fontCJK.deriveFont(fontBase * 3)));
	loadFont(LARGE, colorEffect, new UnicodeFont(fontCJK.deriveFont(fontBase * 2)));
	loadFont(MEDIUM, colorEffect, new UnicodeFont(fontCJK.deriveFont(fontBase * 3 / 2)));
	loadFont(MEDIUMBOLD, colorEffect, new UnicodeFont(fontCJK.deriveFont(Font.BOLD, fontBase * 3 / 2)));
	loadFont(SMALL, colorEffect, new UnicodeFont(fontCJK.deriveFont(fontBase)));
	loadFont(SMALLBOLD, colorEffect, new UnicodeFont(fontCJK.deriveFont(Font.BOLD, fontBase)));
}
 
Example #5
Source File: UnicodeFontRenderer.java    From Minecraft-GUI-API with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@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) / 2;
}
 
Example #6
Source File: HyperiumFontRenderer.java    From Hyperium with GNU Lesser General Public License v3.0 4 votes vote down vote up
public int drawString(String text, float x, float y, int color) {
    if (text == null) return 0;

    ScaledResolution resolution = new ScaledResolution(Minecraft.getMinecraft());

    try {
        if (resolution.getScaleFactor() != prevScaleFactor) {
            prevScaleFactor = resolution.getScaleFactor();
            unicodeFont = new UnicodeFont(getFontByName(name).deriveFont(size * prevScaleFactor / 2));
            unicodeFont.addAsciiGlyphs();
            unicodeFont.getEffects().add(new ColorEffect(java.awt.Color.WHITE));
            unicodeFont.loadGlyphs();
        }
    } catch (FontFormatException | IOException | SlickException e) {
        e.printStackTrace();
    }

    this.antiAliasingFactor = resolution.getScaleFactor();

    GL11.glPushMatrix();
    GlStateManager.scale(1 / antiAliasingFactor, 1 / antiAliasingFactor, 1 / antiAliasingFactor);
    x *= antiAliasingFactor;
    y *= antiAliasingFactor;
    float originalX = x;
    float red = (float) (color >> 16 & 255) / 255.0F;
    float green = (float) (color >> 8 & 255) / 255.0F;
    float blue = (float) (color & 255) / 255.0F;
    float alpha = (float) (color >> 24 & 255) / 255.0F;
    GlStateManager.color(red, green, blue, alpha);

    int currentColor = color;

    char[] characters = text.toCharArray();

    GlStateManager.disableLighting();
    GlStateManager.enableBlend();
    GlStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ZERO);
    GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

    String[] parts = COLOR_CODE_PATTERN.split(text);
    int index = 0;
    for (String s : parts) {
        for (String s2 : s.split("\n")) {
            for (String s3 : s2.split("\r")) {

                unicodeFont.drawString(x, y, s3, new org.newdawn.slick.Color(currentColor));
                x += unicodeFont.getWidth(s3);

                index += s3.length();
                if (index  < characters.length && characters[index ] == '\r') {
                    x = originalX;
                    index++;
                }
            }
            if (index < characters.length && characters[index] == '\n') {
                x = originalX;
                y += getHeight(s2) * 2;
                index++;
            }
        }
        if (index < characters.length) {
            char colorCode = characters[index];
            if (colorCode == 'ยง') {
                char colorChar = characters[index + 1];
                int codeIndex = ("0123456789" +
                    "abcdef").indexOf(colorChar);
                if (codeIndex < 0) {
                    if (colorChar == 'r') {
                        currentColor = color;
                    }
                } else {
                    currentColor = colorCodes[codeIndex];
                }
                index += 2;
            }
        }
    }

    GlStateManager.color(1F, 1F, 1F, 1F);
    GlStateManager.bindTexture(0);
    GlStateManager.popMatrix();
    return (int) x;
}
 
Example #7
Source File: Hiero.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public Hiero () throws SlickException {
	super("Hiero v2.0 - Bitmap Font Tool");
	Splash splash = new Splash(this, "splash.jpg", 2000);
	try {
		initialize();
	} catch (SlickException ex) {
		dispose();
		throw ex;
	}
	splash.close();
	setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
	addWindowListener(new WindowAdapter() {
		public void windowClosing(WindowEvent e) {
			// stop slick2d event loop; maybe slick2d should use awt timer for that:
			// http://www.pushing-pixels.org/2008/07/17/awt-shutdown-and-daemon-threads.html
			canvasContainer.setVisible(false);
			dispose();
		}
	});
	
	prefs = Preferences.userNodeForPackage(Hiero.class);
	java.awt.Color backgroundColor = EffectUtil.fromString(prefs.get("background", "000000"));
	backgroundColorLabel.setIcon(getColorIcon(backgroundColor));
	renderingBackgroundColor = new Color(backgroundColor.getRed(), backgroundColor.getGreen(), backgroundColor.getBlue());
	fontList.setSelectedValue(prefs.get("system.font", "Arial"), true);
	fontFileText.setText(prefs.get("font.file", ""));

	java.awt.Color foregroundColor = EffectUtil.fromString(prefs.get("foreground", "ffffff"));
	colorEffect = new ColorEffect();
	colorEffect.setColor(foregroundColor);
	effectsListModel.addElement(colorEffect);
	effectsListModel.addElement(new GradientEffect());
	effectsListModel.addElement(new OutlineEffect());
	effectsListModel.addElement(new OutlineWobbleEffect());
	effectsListModel.addElement(new OutlineZigzagEffect());
	effectsListModel.addElement(new ShadowEffect());
	new EffectPanel(colorEffect);

	setVisible(true);
	gamePanel.add(canvasContainer);
	gamePanel.setVisible(false);
	canvasContainer.start();
}