Browse Source

Paint rectangular background for non darklaf button borders.

pull/214/head
weisj 4 years ago
parent
commit
da1d622a1d
  1. 37
      core/src/main/java/com/github/weisj/darklaf/ui/button/DarkButtonUI.java

37
core/src/main/java/com/github/weisj/darklaf/ui/button/DarkButtonUI.java

@ -179,18 +179,28 @@ public class DarkButtonUI extends BasicButtonUI implements ButtonConstants {
int width = c.getWidth(); int width = c.getWidth();
int height = c.getHeight(); int height = c.getHeight();
Insets margin = b.getMargin(); Insets margin = b.getMargin();
if (margin instanceof UIResource) if (margin instanceof UIResource) {
margin = null; margin = null;
}
if (ButtonConstants.isBorderlessVariant(c)) { if (ButtonConstants.isBorderlessVariant(c)) {
paintBorderlessBackground(b, g2, arc, width, height, margin); paintBorderlessBackground(b, g2, arc, width, height, margin);
} else if (b.getBorder() instanceof DarkButtonBorder) {
paintDarklafBorderBackground(b, g2, arc, width, height);
} else { } else {
paintDefaultBackground(b, g2, arc, width, height); paintDefaultBackgroud(b, g2, width, height);
} }
} }
} }
protected void paintDefaultBackground(final AbstractButton c, final Graphics2D g, final int arc, final int width, protected void paintDefaultBackgroud(final AbstractButton b, final Graphics2D g, final int width,
final int height) { final int height) {
Insets ins = b.getInsets();
g.setColor(getBackgroundColor(b));
PaintUtil.fillRect(g, ins.left, ins.top, width - ins.left - ins.right, height - ins.top - ins.bottom);
}
protected void paintDarklafBorderBackground(final AbstractButton c, final Graphics2D g, final int arc,
final int width, final int height) {
boolean showShadow = DarkButtonBorder.showDropShadow(c); boolean showShadow = DarkButtonBorder.showDropShadow(c);
int shadow = showShadow ? shadowHeight : 0; int shadow = showShadow ? shadowHeight : 0;
int effectiveArc = ButtonConstants.chooseArcWithBorder(c, arc, 0, 0, borderSize); int effectiveArc = ButtonConstants.chooseArcWithBorder(c, arc, 0, 0, borderSize);
@ -240,10 +250,6 @@ public class DarkButtonUI extends BasicButtonUI implements ButtonConstants {
final int height, final Insets m) { final int height, final Insets m) {
if (isRolloverBorderless(b)) { if (isRolloverBorderless(b)) {
Insets ins = b.getInsets(); Insets ins = b.getInsets();
int x = ins.left;
int y = ins.top;
int w = width - ins.left - ins.right;
int h = height - ins.top - ins.bottom;
Insets margin = m; Insets margin = m;
if (margin == null) { if (margin == null) {
margin = new Insets(0, 0, 0, 0); margin = new Insets(0, 0, 0, 0);
@ -255,19 +261,20 @@ public class DarkButtonUI extends BasicButtonUI implements ButtonConstants {
int prefWidth = r.width + margin.right + margin.left + ins.left + ins.right; int prefWidth = r.width + margin.right + margin.left + ins.left + ins.right;
int prefHeight = r.height + margin.top + margin.bottom + ins.top + ins.bottom; int prefHeight = r.height + margin.top + margin.bottom + ins.top + ins.bottom;
margin = new Insets(margin.top, margin.left, margin.bottom, margin.right); margin = new Insets(margin.top, margin.left, margin.bottom, margin.right);
if (w > prefWidth) { if (width > prefWidth) {
margin.left = r.x - margin.left; margin.left = r.x - margin.left;
margin.right = w - (r.x + r.width + margin.right); margin.right = width - (r.x + r.width + margin.right);
} }
if (h > prefHeight) { if (height > prefHeight) {
margin.top = r.y - margin.top; margin.top = r.y - margin.top;
margin.bottom = h - (r.y + r.height + margin.bottom); margin.bottom = height - (r.y + r.height + margin.bottom);
} }
} }
x += margin.left;
y += margin.top; int x = Math.max(ins.left, margin.left);
w -= margin.left + margin.right; int y = Math.max(ins.top, margin.top);
h -= margin.top + margin.bottom; int w = width - x - Math.max(ins.right, margin.right);
int h = height - y - Math.max(ins.bottom, margin.bottom);
GraphicsUtil.setupAAPainting(g); GraphicsUtil.setupAAPainting(g);
g.setColor(getBorderlessBackground(b)); g.setColor(getBorderlessBackground(b));

Loading…
Cancel
Save