Search in sources :

Example 1 with TypedLayout

use of limelight.ui.text.TypedLayout in project limelight by slagyr.

the class FittingYOffsetStrategy method calculateYOffset.

public int calculateYOffset(limelight.ui.model.text.TextModel model) {
    int yOffset = model.getYOffset();
    Box boundingBox = model.getContainer().getConsumableBounds();
    TextLocation caretLocation = model.getCaretLocation();
    int absoluteCaretY = model.getAbsoluteY(caretLocation);
    int relativeCaretY = absoluteCaretY + yOffset;
    TypedLayout caretLine = model.getLines().get(caretLocation.line);
    int caretHeight = caretLine.getHeight();
    if (caretHeight > boundingBox.height)
        yOffset = (caretHeight - boundingBox.height) / -2;
    else if (relativeCaretY + caretHeight >= boundingBox.height)
        yOffset = -absoluteCaretY - caretHeight + boundingBox.height;
    else if (absoluteCaretY < 0)
        yOffset = 0;
    else if (relativeCaretY < 0)
        yOffset = -absoluteCaretY;
    return yOffset;
}
Also used : TypedLayout(limelight.ui.text.TypedLayout) Box(limelight.util.Box) TextLocation(limelight.ui.text.TextLocation)

Example 2 with TypedLayout

use of limelight.ui.text.TypedLayout in project limelight by slagyr.

the class TextPanelMouseProcessor method processMouseDragged.

public void processMouseDragged(MouseDraggedEvent e) {
    Point mousePoint = e.getLocation();
    ArrayList<TypedLayout> lines = model.getLines();
    TextLocation tempLocation = model.getLocationAt(mousePoint);
    // TODO MDM - This needs work.  Ideally, the text will scroll smoothly, a pixel at a time, without the mouse moving.  The scoll speed increased as the mouse moves away.
    if (mousePoint.x < 3 && tempLocation.index > 0)
        tempLocation = tempLocation.moved(lines, -1);
    else if (mousePoint.x > (model.getContainer().getWidth() - 3) && tempLocation.atEnd(lines))
        tempLocation = tempLocation.moved(lines, +1);
    if (inWordSelectionMode)
        selectWord(tempLocation);
    else
        model.setCaretLocation(tempLocation, XOffsetStrategy.FITTING, YOffsetStrategy.FITTING);
    e.getRecipient().markAsDirty();
}
Also used : TypedLayout(limelight.ui.text.TypedLayout) TextLocation(limelight.ui.text.TextLocation)

Example 3 with TypedLayout

use of limelight.ui.text.TypedLayout in project limelight by slagyr.

the class TextPanelTextPainter method paint.

@Override
public void paint(Graphics2D graphics, limelight.ui.model.text.TextModel model) {
    if (!model.hasText())
        return;
    float y = model.getYOffset();
    Style style = model.getContainer().getStyle();
    graphics.setColor(style.getCompiledTextColor().getColor());
    for (TypedLayout line : model.getLines()) {
        int x = model.getXOffset(line);
        y += line.getAscent();
        line.draw(graphics, x, y);
        y += line.getDescent() + line.getLeading();
    }
}
Also used : TypedLayout(limelight.ui.text.TypedLayout) Style(limelight.styles.Style)

Example 4 with TypedLayout

use of limelight.ui.text.TypedLayout in project limelight by slagyr.

the class MultiLineTextModel method getLineAt.

public TypedLayout getLineAt(int y) {
    int remainingY = y - getYOffset();
    ArrayList<TypedLayout> lines = getLines();
    for (TypedLayout line : lines) {
        int lineHeight = line.getHeight();
        if (lineHeight > remainingY)
            return line;
        else
            remainingY -= lineHeight;
    }
    return lines.get(lines.size() - 1);
}
Also used : TypedLayout(limelight.ui.text.TypedLayout)

Example 5 with TypedLayout

use of limelight.ui.text.TypedLayout in project limelight by slagyr.

the class MultiLineTextModel method getTextDimensions.

@Override
public Dimension getTextDimensions() {
    if (!hasText())
        return new Dimension(0, 0);
    int height = 0;
    int width = 0;
    for (TypedLayout layout : getLines()) {
        height += layout.getHeight();
        int lineWidth = layout.getWidth();
        if (lineWidth > width)
            width = lineWidth;
    }
    return new Dimension(width, height);
}
Also used : TypedLayout(limelight.ui.text.TypedLayout)

Aggregations

TypedLayout (limelight.ui.text.TypedLayout)13 TextLocation (limelight.ui.text.TextLocation)7 Box (limelight.util.Box)3 ArrayList (java.util.ArrayList)1 Style (limelight.styles.Style)1