Skip to content

Commit

Permalink
[runtime] Better default dimensions and positions for preloader
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyfa committed Nov 23, 2023
1 parent 3668fb7 commit 930063d
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions runtime/src/ceramic/Preloader.hx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class Preloader extends Scene {
ceramicLogo.anchor(0.5, 0.5);
add(ceramicLogo);

final targetScale = Math.min(width * 0.2 / ceramicLogo.width, height * 0.4 / ceramicLogo.height);
final targetScale = Math.min(width * 0.2 / ceramicLogo.width, height * 0.2 / ceramicLogo.height);
animateScale(ceramicLogo, targetScale, () -> {
initPreloadable();
createProgressBar();
Expand Down Expand Up @@ -104,13 +104,35 @@ class Preloader extends Scene {
* @param backgroundColor The progress bar background color
* @param foregroundColor The progress bar foreground color
*/
function createProgressBar(yRatio:Float = 0.55, widthRatio:Float = 0.4, backgroundColor:Color = 0x444444, foregroundColor:Color = 0xFFFFFF):Void {
function createProgressBar(yRatio:Float = -1, widthRatio:Float = -1, backgroundColor:Color = 0x444444, foregroundColor:Color = 0xFFFFFF):Void {

if (progressForeground != null)
return;

if (yRatio == -1) {
if (height > 0 && ceramicLogo != null) {
// Default value based on Ceramic Logo dimensions
final targetScale = Math.min(width * 0.2 / ceramicLogo.width, height * 0.2 / ceramicLogo.height);
yRatio = (ceramicLogo.y + ceramicLogo.height * (1 - ceramicLogo.anchorY) * (targetScale + 0.5)) / height;
}
else {
yRatio = 0.55;
}
}

if (widthRatio == -1) {
if (width > 0 && ceramicLogo != null) {
// Default value based on Ceramic Logo dimensions
final targetScale = Math.min(width * 0.2 / ceramicLogo.width, height * 0.2 / ceramicLogo.height);
widthRatio = Math.min(0.4, (ceramicLogo.width * targetScale * 2.5) / width);
}
else {
widthRatio = 0.4;
}
}

final progressWidth = width * widthRatio;
final progressHeight = Math.max(2, height * 0.005);
final progressHeight = Math.max(2, Math.round(height * 0.006));

progressBackground = new Quad();
progressBackground.color = backgroundColor;
Expand Down

0 comments on commit 930063d

Please sign in to comment.