Search in sources :

Example 1 with StyleFormat

use of pl.asie.charset.module.tablet.format.words.StyleFormat in project Charset by CharsetMC.

the class WordPrinterMCText method getWidth.

@Override
public int getWidth(IPrintingContextMinecraft context, WordText word) {
    StringBuilder s = new StringBuilder(word.getText());
    float scale = 1.0f;
    for (IStyle style : context.getStyleList()) {
        if (style instanceof StyleFormat) {
            s.insert(0, ((StyleFormat) style).getMcPrefix());
        } else if (style instanceof StyleScale) {
            scale *= ((StyleScale) style).scale;
        }
    }
    return (int) Math.ceil(context.getFontRenderer().getStringWidth(s.toString()) * scale);
}
Also used : IStyle(pl.asie.charset.module.tablet.format.api.IStyle) StyleScale(pl.asie.charset.module.tablet.format.words.StyleScale) StyleFormat(pl.asie.charset.module.tablet.format.words.StyleFormat)

Example 2 with StyleFormat

use of pl.asie.charset.module.tablet.format.words.StyleFormat in project Charset by CharsetMC.

the class WordPrinterMCText method draw.

@Override
public void draw(IPrintingContextMinecraft context, WordText word, int x, int y, boolean isHovering) {
    StringBuilder s = new StringBuilder(word.getText());
    float scale = 1.0f;
    int color = 0xFF000000;
    for (IStyle style : context.getStyleList()) {
        if (style instanceof StyleFormat) {
            s.insert(0, ((StyleFormat) style).getMcPrefix());
        } else if (style instanceof StyleColor) {
            color = 0xFF000000 | ((StyleColor) style).color;
        } else if (style instanceof StyleScale) {
            scale *= ((StyleScale) style).scale;
        }
    }
    if (scale == 1.0f) {
        context.getFontRenderer().drawString(s.toString(), x, y, color);
    } else {
        GlStateManager.pushMatrix();
        GlStateManager.translate(x, y, 0);
        GlStateManager.scale(scale, scale, scale);
        context.getFontRenderer().drawString(s.toString(), 0, 0, color);
        GlStateManager.popMatrix();
    }
}
Also used : IStyle(pl.asie.charset.module.tablet.format.api.IStyle) StyleScale(pl.asie.charset.module.tablet.format.words.StyleScale) StyleFormat(pl.asie.charset.module.tablet.format.words.StyleFormat) StyleColor(pl.asie.charset.module.tablet.format.words.StyleColor)

Aggregations

IStyle (pl.asie.charset.module.tablet.format.api.IStyle)2 StyleFormat (pl.asie.charset.module.tablet.format.words.StyleFormat)2 StyleScale (pl.asie.charset.module.tablet.format.words.StyleScale)2 StyleColor (pl.asie.charset.module.tablet.format.words.StyleColor)1