Files
InnotexBootloarder/InnotexBootloarder/InnotexBootloarder.script.in
2025-08-23 16:40:06 +02:00

258 lines
8.9 KiB
Plaintext

# Load the image from the BGRT
bgrt_image = Image("InnotexBootloarder.png");
# Create a sprite of the BGRT
bgrt_sprite = Sprite(bgrt_image);
bgrt_sprite.SetPosition(
(Window.GetWidth() / 2) - (bgrt_sprite.GetImage().GetWidth() / 2),
(Window.GetHeight() / 2) - (bgrt_sprite.GetImage().GetHeight() / 2),
1
);
#bgrt_sprite.SetPosition($BGRTLEFT$, $BGRTTOP$, 1);
# Add your code here
# Callbacks which can be hooked
# Plymouth.SetBootProgressFunction: the callback function is called with two numbers, time spent booting so far and the progress (between 0 and 1) [IMPLEMENTED]
# Plymouth.SetRootMountedFunction: the callback function is called when a new root is mounted
# Plymouth.SetKeyboardInputFunction: the callback function is called with a string containing a new character entered on the keyboard
# Plymouth.SetUpdateStatusFunction: the callback function is called with the new boot status string [IMPLEMENTED]
# Plymouth.SetDisplayPasswordFunction: the callback function is called when the display should display a password dialogue. First arg is prompt string, the second is the number of bullets. [IMPLEMENTED]
# Plymouth.SetDisplayQuestionFunction: the callback function is called when the display should display a question dialogue. First arg is prompt string, the second is the entry contents.
# Plymouth.SetDisplayNormalFunction: the callback function is called when the display should return to normal
# Plymouth.SetMessageFunction: the callback function is called when new message should be displayed. First arg is message to display. [IMPLEMENTED]
fun refresh_callback ()
{
# Currently we do nothing here
}
Plymouth.SetRefreshFunction (refresh_callback);
#----------------------------------------- Dialogue --------------------------------
status = "normal";
fun dialog_setup()
{
local.box;
box.image = Image("box.png");
box.sprite = Sprite(box.image);
box.x = Window.GetWidth() * 0.50 - box.image.GetWidth ()/2;
box.y = Window.GetHeight() * 0.75 - box.image.GetHeight()/2;
box.z = 10000;
box.sprite.SetPosition(box.x, box.y, box.z);
global.dialog.box = box;
global.dialog.bullet_image = Image("bullet.png");
dialog_opacity (1);
}
fun dialog_opacity (opacity)
{
dialog.box.sprite.SetOpacity (opacity);
for (index = 0; dialog.bullet[index]; index++)
{
dialog.bullet[index].sprite.SetOpacity(opacity);
}
}
fun display_normal_callback ()
{
global.status = "normal";
if (global.dialog)
dialog_opacity (0);
}
fun display_password_callback (prompt, bullets)
{
global.status = "password";
if (!global.dialog)
dialog_setup();
else
dialog_opacity(1);
for (index = 0; dialog.bullet[index] || index < bullets; index++)
{
if (!dialog.bullet[index])
{
dialog.bullet[index].sprite = Sprite(dialog.bullet_image);
dialog.bullet[index].x = dialog.box.x + 6 + index * dialog.bullet_image.GetWidth();
dialog.bullet[index].y = dialog.box.y + dialog.box.image.GetHeight() / 2 - dialog.bullet_image.GetHeight() / 2;
dialog.bullet[index].z = dialog.box.z + 1;
dialog.bullet[index].sprite.SetPosition(dialog.bullet[index].x, dialog.bullet[index].y, dialog.bullet[index].z);
}
if (index < bullets)
dialog.bullet[index].sprite.SetOpacity(1);
else
dialog.bullet[index].sprite.SetOpacity(0);
}
}
Plymouth.SetDisplayNormalFunction(display_normal_callback);
Plymouth.SetDisplayPasswordFunction(display_password_callback);
#----------------------------------------- Progress Bar --------------------------------
progress_box.image = Image("progress_box.png");
progress_box.sprite = Sprite(progress_box.image);
progress_box.x = Window.GetWidth() * 0.50 - progress_box.image.GetWidth() / 2;
progress_box.y = Window.GetHeight() * 0.90 - progress_box.image.GetHeight() / 2;
progress_box.sprite.SetPosition(progress_box.x, progress_box.y, 0);
progress_bar.original_image = Image("progress_bar.png");
progress_bar.sprite = Sprite();
progress_bar.x = progress_box.x + progress_box.image.GetWidth() / 2 - progress_bar.original_image.GetWidth() / 2;
progress_bar.y = progress_box.y + progress_box.image.GetHeight() / 2 - progress_bar.original_image.GetHeight() / 2;
#progress_bar.y = Window.GetHeight() / 2 * 1.5 - progress_box.image.GetHeight() / 2 + (progress_box.image.GetHeight() - progress_bar.original_image.GetHeight()) / 2;
progress_bar.sprite.SetPosition(progress_bar.x, progress_bar.y, 1);
fun progress_callback (duration, progress)
{
if (progress_bar.image.GetWidth () != Math.Int (progress_bar.original_image.GetWidth () * progress))
{
progress_bar.image = progress_bar.original_image.Scale(progress_bar.original_image.GetWidth(progress_bar.original_image) * progress, progress_bar.original_image.GetHeight());
progress_bar.sprite.SetImage (progress_bar.image);
}
}
Plymouth.SetBootProgressFunction(progress_callback);
#----------------------------------------- Quit --------------------------------
fun quit_callback ()
{
}
Plymouth.SetQuitFunction(quit_callback);
#----------------------------------------- Message --------------------------------
message_sprite = Sprite();
message_sprite.SetPosition(10, 10, 10000);
fun message_callback (text)
{
# If you change this or the font below, also update the initramfs-hook to get them into your initramfs
my_image = Image.Text(text, 1, 1, 1, 1, "Exo Regular 12");
message_sprite.SetImage(my_image);
# HCenter, VNearTop
x = (Window.GetWidth() * 0.50) - (message_sprite.GetImage().GetWidth() / 2);
y = (Window.GetHeight() * 0.05) - (message_sprite.GetImage().GetHeight() / 2);
message_sprite.SetPosition(x, Math.Clamp(y, 1, Window.GetHeight()), 0);
}
Plymouth.SetMessageFunction(message_callback);
#----------------------------------------- Message --------------------------------
# If you change this or the font above, also update the initramfs-hook to get them into your initramfs
FONT = "Quicksand Medium 24";
NUM_SCROLL_LINES = 5;
NUM_SCROLL_COLS = 60;
test_str = "";
for (i=0; i < NUM_SCROLL_COLS; i++) {
test_str += "x";
}
LINE_WIDTH = Image.Text(test_str, 1, 1, 1, 1, FONT).GetWidth();
LINE_HEIGHT = Image.Text(FONT, 1, 1, 1, 1, FONT).GetHeight();
update_x = $BGRTLEFT$ + ( bgrt_sprite.GetImage().GetWidth() / 2 ) - ( LINE_WIDTH / 2);
update_y = $BGRTTOP$ + ( bgrt_sprite.GetImage().GetHeight() + 10);
STRT = Image.Text(".... ", 0.8, 0.8, 0.8, 1.0, FONT);
GOOD = Image.Text(" OK ", 0.0, 1.0, 0.0, 1.0, FONT);
FAIL = Image.Text("FAIL ", 1.0, 0.0, 0.0, 1.0, FONT);
WARN = Image.Text("WARN ", 1.0, 1.0, 1.0, 1.0, FONT);
INFO = Image.Text("INFO ", 0.0, 1.0, 1.0, 1.0, FONT);
DONE = Image.Text("DONE ", 0.8, 0.8, 0.8, 1.0, FONT);
status_width = Math.Max(STRT.GetWidth(), Math.Max(GOOD.GetWidth(), Math.Max(FAIL.Getwidth(), Math.Max(WARN.GetWidth(), Math.Max(INFO.GetWidth(), DONE.GetWidth())))));
status_x = update_x - status_width;
// Initialising text images and their positions
for (i=0; i < NUM_SCROLL_LINES; i++) {
lines[i] = "";
message_sprite[i] = Sprite();
message_sprite[i].SetPosition(update_x, update_y + (i * LINE_HEIGHT), 10000);
status_sprite[i] = Sprite();
status_sprite[i].SetPosition(status_x, update_y + (i * LINE_HEIGHT), 10000);
}
// From ubuntu-logo
fun StringLength(string) {
index = 0;
str = String(string);
while(str.CharAt(index)) index++;
return index;
}
fun scroll_message_callback(text) {
msg = String(text);
noscroll = 0;
if (msg.SubString(0,8) == "[status]") {
msg = msg.SubString(8, StringLength(msg));
noscroll = 1;
if (msg == "0") {
status_sprite[NUM_SCROLL_LINES - 1].SetImage(GOOD);
} else if (msg == "255") {
status_sprite[NUM_SCROLL_LINES - 1].SetImage(WARN);
} else {
status_sprite[NUM_SCROLL_LINES - 1].SetImage(FAIL);
}
} else if (msg.SubString(0,5) == "[...]") {
msg = msg.SubString(7, StringLength(msg));
noscroll = 1;
status_sprite[NUM_SCROLL_LINES - 1].SetImage(STRT);
} else if (msg.SubString(0,6) == "[info]") {
msg = msg.SubString(6, StringLength(msg));
noscroll = 0;
status_sprite[NUM_SCROLL_LINES - 1].SetImage(INFO);
} else if (msg.SubString(0,6) == "[done]") {
msg = msg.SubString(6, StringLength(msg));
noscroll = 0;
status_sprite[NUM_SCROLL_LINES - 1].SetImage(DONE);
} else if (msg.SubString(0,6) == "[fail]") {
msg = msg.SubString(6, StringLength(msg));
noscroll = 0;
status_sprite[NUM_SCROLL_LINES - 1].SetImage(FAIL);
}
// Truncate the message if too long
if (StringLength(msg) > NUM_SCROLL_COLS) {
msg = msg.SubString(0, NUM_SCROLL_COLS - 3);
msg += "...";
}
if (noscroll == 0) {
// Shift message one up
for (i = 0; i < NUM_SCROLL_LINES - 1; i++) {
lines[i] = lines[i+1];
}
lines[i] = msg;
// Re-positioning the msg images
for (i = 0; i < NUM_SCROLL_LINES; i++) {
if (i < NUM_SCROLL_LINES - 1) {
message_sprite[i].SetImage(Image.Text(lines[i], 0.8, 0.8, 0.8, 0.8, FONT));
} else {
message_sprite[i].SetImage(Image.Text(lines[i], 1.0, 1.0, 1.0, 1.0, FONT));
}
status_sprite[i].SetImage(status_sprite[i+1].GetImage());
}
}
}
// Uncomment if you want the status messages
#Plymouth.SetUpdateStatusFunction(scroll_message_callback);