Skip to content

fix: ensure canvas resolution scales with the parent containers to avoid blurry fonts #585

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 7 commits into from
Jul 19, 2022
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion html_export/index_template.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
Errors happened while loading:<br />
</div>
</div>
<div class="layer mobile-only" id="mobile-warning">
<div class="fullscreen mobile-only" id="mobile-warning">
<div class="mobile-warning-modal notices">
<p>
Your browser window seems to be too narrow. This application is not
Expand Down
34 changes: 19 additions & 15 deletions html_export/static/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ window.GDQUEST = ((/** @type {GDQuestLib} */ GDQUEST) => {
(currentWidth = window.innerWidth, currentHeight = window.innerHeight) => {
const ratioW = currentWidth / maxW;
const ratioH = currentHeight / maxH;
const ratio = Math.min(Math.min(ratioW, ratioH), 1);
const ratio = Math.min(ratioW, ratioH);
const width = maxW * ratio;
const height = maxH * ratio;
return { width, height, ratio };
Expand Down Expand Up @@ -68,7 +68,9 @@ window.GDQUEST = ((/** @type {GDQuestLib} */ GDQUEST) => {
if (!isDebugMode) {
return { app: true };
}
const modulesList = params.get("debug").split(",").filter(Boolean);
const modulesList = (params.get("debug") || "")
.split(",")
.filter(Boolean);
if (modulesList.length == 0) {
return { "*": true };
}
Expand Down Expand Up @@ -129,8 +131,6 @@ window.GDQUEST = ((/** @type {GDQuestLib} */ GDQUEST) => {
resize: {
const onResize = () => {
const { width, height, ratio } = aspectRatioCanvas();
canvas.width = width;
canvas.height = height;
canvasContainer.style.setProperty(`width`, `${width}px`);
canvasContainer.style.setProperty(`height`, `${height}px`);
document.documentElement.style.setProperty("--scale", `${ratio}`);
Expand Down Expand Up @@ -186,22 +186,23 @@ window.GDQUEST = ((/** @type {GDQuestLib} */ GDQUEST) => {
console.error(msg);
setStatusMode(StatusMode.NOTICE);
const statusNotice = document.getElementById("notices");
msg.split("\n").forEach((line) => {
statusNotice.appendChild(document.createTextNode(line));
statusNotice.appendChild(document.createElement("br"));
});
statusNotice &&
msg.split("\n").forEach((line) => {
statusNotice.appendChild(document.createTextNode(line));
statusNotice.appendChild(document.createElement("br"));
});
is_done = true;
};

const loaderElement = document.getElementById("loader");
/**
* Grows the visual loading bar
* @param {number} percentage
* @returns
*/
const displayPercentage = (percentage = 0) =>
document
.getElementById("loader")
.style.setProperty("--progress", percentage * 100 + "%");
loaderElement &&
loaderElement.style.setProperty("--progress", percentage * 100 + "%");

/**
* Callback used during the loading of the engine and packages
Expand Down Expand Up @@ -289,9 +290,12 @@ window.GDQUEST = ((/** @type {GDQuestLib} */ GDQUEST) => {
localStorage.setItem(KEY, "true");
};

document
.getElementById("mobile-warning-dismiss-button")
.addEventListener("click", forceAppOnMobile);
const mobileWarningButton = document.getElementById(
"mobile-warning-dismiss-button"
);

mobileWarningButton &&
mobileWarningButton.addEventListener("click", forceAppOnMobile);

const currentValue = JSON.parse(localStorage.getItem(KEY) || "false");

Expand Down Expand Up @@ -347,7 +351,7 @@ window.GDQUEST = ((/** @type {GDQuestLib} */ GDQUEST) => {
const download = () =>
generateDownloadableFile(
`gdquest-${Date.now()}.log`,
localStorage.getItem(KEY)
localStorage.getItem(KEY) || ""
);

const makeLogFunction =
Expand Down
22 changes: 16 additions & 6 deletions html_export/static/style.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* --- BASE --- */

:root {
--max-width: 1920px;
/*--background-color: #303049;*/
--game-background-color: #090a20;
--bar-height: 14px;
Expand Down Expand Up @@ -30,8 +29,8 @@ body {
background-color: var(--game-background-color);
}

.layer {
position: absolute;
.layer,
.fullscreen {
left: 0;
top: 0;
right: 0;
Expand All @@ -40,24 +39,33 @@ body {
flex-direction: column;
justify-content: center;
align-items: center;
max-width: var(--max-width);
margin: 0 auto;
}

.layer {
position: absolute;
}

.fullscreen {
position: fixed;
width: 100vw;
height: 100vh;
}

/* --- /BASE --- */

/* --- CANVAS CONTAINER --- */

#canvas-container {
background-color: var(--game-background-color);
max-width: var(--render-width);
max-height: var(--render-height);
width: 100%;
height: 100%;
position: relative;
display: flex;
align-items: center;
justify-content: center;
/**transform: scale(var(--scale));
transform-origin: center center;*/
}

/* --- /CANVAS CONTAINER --- */
Expand All @@ -73,6 +81,8 @@ body {
margin: 0;
border: none;
background-color: var(--game-background-color);
width: 100%;
height: 100%;
}

#canvas:focus {
Expand Down
6 changes: 5 additions & 1 deletion run
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ web_debug(){
echo "be in your \$PATH"
exit 0
fi
echo "You need the custom templates. Please make sure to run prepare:local at least once!"
debug=true
clean_web
export_web
Expand Down Expand Up @@ -402,7 +403,10 @@ prepare_ci_gettemplates(){
fi
echo "Will get the custom templates for ${GODOT_VERSION}"
echo "wget https://github.com/Razoric480/godot/releases/download/${GODOT_VERSION}-parser/$(sed 's/\.//g' <<< ${GODOT_VERSION})custom-templates.zip"
wget https://github.com/Razoric480/godot/releases/download/${GODOT_VERSION}-parser/$(sed 's/\.//g' <<< ${GODOT_VERSION})custom-templates.zip
wget https://github.com/Razoric480/godot/releases/download/${GODOT_VERSION}-parser/$(sed 's/\.//g' <<< ${GODOT_VERSION})custom-templates.zip || {
echo "Templates for \`${GODOT_VERSION}\` not found"
exit 1
}
echo "✓ Downloaded templates"
echo "Will unzip templates"
echo "unzip $(sed 's/\.//g' <<< ${GODOT_VERSION})custom-templates.zip -d templates"
Expand Down