use of limelight.util.Box 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.util.Box in project limelight by slagyr.
the class BackgroundPainter method paint.
public void paint(Graphics2D graphics, PaintablePanel panel) {
Style style = panel.getStyle();
Border border = panel.getBorderShaper();
Shape insideBorder = border.getShapeInsideBorder();
Color backgroundColor = style.getCompiledBackgroundColor().getColor();
if (style.getCompiledGradient().isOn())
GradientPainter.instance.paint(graphics, panel);
else {
if (backgroundColor.getAlpha() > 0) {
graphics.setColor(backgroundColor);
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
graphics.fill(insideBorder);
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
}
}
NoneableValue<StringValue> backgroundImageAttribute = style.getCompiledBackgroundImage();
if (!backgroundImageAttribute.isNone()) {
try {
Box borderFrame = panel.getBorderedBounds();
Scene rootPanel = panel.getRoot();
// TODO MDM - getting a NullPointer here. The Panel was removed from the scene in between the start of the paint cycle and here.
if (rootPanel == null)
return;
ImageCache cache = rootPanel.getImageCache();
Image image = cache.getImage(backgroundImageAttribute.getAttribute().getValue());
Graphics2D borderedGraphics = (Graphics2D) graphics.create(borderFrame.x, borderFrame.y, borderFrame.width, borderFrame.height);
style.getCompiledBackgroundImageFillStrategy().fill(borderedGraphics, image, style.getCompiledBackgroundImageX(), style.getCompiledBackgroundImageY());
} catch (IOException e) {
e.printStackTrace();
}
}
}
use of limelight.util.Box in project limelight by slagyr.
the class TextInputPanel method markCursorRegionAsDirty.
protected void markCursorRegionAsDirty() {
Scene rootPanel = getRoot();
if (rootPanel != null) {
Box caret = model.getCaretShape().translated(getAbsoluteLocation());
rootPanel.addDirtyRegion(caret);
}
}
use of limelight.util.Box in project limelight by slagyr.
the class TextPanelCaretPainter method paint.
public void paint(Graphics2D graphics, limelight.ui.model.text.TextModel model) {
if (!model.isCaretOn() || model.hasSelection())
return;
Box caret = model.getCaretShape();
graphics.setColor(model.getContainer().getStyle().getCompiledTextColor().getColor());
graphics.fill(caret);
}
use of limelight.util.Box in project limelight by slagyr.
the class CenteredXOffsetStrategy method calculateXOffset.
public int calculateXOffset(limelight.ui.model.text.TextModel model) {
int xOffset = model.getXOffset();
Box boundingBox = model.getContainer().getConsumableBounds();
int absoluteCaretX = model.getAbsoluteX(model.getCaretLocation());
int relativeCaretX = absoluteCaretX + xOffset;
if (relativeCaretX >= boundingBox.width || relativeCaretX < 0) {
xOffset = (absoluteCaretX - boundingBox.width / 2) * -1;
int maxOffset = boundingBox.width - model.getTextDimensions().width - model.getCaretWidth();
if (xOffset < maxOffset)
xOffset = maxOffset;
else if (xOffset > 0)
xOffset = 0;
relativeCaretX = absoluteCaretX + xOffset;
if (relativeCaretX == boundingBox.width)
xOffset -= model.getCaretWidth();
}
return xOffset;
}
Aggregations