Files
hfgos_falbella_theme/bootscreen/plymouth/falbella/falbella.script
T

605 lines
19 KiB
Plaintext
Raw Normal View History

2026-09-02 21:48:52 +02:00
# ceratopsian.script - boot splash using script plugin
#
# Copyright (C) 2009 Canonical Ltd.
# Copyright © 2010-2021 Aurélien Couderc <coucouf@debian.org>
# Copyright © 2014-2022 Juliette Taka <juliette.belin@logilab.fr>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
# 02111-1307, USA.
#
# Written by: Alberto Milone <alberto.milone@canonical.com>
#
# Based on the example provided with the "script plugin" written by:
# Charlie Brej <cbrej@cs.man.ac.uk>
#
#------------------------------- Constants -----------------------------------------
NB_ANIM_STEPS = 360;
NB_REFRESHS_BETWEEN_ANIMS = 1;
#------------------------------- Globals -------------------------------------------
# are we currently prompting for a password?
prompt_active = 0;
# Globals to share progress time / percent with intersted functions
progress_time = 0;
progress_pct = 0;
# Variables for glow rotation animation
anim_start_time = NULL;
anim_status = "stopped";
refresh_iter = 0;
anim_iter = 0;
#-----------------------------Text-image functions----------------------------
# Set the text colour in (rgb / 256)
text_colour.red = 1.0;
text_colour.green = 1.0;
text_colour.blue = 1.0;
# Tinted text #988592
tinted_text_colour.red = 1.0;
tinted_text_colour.green = 1.0;
tinted_text_colour.blue = 1.0;
# Action Text - #ffffff - RGB 255 255 255
action_text_colour.red = 1.0;
action_text_colour.green = 1.0;
action_text_colour.blue = 1.0;
# Orange - #ff4012 - RGB 255 64 18
debugsprite = Sprite();
debugsprite_bottom = Sprite();
debugsprite_bottom.SetPosition(0, (Window.GetHeight (0) - 20), 1);
debugsprite_medium = Sprite();
debugsprite_medium.SetPosition(0, (Window.GetHeight (0) - 100), 1);
# General purpose function to create text
fun WriteText (text, colour) {
image = Image.Text (text, colour.red, colour.green, colour.blue);
return image;
}
fun ImageFromText (text) {
image = WriteText (text, text_colour);
return image;
}
fun ImageFromTintedText (text) {
image = WriteText (text, tinted_text_colour);
return image;
}
fun ImageFromActionText (text) {
image = WriteText (text, action_text_colour);
return image;
}
fun Debug(text) {
debugsprite.SetImage(ImageFromText (text));
}
fun DebugBottom(text) {
debugsprite_bottom.SetImage(ImageFromText (text));
}
fun DebugMedium(text) {
debugsprite_medium.SetImage(ImageFromText (text));
}
#Debug("Window.GetHeight(0) = " + Window.GetHeight(0));
fun TextYOffset() {
local.y;
local.text_height;
local.min_height;
# Put the 1st line below the logo + some spacing
# TODO position from lower edge
#y = logo_sprite.GetY() + logo.GetHeight();
# Put the first line at the midpoint
y = 0.5*Window.GetHeight();
#Debug("y = " + y);
text_height = first_line_height * 7.5;
# subtract Window.GetY() to show info also at smallest of dual srceens
min_height = window_max.height - 2 * first_line_height - Window.GetY();
#Debug("text_height=" + text_height + "; min_height=" + min_height);
if (y + text_height > min_height)
y = min_height - text_height;
return y;
}
#----------------------------- Screen/window setup ---------------------------
# Compute screen/image ratio and scale the background accordingly
window_max.width = Window.GetWidth();
window_max.height = Window.GetHeight();
screen_ratio = window_max.width / window_max.height;
small_dimension = Math.Min(window_max.width, window_max.height);
#Debug("Window.GetX():" + Window.GetX() + ", Window.GetY():" + Window.GetY());
#Debug("Window is [" + window_max.width + ";" + window_max.height + "], ratio=" + screen_ratio);
#---------------------------- Frills ---------------------------------
2026-09-04 22:12:26 +02:00
fun calcfmt(logo_base) {
2026-09-02 21:48:52 +02:00
x0 = Window.GetWidth();
y0 = Window.GetHeight();
xlogo = logo_base.GetWidth();
ylogo = logo_base.GetHeight();
coef = 0.6;
logoscale = 0.1;
if (xlogo<logoscale*x0) {
dim.logo.xsize = xlogo;
dim.logo.ysize = ylogo;
}
else {
dim.logo.xsize = logoscale*x0;
dim.logo.ysize = (logoscale*x0/xlogo)*ylogo;
}
2026-09-04 22:12:26 +02:00
2026-09-02 21:48:52 +02:00
dim.logo.x = 0.01*x0;
dim.logo.y = 0.99*y0 - dim.logo.ysize;
return dim;
}
logo = Image("logo.png");
2026-09-04 22:12:26 +02:00
logodim = calcfmt(logo);
logo = logo.Scale(logodim.logo.xsize,logodim.logo.ysize);
2026-09-02 21:48:52 +02:00
logo_sprite = Sprite(logo);
2026-09-04 22:12:26 +02:00
logo_sprite.SetPosition(logodim.logo.x,logodim.logo.y,-4);
2026-09-02 21:48:52 +02:00
#------------------------------String functions-------------------------------
# This is the equivalent for strstr()
fun StringString(string, substring) {
start = 0;
while (String(string).CharAt (start)) {
walk = 0;
while (String(substring).CharAt (walk) == String(string).CharAt (start + walk) ) {
walk++;
if (!String(substring).CharAt (walk)) return start;
}
start++;
}
return NULL;
}
fun StringLength (string) {
index = 0;
while (String(string).CharAt(index)) index++;
return index;
}
fun StringCopy (source, beginning, end) {
local.destination = "";
for (index = beginning; ( ( (end == NULL) || (index <= end) ) && (String(source).CharAt(index)) ); index++) {
local.destination += String(source).CharAt(index);
}
return local.destination;
}
fun StringReplace (source, pattern, replacement) {
local.found = StringString(source, pattern);
if (local.found == NULL)
return source;
local.new_string = StringCopy (source, 0, local.found - 1) +
replacement +
StringCopy (source, local.found + StringLength(pattern), NULL);
return local.new_string;
}
# it makes sense to use it only for
# numbers up to 100
fun StringToInteger (str) {
int = -1;
for (i=0; i<=100; i++) {
if (i+"" == str) {
int = i;
break;
}
}
return int;
}
#-----------------------------------------------------------------------------
# Top background colour -> RGB/256
# #263a47 --> 0.1484, 0.2266, 0.2773
# Bottom background colour
# #263a47 --> 0.1484, 0.2266, 0.2773
2026-09-04 22:12:26 +02:00
fun calchorse(horse_base) {
x0 = Window.GetWidth();
y0 = Window.GetHeight();
xhorse = horse_base.GetWidth();
yhorse = horse_base.GetHeight();
dim.horse.xsize = x0;
dim.horse.ysize = y0;
return dim;
}
horse = Image("falbella.png");
Window.SetBackgroundTopColor (0.0, 1.0, 1.0); # Nice colour on top of the screen fading to
Window.SetBackgroundBottomColor (1.0, 1.0, 0.0); # an equally nice colour on the bottom
2026-09-02 21:48:52 +02:00
bits_per_pixel = Window.GetBitsPerPixel ();
2026-09-04 22:12:26 +02:00
password_dot_filename = "password_dot.png";
password_field_filename = "password_field.png";
2026-09-02 21:48:52 +02:00
message_notification[0].image = ImageFromTintedText ("");
message_notification[1].image = ImageFromTintedText ("");
status = "normal";
# use a fixed string with ascending and descending stems to calibrate the
# bounding box for the first message, so the messages below don't move up
# and down according to *their* height.
first_line_height = ImageFromTintedText ("AfpqtM").GetHeight();
# if the user has a 640x480 or 800x600 display, we can't quite fit everything
# (including passphrase prompts) with the target spacing, so scoot the text up
# a bit if needed.
top_of_the_text = TextYOffset();
2026-09-04 22:12:26 +02:00
horse_dim = calchorse(horse);
horse = horse.Scale(Window.GetWidth(), Window.GetHeight());
horse_sprite = Sprite(horse);
SetPosition(horse_sprite, 0, 0, 0);
2026-09-02 21:48:52 +02:00
#-------------------------------Progress Indicator-----------------------------
# Implement in boot progress callback
fun animate_progress_indicator (time, progress) {
2026-09-04 22:12:26 +02:00
# progress_time = time;
# progress_pct = progress;
2026-09-02 21:48:52 +02:00
#Debug ("mode = " + Plymouth.GetMode() + ", progress_time = " + progress_time + ", progress_pct = " + progress_pct);
}
#-----------------------------------------Message stuff --------------------------------
#
# Set up a message label
#
# NOTE: this is called when doing something like 'plymouth message "hello world"'
#
fun setup_message (message_text, x, y, z, index) {
#DebugMedium("Message setup: " + message_text);
global.message_notification[index].image = (index) && ImageFromActionText (message_text) || ImageFromTintedText (message_text);
# Set up the text message, if any
message_notification[index].x = x;
message_notification[index].y = y;
message_notification[index].z = z;
message_notification[index].sprite = Sprite ();
message_notification[index].sprite.SetImage (message_notification[index].image);
message_notification[index].sprite.SetX (message_notification[index].x);
message_notification[index].sprite.SetY (message_notification[index].y);
message_notification[index].sprite.SetZ (message_notification[index].z);
}
fun show_message (index) {
if (global.message_notification[index].sprite) global.message_notification[index].sprite.SetOpacity(1);
}
fun hide_message (index) {
if (global.message_notification[index].sprite) global.message_notification[index].sprite.SetOpacity(0);
}
# the callback function is called when new message should be displayed.
# First arg is message to display.
fun message_callback (message)
{
# Debug("Message callback");
is_fake = 0;
if (!message || (message == "")) is_fake = 1;
local.substring = "keys:";
# Look for the "keys:" prefix
local.keys = StringString(message, local.substring);
local.is_action_line = (keys != NULL);
#Debug("keys " + local.keys + " substring length = " + StringLength(local.substring));
# Get the message without the "keys:" prefix
if (keys != NULL)
message = StringCopy (message, keys + StringLength(local.substring), NULL);
# Get the message without the "fsckd-cancel-msg" prefix as we don't support i18n
substring = "fsckd-cancel-msg:";
keys = StringString(message, substring);
if (keys != NULL)
message = StringCopy(message, keys + StringLength(substring), NULL);
local.label.is_fake = is_fake;
label = get_message_label(message, is_fake, is_action_line);
label.z = 10000;
setup_message (message, label.x, label.y, label.z, is_action_line);
if (prompt_active && local.is_action_line)
hide_message (is_action_line);
else
show_message (is_action_line);
}
#-----------------------------------------Display Password stuff -----------------------
#
fun password_dialogue_setup (message_label) {
#Debug("Password dialog setup");
local.entry;
local.bullet_image;
bullet_image = Image (password_dot_filename);
entry.image = Image (password_field_filename);
# Hide the normal labels
prompt_active = 1;
if (message_notification[1].sprite) hide_message (1);
# Set the prompt label
label = get_message_label(message_label, 0, 1);
label.z = 10000;
setup_message (message_label, label.x, label.y, label.z, 2);
show_message (2);
# Set up the text entry which contains the bullets
entry.sprite = Sprite ();
entry.sprite.SetImage (entry.image);
# Centre the box horizontally
entry.x = Window.GetX () + Window.GetWidth () / 2 - entry.image.GetWidth () / 2;
# Put the entry below the second label.
entry.y = message_notification[2].y + label.height * 1.5;
#DebugMedium("entry x = " + entry.x + ", y = " + entry.y);
entry.z = 10000;
entry.sprite.SetX (entry.x);
entry.sprite.SetY (entry.y);
entry.sprite.SetZ (entry.z);
global.password_dialogue = local;
}
fun password_dialogue_opacity (opacity) {
#Debug("Setting password dialog opacity to " + opacity);
global.password_dialogue.opacity = opacity;
local = global.password_dialogue;
# You can make the box translucent with a float
# entry.sprite.SetOpacity (0.3);
entry.sprite.SetOpacity (opacity);
label.sprite.SetOpacity (opacity);
if (bullets) {
for (index = 0; bullets[index]; index++) {
bullets[index].sprite.SetOpacity (opacity);
}
}
}
# 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.
fun display_password_callback (prompt, bullets) {
#Debug("Password dialog setup");
global.status = "password";
if (!global.password_dialogue) password_dialogue_setup(prompt);
password_dialogue_opacity (1);
bullet_width = password_dialogue.bullet_image.GetWidth();
bullet_y = password_dialogue.entry.y +
password_dialogue.entry.image.GetHeight () / 2 -
password_dialogue.bullet_image.GetHeight () / 2;
margin = bullet_width;
spaces = Math.Int( (password_dialogue.entry.image.GetWidth () - (margin * 2)) / (bullet_width / 2 ) );
#DebugMedium ("spaces = " + spaces + ", bullets = " + bullets);
bullets_area.width = margin + spaces * (bullet_width / 2);
bullets_area.x = Window.GetX () + Window.GetWidth () / 2 - bullets_area.width / 2;
#DebugBottom ("pwd_entry (x,y) = " + password_dialogue.entry.x + "," + password_dialogue.entry.y
# + "), bullets_area.x = " + bullets_area.x + ", bullets_area.width = " + bullets_area.width);
if (bullets > spaces)
bullets = spaces;
for (index = 0; password_dialogue.bullets[index] || index < bullets; index++){
if (!password_dialogue.bullets[index]) {
password_dialogue.bullets[index].sprite = Sprite ();
password_dialogue.bullets[index].sprite.SetImage (password_dialogue.bullet_image);
password_dialogue.bullets[index].x = bullets_area.x + # password_dialogue.entry.x + margin +
index * bullet_width / 2;
password_dialogue.bullets[index].sprite.SetX (password_dialogue.bullets[index].x);
password_dialogue.bullets[index].y = bullet_y;
password_dialogue.bullets[index].sprite.SetY (password_dialogue.bullets[index].y);
password_dialogue.bullets[index].z = password_dialogue.entry.z + 1;
password_dialogue.bullets[index].sprite.SetZ (password_dialogue.bullets[index].z);
}
password_dialogue.bullets[index].sprite.SetOpacity (0);
if (index < bullets) {
password_dialogue.bullets[index].sprite.SetOpacity (1);
}
}
}
Plymouth.SetDisplayPasswordFunction (display_password_callback);
Plymouth.SetMessageFunction (message_callback);
Plymouth.SetBootProgressFunction (animate_progress_indicator);
# Plymouth.SetBootProgressFunction: the callback function is called with two numbers, the progress (between 0 and 1) and the time spent booting so far
# 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
#-----------------------------------------Update Status stuff --------------------------
#
# The update_status_callback is what we can use to pass plymouth whatever we want so
# as to make use of features which are available only in this program (as opposed to
# being available for any theme for the script plugin).
#
# Example:
#
# Thanks to the current implementation, some scripts can call "plymouth --update=fsck:sda1:40"
# and this program will know that 1) we're performing and fsck check, 2) we're checking sda1,
# 3) the program should set the label progress to 40%
#
# Other features can be easily added by parsing the string that we pass plymouth with "--update"
#
fun update_status_callback (status) {
# Debug(status);
if (!status) return;
string_it = 0;
update_strings[string_it] = "";
for (i=0; (String(status).CharAt(i) != ""); i++) {
local.temp_char = String(status).CharAt(i);
if (temp_char != ":")
update_strings[string_it] += temp_char;
else
update_strings[++string_it] = "";
}
# my_string = update_strings[0] + " " + update_strings[1] + " " + update_strings[2];
# Debug(my_string);
}
Plymouth.SetUpdateStatusFunction (update_status_callback);
#-----------------------------------------Display Question stuff -----------------------
#
# TODO: Implement this if needed
#
# The callback function is called when the display should display a question dialogue.
# First arg is prompt string, the second is the entry contents.
#fun display_question_callback (prompt_string, entry_contents)
#{
# time++;
#}
#
#Plymouth.SetDisplayQuestionFunction (display_question_callback);
#fun rotate_img(source_img, current_step, nb_steps) {
# angle = Math.Sin(current_step / nb_steps * Math.Pi / 2) * 2 * Math.Pi;
# #debug_sin = Math.Sin(current_step / nb_steps * Math.Pi / 2);
# #DebugMedium("Sin = " + debug_sin);
# rotated_img = source_img.Rotate(angle);
# return rotated_img;
#}
2026-09-04 22:12:26 +02:00
fun update_horse () {
# if (global.anim_iter > NB_ANIM_STEPS) {
# global.anim_iter = 0;
# }
# #DebugMedium("iter = " + global.anim_iter);
# #glow_opacity = 0.6 + 0.3 * Math.Cos(global.anim_iter / NB_ANIM_STEPS * 2 * Math.Pi);
# #Debug("glow_opacity = " + glow_opacity);
# if (global.anim_start_time != global.progress_time && global.anim_status != "running") {
# global.anim_start_time = global.progress_time;
# global.anim_iter = 0;
# global.anim_status = "running";
# }
#
# if (global.anim_status == "running") {
# global.glow_sprite.SetOpacity(glow_opacity);
# global.anim_iter++;
#
# if (global.anim_iter >= NB_ANIM_STEPS) {
# global.anim_status = "stopped";
# }
# }
2026-09-02 21:48:52 +02:00
}
#-----------------------------------------Refresh stuff --------------------------------
#
# Calling Plymouth.SetRefreshFunction with a function will set that function to be
# called up to 50 times every second, e.g.
#
# NOTE: if a refresh function is not set, Plymouth doesn't seem to be able to update
# the screen correctly
#
fun refresh_callback ()
{
global.refresh_iter++;
if (global.refresh_iter == NB_REFRESHS_BETWEEN_ANIMS) {
global.refresh_iter = 0;
2026-09-04 22:12:26 +02:00
update_horse();
2026-09-02 21:48:52 +02:00
}
#DebugBottom ("refresh_iter=" + refresh_iter + "; anim_status=" + anim_status + "; anim_start_time=" + anim_start_time + "; anim_iter=" + anim_iter);
}
Plymouth.SetRefreshFunction (refresh_callback);
#-----------------------------------------Display Normal stuff -----------------------
#
# The callback function is called when the display should return to normal
fun display_normal_callback ()
{
global.status = "normal";
if (global.password_dialogue) {
password_dialogue_opacity (0);
global.password_dialogue = NULL;
if (message_notification[2].sprite) hide_message(2);
prompt_active = 0;
}
if (message_notification[1].sprite) {
show_message (1);
}
}
Plymouth.SetDisplayNormalFunction (display_normal_callback);
#----------------------------------------- Quit --------------------------------
fun quit_callback ()
{
}
Plymouth.SetQuitFunction(quit_callback);