Search in sources :

Example 1 with TextLocation

use of limelight.ui.text.TextLocation 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 TextLocation

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

the class TextPanelMouseProcessor method processMousePressed.

public void processMousePressed(MousePressedEvent e) {
    final Panel panel = e.getRecipient();
    inWordSelectionMode = false;
    TextLocation location = model.getLocationAt(e.getLocation());
    model.startSelection(location);
    model.setCaretLocation(location, XOffsetStrategy.FITTING, YOffsetStrategy.FITTING);
    model.setCaretOn(true);
    handleMultipleClicks(e);
    panel.markAsDirty();
    panel.getStage().getKeyListener().focusOn(panel);
    lastClickTime = System.currentTimeMillis();
}
Also used : Panel(limelight.ui.Panel) TextLocation(limelight.ui.text.TextLocation)

Example 3 with TextLocation

use of limelight.ui.text.TextLocation 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 4 with TextLocation

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

the class MultiLineTextModel method getCaretShape.

@Override
public Box getCaretShape() {
    TextLocation caretLocation = getCaretLocation();
    TypedLayout line = getLines().get(caretLocation.line);
    Box caretShape = line.getCaretShape(caretLocation.index);
    caretShape.translate(getXOffset(line), getY(caretLocation));
    return caretShape;
}
Also used : TypedLayout(limelight.ui.text.TypedLayout) Box(limelight.util.Box) TextLocation(limelight.ui.text.TextLocation)

Example 5 with TextLocation

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

the class MultiLineTextModel method getSelectionRegions.

@Override
public ArrayList<Box> getSelectionRegions() {
    ArrayList<Box> regions = new ArrayList<Box>();
    boolean startsAtCaret = getCaretLocation().before(getSelectionLocation());
    TextLocation start = startsAtCaret ? getCaretLocation() : getSelectionLocation();
    TextLocation end = startsAtCaret ? getSelectionLocation() : getCaretLocation();
    ArrayList<TypedLayout> lines = getLines();
    int y = getY(start);
    for (int i = start.line; i <= end.line; i++) {
        TypedLayout line = lines.get(i);
        int startX = i == start.line ? line.getX(start.index) + getXOffset(line) : 0;
        int endX = i == end.line ? line.getX(end.index) + getXOffset(line) : getContainer().getWidth();
        regions.add(new Box(startX, y, endX - startX, line.getHeight()));
        y += line.getHeight() + line.getLeading();
    }
    return regions;
}
Also used : TypedLayout(limelight.ui.text.TypedLayout) ArrayList(java.util.ArrayList) Box(limelight.util.Box) TextLocation(limelight.ui.text.TextLocation)

Aggregations

TextLocation (limelight.ui.text.TextLocation)8 TypedLayout (limelight.ui.text.TypedLayout)7 Box (limelight.util.Box)3 ArrayList (java.util.ArrayList)1 Panel (limelight.ui.Panel)1