mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Darcula & HiDPI: button border should respect scaling
This commit is contained in:
+16
-12
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -18,6 +18,7 @@ package com.intellij.ide.ui.laf.darcula.ui;
|
||||
import com.intellij.ide.ui.laf.darcula.DarculaUIUtil;
|
||||
import com.intellij.openapi.ui.GraphicsConfig;
|
||||
import com.intellij.ui.Gray;
|
||||
import com.intellij.util.ui.JBUI;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
|
||||
import javax.swing.*;
|
||||
@@ -38,12 +39,14 @@ public class DarculaButtonPainter implements Border, UIResource {
|
||||
final Insets ins = getBorderInsets(c);
|
||||
final int yOff = (ins.top + ins.bottom) / 4;
|
||||
final boolean square = DarculaButtonUI.isSquare(c);
|
||||
int offset = square ? 1 : getOffset();
|
||||
int offset = JBUI.scale(square ? 1 : getOffset());
|
||||
int w = c.getWidth();
|
||||
int h = c.getHeight();
|
||||
int diam = JBUI.scale(22);
|
||||
|
||||
if (c.hasFocus()) {
|
||||
if (DarculaButtonUI.isHelpButton((JComponent)c)) {
|
||||
int w = c.getWidth();
|
||||
int h = c.getHeight();
|
||||
DarculaUIUtil.paintFocusOval(g2d, (w - 22) / 2, (h - 22) / 2, 22, 22);
|
||||
DarculaUIUtil.paintFocusOval(g2d, (w - diam) / 2, (h - diam) / 2, diam, diam);
|
||||
} else {
|
||||
DarculaUIUtil.paintFocusRing(g2d, offset, yOff, width - 2 * offset, height - 2 * yOff);
|
||||
}
|
||||
@@ -51,15 +54,16 @@ public class DarculaButtonPainter implements Border, UIResource {
|
||||
final GraphicsConfig config = new GraphicsConfig(g);
|
||||
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
g2d.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_DEFAULT);
|
||||
g2d.setPaint(UIUtil.getGradientPaint(width / 2, y + yOff + 1, Gray._80.withAlpha(90), width / 2, height - 2 * yOff, Gray._90.withAlpha(90)));
|
||||
g2d.setPaint(UIUtil.getGradientPaint(width / 2, y + yOff + JBUI.scale(1), Gray._80.withAlpha(90), width / 2, height - 2 * yOff, Gray._90.withAlpha(90)));
|
||||
//g.drawRoundRect(x + offset + 1, y + yOff + 1, width - 2 * offset, height - 2*yOff, 5, 5);
|
||||
((Graphics2D)g).setPaint(Gray._100.withAlpha(180));
|
||||
if (DarculaButtonUI.isHelpButton((JComponent)c)) {
|
||||
int w = c.getWidth();
|
||||
int h = c.getHeight();
|
||||
g.drawOval((w - 22) / 2, (h - 22) / 2, 22, 22);
|
||||
g.drawOval((w - diam) / 2, (h - diam) / 2, diam, diam);
|
||||
} else {
|
||||
g.drawRoundRect(x + offset, y + yOff, width - 2 * offset, height - 2 * yOff, square ? 3 : 5, square ? 3 : 5);
|
||||
g.translate(x,y);
|
||||
int r = JBUI.scale(square ? 3 : 5);
|
||||
g.drawRoundRect(offset, yOff, width - 2 * offset, height - 2 * yOff, r, r);
|
||||
g.translate(-x,-y);
|
||||
}
|
||||
|
||||
config.restore();
|
||||
@@ -69,9 +73,9 @@ public class DarculaButtonPainter implements Border, UIResource {
|
||||
@Override
|
||||
public Insets getBorderInsets(Component c) {
|
||||
if (DarculaButtonUI.isSquare(c)) {
|
||||
return new InsetsUIResource(2, 0, 2, 0);
|
||||
return JBUI.insets(2, 0, 2, 0).asUIResource();
|
||||
}
|
||||
return new InsetsUIResource(8, 16, 8, 14);
|
||||
return JBUI.insets(8, 16, 8, 14).asUIResource();
|
||||
}
|
||||
|
||||
protected int getOffset() {
|
||||
|
||||
Reference in New Issue
Block a user