Search in sources :

Example 41 with Box

use of limelight.util.Box in project limelight by slagyr.

the class TextPanel method paintOn.

public void paintOn(Graphics2D graphics) {
    graphics.setColor(getStyle().getCompiledTextColor().getColor());
    float y = 0;
    if (lines == null)
        return;
    synchronized (this) {
        for (TextLayout textLayout : lines) {
            y += textLayout.getAscent();
            int x = getStyle().getCompiledHorizontalAlignment().getX((int) widthOf(textLayout), new Box(0, 0, getWidth(), getHeight()));
            textLayout.draw(graphics, x, y);
            y += textLayout.getDescent() + textLayout.getLeading();
        }
    }
}
Also used : Box(limelight.util.Box) TextLayout(java.awt.font.TextLayout)

Example 42 with Box

use of limelight.util.Box 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 43 with Box

use of limelight.util.Box 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)

Example 44 with Box

use of limelight.util.Box in project limelight by slagyr.

the class TextModel method recalculateOffset.

public void recalculateOffset(XOffsetStrategy xOffsetStrategy, YOffsetStrategy yOffsetStrategy) {
    Box boundingBox = getContainer().getConsumableBounds();
    Dimension textDimensions = getTextDimensions();
    int xOffset, yOffset;
    if (textDimensions.width < boundingBox.width)
        xOffset = getHorizontalAlignment().getX(textDimensions.width, boundingBox);
    else
        xOffset = xOffsetStrategy.calculateXOffset(this);
    if (textDimensions.height < boundingBox.height)
        yOffset = getVerticalAlignment().getY(textDimensions.height, boundingBox);
    else
        yOffset = yOffsetStrategy.calculateYOffset(this);
    setOffset(xOffset, yOffset);
}
Also used : Box(limelight.util.Box)

Example 45 with Box

use of limelight.util.Box in project limelight by slagyr.

the class ScrollMouseProcessor method mousePressed.

public void mousePressed(MousePressedEvent e) {
    sliderDragOn = false;
    unitIncrementOn = false;
    blockIncrementOn = false;
    mouseLocation = e.getLocation();
    if (scrollBar.getIncreasingButtonBounds().contains(mouseLocation))
        initiateUnitIncrement(scrollBar.getUnitIncrement());
    else if (scrollBar.getDecreasingButtonBounds().contains(mouseLocation))
        initiateUnitIncrement(-scrollBar.getUnitIncrement());
    else if (scrollBar.getTrackBounds().contains(mouseLocation)) {
        Box sliderBounds = scrollBar.getSliderBounds();
        if (isAfterSlider(mouseLocation, sliderBounds))
            initiateBlockIncrement(scrollBar.getBlockIncrement());
        else if (isBeforeSlider(mouseLocation, sliderBounds))
            initiateBlockIncrement(-scrollBar.getBlockIncrement());
        else if (scrollBar.getSliderBounds().contains(mouseLocation)) {
            sliderDragOn = true;
            sliderDragDelta = (int) (scrollBar.isHorizontal() ? mouseLocation.getX() - scrollBar.getSliderPosition() : mouseLocation.getY() - scrollBar.getSliderPosition());
        }
    }
}
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