Skip to content

Commit

Permalink
Tweak scale factor for drawing the crayons image in color choosers
Browse files Browse the repository at this point in the history
For #457
  • Loading branch information
kirill-grouchnikov committed Jan 23, 2024
1 parent 367f2d9 commit 6e452e7
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,15 +167,20 @@ public Color getColor() {
public void paintComponent(Graphics gr) {
Graphics2D g2d = (Graphics2D) gr.create();
RadianceCommonCortex.installDesktopHints(g2d, getFont());
double scaleFactor = RadianceCommonCortex.getScaleFactor(this);
RadianceCommonCortex.drawImageWithScale(g2d, scaleFactor, crayonsImage, 0, 0);

// The crayons image is created once at Radiance initialization based on the scale
// max scale factor of all connected screens. Use that same scale factor to draw
// that image, no matter what the scale factor of the current monitor is.
double imageScaleFactor = RadianceCommonCortex.getScaleFactor(null);
RadianceCommonCortex.drawImageWithScale(g2d, imageScaleFactor, crayonsImage, 0, 0);

if (selectedCrayon != null) {
Color selectedTextColor = RadianceColorSchemeUtilities.getColorScheme(
this, ComponentState.ENABLED).getForegroundColor();
g2d.setColor(selectedTextColor);
FontMetrics fm = g2d.getFontMetrics();
int nameWidth = fm.stringWidth(selectedCrayon.name);
double scaleFactor = RadianceCommonCortex.getScaleFactor(this);
g2d.drawString(selectedCrayon.name,
((int) (crayonsImage.getWidth() / scaleFactor) - nameWidth) / 2,
fm.getAscent() + 1);
Expand Down

0 comments on commit 6e452e7

Please sign in to comment.