Search in sources :

Example 6 with TextLayoutInfo

use of automenta.vivisect.gui.StyledString.TextLayoutInfo in project opennars by opennars.

the class GTextArea method moveCaretUp.

protected boolean moveCaretUp(TextLayoutHitInfo currPos) {
    if (currPos.tli.lineNo == 0)
        return false;
    TextLayoutInfo ntli = stext.getTLIforLineNo(currPos.tli.lineNo - 1);
    TextHitInfo nthi = ntli.layout.hitTestChar(caretX, 0);
    currPos.tli = ntli;
    currPos.thi = nthi;
    return true;
}
Also used : TextHitInfo(java.awt.font.TextHitInfo) TextLayoutInfo(automenta.vivisect.gui.StyledString.TextLayoutInfo)

Example 7 with TextLayoutInfo

use of automenta.vivisect.gui.StyledString.TextLayoutInfo in project opennars by opennars.

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() && promptText != null)
            lines = promptText.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(automenta.vivisect.gui.StyledString.TextLayoutHitInfo) Shape(java.awt.Shape) TextLayoutInfo(automenta.vivisect.gui.StyledString.TextLayoutInfo) Graphics2D(java.awt.Graphics2D) TextLayout(java.awt.font.TextLayout)

Example 8 with TextLayoutInfo

use of automenta.vivisect.gui.StyledString.TextLayoutInfo in project opennars by opennars.

the class GTextArea method updateBuffer.

/**
 * If the buffer is invalid then redraw it.
 */
protected void updateBuffer() {
    if (bufferInvalid) {
        Graphics2D g2d = buffer.g2;
        // Get the latest lines of text
        LinkedList<TextLayoutInfo> lines = stext.getLines(g2d);
        if (lines.isEmpty() && promptText != null)
            lines = promptText.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);
        // Translate in preparation for display selection and text
        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 = 0;
                ss = (lineInfo.compareTo(startSelTLHI.tli) == 0) ? startSelTLHI.thi.getInsertionIndex() : 0;
                int ee = endSelTLHI.thi.getInsertionIndex();
                ee = (lineInfo.compareTo(endSelTLHI.tli) == 0) ? endSelTLHI.thi.getInsertionIndex() : lineInfo.nbrChars - 1;
                g2d.setColor(jpalette[14]);
                Shape selShape = layout.getLogicalHighlightShape(ss, ee);
                g2d.fill(selShape);
            }
            // display 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(automenta.vivisect.gui.StyledString.TextLayoutHitInfo) Shape(java.awt.Shape) TextLayoutInfo(automenta.vivisect.gui.StyledString.TextLayoutInfo) Graphics2D(java.awt.Graphics2D) TextLayout(java.awt.font.TextLayout)

Example 9 with TextLayoutInfo

use of automenta.vivisect.gui.StyledString.TextLayoutInfo in project opennars by opennars.

the class GTextArea method moveCaretDown.

protected boolean moveCaretDown(TextLayoutHitInfo currPos) {
    if (currPos.tli.lineNo == stext.getNbrLines() - 1)
        return false;
    TextLayoutInfo ntli = stext.getTLIforLineNo(currPos.tli.lineNo + 1);
    TextHitInfo nthi = ntli.layout.hitTestChar(caretX, 0);
    currPos.tli = ntli;
    currPos.thi = nthi;
    return true;
}
Also used : TextHitInfo(java.awt.font.TextHitInfo) TextLayoutInfo(automenta.vivisect.gui.StyledString.TextLayoutInfo)

Example 10 with TextLayoutInfo

use of automenta.vivisect.gui.StyledString.TextLayoutInfo in project opennars by opennars.

the class GTextArea method moveCaretRight.

/**
 * Move caret right by one character. If necessary move to the start of the next line
 * @return true if caret was moved else false
 */
protected boolean moveCaretRight(TextLayoutHitInfo currPos) {
    TextLayoutInfo ntli;
    TextHitInfo nthi = currPos.tli.layout.getNextRightHit(currPos.thi);
    if (nthi == null) {
        // Move the caret to the start of the next line the previous line
        if (currPos.tli.lineNo >= stext.getNbrLines() - 1)
            // Can't goto next line because this is the last line
            return false;
        else {
            // Move to start of next line
            ntli = stext.getTLIforLineNo(currPos.tli.lineNo + 1);
            nthi = ntli.layout.getNextLeftHit(1);
            currPos.tli = ntli;
            currPos.thi = nthi;
        }
    } else {
        // Move the caret to the right of current position
        currPos.thi = nthi;
    }
    return true;
}
Also used : TextHitInfo(java.awt.font.TextHitInfo) TextLayoutInfo(automenta.vivisect.gui.StyledString.TextLayoutInfo)

Aggregations

TextLayoutInfo (automenta.vivisect.gui.StyledString.TextLayoutInfo)17 Graphics2D (java.awt.Graphics2D)8 TextHitInfo (java.awt.font.TextHitInfo)6 TextLayout (java.awt.font.TextLayout)6 TextLayoutHitInfo (automenta.vivisect.gui.StyledString.TextLayoutHitInfo)5 Shape (java.awt.Shape)2