Search in sources :

Example 66 with TextLayout

use of java.awt.font.TextLayout in project hid-serial by rayshobby.

the class GTextField method updateBuffer.

/**
	 * If the buffer is invalid then redraw it.
	 * @TODO need to use palette for colours
	 */
protected void updateBuffer() {
    if (bufferInvalid) {
        Graphics2D g2d = buffer.g2;
        // Get the latest lines of text
        LinkedList<TextLayoutInfo> lines = stext.getLines(g2d);
        if (lines.isEmpty() && defaultText != null)
            lines = defaultText.getLines(g2d);
        bufferInvalid = false;
        TextLayoutHitInfo startSelTLHI = null, endSelTLHI = null;
        buffer.beginDraw();
        // Whole control surface if opaque
        if (opaque)
            buffer.background(palette[6]);
        else
            buffer.background(buffer.color(255, 0));
        // Now move to top left corner of text display area
        buffer.translate(tx, ty);
        // Typing area surface
        buffer.noStroke();
        buffer.fill(palette[7]);
        buffer.rect(-1, -1, tw + 2, th + 2);
        g2d.setClip(gpTextDisplayArea);
        buffer.translate(-ptx, -pty);
        if (hasSelection()) {
            if (endTLHI.compareTo(startTLHI) == -1) {
                startSelTLHI = endTLHI;
                endSelTLHI = startTLHI;
            } else {
                startSelTLHI = startTLHI;
                endSelTLHI = endTLHI;
            }
        }
        // Display selection and text
        for (TextLayoutInfo lineInfo : lines) {
            TextLayout layout = lineInfo.layout;
            buffer.translate(0, layout.getAscent());
            // Draw selection if any
            if (hasSelection() && lineInfo.compareTo(startSelTLHI.tli) >= 0 && lineInfo.compareTo(endSelTLHI.tli) <= 0) {
                int ss = startSelTLHI.thi.getInsertionIndex();
                int ee = endSelTLHI.thi.getInsertionIndex();
                g2d.setColor(jpalette[14]);
                Shape selShape = layout.getLogicalHighlightShape(ss, ee);
                g2d.fill(selShape);
            }
            // Draw text
            g2d.setColor(jpalette[2]);
            lineInfo.layout.draw(g2d, 0, 0);
            buffer.translate(0, layout.getDescent() + layout.getLeading());
        }
        g2d.setClip(null);
        buffer.endDraw();
    }
}
Also used : TextLayoutHitInfo(g4p_controls.StyledString.TextLayoutHitInfo) Shape(java.awt.Shape) TextLayoutInfo(g4p_controls.StyledString.TextLayoutInfo) Graphics2D(java.awt.Graphics2D) TextLayout(java.awt.font.TextLayout)

Example 67 with TextLayout

use of java.awt.font.TextLayout in project hid-serial by rayshobby.

the class GToggleControl 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)
            if (selected)
                buffer.image(bicon[1], siX, siY);
            else
                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.getAdvance();
                    tw = (tw > wrapWidth) ? tw - wrapWidth : tw;
                    sx = (wrapWidth - tw) / 2;
                    break;
                case RIGHT:
                    tw = layout.getAdvance();
                    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)

Example 68 with TextLayout

use of java.awt.font.TextLayout 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)

Example 69 with TextLayout

use of java.awt.font.TextLayout in project hid-serial by rayshobby.

the class GLinearTrackControl method drawLabels.

