Skip to content

Commit

Permalink
Tooltip: Replace hacky method of keeping a consistent shadow opacity …
Browse files Browse the repository at this point in the history
…with better approach.

Previously we checked whether the window of the tooltip could possibly be painted multiple times and then set a flag to prevent the shadow from being painted more than once. It is a lot easier to simply erase the background with a transparent color. This may also help with #233.
  • Loading branch information
weisJ committed Mar 14, 2021
1 parent e937d09 commit d6525b6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,13 @@ protected boolean useDecoratedPopup() {

@Override
public void update(final Graphics g, final JComponent c) {
// Ensures no background is painted.
if (style.isOpqaue()) {
g.setColor(c.getBackground());
} else {
// Erase background completely.
g.setColor(PaintUtil.TRANSPARENT_COLOR);
}
g.fillRect(0, 0, c.getWidth(), c.getHeight());
paint(g, c);
}

Expand Down Expand Up @@ -419,10 +425,6 @@ public void paintNow(final float fraction) {
Window window = SwingUtilities.getWindowAncestor(toolTip);
if (DarkUIUtil.isDecorated(window)) return;
if (window != null) window.setOpacity(alpha);
Border border = toolTip.getBorder();
if (border instanceof DarkTooltipBorder) {
((DarkTooltipBorder) border).setSkipShadow(false);
}
}

@Override
Expand All @@ -431,10 +433,6 @@ protected void paintCycleEnd() {
Window window = SwingUtilities.getWindowAncestor(toolTip);
if (window != null && !DarkUIUtil.isDecorated(window)) {
window.setOpacity(alpha);
Border border = toolTip.getBorder();
if (window.getFocusableWindowState() && border instanceof DarkTooltipBorder) {
((DarkTooltipBorder) border).setSkipShadow(true);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public class DarkTooltipBorder implements Border, AlignableTooltipBorder {
private final DropShadowBorder shadowBorder;
private final BubbleBorder bubbleBorder;
private final boolean paintShadow;
private boolean skipShadow;
private Insets margin;
private Alignment alignment;
private boolean showPointer;
Expand Down Expand Up @@ -117,7 +116,7 @@ public void paintBorder(final Component c, final Graphics g, final int x, final
adjustInsets(ins);
Area innerArea = bubbleBorder.getBubbleArea(x + ins.left, y + ins.top, width - ins.left - ins.right,
height - ins.top - ins.bottom, bubbleBorder.getThickness());
if (!skipShadow && paintShadow) {
if (paintShadow) {
paintShadow(c, g, x, y, width, height, innerArea);
}
Area outerArea = bubbleBorder.getBubbleArea(x + ins.left, y + ins.top, width - ins.left - ins.right,
Expand Down Expand Up @@ -191,10 +190,6 @@ public int getShadowSize(final Component c) {
return shadowBorder.getShadowSize();
}

public void setSkipShadow(final boolean skip) {
this.skipShadow = skip;
}

@Override
public Point alignTooltip(final Component c, final Point p, final Alignment align, final Dimension dim,
final boolean outside) {
Expand Down

0 comments on commit d6525b6

Please sign in to comment.