Search in sources :

Example 1 with AlignmentExt

use of com.github.weisj.darklaf.util.AlignmentExt in project darklaf by weisJ.

the class DarkButtonBorder method paintBorder.

@Override
public void paintBorder(final Component c, final Graphics g, final int x, final int y, final int width, final int height) {
    if (ButtonConstants.isBorderlessVariant(c)) {
        paintBorderlessBorder(c, g, x, y, width, height);
        return;
    }
    Graphics2D g2 = (Graphics2D) g;
    g2.translate(x, y);
    int arc = getArc(c);
    int focusArc = getFocusArc(c);
    GraphicsContext config = new GraphicsContext(g);
    AlignmentExt corner = getCornerFlag(c);
    boolean paintShadow = showDropShadow(corner);
    boolean focus = paintFocus(c);
    int shadowHeight = paintShadow ? getShadowSize() : 0;
    int borderSize = getBorderSize();
    Insets insetMask = new Insets(borderSize, borderSize, Math.max(borderSize, shadowHeight), borderSize);
    Insets focusIns = new Insets(0, 0, 0, 0);
    if (corner != null) {
        focusIns = corner.maskInsets(focusIns, -borderSize - focusArc);
        insetMask = corner.maskInsets(insetMask, -arc);
    }
    int bx = insetMask.left;
    int by = insetMask.top;
    int bw = width - insetMask.left - insetMask.right;
    int bh = height - insetMask.top - insetMask.bottom;
    int fx = focusIns.left;
    int fy = focusIns.top;
    int fw = width - focusIns.left - focusIns.right;
    int fh = by + bh + borderSize - focusIns.top - focusIns.bottom;
    if (paintFocus(c)) {
        paintFocusBorder(g2, focusArc, borderSize, fx, fy, fw, fh);
    }
    paintLineBorder(c, g2, arc, focus, bx, by, bw, bh);
    if (corner != null) {
        paintNeighbourFocus(g2, c, width, height);
    }
    config.restore();
}
Also used : GraphicsContext(com.github.weisj.darklaf.util.graphics.GraphicsContext) AlignmentExt(com.github.weisj.darklaf.util.AlignmentExt)

Example 2 with AlignmentExt

use of com.github.weisj.darklaf.util.AlignmentExt in project darklaf by weisJ.

the class DarkButtonBorder method paintNeighbourFocus.

