From 0125b3cd7687019296dd01557813f18e380b5275 Mon Sep 17 00:00:00 2001 From: Julien Lavergne Date: Sun, 28 Mar 2010 19:14:04 +0200 Subject: [PATCH] lubuntu-logo.script: Backport changes made on ubuntu-logo.script. --- debian/changelog | 1 + .../themes/lubuntu-logo/lubuntu-logo.script | 1086 ++++++++++------- 2 files changed, 635 insertions(+), 452 deletions(-) diff --git a/debian/changelog b/debian/changelog index 343ec91..a6bf64d 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,6 +1,7 @@ lubuntu-artwork (0.5) UNRELEASED; urgency=low * Update logo with the new branding. + * lubuntu-logo.script: Backport changes made on ubuntu-logo.script. -- Julien Lavergne Sat, 13 Mar 2010 18:29:26 +0100 diff --git a/lib/plymouth/themes/lubuntu-logo/lubuntu-logo.script b/lib/plymouth/themes/lubuntu-logo/lubuntu-logo.script index 04d1953..550b66d 100644 --- a/lib/plymouth/themes/lubuntu-logo/lubuntu-logo.script +++ b/lib/plymouth/themes/lubuntu-logo/lubuntu-logo.script @@ -1,5 +1,4 @@ # lubuntu-logo.script - boot splash plugin -# based on ubuntu-logo.script # # Copyright (C) 2009 Canonical Ltd. # @@ -18,23 +17,54 @@ # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA # 02111-1307, USA. # -# Written by: Alberto Milone +# Re-written by Rafael Laguna based from +# original by Alberto Milone # # Based on the example provided with the "script plugin" written by: # Charlie Brej # -# Set the text colour in rgb -text_colour.red = 255; -text_colour.green = 255; -text_colour.blue = 255; +# 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 = 0.59; +tinted_text_colour.green = 0.52; +tinted_text_colour.blue = 0.57; + +# 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_medium = Sprite(); +# are we currently prompting for a password? +prompt_active = 0; + +# General purpose function to create text +fun WriteText (text, colour) { + image = Image.Text (text, colour.red, colour.green, colour.blue); + return image; +} + fun ImageToText (text) { - image = Image.Text (text, text_colour.red, text_colour.green, text_colour.blue); + image = WriteText (text, text_colour); + return image; +} + +fun ImageToTintedText (text) { + image = WriteText (text, tinted_text_colour); + return image; +} + +fun ImageToActionText (text) { + image = WriteText (text, action_text_colour); return image; } @@ -52,154 +82,437 @@ fun DebugMedium(text) { debugsprite_medium.SetPosition(0, (Window.GetHeight (0) - 60), 1); } -Window.SetBackgroundTopColor (0, 0, 0); # Nice blue on top of the screen fading to -Window.SetBackgroundBottomColor (0, 0, 0); # an equally nice brown on the bottom +fun TextYOffset() { + local.y; + local.text_height; + local.min_height; -screen_width = Window.GetWidth (); -screen_height = Window.GetHeight (); -wallpaper_image = Image ("wall_blue_2560x1600.png"); -resized_wallpaper_image = wallpaper_image.Scale (screen_width, screen_height); -wallpaper_sprite = Sprite (resized_wallpaper_image); -wallpaper_sprite.SetZ (-10000); + # Put the 1st line below the logo + some spacing + y = logo.y + logo.height + (progress_indicator.bullet_height * 7 ); # + logo_spacing; -logo.image = Image ("lubuntu-logo.png"); + text_height = first_line_height * 7.5; + min_height = Window.GetHeight(); + if (y + text_height > min_height) + y = min_height - text_height; + + if (y < progress_indicator.y + progress_indicator.height) + return progress_indicator.y + progress_indicator.height; + return y; +} + +#------------------------------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; +} + +# 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; +} + +#----------------------------------------------------------------------------- +# Previous background colour +# #300a24 --> 0.19, 0.04, 0.14 +# New background colour +# #2c001e --> 0.16, 0.00, 0.12 +# +# New Lubuntu background +# 0.00, 0.09, 0.17 +Window.SetBackgroundTopColor (0.00, 0.09, 0.17); # Nice colour on top of the screen fading to +Window.SetBackgroundBottomColor (0.00, 0.09, 0.17); # an equally nice colour on the bottom + +logo.image = Image ("lubuntu_logo.png"); # "special://logo" is a special keyword which finds the logo image logo.sprite = Sprite (); logo.sprite.SetImage (logo.image); - logo.width = logo.image.GetWidth (); logo.height = logo.image.GetHeight (); -logo.x = Window.GetWidth (0) / 2 - logo.width / 2; -logo.y = Window.GetHeight (0) / 2 - logo.height / 2; +logo.x = Window.GetX () + Window.GetWidth () / 2 - logo.width / 2; +logo.y = Window.GetY () + Window.GetHeight () / 2 - logo.height; logo.z = 1000; logo.sprite.SetX (logo.x); -# label_area_y = logo_area_y + (*label_height * 2) + 60; logo.sprite.SetY (logo.y); -logo.sprite.SetY (logo.z); +logo.sprite.SetZ (logo.z); logo.sprite.SetOpacity (1); # Spacing below the logo - in pixels -logo_spacing = 0; +logo_spacing = logo.height * 4; -message_notification.image = ImageToText (""); +message_notification[0].image = ImageToTintedText (""); +message_notification[1].image = ImageToTintedText (""); +fsck_notification.image = ImageToActionText (""); status = "normal"; +progress_indicator.bullet_off = Image ("progress_dot_off.png"); +progress_indicator.bullet_on = Image ("progress_dot_on.png"); +progress_indicator.bullet_width = progress_indicator.bullet_off.GetWidth (); +progress_indicator.bullet_height = progress_indicator.bullet_off.GetHeight (); +progress_indicator.bullet_hspacing = progress_indicator.bullet_width * 1.1; +progress_indicator.width = progress_indicator.bullet_width * 5; +progress_indicator.height = progress_indicator.bullet_height; +progress_indicator.y = logo.y + logo.height + (logo.height / 4); +progress_indicator.x = Window.GetX () + Window.GetWidth () / 2 - progress_indicator.width / 2; # logo.x + 26; + +# 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 = ImageToTintedText ("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(); + +#-----------------------------------------Logo functions------------------------------ + +# Call this when updating the screen +fun draw_logo () { + logo.sprite.SetX (logo.x); + logo.sprite.SetY (logo.y); + logo.sprite.SetZ (logo.z); + logo.sprite.SetOpacity (1); +} + +#-----------------------------------------Progress Indicator-------------------------- +fun set_progress_indicator () { + + + # Here we assume that we can store half bullets on each half of the screen + # together with some spacing + local.x = progress_indicator.x; + + for (index = 0; index <= 4; index++) { + # Set the "off" bullets + progress_indicator.bullets_off[index].sprite = Sprite (progress_indicator.bullet_off); + progress_indicator.bullets_off[index].sprite.SetPosition (local.x, progress_indicator.y, 1000); + progress_indicator.bullets_off[index].x = local.x; + progress_indicator.bullets_off[index].y = progress_indicator.y; + progress_indicator.bullets_off[index].sprite.SetOpacity (1); + + #local.debug_medium_string = "Progress indicator " + index + ": x = " + progress_indicator.bullets_off[index].x + + # ", y = " + progress_indicator.bullets_off[index].y + ", logo width = " + logo.width + + # ", logo height = " + logo.height + " " + screen_width + " " + screen_height; + # + #(index % 2) && DebugMedium (local.debug_medium_string) || DebugBottom (local.debug_medium_string); + + # Set the "on" bullets on top of the "off" bullets and make them transparent + progress_indicator.bullets_on[index].sprite = Sprite (progress_indicator.bullet_on); + progress_indicator.bullets_on[index].x = progress_indicator.bullets_off[index].x; + progress_indicator.bullets_on[index].y = progress_indicator.bullets_off[index].y; + progress_indicator.bullets_on[index].sprite.SetPosition (progress_indicator.bullets_on[index].x, progress_indicator.bullets_on[index].y, 10000); + + progress_indicator.bullets_on[index].sprite.SetOpacity (0); + + local.x += progress_indicator.bullet_hspacing; + } + #local.debug_string = "Progress indicator: x1 = " + progress_indicator.x + ", x2 = " + local.x + ", y = " + progress_indicator.y + + # ", x logo = " + logo.x + ", y logo = " + logo.y + ", indicator width = " + progress_indicator.width; + #Debug(progress_indicator.bullets_off[0].x); +} -#-----------------------------------------Label utility functions--------------------- -fun get_label_position (label, is_fake) { - # Debug("Get Label position"); - screen_width = Window.GetWidth (0); - screen_height = Window.GetHeight (0); - local.message_label; +# We have 2 bullets, one on top of the other: +# The white one is on top of the red one and the former should +# slowly fade so as to get a nice transition effect. +fun switch_on_bullet (bullets_off, bullets_on, bullet_number, opacity) { + local.x = bullets_on[bullet_number].x; + local.y = bullets_on[bullet_number].y; + local.z = bullets_on[bullet_number].z; - if (is_fake) { - # Create a fake label so as to get the y coordinate of - # a standard-lenght label. - # This is useful when prompting without providing a - # message - local.message_image = ImageToText ("This is a fake message"); - message_label.width = message_image.GetWidth (); - message_label.height = message_image.GetHeight (); + # Hide the bullets which are off + bullets_off[bullet_number].sprite.SetOpacity (0); + + # Show the bullets which are on + bullets_on[bullet_number].sprite.SetPosition (local.x, local.y, local.z); + bullets_on[bullet_number].sprite.SetOpacity (opacity); + + # Bump the number of times we have switched on bullets + global.times_bullets_switched++; +} + +fun switch_off_bullets () { + # Debug("Switching off progress indicator"); + + set_progress_indicator (); + global.times_bullets_switched = 0; + global.on_off = 1; +} + +# This is something that we can call when we exit +fun switch_on_bullets () { + # Debug("Switching off progress indicator"); + if (!global.progress_indicator.bullets_on) set_progress_indicator (); + local = global.progress_indicator; + + for (index = 0; bullets_on[index]; index++) { + switch_on_bullet (bullets_off, bullets_on, index, 1.0); } - else { - local.message_image = ImageToText (label); - message_label.width = message_image.GetWidth (); - message_label.height = message_image.GetHeight (); +} + + +# Implement in boot progress callback +fun animate_progress_indicator (progress, time) { + if (global.progress_time == NULL) { + global.progress_time = progress; #time; + switch_off_bullets (); + } + +# Debug ("progress = " + progress + ", time = " + time + " times switched = " + global.times_bullets_switched + " on_off " + global.on_off); + +# if (global.times_bullets_switched == NULL) +# global.times_bullets_switched = 5; + +# if (global.on_off == NULL) +# global.on_off = 0; + + if ((progress - global.progress_time) >= 1.0) { + global.progress_time = progress; + + if (global.times_bullets_switched == 5) { + # Change which bullets are switched on + # and which ones are switched off + global.on_off = !global.on_off; + global.times_bullets_switched = 0; + } + + if (global.on_off) { + switch_on_bullet (progress_indicator.bullets_off, progress_indicator.bullets_on, + global.times_bullets_switched, 1.0); + } + else { + switch_on_bullet (progress_indicator.bullets_on, progress_indicator.bullets_off, + global.times_bullets_switched, 1.0); + } } - # Centre the label horizontally - message_label.x = (screen_width / 2) - (message_label.width / 2); - # Place the label below the logo - message_label.y = logo.y + logo.height + logo_spacing; # message_label.height / 2; + # Start setting bullets to "on" with translucency +# for (index = 0; index <= 5; index++) { +# opacity = 0.0; +# while (opacity <= 1.0) { +# switch_on_bullet (progress_indicator.bullets_off, progress_indicator.bullets_on, +# index, opacity); +# opacity += 0.1; +# } +# } +} + + +#-----------------------------------------Label utility functions--------------------- + +# label should be either a string or NULL +# Images for n lines will be created and returned as items of the +# message_label array +# +fun get_message_label (label, is_fake, is_action_line) { + # Debug("Get Label position"); + local.message_label; + if (is_fake) + # Create a fake label so as to get the y coordinate of + # a standard-length label. + local.message_image = ImageToTintedText ("This is a fake message"); + else + local.message_image = (is_action_line) && ImageToActionText (label) || ImageToTintedText (label); + + message_label.width = message_image.GetWidth (); + message_label.height = message_image.GetHeight (); + + # Center the line horizontally + message_label.x = Window.GetX () + Window.GetWidth () / 2 - message_label.width / 2; + + message_label.y = top_of_the_text; + + # Put the 2nd line below the fsck line + if (is_action_line) { + local.fsck_label.y = message_label.y + (first_line_height + first_line_height / 2); + message_label.y = local.fsck_label.y + (first_line_height * 2); + } + + # Debug("action label x = " + message_label.x + " y = " + message_label.y ); + # message_debug = "msg_x = " + message_label.x + " msg_y = " + message_label.y + # "msg_width = " + message_label.width + " msg_height = " + # message_label.height + " message = " + label; # Debug(message_debug); return message_label; + +} + +# Create an fsck label and/or get its position +fun get_fsck_label (label, is_fake) { + # Debug("Get Label position"); + local.fsck_label = global.progress_label; + + if (is_fake) + fsck_label.image = ImageToTintedText ("This is a fake message"); + else + fsck_label.image = ImageToTintedText (label); + + fsck_label.width = fsck_label.image.GetWidth (); + fsck_label.height = fsck_label.image.GetHeight (); + + # Centre the label horizontally + fsck_label.x = Window.GetX () + Window.GetWidth () / 2 - fsck_label.width / 2; + + local.first_label = get_message_label (label, 1, 0); + + # Place the label below the 1st message line + fsck_label.y = local.first_label.y + local.first_label.height + (local.first_label.height / 2); + +# message_debug = "msg_x = " + fsck_label.x + " msg_y = " + fsck_label.y + +# "msg_width = " + fsck_label.width + " msg_height = " + +# fsck_label.height + " message = " + label; +# Debug(message_debug); + + return fsck_label; +} + +#-----------------------------------------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) { + # Debug("Message setup"); + global.message_notification[index].image = (index) && ImageToActionText (message_text) || ImageToTintedText (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); + + 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) { +fun password_dialogue_setup (message_label) { # Debug("Password dialog setup"); - local.box; - local.lock; local.entry; local.bullet_image; - local.is_fake = 0; - bullet_image = Image ("bullet.png"); - box.image = Image ("box.png"); - entry.image = Image ("entry.png"); - lock.image = Image ("lock.png"); + bullet_image = Image ("progress_dot_off.png"); + entry.image = Image ("password_field.png"); - if (!message_label) is_fake = 1; + # Hide the normal labels + prompt_active = 1; + if (message_notification[1].sprite) hide_message (1); - local.label = get_label_position(message_label, is_fake); - - label.is_fake = is_fake; + # Set the prompt label + label = get_message_label(message_label, 0, 1); + label.z = 10000; - # Make sure that the prompt label is placed below the message label - # NOTE: here we assume that all labels have the same height. - label.y += label.height; + setup_message (message_label, label.x, label.y, label.z, 2); + show_message (2); - # Set up the text message, if any - if (!is_fake) { - label.z = 10000; - label.image = ImageToText (message_label); - label.sprite = Sprite (); - label.sprite.SetImage (label.image); - label.sprite.SetX (label.x); - label.sprite.SetY (label.y); - label.sprite.SetZ (label.z); - } - - # Set up the box area which contains the text entry and the lock icon - box.sprite = Sprite (); - box.sprite.SetImage (box.image); - # Centre the box horizontally - box.x = Window.GetWidth (0) / 2 - box.image.GetWidth () / 2; - # Put the box below the label. Leave the space for 2 labels. - box.y = label.y + label.height * 2; - box.z = 10000; - box.sprite.SetX (box.x); - box.sprite.SetY (box.y); - box.sprite.SetZ (box.z); - - - # Set up the lock icon - lock.sprite = Sprite (); - lock.sprite.SetImage (lock.image); - lock.x = (Window.GetWidth (0) / 2) - ((lock.image.GetWidth () + entry.image.GetWidth ()) / 2); - lock.y = box.y + (box.image.GetHeight () / 2) - (lock.image.GetHeight () / 2); - lock.z = box.z + 1; - lock.sprite.SetX (lock.x); - lock.sprite.SetY (lock.y); - lock.sprite.SetZ (lock.z); - - - # Set up the text entry + # Set up the text entry which contains the bullets entry.sprite = Sprite (); entry.sprite.SetImage (entry.image); - # FIXME: Maybe we should add some horizontal space between the icon and the entry? - entry.x = lock.x + lock.image.GetWidth (); - entry.y = box.y + (box.image.GetHeight () / 2) - (entry.image.GetHeight () / 2); - entry.z = lock.z; + # 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; + + #Debug ("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; } @@ -209,15 +522,14 @@ fun password_dialogue_opacity (opacity) { local = global.password_dialogue; # You can make the box translucent with a float - # box.sprite.SetOpacity (0.3); - box.sprite.SetOpacity (opacity); - - lock.sprite.SetOpacity (opacity); + # entry.sprite.SetOpacity (0.3); entry.sprite.SetOpacity (opacity); - if (!label.is_fake) label.sprite.SetOpacity (opacity); + label.sprite.SetOpacity (opacity); - for (index = 0; bullet[index]; index++) { - bullet[index].sprite.SetOpacity (opacity); + if (bullets) { + for (index = 0; bullets[index]; index++) { + bullets[index].sprite.SetOpacity (opacity); + } } } @@ -230,89 +542,159 @@ fun display_password_callback (prompt, bullets) { global.status = "password"; if (!global.password_dialogue) password_dialogue_setup(prompt); password_dialogue_opacity (1); - for (index = 0; password_dialogue.bullet[index] || index < bullets; index++){ - if (!password_dialogue.bullet[index]) { - password_dialogue.bullet[index].sprite = Sprite (); - password_dialogue.bullet[index].sprite.SetImage (password_dialogue.bullet_image); - password_dialogue.bullet[index].x = password_dialogue.entry.x + - index * password_dialogue.bullet_image.GetWidth (); - password_dialogue.bullet[index].sprite.SetX (password_dialogue.bullet[index].x); - password_dialogue.bullet[index].y = password_dialogue.entry.y + - password_dialogue.entry.image.GetHeight () / 2 - - password_dialogue.bullet_image.GetHeight () / 2; - password_dialogue.bullet[index].sprite.SetY (password_dialogue.bullet[index].y); - password_dialogue.bullet[index].z = password_dialogue.entry.z + 1; - password_dialogue.bullet[index].sprite.SetZ (password_dialogue.bullet[index].z); + 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 ) ); + #Debug ("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 = " + password_dialogue.entry.x + ", 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.bullet[index].sprite.SetOpacity (0); + password_dialogue.bullets[index].sprite.SetOpacity (0); if (index < bullets) { - password_dialogue.bullet[index].sprite.SetOpacity (1); + 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 -#-----------------------------------------Message stuff -------------------------------- -# +#----------------------------------------- FSCK Counter -------------------------------- -# 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) { - # Debug("Message setup"); - message_notification.image = ImageToText (message_text); +# Initialise the counter +fun init_fsck_count () { + # The number of fsck checks in this cycle + global.counter.total = 0; + # The number of fsck checks already performed + the current one + global.counter.current = 1; + # The previous fsck + global.counter.last = 0; +} - # Set up the text message, if any - message_notification.x = x; - message_notification.y = y; - message_notification.z = z; - - message_notification.sprite = Sprite (); - message_notification.sprite.SetImage (message_notification.image); - message_notification.sprite.SetX (message_notification.x); - message_notification.sprite.SetY (message_notification.y); - message_notification.sprite.SetZ (message_notification.z); +# Increase the total counter +fun increase_fsck_count () { + global.counter.total++; +} + +fun increase_current_fsck_count () { + global.counter.last = global.counter.current++; +} +# Clear the counter +fun clear_fsck_count () { + global.counter = NULL; + init_fsck_count (); } -fun show_message () { - if (global.message_notification.sprite) global.message_notification.sprite.SetOpacity(1); +#----------------------------------------- Progress Label ------------------------------ + + +# Change the opacity level of a progress label +# +# opacity = 1 -> show +# opacity = 0 -> hide +# opacity = 0.3 (or any other float) -> translucent +# +fun set_progress_label_opacity (opacity) { + # the label + progress_label.sprite.SetOpacity (opacity); + + # Make the slot available again when hiding the bar + # So that another bar can take its place + if (opacity == 0) { + progress_label.is_available = 1; + progress_label.device = ""; + } } -fun hide_message () { - if (global.message_notification.sprite) global.message_notification.sprite.SetOpacity(0); +# Set up a new Progress Bar +# +# TODO: Make it possible to reuse (rather than recreate) a bar +# if .is_available = 1. Ideally this would just reset the +# label, the associated +# device and the image size of the sprite. + +fun init_progress_label (device) { + # Make the slot unavailable + global.progress_label.is_available = 0; + progress_label.progress = 0; + progress_label.device = device; } +# See if the progress label is keeping track of the fsck +# of "device" +# +fun device_has_progress_label (device) { + #DebugBottom ("label device = " + progress_label.device + " checking device " + device); + return (progress_label.device == device); +} -# 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; +# Update the Progress bar which corresponds to index +# +fun update_progress_label (progress) { + # If progress is NULL then we just refresh the label. + # This happens when only counter.total has changed. + if (progress != NULL) { + progress_label.progress = progress; - local.label.is_fake = is_fake; - label = get_label_position(message, is_fake); - label.z = 10000; + #Debug("device " + progress_label.device + " progress " + progress); - setup_message (message, label.x, label.y, label.z); - show_message (); + # If progress >= 100% hide the label and make it available again + if (progress >= 100) { + set_progress_label_opacity (0); + + # See if we any other fsck check is complete + # and, if so, hide the progress bars and the labels + on_fsck_completed (); + + return 0; + } + } + # Update progress label here + label = "Checking disk " + global.counter.current + " of " + global.counter.total + " (" + progress_label.progress + "% complete)"; -} -Plymouth.SetMessageFunction (message_callback); + progress_label = get_fsck_label (label, 0); + #progress_label.progress = progress; + progress_label.sprite = Sprite (progress_label.image); + + # Set up the bar + progress_label.sprite.SetPosition(progress_label.x, progress_label.y, 1); -# 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 + set_progress_label_opacity (1); + +} + +# Refresh the label so as to update counters +fun refresh_progress_label () { + update_progress_label (NULL); +} #----------------------------------------- FSCK Queue ---------------------------------- @@ -357,19 +739,28 @@ fun add_fsck_to_queue (device, progress) { if (local.index > global.fsck_queue.biggest_item) global.fsck_queue.biggest_item = local.index; -# DebugMedium ("Adding " + device + " at " + local.index); + #DebugMedium ("Adding " + device + " at " + local.index); +} + +fun is_queue_empty () { + return (fsck_queue.counter == 0); } +fun is_progress_label_available () { + return (progress_label.is_available == 1); +} + + # This should cover the case in which the fsck checks in # the queue are completed before the ones showed in the -# progress bars +# progress label fun on_queued_fsck_completed () { if (!is_queue_empty ()) return; # Hide the extra label, if any - if (progress_bar.extra_label.sprite) - progress_bar.extra_label.sprite.SetOpacity(0); + #if (progress_bar.extra_label.sprite) + # progress_bar.extra_label.sprite.SetOpacity(0); } fun remove_fsck_from_queue (index) { @@ -386,31 +777,25 @@ fun remove_fsck_from_queue (index) { on_queued_fsck_completed (); } -fun is_queue_empty () { - return (fsck_queue.counter == 0); -} - fun on_fsck_completed () { - if (!are_bars_empty ()) + # We have moved on to tracking the next fsck + increase_current_fsck_count (); + + if (!is_progress_label_available ()) return; if (!is_queue_empty ()) return; - # Hide all progress bars - for (index=0; index < progress_bar.max_number; index++) { - set_bar_opacity (index, 0); - } - - # Make sure that the bar counter is 0 - progress_bar.counter = 0; - - # Hide the extra label, if any - if (progress_bar.extra_label.sprite) - progress_bar.extra_label.sprite.SetOpacity(0); + # Hide the progress label + if (progress_label.sprite) + progress_label.sprite.SetOpacity (0); # Clear the queue clear_queue (); + + # Clear the fsck counter + clear_fsck_count (); } # Update an fsck process that we keep track of in the queue @@ -427,309 +812,97 @@ fun update_progress_in_queue (index, device, progress) { } +# TODO: Move it to some function # Create an empty queue -init_queue (); - -#----------------------------------------- Progress Bar -------------------------------- - -progress_box.image = Image ("progress_box.png"); -#progress_box.height = progress_box.image.GetHeight (); +#init_queue (); -progress_bar.original_image = Image ("progress_bar.png"); -#progress_bar.original_height = progress_bar.original_image.GetHeight (); -progress_bar.counter = 0; -progress_bar.global_counter = 0; -progress_bar.max_number = 3; -progress_bar.extra_label.message; -# Prepare empty progress bars -for (i=0; i < progress_bar.max_number ; i++) { - progress_bar[i].is_available = 1; - progress_bar[i].progress = 0; -} +#----------------------------------------- FSCK Functions ------------------------------ -# See if all progress bars are empty -fun are_bars_empty () { - for (i=0; i < progress_bar.max_number ; i++) { - if (progress_bar[i].is_available == 0) - return 0; - } - return 1; -} -# Change the opacity level of a progress bar and of its label -# -# opacity = 1 -> show -# opacity = 0 -> hide -# opacity = 0.3 (or any other float) -> translucent -# -fun set_bar_opacity (index, opacity) { - # the label - if (!progress_bar[index].label.is_fake) - progress_bar[index].label.sprite.SetOpacity(opacity); - - # the bar - progress_bar[index].sprite.SetOpacity(opacity); - - # the box - progress_bar[index].box.sprite.SetOpacity(opacity); - - # Make the slot available again when hiding the bar - # So that another bar can take its place - if (opacity == 0) { - progress_bar[index].is_available = 1; - progress_bar[index].device = ""; - progress_bar.counter--; - } -} - -# Set up a new Progress Bar +# Either add a new bar for fsck checks or update an existing bar # -# TODO: Make it possible to reuse (rather than recreate) a bar -# if .is_available = 1. Ideally this would just reset the -# label, the associated -# device and the image size of the sprite. -fun setup_progress_bar (message, index, device) { - # Make the slot unavailable - progress_bar[index].is_available = 0; - - progress_bar.counter++; - - # Fill the slot - progress_bar[index].device = device; - progress_bar[index].image = progress_bar.original_image; - progress_bar[index].sprite = Sprite(); - progress_bar[index].sprite.SetImage(progress_bar[index].image); - - is_fake = 0; - if (!message || (message == "")) is_fake = 1; - - local.label.is_fake = is_fake; - label = get_label_position(message, is_fake); - label.z = 10000; - - if (index > 0) { - # Put the label of the "nth" bar below the bar of the "nth - 1" bar - label.y = progress_bar[index - 1].y + progress_bar.original_image.GetHeight() + progress_bar[index - 1].label.height; - } - else { - # index == 0 - # Leave some space so that a message can be shown above the label - # For example if we wanted to show "Press Q to stop the disk checks" - # - label.y = label.y + label.height + label.height / 2; # Maybe we should add more space - } - - - # Set up the bar - progress_bar[index].x = Window.GetWidth (0) / 2 - progress_bar.original_image.GetWidth () / 2; - progress_bar[index].y = label.y + label.height + label.height / 3; - progress_bar[index].sprite.SetPosition(progress_bar[index].x, progress_bar[index].y, 1); - - # Set up the message label, if any - progress_bar[index].label = label; - if (!progress_bar[index].label.is_fake) { - local.label_image = ImageToText (message); - progress_bar[index].label.sprite = Sprite (); - progress_bar[index].label.sprite.SetImage(local.label_image); - progress_bar[index].label.sprite.SetPosition(progress_bar[index].label.x, progress_bar[index].label.y, 1); - } - - - # Set up the Box which contains the bar - progress_bar[index].box.sprite = Sprite(progress_box.image); - progress_bar[index].x = Window.GetWidth (0) / 2 - progress_box.image.GetWidth () / 2; - progress_bar[index].y = progress_bar[index].y + (progress_bar.original_image.GetHeight () / 2) - (progress_box.image.GetHeight () / 2) ; - progress_bar[index].box.sprite.SetPosition(progress_bar[index].x, progress_bar[index].y, 0); - -} - -# Get the index of the progress bar which keeps track of the fsck -# of "device" +# NOTE: no more than "progress_bar.max_number" bars are allowed # -fun get_progress_bar_index_from_device (device) { - local.device_index = -1; - for (index=0; index < progress_bar.max_number; index++) { - if (progress_bar[index].device == device) { - local.device_index = index; - break; - } - } - return device_index; -} +fun fsck_check (device, progress) { -# See if a progress bar slot is available and return its index -# -fun get_available_progress_bar_index () { - local.available_index = -1; - for (index=0; index < progress_bar.max_number; index++) { - if (progress_bar[index].is_available) { - local.available_index = index; - break; - } - } - return local.available_index; -} + # The 1st time this will take place + if (!global.progress_label) { + # Increase the fsck counter + increase_fsck_count (); -# Update the Progress bar which corresponds to index -# -fun update_progress_bar_by_index (index, progress) { - progress_bar[index].progress = progress; - -# Debug(progress); - - # If progress >= 100% hide the bar and make it available again - if (progress >= 100) { - set_bar_opacity (index, 0); - - # See if we any other fsck check is complete - # and, if so, hide the progress bars and the labels - on_fsck_completed (); - - return 0; - } - -# progress_new = progress + 1; -# multiplied = progress_bar.original_image.GetWidth () * progress; -# cur_bar_width = progress_bar[index].image.GetWidth (); -# -# my_string = "progress+1 = " + progress_new + " original * progress = " + multiplied + " current bar width = " + cur_bar_width; -# Debug(my_string); + # Set up a new label for the check + init_progress_label (device); + update_progress_label (progress); - if (progress_bar[index].image.GetWidth () != Math.Int (progress_bar.original_image.GetWidth () / 100 * progress)) { - progress_bar[index].image = progress_bar.original_image.Scale(progress_bar.original_image.GetWidth(progress_bar.original_image) - / 100 * progress, progress_bar.original_image.GetHeight()); - - progress_bar[index].sprite.SetImage (progress_bar[index].image); - progress_bar[index].sprite.SetPosition(progress_bar[index].x, progress_bar[index].y, 1000); + return; } -} - - -#-----------------------------------------Fsck stuff ----------------------------- -# - -# Create a label which tells users that other fsck checks are running in the -# background -# -# NOTE: the bar is hidden by default. You can make it visible with SetOpacity(1) -# -fun create_extra_fsck_label () { - - message = "Further disk checks are taking place in the background. Please wait..."; - - progress_bar.extra_label = get_label_position(message, 0); - - # Put the label of below the last bar - progress_bar.extra_label.y = progress_bar[progress_bar.max_number - 1].y + - progress_bar.original_image.GetHeight() + - progress_bar[progress_bar.max_number - 1].label.height; - - progress_bar.extra_label.z = 10000; - # Set up the message label - progress_bar.extra_label_image = ImageToText (message); - progress_bar.extra_label.sprite = Sprite (); - progress_bar.extra_label.sprite.SetImage(progress_bar.extra_label_image); - progress_bar.extra_label.sprite.SetPosition(progress_bar.extra_label.x, - progress_bar.extra_label.y, - progress_bar.extra_label.z); - - # Keep the bar hidden by default - progress_bar.extra_label.sprite.SetOpacity(0); -} - - -# Either add a new bar for fsck checks or update an existing bar -# -# NOTE: no more than "progress_bar.max_number" bars are allowed -# -fun fsck_check (device, progress) { - # See if we already have a bar for the device check - local.device_index = get_progress_bar_index_from_device (device); - - if (device_index >= 0) { -# Debug("Update the progress of the existing bar"); - # Update the progress of the existing bar - update_progress_bar_by_index (device_index, progress); + if (device_has_progress_label (device)) { + # Update the progress of the existing label + update_progress_label (progress); } else { # See if there's already a slot in the queue for the device local.queue_device_index = queue_look_up_by_device(device); - # See if there is an available slot - # NOTE: we don't allow more than "progress_bar.max_number" bars - if (progress_bar.counter < progress_bar.max_number) { - # Get the index for the 1st available slot - local.available_index = get_available_progress_bar_index (); + # See if the progress_label is available + if (progress_label.is_available) { # local.my_string = "available index " + local.available_index + " progress_bar counter is " + progress_bar.counter; # Debug(local.my_string); - if (local.available_index >= 0) { - - # If the fsck check for the device was in the queue, then - # remove it from the queue - if (local.queue_device_index >= 0) - remove_fsck_from_queue (index); - - # Set up a new label for the check - local.message = "Routine check of drive " + device; -# local.my_string += local.message; -# Debug(local.my_string); - - # Set up a new bar for the check - setup_progress_bar (message, local.available_index, device); - update_progress_bar_by_index (local.available_index, progress); + # If the fsck check for the device was in the queue, then + # remove it from the queue + if (local.queue_device_index >= 0) { + remove_fsck_from_queue (index); + } + else { + # Increase the fsck counter + increase_fsck_count (); } +# local.my_string += local.message; + #Debug("setting new label for device " + device + " progress " + progress); + + # Set up a new label for the check + init_progress_label (device); + update_progress_label (progress); + } - # If there's no available progress bar slot + # If the progress_label is not available else { # If the fsck check for the device is already in the queue # just update its progress in the queue if (local.queue_device_index >= 0) { -# DebugMedium("Updating queue at " + local.queue_device_index + " for device " + device); + #DebugMedium("Updating queue at " + local.queue_device_index + " for device " + device); update_progress_in_queue (local.queue_device_index, device, progress); } # Otherwise add the check to the queue else { -# DebugMedium("Adding device " + device + " to queue at " + local.queue_device_index); + #DebugMedium("Adding device " + device + " to queue at " + local.queue_device_index); add_fsck_to_queue (device, progress); + + # Increase the fsck counter + increase_fsck_count (); + + refresh_progress_label (); } } } - if (!is_queue_empty ()) { +# if (!is_queue_empty ()) { # DebugBottom("Extra label for "+ device); - # Create a label which tells users that other fsck checks are running in the - # background - create_extra_fsck_label (); - # Make the label visible - progress_bar.extra_label.sprite.SetOpacity(1); - } + #} # else { # DebugBottom("No extra label for " + device + ". 1st Device in the queue "+ fsck_queue[0].device + " counter = " + global.fsck_queue.counter); # } } -# A temporary replacement for atoi() -# it makes sense to use it only for -# numbers up to 100 -fun string_to_integer (str) { - int = -1; - for (i=0; i<=100; i++) { - if (i+"" == str) { - int = i; - break; - } - } - return int; -} #-----------------------------------------Update Status stuff -------------------------- # @@ -741,7 +914,7 @@ fun string_to_integer (str) { # # 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 bar progress to 40% +# 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" # @@ -769,14 +942,18 @@ fun update_status_callback (status) { progress = update_strings[2]; if ((device != "") && (progress != "")) { - progress = string_to_integer (progress); + progress = StringToInteger (progress); # Make sure that the fsck_queue is initialised if (!global.fsck_queue) init_queue (); - - if (!global.progress_bar.extra_label.sprite) - create_extra_fsck_label (); + + # Make sure that the fsck counter is initialised + if (!global.counter) + init_fsck_count (); + +# if (!global.progress_bar.extra_label.sprite) +# create_extra_fsck_label (); # Keep track of the fsck check fsck_check (device, progress); @@ -787,8 +964,6 @@ fun update_status_callback (status) { } Plymouth.SetUpdateStatusFunction (update_status_callback); - - #-----------------------------------------Display Question stuff ----------------------- # # TODO: Implement this if needed @@ -812,10 +987,7 @@ Plymouth.SetUpdateStatusFunction (update_status_callback); # fun refresh_callback () { - logo.sprite.SetX (logo.x); - logo.sprite.SetY (logo.y); - logo.sprite.SetZ (logo.z); - logo.sprite.SetOpacity (1); + draw_logo (); } Plymouth.SetRefreshFunction (refresh_callback); @@ -826,9 +998,16 @@ Plymouth.SetRefreshFunction (refresh_callback); fun display_normal_callback () { global.status = "normal"; - if (global.password_dialogue) password_dialogue_opacity (0); + 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); + - if (message_notification.sprite) hide_message (); } Plymouth.SetDisplayNormalFunction (display_normal_callback); @@ -836,9 +1015,12 @@ Plymouth.SetDisplayNormalFunction (display_normal_callback); #----------------------------------------- Quit -------------------------------- +# TODO: Maybe we should also hide any other dialog +# Show the logo and make the progress indicator look full when on exit fun quit_callback () { logo.sprite.SetOpacity (1); + switch_on_bullets (); } Plymouth.SetQuitFunction(quit_callback);