Skip to content

Commit

Permalink
hidpi support for line stroke width/height
Browse files Browse the repository at this point in the history
  • Loading branch information
prsadhuk committed Jan 24, 2025
1 parent abb2851 commit 6ec1d16
Showing 1 changed file with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.awt.Graphics2D;
import java.awt.Insets;
import java.awt.Rectangle;
import java.awt.geom.AffineTransform;

import javax.swing.JComponent;
import javax.swing.JProgressBar;
Expand Down Expand Up @@ -128,12 +129,19 @@ protected void paintDeterminate(Graphics g, JComponent c) {
if (xp != null) {
boolean vertical = (progressBar.getOrientation() == JProgressBar.VERTICAL);
boolean isLeftToRight = WindowsGraphicsUtils.isLeftToRight(c);
int barRectWidth = progressBar.getWidth();
int barRectHeight = progressBar.getHeight()-1;
Graphics2D g2 = (Graphics2D) g;
AffineTransform at = g2.getTransform();
double scaleX = at.getScaleX();
double scaleY = at.getScaleY();

int barRectWidth = (int)Math.ceil(progressBar.getWidth() * scaleX);
int barRectHeight = (int)Math.ceil(progressBar.getHeight() * scaleY);

// amount of progress to draw
int amountFull = getAmountFull(null, barRectWidth, barRectHeight);
int amountFull = (int)(getAmountFull(null, barRectWidth, barRectHeight) / scaleX);

paintXPBackground(g, vertical, barRectWidth, barRectHeight);

// Paint progress
if (progressBar.isStringPainted()) {
// Do not paint the standard stripes from the skin, because they obscure
Expand All @@ -144,7 +152,6 @@ protected void paintDeterminate(Graphics g, JComponent c) {
return;
}

Graphics2D g2 = (Graphics2D)g;
g2.setStroke(new BasicStroke((float)(vertical ? barRectWidth : barRectHeight),
BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));
if (!vertical) {
Expand All @@ -157,7 +164,8 @@ protected void paintDeterminate(Graphics g, JComponent c) {
2 + barRectWidth - (amountFull - 2),
barRectHeight / 2 + 1);
}
paintString(g, 0, 0, barRectWidth, barRectHeight, amountFull, null);
paintString(g, 0, 0, (int)(barRectWidth / scaleX),
(int)(barRectHeight / scaleY), amountFull, null);
} else {
g2.drawLine(barRectWidth/2 + 1, barRectHeight + 1,
barRectWidth/2 + 1, barRectHeight + 1 - amountFull + 2);
Expand Down

0 comments on commit 6ec1d16

Please sign in to comment.