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;
}
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();
}
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();
}
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;
}
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;
}
Aggregations