From 9015a4d56b2834f69e384b9b6dca8aaa4c22cd36 Mon Sep 17 00:00:00 2001 From: Karl Tauber Date: Sat, 23 Jan 2021 16:59:53 +0100 Subject: [PATCH] Window decorations: fixed top window border in dark themes when running in JetBrains Runtime (issue #244) fixed/improved calculation of active border color --- CHANGELOG.md | 2 ++ .../flatlaf/ui/JBRCustomDecorations.java | 24 ++++++++++++++----- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f4536c7f..8aa6132c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,8 @@ FlatLaf Change Log color is different to default background color, even if component is not opaque (which is the default). This paints selection if using the component as cell renderer a Table, Tree or List. +- Custom window decorations: Fixed top window border in dark themes when running + in JetBrains Runtime. ## 1.0-rc1 diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/JBRCustomDecorations.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/JBRCustomDecorations.java index c8abc5a6..e3d68e7d 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/JBRCustomDecorations.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/JBRCustomDecorations.java @@ -227,7 +227,6 @@ public class JBRCustomDecorations private final Color defaultActiveBorder = new Color( 0x707070 ); private final Color inactiveLightColor = new Color( 0xaaaaaa ); - private final Color inactiveDarkColor = new Color( 0x3f3f3f ); private boolean colorizationAffectsBorders; private Color activeColor = defaultActiveBorder; @@ -273,7 +272,7 @@ public class JBRCustomDecorations Object colorizationColorBalanceObj = toolkit.getDesktopProperty( "win.dwm.colorizationColorBalance" ); if( colorizationColorBalanceObj instanceof Integer ) { int colorizationColorBalance = (Integer) colorizationColorBalanceObj; - if( colorizationColorBalance < 0 ) + if( colorizationColorBalance < 0 || colorizationColorBalance > 100 ) colorizationColorBalance = 100; if( colorizationColorBalance == 0 ) @@ -283,9 +282,15 @@ public class JBRCustomDecorations float alpha = colorizationColorBalance / 100.0f; float remainder = 1 - alpha; - int r = Math.round( (colorizationColor.getRed() * alpha + 0xD9 * remainder) ); - int g = Math.round( (colorizationColor.getGreen() * alpha + 0xD9 * remainder) ); - int b = Math.round( (colorizationColor.getBlue() * alpha + 0xD9 * remainder) ); + int r = Math.round( colorizationColor.getRed() * alpha + 0xD9 * remainder ); + int g = Math.round( colorizationColor.getGreen() * alpha + 0xD9 * remainder ); + int b = Math.round( colorizationColor.getBlue() * alpha + 0xD9 * remainder ); + + // avoid potential IllegalArgumentException in Color constructor + r = Math.min( Math.max( r, 0 ), 255 ); + g = Math.min( Math.max( g, 0 ), 255 ); + b = Math.min( Math.max( b, 0 ), 255 ); + return new Color( r, g, b ); } return colorizationColor; @@ -300,7 +305,14 @@ public class JBRCustomDecorations Window window = SwingUtilities.windowForComponent( c ); boolean active = (window != null) ? window.isActive() : false; - g.setColor( active ? activeColor : (FlatLaf.isLafDark() ? inactiveDarkColor : inactiveLightColor) ); + // paint top border + // - in light themes + // - in dark themes only for active windows if colorization affects borders + boolean paintTopBorder = !FlatLaf.isLafDark() || (active && colorizationAffectsBorders); + if( !paintTopBorder ) + return; + + g.setColor( active ? activeColor : inactiveLightColor ); HiDPIUtils.paintAtScale1x( (Graphics2D) g, x, y, width, height, this::paintImpl ); }