protected void drawLabels() {
    Graphics2D g2d = buffer.g2;
    float px, py;
    TextLayout line;
    if (labelsInvalid) {
        ssStartLimit = new StyledString(getNumericDisplayString(startLimit));
        ssEndLimit = new StyledString(getNumericDisplayString(endLimit));
        limitsInvalid = false;
    }
    float deltaX = 1.0f / (nbrTicks - 1);
    switch(textOrientation) {
        case ORIENT_LEFT:
            for (int i = 0; i < labels.length; i++) {
                line = labels[i].getLines(g2d).getFirst().layout;
                px = (i * deltaX - 0.5f) * trackLength + line.getDescent();
                py = trackOffset + line.getVisibleAdvance();
                buffer.pushMatrix();
                buffer.translate(px, py);
                buffer.rotate(-PI / 2);
                line.draw(g2d, 0, 0);
                buffer.popMatrix();
            }
            break;
        case ORIENT_RIGHT:
            for (int i = 0; i < labels.length; i++) {
                line = labels[i].getLines(g2d).getFirst().layout;
                px = (i * deltaX - 0.5f) * trackLength - line.getDescent();
                py = trackOffset;
                buffer.pushMatrix();
                buffer.translate(px, py);
                buffer.rotate(PI / 2);
                line.draw(g2d, 0, 0);
                buffer.popMatrix();
            }
            break;
        case ORIENT_TRACK:
            for (int i = 0; i < labels.length; i++) {
                line = labels[i].getLines(g2d).getFirst().layout;
                px = (i * deltaX - 0.5f) * trackLength - 0.5f * line.getVisibleAdvance();
                py = trackOffset + line.getAscent();
                line.draw(g2d, px, py);
            }
            break;
    }
}
Also used : Graphics2D(java.awt.Graphics2D) TextLayout(java.awt.font.TextLayout)

Example 70 with TextLayout

use of java.awt.font.TextLayout in project hid-serial by rayshobby.

the class GLinearTrackControl method drawValue.

protected void drawValue() {
    Graphics2D g2d = buffer.g2;
    float px, py;
    TextLayout line;
    ssValue = new StyledString(getNumericDisplayString(getValueF()));
    line = ssValue.getLines(g2d).getFirst().layout;
    float advance = line.getVisibleAdvance();
    switch(textOrientation) {
        case ORIENT_LEFT:
            px = (parametricPos - 0.5f) * trackLength + line.getDescent();
            py = -trackOffset;
            buffer.pushMatrix();
            buffer.translate(px, py);
            buffer.rotate(-PI / 2);
            line.draw(g2d, 0, 0);
            buffer.popMatrix();
            break;
        case ORIENT_RIGHT:
            px = (parametricPos - 0.5f) * trackLength - line.getDescent();
            py = -trackOffset - advance;
            buffer.pushMatrix();
            buffer.translate(px, py);
            buffer.rotate(PI / 2);
            line.draw(g2d, 0, 0);
            buffer.popMatrix();
            break;
        case ORIENT_TRACK:
            px = (parametricPos - 0.5f) * trackLength - advance / 2;
            if (px < -trackDisplayLength / 2)
                px = -trackDisplayLength / 2;
            else if (px + advance > trackDisplayLength / 2)
                px = trackDisplayLength / 2 - advance;
            py = -trackOffset - line.getDescent();
            line.draw(g2d, px, py);
            line = ssEndLimit.getLines(g2d).getFirst().layout;
            break;
    }
}
Also used : Graphics2D(java.awt.Graphics2D) TextLayout(java.awt.font.TextLayout)

Aggregations

TextLayout (java.awt.font.TextLayout)108 AttributedString (java.text.AttributedString)32 Graphics2D (java.awt.Graphics2D)25 FontRenderContext (java.awt.font.FontRenderContext)25 Font (java.awt.Font)20 AttributedCharacterIterator (java.text.AttributedCharacterIterator)17 LineBreakMeasurer (java.awt.font.LineBreakMeasurer)16 Point (java.awt.Point)11 Rectangle (java.awt.Rectangle)10 Rectangle2D (java.awt.geom.Rectangle2D)10 Color (java.awt.Color)9 Paint (java.awt.Paint)8 AffineTransform (java.awt.geom.AffineTransform)8 Shape (java.awt.Shape)7 TextLayoutInfo (g4p_controls.StyledString.TextLayoutInfo)5 Dimension (java.awt.Dimension)5 TextHitInfo (java.awt.font.TextHitInfo)4 ArrayList (java.util.ArrayList)4 Graphics (java.awt.Graphics)3 Insets (java.awt.Insets)3