-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLoadingScreen.js
More file actions
39 lines (39 loc) · 1.42 KB
/
Copy pathLoadingScreen.js
File metadata and controls
39 lines (39 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
unction ImageLoadBar_hook(ctx, width, height, total, current, image) {
// change these to your liking:
var backgroundColor = "#000000";
var barBackgroundColor = "#000000";
var barForegroundColor = "#000000";
var barBorderColor = "#000000";
var barWidth = Math.round(width * 0.6);
var barHeight = 20;
var barBorderWidth = 2;
var barOffset = 10;
// background:
ctx.fillStyle = backgroundColor;
ctx.fillRect(0, 0, width, height);
// image:
var totalHeight, barTop;
if (image != null) {
totalHeight = image.height + barOffset + barHeight;
var image_y = (height - totalHeight) >> 1;
ctx.drawImage(image, (width - image.width) >> 1, image_y);
barTop = image_y + image.height + barOffset;
} else barTop = (height - barHeight) >> 1;
// bar border:
var barLeft = (width - barWidth) >> 1;
ctx.fillStyle = barBorderColor;
ctx.fillRect(barLeft, barTop, barWidth, barHeight);
//
var barInnerLeft = barLeft + barBorderWidth;
var barInnerTop = barTop + barBorderWidth;
var barInnerWidth = barWidth - barBorderWidth * 2;
var barInnerHeight = barHeight - barBorderWidth * 2;
// bar background:
ctx.fillStyle = barBackgroundColor;
ctx.fillRect(barInnerLeft, barInnerTop, barInnerWidth, barInnerHeight);
// bar foreground:
var barLoadedWidth = Math.round(barInnerWidth * current / total);
ctx.fillStyle = barForegroundColor;
ctx.fillRect(barInnerLeft, barInnerTop, barLoadedWidth, barInnerHeight);
console.log(current + "/" + total);
}