Skip to content

Refactor: Move Cocoa-specific DPI methods to CocoaDPIUtil #2278

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 3, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1822,11 +1822,28 @@ public String toString () {
* @noreference This method is not intended to be referenced by clients.
*/
public static void drawScaled(GC gc, Image original, int width, int height, float scaleFactor) {
gc.drawImage (original, 0, 0, DPIUtil.autoScaleDown (width), DPIUtil.autoScaleDown (height),
gc.drawImage (original, 0, 0, CocoaDPIUtil.autoScaleDown (width), CocoaDPIUtil.autoScaleDown (height),
/* E.g. destWidth here is effectively DPIUtil.autoScaleDown (scaledWidth), but avoiding rounding errors.
* Nevertheless, we still have some rounding errors due to the point-based API GC#drawImage(..).
*/
0, 0, Math.round (DPIUtil.autoScaleDown (width * scaleFactor)), Math.round (DPIUtil.autoScaleDown (height * scaleFactor)));
0, 0, Math.round (CocoaDPIUtil.autoScaleDown (width * scaleFactor)), Math.round (CocoaDPIUtil.autoScaleDown (height * scaleFactor)));
}

private final class CocoaDPIUtil {

/**
* Auto-scale down int dimensions.
*/
public static int autoScaleDown(int size) {
return DPIUtil.scaleDown(size, DPIUtil.getDeviceZoom());
}

/**
* Auto-scale down float dimensions.
*/
public static float autoScaleDown(float size) {
return DPIUtil.scaleDown(size, DPIUtil.getDeviceZoom());
}
}

}
Expand Down
Loading