Search in sources :

Example 11 with TextLayoutInfo

use of g4p_controls.StyledString.TextLayoutInfo in project hid-serial by rayshobby.

the class GLabel method updateBuffer.

protected void updateBuffer() {
    if (bufferInvalid) {
        Graphics2D g2d = buffer.g2;
        // Get the latest lines of text
        LinkedList<TextLayoutInfo> lines = stext.getLines(g2d);
        bufferInvalid = false;
        buffer.beginDraw();
        // Back ground colour
        if (opaque == true)
            buffer.background(palette[6]);
        else
            buffer.background(buffer.color(255, 0));
        // Calculate text and icon placement
        calcAlignment();
        // If there is an icon draw it
        if (iconW != 0)
            buffer.image(bicon[0], siX, siY);
        float wrapWidth = stext.getWrapWidth();
        float sx = 0, tw = 0;
        buffer.translate(stX, stY);
        for (TextLayoutInfo lineInfo : lines) {
            TextLayout layout = lineInfo.layout;
            buffer.translate(0, layout.getAscent());
            switch(textAlignH) {
                case CENTER:
                    tw = layout.getVisibleAdvance();
                    tw = (tw > wrapWidth) ? tw - wrapWidth : tw;
                    sx = (wrapWidth - tw) / 2;
                    break;
                case RIGHT:
                    tw = layout.getVisibleAdvance();
                    tw = (tw > wrapWidth) ? tw - wrapWidth : tw;
                    sx = wrapWidth - tw;
                    break;
                case LEFT:
                case JUSTIFY:
                default:
                    sx = 0;
            }
            // display text
            g2d.setColor(jpalette[2]);
            lineInfo.layout.draw(g2d, sx, 0);
            buffer.translate(0, layout.getDescent() + layout.getLeading());
        }
        buffer.endDraw();
    }
}
Also used : TextLayoutInfo(g4p_controls.StyledString.TextLayoutInfo) Graphics2D(java.awt.Graphics2D) TextLayout(java.awt.font.TextLayout)

Aggregations

TextLayoutInfo (g4p_controls.StyledString.TextLayoutInfo)11 Graphics2D (java.awt.Graphics2D)5 TextHitInfo (java.awt.font.TextHitInfo)5 TextLayout (java.awt.font.TextLayout)5 TextLayoutHitInfo (g4p_controls.StyledString.TextLayoutHitInfo)3 Shape (java.awt.Shape)2