Browse Source

Changed title bar icon scaling to allow for higher resolution images.

Signed-off-by: weisj <weisj@arcor.de>
pull/15/head
weisj 5 years ago
parent
commit
becd7a938b
  1. 40
      src/main/java/com/github/weisj/darklaf/ui/rootpane/DarkTitlePane.java
  2. BIN
      src/main/resources/com/github/weisj/darklaf/platform/windows/x64/jniplatform.dll
  3. BIN
      src/main/resources/com/github/weisj/darklaf/platform/windows/x86/jniplatform.dll
  4. 4
      src/test/java/UIDemo.java
  5. BIN
      src/test/resources/mima.png

40
src/main/java/com/github/weisj/darklaf/ui/rootpane/DarkTitlePane.java

@ -57,8 +57,7 @@ public class DarkTitlePane extends JComponent {
private static final int BAR_HEIGHT = (int) (56 / GraphicsUtil.SCALE_Y); private static final int BAR_HEIGHT = (int) (56 / GraphicsUtil.SCALE_Y);
private static final int BUTTON_WIDTH = (int) (92.5 / GraphicsUtil.SCALE_X); private static final int BUTTON_WIDTH = (int) (92.5 / GraphicsUtil.SCALE_X);
private static final int ICON_WIDTH = (int) (65 / GraphicsUtil.SCALE_X); private static final int ICON_WIDTH = (int) (65 / GraphicsUtil.SCALE_X);
private static final int IMAGE_HEIGHT = 16; private static final int ICON_SIZE = ICON_WIDTH - 3 * PAD;
private static final int IMAGE_WIDTH = 16;
private final JRootPane rootPane; private final JRootPane rootPane;
private final ContainerListener rootPaneContainerListener = new ContainerListener() { private final ContainerListener rootPaneContainerListener = new ContainerListener() {
@Override @Override
@ -581,12 +580,17 @@ public class DarkTitlePane extends JComponent {
List<Image> icons = window.getIconImages(); List<Image> icons = window.getIconImages();
assert icons != null; assert icons != null;
Icon systemIcon; Icon systemIcon;
if (icons.size() == 0) { if (icons.size() == 0) {
systemIcon = UIManager.getIcon("TitlePane.icon"); systemIcon = UIManager.getIcon("TitlePane.icon");
} else if (icons.size() == 1) {
systemIcon = new ScaledIcon(icons.get(0).getScaledInstance((int) (ICON_SIZE * GraphicsUtil.SCALE_X),
(int) (ICON_SIZE * GraphicsUtil.SCALE_Y),
Image.SCALE_AREA_AVERAGING));
} else { } else {
systemIcon = new ImageIcon(SunToolkit.getScaledIconImage(icons, IMAGE_WIDTH, IMAGE_HEIGHT)); systemIcon = new ScaledIcon(SunToolkit.getScaledIconImage(icons, (int) (ICON_SIZE * GraphicsUtil.SCALE_X),
(int) (ICON_SIZE * GraphicsUtil.SCALE_Y))
);
} }
if (windowIconButton != null) { if (windowIconButton != null) {
windowIconButton.setIcon(systemIcon); windowIconButton.setIcon(systemIcon);
@ -762,4 +766,32 @@ public class DarkTitlePane extends JComponent {
setActive(false); setActive(false);
} }
} }
protected static class ScaledIcon implements Icon {
private Image img;
@Contract(pure = true)
protected ScaledIcon(final Image img) {
this.img = img;
}
@Override
public void paintIcon(final Component c, final Graphics g2, final int x, final int y) {
var g = (Graphics2D) g2;
g.translate(x, y);
g.scale(1.0 / GraphicsUtil.SCALE_X, 1.0 / GraphicsUtil.SCALE_Y);
g.drawImage(img, 0, 0, img.getWidth(null), img.getHeight(null), null);
}
@Override
public int getIconWidth() {
return (int) (img.getWidth(null) / GraphicsUtil.SCALE_X);
}
@Override
public int getIconHeight() {
return (int) (img.getHeight(null) / GraphicsUtil.SCALE_Y);
}
}
} }

BIN
src/main/resources/com/github/weisj/darklaf/platform/windows/x64/jniplatform.dll

Binary file not shown.

BIN
src/main/resources/com/github/weisj/darklaf/platform/windows/x86/jniplatform.dll

Binary file not shown.

4
src/test/java/UIDemo.java

@ -38,6 +38,10 @@ public final class UIDemo {
taskpanecontainer.add(taskpane); taskpanecontainer.add(taskpane);
JFrame frame = new JFrame("UIDemo"); JFrame frame = new JFrame("UIDemo");
frame.setIconImage(Toolkit.getDefaultToolkit().createImage(
UIDemo.class.getClassLoader().getResource("mima.png")
));
Icon folderIcon = IconLoader.get().getUIAwareIcon("files/folder.svg", 19, 19); Icon folderIcon = IconLoader.get().getUIAwareIcon("files/folder.svg", 19, 19);
var panel = new JPanel(new GridLayout(3, 4)); var panel = new JPanel(new GridLayout(3, 4));

BIN
src/test/resources/mima.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 294 KiB

Loading…
Cancel
Save