Search in sources :

Example 1 with Box

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;
}
Also used : TypedLayout(limelight.ui.text.TypedLayout) Box(limelight.util.Box) TextLocation(limelight.ui.text.TextLocation)

Example 2 with Box

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();
        }
    }
}
Also used : ImageCache(limelight.ui.model.ImageCache) Style(limelight.styles.Style) Box(limelight.util.Box) IOException(java.io.IOException) StringValue(limelight.styles.abstrstyling.StringValue) Scene(limelight.ui.model.Scene)

Example 3 with Box

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);
    }
}
Also used : Box(limelight.util.Box)

Example 4 with Box

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);
}
Also used : Box(limelight.util.Box)

Example 5 with Box

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;
}
Also used : Box(limelight.util.Box)

Aggregations

Box (limelight.util.Box)80 Test (org.junit.Test)31 MockGraphics (limelight.ui.MockGraphics)11 Before (org.junit.Before)6 AffineTransform (java.awt.geom.AffineTransform)5 Style (limelight.styles.Style)3 TextLocation (limelight.ui.text.TextLocation)3 TypedLayout (limelight.ui.text.TypedLayout)3 BufferedImage (java.awt.image.BufferedImage)2 Panel (limelight.ui.Panel)2 TextLayout (java.awt.font.TextLayout)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 LimelightException (limelight.LimelightException)1 FlatStyle (limelight.styles.FlatStyle)1 StringValue (limelight.styles.abstrstyling.StringValue)1 AutoDimensionValue (limelight.styles.values.AutoDimensionValue)1 GreedyDimensionValue (limelight.styles.values.GreedyDimensionValue)1 BufferedImagePool (limelight.ui.BufferedImagePool)1 MockPanel (limelight.ui.MockPanel)1