mirror of
https://github.com/UnickSoft/graphonline.git
synced 2026-02-16 02:30:51 +00:00
Refactor canvas rendering and DPI handling for improved quality and performance
This commit is contained in:
@@ -69,4 +69,30 @@ function InvertColor(hex) {
|
||||
const toHex = (n) => n.toString(16).padStart(2, '0');
|
||||
|
||||
return `#${toHex(r)}${toHex(g)}${toHex(b)}`;
|
||||
}
|
||||
|
||||
function setDPIForCanvas(canvas, width, height) {
|
||||
const dpr = window.devicePixelRatio || 1;
|
||||
|
||||
canvas.width = Math.round(width * dpr);
|
||||
canvas.height = Math.round(height * dpr);
|
||||
|
||||
if (dpr != 1)
|
||||
{
|
||||
canvas.style.width = Math.round(width) + "px";
|
||||
canvas.style.height = Math.round(height) + "px";
|
||||
}
|
||||
|
||||
const ctx = canvas.getContext("2d");
|
||||
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
|
||||
}
|
||||
|
||||
function getCanvasLogicWidth(canvas) {
|
||||
const dpr = window.devicePixelRatio || 1;
|
||||
return canvas.width / dpr;
|
||||
}
|
||||
|
||||
function getCanvasLogicHeight(canvas) {
|
||||
const dpr = window.devicePixelRatio || 1;
|
||||
return canvas.height / dpr;
|
||||
}
|
||||
Reference in New Issue
Block a user