protected void paintNeighbourFocus(final Graphics2D g2, final Component c, final int width, final int height) {
    JComponent left = ButtonConstants.getNeighbour(DarkButtonUI.KEY_LEFT_NEIGHBOUR, c);
    boolean paintLeft = DarkUIUtil.hasFocus(left);
    if (paintLeft) {
        AlignmentExt corner = getCornerFlag(left);
        Insets ins = new Insets(0, 0, 0, 0);
        if (corner != null)
            ins = corner.maskInsets(ins, borderSize);
        int h = height - Math.max(0, getShadowSize(left) - borderSize);
        paintFocusBorder(g2, getFocusArc(left), borderSize, -3 * borderSize + 1, -ins.top, 4 * borderSize, h + ins.top + ins.bottom);
    }
    JComponent right = ButtonConstants.getNeighbour(DarkButtonUI.KEY_RIGHT_NEIGHBOUR, c);
    boolean paintRight = DarkUIUtil.hasFocus(right);
    if (paintRight) {
        AlignmentExt corner = getCornerFlag(right);
        Insets ins = new Insets(0, 0, 0, 0);
        if (corner != null)
            ins = corner.maskInsets(ins, borderSize);
        int h = height - Math.max(0, getShadowSize(right) - borderSize);
        paintFocusBorder(g2, getFocusArc(right), borderSize, width - borderSize - 1, -ins.top, 4 * borderSize, h + ins.top + ins.bottom);
    }
    JComponent top = ButtonConstants.getNeighbour(DarkButtonUI.KEY_TOP_NEIGHBOUR, c);
    boolean paintTop = DarkUIUtil.hasFocus(top);
    if (paintTop) {
        AlignmentExt corner = getCornerFlag(top);
        Insets ins = new Insets(0, 0, 0, 0);
        if (corner != null)
            ins = corner.maskInsets(ins, borderSize);
        paintFocusBorder(g2, getFocusArc(top), borderSize, -ins.left, -3 * borderSize + 1, width + ins.right + ins.left, 4 * borderSize);
    }
    JComponent topLeft = ButtonConstants.getNeighbour(DarkButtonUI.KEY_TOP_LEFT_NEIGHBOUR, c);
    boolean paintTopLeft = DarkUIUtil.hasFocus(topLeft);
    if (paintTopLeft) {
        paintFocusBorder(g2, getFocusArc(topLeft), borderSize, -3 * borderSize + 1, -3 * borderSize + 1, 4 * borderSize, 4 * borderSize);
    }
    JComponent topRight = ButtonConstants.getNeighbour(DarkButtonUI.KEY_TOP_RIGHT_NEIGHBOUR, c);
    boolean paintTopRight = DarkUIUtil.hasFocus(topRight);
    if (paintTopRight) {
        paintFocusBorder(g2, getFocusArc(topRight), borderSize, width - borderSize - 1, -3 * borderSize + 1, 4 * borderSize, 4 * borderSize);
    }
    JComponent bottom = ButtonConstants.getNeighbour(DarkButtonUI.KEY_BOTTOM_NEIGHBOUR, c);
    boolean paintBottom = DarkUIUtil.hasFocus(bottom);
    if (paintBottom) {
        AlignmentExt corner = getCornerFlag(bottom);
        Insets ins = new Insets(0, 0, 0, 0);
        if (corner != null)
            ins = corner.maskInsets(ins, borderSize);
        paintFocusBorder(g2, getFocusArc(bottom), borderSize, -ins.left, height - borderSize - 1, width + ins.left + ins.right, 4 * borderSize);
    }
    JComponent bottomLeft = ButtonConstants.getNeighbour(DarkButtonUI.KEY_BOTTOM_LEFT_NEIGHBOUR, c);
    boolean paintBottomLeft = DarkUIUtil.hasFocus(bottomLeft);
    if (paintBottomLeft) {
        paintFocusBorder(g2, getFocusArc(bottomLeft), borderSize, -3 * borderSize + 1, height - borderSize - 1, 4 * borderSize, 4 * borderSize);
    }
    JComponent bottomRight = ButtonConstants.getNeighbour(DarkButtonUI.KEY_BOTTOM_RIGHT_NEIGHBOUR, c);
    boolean paintBottomRight = DarkUIUtil.hasFocus(bottomRight);
    if (paintBottomRight) {
        paintFocusBorder(g2, getFocusArc(bottomRight), borderSize, width - borderSize - 1, height - borderSize - 1, 4 * borderSize, 4 * borderSize);
    }
}
Also used : AlignmentExt(com.github.weisj.darklaf.util.AlignmentExt)

Example 3 with AlignmentExt

use of com.github.weisj.darklaf.util.AlignmentExt in project darklaf by weisJ.

the class DarkButtonBorder method maskInsets.

protected Insets maskInsets(final Insets ins, final Component c, final int shadow) {
    AlignmentExt alignment = getCornerFlag(c);
    if (alignment == null)
        return ins;
    Insets insetMask = new Insets(borderSize, borderSize, Math.max(borderSize, shadow), borderSize);
    insetMask = alignment.maskInsetsInverted(insetMask);
    ins.top -= insetMask.top;
    ins.bottom -= insetMask.bottom;
    ins.left -= insetMask.left;
    ins.right -= insetMask.right;
    return ins;
}
Also used : AlignmentExt(com.github.weisj.darklaf.util.AlignmentExt)

Example 4 with AlignmentExt

use of com.github.weisj.darklaf.util.AlignmentExt in project darklaf by weisJ.

the class DarkButtonUI method paintDarklafBorderBackground.

protected void paintDarklafBorderBackground(final AbstractButton c, final Graphics2D g, final int arc, final int width, final int height) {
    boolean showShadow = DarkButtonBorder.showDropShadow(c);
    int shadow = showShadow ? shadowHeight : 0;
    int effectiveArc = ButtonConstants.chooseArcWithBorder(c, arc, 0, 0, borderSize);
    AlignmentExt corner = DarkButtonBorder.getCornerFlag(c);
    Rectangle bgRect = getEffectiveRect(width, height, -(effectiveArc + 1), corner);
    paintDarklafBorderBgImpl(c, g, showShadow, shadow, effectiveArc, bgRect);
}
Also used : AlignmentExt(com.github.weisj.darklaf.util.AlignmentExt)

Aggregations

AlignmentExt (com.github.weisj.darklaf.util.AlignmentExt)4 GraphicsContext (com.github.weisj.darklaf.util.graphics.GraphicsContext)1