melawy-plymouth-theme-lera-.../dev/script.js

704 lines
24 KiB
JavaScript
Raw Normal View History

2023-04-17 11:56:17 +05:00
/*
2023-10-25 16:38:37 +05:00
Theme Name: Melawy
2023-04-17 11:56:17 +05:00
Version: 1.0
Description: My theme
Author: Valeria Fadeeva - https://github.com/Valeria-Fadeeva
Date: 2023.04.04
License: GNU AFFERO GENERAL PUBLIC LICENSE, see <http://www.gnu.org/licenses/>
*/
Window.GetMaxWidth = function() {
i = 0;
width = 0;
while (Window.GetWidth(i)){
width = Math.Max(width, Window.GetWidth(i));
i++;
}
return width;
};
Window.GetMaxHeight = function() {
i = 0;
height = 0;
while (Window.GetHeight(i)){
height = Math.Max(height, Window.GetHeight(i));
i++;
}
return height;
};
Percent = function(perc, pixels) {
result = Math.Int(Math.Abs(Math.Int(pixels)) / 100 * Math.Abs(Math.Int(perc)));
return result;
};
Limit = function(width, height, perc) {
local.this;
this.width = width;
this.height = height;
this.perc = perc;
this.GetWidth = function() {
width = Percent(this.perc, this.width);
return width;
};
this.GetHeight = function() {
height = Percent(this.perc, this.height);
return height;
};
return this;
};
ScaleImage = function(image1, image2) {
img1.width = image1.GetWidth();
img1.height = image1.GetHeight();
img1.ratio = img1.width / img1.height;
img2.width = image2.GetWidth();
img2.height = image2.GetHeight();
img2.ratio = img2.width / img2.height;
if (img1.ratio == 1 || (img1.width < 200 && img1.height < 200)) {
img1.scaled = image1.Scale(img2.width, img2.height);
return img1.scaled;
}
if (img1.width == img2.width && img1.height == img2.height) {
return image1;
}
if (img2.ratio < img1.ratio) {
factor = img2.height / img1.height;
} else {
factor = img2.width / img1.width;
}
img1.scaled = image1.Scale(img1.width * factor, img1.height * factor);
return img1.scaled;
};
FitIntoDimensions = function(image1, image2) {
img1.width = image1.GetWidth();
img1.height = image1.GetHeight();
img2.width = image2.GetWidth();
img2.height = image2.GetHeight();
ma = Math.Max(img1.width, img2.height);
mi = Math.Min(img1.height, img2.height);
factor = ma / mi;
img1.fit = image1.Scale(Math.Int(img1.width / factor), Math.Int(img1.height / factor));
};
SetSpriteImage = function(asset, x, y, z) {
local.sprite = Sprite();
sprite.image = Image(asset);
sprite.width = sprite.image.GetWidth();
sprite.height = sprite.image.GetHeight();
sprite.SetImage(sprite.image);
sprite.SetPosition(x, y, z);
return sprite;
};
2023-11-24 21:30:49 +05:00
Blur = function(background_src, foreground_src, x, y, z, width, height, scale_width, scale_height) {
index = 0;
local.image[index];
image[index].image = Image(background_src);
image[index].image = ScaleImage(image[index].image, Limit(scale_width, scale_height, 100));
image[index].image = image[index].image.Crop(x, y, width, height);
image[index].image = ScaleImage(image[index].image, Limit(Percent(120, width), Percent(120, height), 100));
image[index].image = image[index].image.Crop(x, y, width, height);
image[index].sprite0 = Sprite(image[index].image);
image[index].sprite1 = Sprite(image[index].image);
image[index].sprite2 = Sprite(image[index].image);
image[index].sprite3 = Sprite(image[index].image);
image[index].sprite4 = Sprite(image[index].image);
image[index].sprite0.SetOpacity(0.25);
image[index].sprite1.SetOpacity(0.25);
image[index].sprite2.SetOpacity(0.25);
image[index].sprite3.SetOpacity(0.25);
image[index].sprite4.SetOpacity(0.25);
image[index].sprite0.SetPosition(x, y, z);
image[index].sprite1.SetPosition(x++, y, z++);
image[index].sprite2.SetPosition(x, y++, z++);
image[index].sprite3.SetPosition(x--, y, z++);
image[index].sprite5.SetPosition(x, y--, z++);
index = 1;
image[index].image = Image(foreground_src);
image[index].image = image[index].image.Scale(width, height);
image[index].sprite = Sprite(image[index].image);
image[index].sprite.SetOpacity(0.75);
image[index].sprite.SetPosition(x, y, z++);
return local.image;
};
2023-04-17 11:56:17 +05:00
// TEXT
2023-05-16 18:47:46 +05:00
common_font = "Noto Sans Mono Regular 10";
2023-11-22 14:24:25 +05:00
progress_font = "Noto Sans Mono Regular 12";
2023-05-16 18:47:46 +05:00
link_font = "Noto Sans Italic 16";
2023-11-24 21:30:49 +05:00
common_symbol.image = Image.Text("M", 0.5, 0.5, 0.5, 1, common_font);
common_symbol.height = common_symbol.image.GetHeight(); // высота символа
common_symbol.width = common_symbol.image.GetWidth(); // ширина символа
progress_symbol.image = Image.Text("M", 0.5, 0.5, 0.5, 1, progress_font);
progress_symbol.height = progress_symbol.image.GetHeight(); // высота символа
progress_symbol.width = progress_symbol.image.GetWidth(); // ширина символа
link_symbol.image = Image.Text("M", 0.5, 0.5, 0.5, 1, link_font);
link_symbol.height = link_symbol.image.GetHeight(); // высота символа
link_symbol.width = link_symbol.image.GetWidth(); // ширина символа
2023-04-17 11:56:17 +05:00
starting_text = "Starting up...";
bye_text = "System is shutting down";
progress_t= 0;
x0 = Window.GetX();
y0 = Window.GetY();
z0 = Window.GetZ();
Window.SetBackgroundTopColor(0, 0, 0);
Window.SetBackgroundBottomColor(0, 0, 0);
screen.width = Window.GetMaxWidth();
screen.height = Window.GetMaxHeight();
// BACKGROUND
background.image = Image("BACKGROUND.png");
background.image = ScaleImage(background.image, Limit(screen.width, screen.height, 100));
background.width = background.image.GetWidth();
background.height = background.image.GetHeight();
background.x = x0 + screen.width / 2 - background.width / 2;
background.y = y0 + screen.height / 2 - background.height / 2;
//background.x = x0;
//background.y = y0;
background.sprite = SpriteNew();
background.sprite.SetImage(background.image);
background.sprite.SetOpacity(1);
2023-11-24 21:30:49 +05:00
background.sprite.SetPosition(background.x, background.y, 0);
2023-04-17 11:56:17 +05:00
2023-07-01 14:28:09 +05:00
// SIDE BACKGROUND
2023-11-24 21:30:49 +05:00
side_panel.background_src = "BACKGROUND.png";
side_panel.foreground_src = "SIDE_BACKGROUND2.png";
2023-07-01 14:28:09 +05:00
side_panel.x = x0;
side_panel.y = y0;
2023-11-24 21:30:49 +05:00
side_panel.z = 1;
side_panel.width = Percent(33.33, screen.width);
side_panel.height = Percent(100, screen.height);
2023-05-03 20:58:31 +05:00
2023-11-24 21:30:49 +05:00
blur = Blur(side_panel.background_src, side_panel.foreground_src, side_panel.x, side_panel.y, side_panel.z, side_panel.width, side_panel.height, screen.width, screen.height);
2023-07-01 14:28:09 +05:00
// MESSAGES BOX
messages_box.image = Image("MESSAGES_BOX.png");
messages_box.image = messages_box.image.Scale(Percent(80, side_panel.width), Percent(40, side_panel.height));
messages_box.width = messages_box.image.GetWidth();
messages_box.height = messages_box.image.GetHeight();
messages_box.x = Percent(50, side_panel.width) - messages_box.width / 2;
messages_box.y = Percent(45, side_panel.height) - messages_box.height;
messages_box.sprite = Sprite(messages_box.image);
messages_box.sprite.SetOpacity(1);
2023-11-24 21:30:49 +05:00
messages_box.sprite.SetPosition(messages_box.x, messages_box.y, 12);
2023-05-03 20:58:31 +05:00
// Sise Logo
side_logo.image = Image("Melawy_Linux_640x320.png");
side_logo.image = ScaleImage(side_logo.image, Limit(screen.width, screen.height, 20));
side_logo.width = side_logo.image.GetWidth();
side_logo.height = side_logo.image.GetHeight();
2023-07-01 14:28:09 +05:00
side_logo.x = (side_panel.width - side_logo.width) / 2;
side_logo.y = side_panel.height - side_panel.height * 0.25;
2023-05-03 20:58:31 +05:00
side_logo.sprite = Sprite(side_logo.image);
side_logo.sprite.SetOpacity(1);
2023-11-24 21:30:49 +05:00
side_logo.sprite.SetPosition(side_logo.x, side_logo.y, 12);
2023-04-17 11:56:17 +05:00
// **************************************** //
2023-10-25 16:38:37 +05:00
project_link.image = Image.Text("https://Melawy.ru", 0.5, 0.5, 0.5, 1, link_font);
2023-05-03 20:58:31 +05:00
project_link.width = project_link.image.GetWidth();
project_link.height = project_link.image.GetHeight();
project_link.sprite = Sprite(project_link.image);
2023-07-01 14:28:09 +05:00
project_link.x = (side_panel.width - project_link.width) / 2;
2023-05-03 20:58:31 +05:00
project_link.y = side_logo.y + side_logo.height;
project_link.sprite.SetOpacity(1);
2023-11-24 21:30:49 +05:00
project_link.sprite.SetPosition(project_link.x, project_link.y, 12);
2023-04-17 11:56:17 +05:00
// **************************************** //
// LOGO
logo.image = Image("MAIN_LOGO.png");
logo.image = FitIntoDimensions(logo.image, Limit(screen.width, screen.height, 35));
logo.sprite = Sprite(logo.image);
logo.x = screen.width / 2 - logo.image.GetWidth() / 2; // позиция логотипа X
logo.y = Percent(10, screen.height); // позиция логотипа Y
logo.sprite.SetOpacity(1);
2023-11-24 21:30:49 +05:00
logo.sprite.SetPosition(logo.x, logo.y, 12);
2023-04-17 11:56:17 +05:00
2023-05-08 17:37:03 +05:00
// PROGRESS FORM
progress_form.image = Image("PROGRESS_FORM.png");
2023-07-01 14:28:09 +05:00
progress_form.image = progress_form.image.Scale(Percent(80, side_panel.width), Percent(10, side_panel.height));
2023-04-17 11:56:17 +05:00
2023-05-08 17:37:03 +05:00
progress_form.width = progress_form.image.GetWidth();
progress_form.height = progress_form.image.GetHeight();
2023-04-17 11:56:17 +05:00
2023-07-01 14:28:09 +05:00
progress_form.x = Percent(50, side_panel.width) - progress_form.width / 2;
progress_form.y = Percent(75, side_panel.height) - progress_form.height;
2023-04-17 11:56:17 +05:00
2023-05-08 17:37:03 +05:00
progress_form.sprite = Sprite(progress_form.image);
2023-05-12 18:40:55 +05:00
progress_form.sprite.SetOpacity(1);
2023-11-24 21:30:49 +05:00
progress_form.sprite.SetPosition(progress_form.x, progress_form.y, 12);
2023-04-17 11:56:17 +05:00
// SPINNER
spinner.image = Image("SPINNER.png");
spinner.image = spinner.image.Scale(Percent(1, screen.width), Percent(1, screen.width));
spinner.width = spinner.image.GetWidth();
spinner.height = spinner.image.GetHeight();
2023-06-19 21:53:07 +05:00
spinner.x = progress_form.x + progress_form.width - Percent(10, progress_form.width);
spinner.y = progress_form.y + Percent(10, progress_form.height);
2023-04-17 11:56:17 +05:00
spinner.sprite = Sprite(spinner.image);
2023-11-24 21:30:49 +05:00
spinner.sprite.SetPosition(spinner.x, spinner.y, 13); // позиция за или перед
2023-04-17 11:56:17 +05:00
// PROGRESS TEXT
2023-11-22 14:24:25 +05:00
progress_text.image = Image.Text(progress_t + "%", 0.5, 0.5, 0.5, 1, progress_font);
2023-04-17 11:56:17 +05:00
progress_text.width = progress_text.image.GetWidth();
progress_text.height = progress_text.image.GetHeight();
2023-06-19 21:53:07 +05:00
progress_text.x = progress_form.x + Percent(5, progress_form.width); // позиция % по X
progress_text.y = progress_form.y + Percent(10, progress_form.height); // позиция % по Y
2023-04-17 11:56:17 +05:00
progress_text.sprite = SpriteNew();
2023-11-24 21:30:49 +05:00
progress_text.sprite.SetPosition(progress_text.x, progress_text.y, 13);
2023-04-17 11:56:17 +05:00
// PROGRESS BOX
progress_box.image = Image("PROGRESS_BOX.png");
2023-05-08 17:37:03 +05:00
progress_box.image = progress_box.image.Scale(Percent(90, progress_form.width), Percent(15, progress_form.height));
2023-04-17 11:56:17 +05:00
progress_box.width = progress_box.image.GetWidth();
progress_box.height = progress_box.image.GetHeight();
2023-05-08 17:37:03 +05:00
progress_box.x = progress_form.x + (progress_form.width - progress_box.width) / 2;
progress_box.y = progress_form.y + (progress_form.height - progress_box.height) / 2;
2023-04-17 11:56:17 +05:00
progress_box.sprite = Sprite(progress_box.image);
2023-11-24 21:30:49 +05:00
progress_box.sprite.SetPosition(progress_box.x, progress_box.y, 13);
2023-04-17 11:56:17 +05:00
// PROGRESS BAR
progress_bar.original_image = Image("PROGRESS_BAR.png");
2023-05-08 17:37:03 +05:00
progress_bar.original_image = progress_bar.original_image.Scale(Percent(90, progress_form.width), Percent(15, progress_form.height));
2023-04-17 11:56:17 +05:00
progress_bar.width = progress_bar.original_image.GetWidth();
progress_bar.height = progress_bar.original_image.GetHeight();
2023-05-08 17:37:03 +05:00
progress_bar.x = progress_form.x + (progress_form.width - progress_bar.original_image.GetWidth()) / 2;
progress_bar.y = progress_form.y + (progress_form.height - progress_bar.original_image.GetHeight()) / 2;
2023-04-17 11:56:17 +05:00
progress_bar.sprite = Sprite();
2023-11-24 21:30:49 +05:00
progress_bar.sprite.SetPosition(progress_bar.x, progress_bar.y, 14);
2023-04-17 11:56:17 +05:00
// PROGRESS FADE
progress_fade.image = Image("PROGRESS_FADE.png");
2023-05-08 17:37:03 +05:00
progress_fade.image = progress_fade.image.Scale(Percent(10, progress_form.width), Percent(15, progress_form.height));
2023-04-17 11:56:17 +05:00
progress_fade.width = progress_fade.image.GetWidth();
progress_fade.height = progress_fade.image.GetHeight();
progress_fade.sprite = Sprite(progress_fade.image);
fade_dir = 0; // 0 = right, 1 = left
counter = 0;
max_counter = progress_box.width - progress_fade.width;
function 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);
f = Math.Int(progress_bar.image.GetWidth() /progress_bar.original_image.GetWidth() * 100);
2023-11-22 14:24:25 +05:00
progress_t.image = Image.Text(f + "%", 0.5, 0.5, 0.5, 1, progress_font);
2023-04-17 11:56:17 +05:00
progress_text.sprite.SetImage(progress_t.image);
}
}
Plymouth.SetBootProgressFunction(progress_callback);
2023-07-01 14:28:09 +05:00
2023-04-17 11:56:17 +05:00
// DIALOG
status = "normal";
//count = 0;
2023-11-24 21:30:49 +05:00
2023-04-17 11:56:17 +05:00
function dialog_setup() {
2023-05-08 17:37:03 +05:00
local.box_form;
2023-04-17 11:56:17 +05:00
local.lock;
local.entry;
2023-05-16 18:47:46 +05:00
local.hint;
local.bullet_i;
2023-04-17 11:56:17 +05:00
2023-05-08 17:37:03 +05:00
box_form.image = Image("BOX.png");
2023-11-24 21:30:49 +05:00
box_form.image = box_form.image.Scale(Percent(80, side_panel.width), Percent(18, side_panel.height));
2023-04-17 11:56:17 +05:00
2023-05-08 17:37:03 +05:00
box_form.width = box_form.image.GetWidth();
box_form.height = box_form.image.GetHeight();
2023-04-17 11:56:17 +05:00
2023-05-08 17:37:03 +05:00
box_form.x = progress_form.x;
2023-07-01 14:28:09 +05:00
box_form.y = progress_form.y - box_form.height - Percent(1, side_panel.height);
2023-05-08 17:37:03 +05:00
box_form.z = 10000;
2023-04-17 11:56:17 +05:00
2023-05-08 17:37:03 +05:00
box_form.sprite = Sprite(box_form.image);
2023-05-12 18:40:55 +05:00
box_form.sprite.SetOpacity(1);
2023-11-24 21:30:49 +05:00
box_form.sprite.SetPosition(box_form.x, box_form.y, box_form.z);
2023-04-17 11:56:17 +05:00
entry.image = Image("ENTRY.png");
2023-11-24 21:30:49 +05:00
entry.image = entry.image.Scale(Percent(90, box_form.width), Percent(20, box_form.height));
2023-04-17 11:56:17 +05:00
entry.width = entry.image.GetWidth();
entry.height = entry.image.GetHeight();
2023-05-08 17:37:03 +05:00
entry.x = box_form.x + box_form.width/2 - entry.width/2;
2023-11-24 21:30:49 +05:00
entry.y = box_form.y + (box_form.height/3 * 2) - entry.height/2;
2023-05-08 17:37:03 +05:00
entry.z = box_form.z + 1;
2023-04-17 11:56:17 +05:00
entry.sprite = Sprite(entry.image);
entry.sprite.SetPosition(entry.x, entry.y, entry.z);
lock.image = Image("LOCK.png");
lock.image = lock.image.Scale(Percent(95, entry.height), Percent(95, entry.height));
lock.width = lock.image.GetWidth();
lock.height = lock.image.GetHeight();
lock.x = entry.x + entry.width - lock.width - (entry.height - lock.height);
lock.y = entry.y + entry.height/2 - lock.height/2;
2023-05-08 17:37:03 +05:00
lock.z = box_form.z + 2;
2023-04-17 11:56:17 +05:00
lock.sprite = Sprite(lock.image);
lock.sprite.SetPosition(lock.x, lock.y, lock.z);
2023-05-16 18:47:46 +05:00
hint.sprite = SpriteNew();
2023-06-19 21:53:07 +05:00
hint.sprite.SetPosition(entry.x, box_form.y + Percent(5, box_form.height), box_form.z + 1);
2023-05-16 18:47:46 +05:00
bullet_i.image = Image("BULLET.png");
bullet_i.image = bullet_i.image.Scale(Percent(50, entry.height), Percent(50, entry.height));
bullet_i.width = bullet_i.image.GetWidth();
bullet_i.height = bullet_i.image.GetHeight();
2023-04-17 11:56:17 +05:00
2023-05-08 17:37:03 +05:00
global.dialog.box_form = box_form;
2023-04-17 11:56:17 +05:00
global.dialog.lock = lock;
global.dialog.entry = entry;
2023-05-16 18:47:46 +05:00
global.dialog.hint = hint;
global.dialog.bullet_i = bullet_i;
2023-04-17 11:56:17 +05:00
dialog_opacity(1);
}
2023-11-24 21:30:49 +05:00
2023-04-17 11:56:17 +05:00
function dialog_opacity(opacity) {
if (opacity == 0) {
2023-05-08 17:37:03 +05:00
dialog.box_form.sprite.SetOpacity(opacity);
2023-04-17 11:56:17 +05:00
dialog.lock.sprite.SetOpacity(opacity);
dialog.entry.sprite.SetOpacity(opacity);
}
else {
dialog.lock.sprite.SetOpacity(opacity);
dialog.entry.sprite.SetOpacity(opacity);
}
2023-05-16 18:47:46 +05:00
dialog.hint.sprite.SetOpacity(opacity);
2023-04-17 11:56:17 +05:00
2023-10-14 23:36:50 +05:00
for (index = 0; dialog.bullet[index]; index++) {
2023-04-17 11:56:17 +05:00
dialog.bullet[index].sprite.SetOpacity(opacity);
}
}
2023-05-16 18:47:46 +05:00
2023-04-17 11:56:17 +05:00
function display_normal_callback() {
global.status = "normal";
if (global.dialog)
dialog_opacity(0);
}
2023-05-16 18:47:46 +05:00
Plymouth.SetDisplayNormalFunction(display_normal_callback);
function display_password_callback(prompt_text, bullets) {
2023-04-17 11:56:17 +05:00
global.status = "password";
2023-11-24 21:30:49 +05:00
if(!global.dialog)
2023-04-17 11:56:17 +05:00
dialog_setup();
else
dialog_opacity(1);
2023-11-24 21:30:49 +05:00
padding_top_bottom = Percent(10, dialog.box_form.height); // отступы сверху и снизу
padding_left_right = Percent(5, dialog.box_form.width); // отступы слева и справа
LINE_WIDTH = 100;
for(index = LINE_WIDTH; index > 0; index--) {
if((LINE_WIDTH * common_symbol.width) > (dialog.box_form.width - (padding_left_right * 2))) {
LINE_WIDTH = LINE_WIDTH - 1;
}
else {
break;
}
}
str_len = StringLength(prompt_text);
for (i = 1; LINE_WIDTH * i <= str_len; i++) {
line_count = i;
}
if (str_len % line_count > 0) {
line_count = line_count + 1;
}
i = 1;
start = 0;
end = LINE_WIDTH;
text = "";
for(i = 1; i <= line_count; i++) {
text += prompt_text.SubString(start, end);
text += "\n";
start = end;
if (LINE_WIDTH * i < str_len) {
end = end + LINE_WIDTH;
}
else {
end = str_len - 1;
}
}
prompt_text = text;
2023-07-01 14:28:09 +05:00
dialog.hint.image = Image.Text(prompt_text, 0.5, 0.5, 0.5, 1, common_font);
2023-05-16 18:47:46 +05:00
dialog.hint.sprite.SetImage(dialog.hint.image);
2023-04-17 11:56:17 +05:00
2023-10-14 23:36:50 +05:00
for (index = 0; dialog.bullet[index] || index < bullets; index++) {
2023-04-17 11:56:17 +05:00
if (!dialog.bullet[index]) {
2023-05-16 18:47:46 +05:00
dialog.bullet[index].sprite = Sprite(dialog.bullet_i.image);
dialog.bullet[index].x = dialog.entry.x + index * dialog.bullet_i.width / 0.9 - dialog.entry.height * -0.2; // отступ точки от точки и от поля(modified)
dialog.bullet[index].y = dialog.entry.y + (dialog.entry.height - dialog.bullet_i.height) / 2;
2023-04-17 11:56:17 +05:00
dialog.bullet[index].z = dialog.entry.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.SetDisplayPasswordFunction(display_password_callback);
2023-05-16 18:47:46 +05:00
2023-04-17 11:56:17 +05:00
time = 1;
function refreshHandler() {
if (global.status == "normal" && Plymouth.GetMode() == "boot") {
progress_fade.sprite.SetOpacity (0); // полностью прозрачный
progress_bar.sprite.SetOpacity (1);
2023-05-16 18:47:46 +05:00
text.image = Image.Text(starting_text, 0.5, 0.5, 0.5, 1, common_font);
2023-04-17 11:56:17 +05:00
text.sprite = Sprite(text.image);
text.x = progress_box.x;
text.y = progress_box.y - progress_text.image.GetHeight() * 2;
2023-11-24 21:30:49 +05:00
text.sprite.SetPosition(text.x, text.y, 13);
2023-04-17 11:56:17 +05:00
}
else {
progress_fade.sprite.SetOpacity (1);
progress_bar.sprite.SetOpacity (0);
2023-05-16 18:47:46 +05:00
text_end.image = Image.Text(bye_text, 0.5, 0.5, 0.5, 1, common_font);
2023-04-17 11:56:17 +05:00
text_end.sprite = Sprite(text_end.image);
text_end.x = progress_box.x;
text_end.y = progress_box.y - progress_text.image.GetHeight() * 2;
2023-11-24 21:30:49 +05:00
text_end.sprite.SetPosition(text_end.x, text_end.y, 13);
2023-04-17 11:56:17 +05:00
}
progress_fade.x = progress_bar.x;
progress_fade.y = progress_bar.y;
2023-11-24 21:30:49 +05:00
progress_fade.sprite.SetPosition(counter + progress_fade.x, progress_fade.y, 14);
2023-04-17 11:56:17 +05:00
if (fade_dir == 0) {
counter++;
if (counter >= max_counter) {
fade_dir = 1;
}
}
else {
counter--;
if (counter <= 0) {
fade_dir = 0;
}
}
/* if fsck is running or the password is prompted, hide the spinner */
if (fsck_running == 1 || passw_dialog_input_sprite.GetOpacity() == 1) {
spinner.sprite.SetOpacity(0);
}
else {
spinner.sprite.SetOpacity(1);
time++;
theta = time / (Math.Pi * 2);
spinner.sprite.SetImage(spinner.image.Rotate(theta));
}
if ((fsck_running == 1) && (fsck_done_fading == 0)) {
fsck_progress_meter_sprite.SetOpacity(fsck_fade_in_counter);
fsck_progress_fade_sprite.SetOpacity(fsck_fade_in_counter);
if (fsck_fade_in_counter < 1) {
fsck_fade_in_counter+= 0.025;
}
else {
fsck_done_fading = 1;
}
}
}
Plymouth.SetRefreshFunction(refreshHandler);
2023-05-16 18:47:46 +05:00
2023-07-01 14:28:09 +05:00
message_status.sprite = SpriteNew();
2023-04-17 11:56:17 +05:00
2023-05-16 18:47:46 +05:00
function message_callback(prompt_text) {
2023-07-01 14:28:09 +05:00
message_status.image = Image.Text(prompt_text, 0.5, 0.5, 0.5, 1, common_font);
message_status.sprite.SetImage(message_status.image);
message_status.height = message_status.image.GetHeight();
message_status.x = messages_box.x + Percent(5, messages_box.width);
message_status.y = messages_box.y + messages_box.height - Percent(7, messages_box.height);
message_status.sprite.SetOpacity(1);
2023-11-24 21:30:49 +05:00
message_status.sprite.SetPosition(message_status.x, message_status.y, 13);
2023-04-17 11:56:17 +05:00
}
Plymouth.SetMessageFunction(message_callback);
2023-11-24 21:30:49 +05:00
2023-10-14 23:36:50 +05:00
// высота messages_box = screen.height - 40% (1080 * 0,4 = 432)
// высота всех сообщений = NUM_SCROLL_LINES (20) * (LINE_HEIGHT) 17 = 340
// 10 процентов сверху от начала messages_box.x = 432 - 10% (432 * 0,1) = 432 - 43 = 389
// конечная точка, где допустимо показывать сообщения = 389 - 43 (10% от высоты messages_box.x) = 346
// если высота всех сообщений выше, чем высота (messages_box.height - 20%), то уменьшать количество строк, пока высота всех сообщений не быдет меньше (messages_box.height - 20%)
2023-07-01 14:28:09 +05:00
2023-11-22 14:24:25 +05:00
// высота символа = common_font = 10pt, предположим что 10px
// предположим, что ширина символа = 60% от высоты символа = 6px
// ширина side_panel = 25% от screen.width = 1080 * 0.25 = 270
// ширина messages_box = 80 % от side_panel = 270 * 0.8 = 216
// ширина всех сообщений = LINE_WIDTH * ширину символа = 40 * 6 = 240
// необходимо снижать количество LINE_WIDTH пока реальная ширина сообщения не будет меньше или равно ширине messages_box
padding_top_bottom = Percent(10, messages_box.height); // отступы сверху и снизу
padding_left_right = Percent(5, messages_box.width); // отступы слева и справа
2023-10-15 02:30:06 +05:00
2023-10-15 20:46:58 +05:00
message_sprite_.x = messages_box.x + (padding_left_right); // позиция % по X (слева направо)
message_sprite_.y = messages_box.y + (padding_top_bottom); // позиция % по Y (сверху вниз)
2023-07-01 14:28:09 +05:00
// LOG //
2023-11-22 20:11:38 +05:00
NUM_SCROLL_LINES=100; //количество строк лога
LINE_WIDTH=100; //ширина строк лога
2023-11-22 14:24:25 +05:00
LINE_HEIGHT = common_symbol.height * 1.5; // межстрочный интервал x1,5
2023-10-14 23:36:50 +05:00
for (index = NUM_SCROLL_LINES; index > 0; index--) {
2023-10-15 02:30:06 +05:00
if ((NUM_SCROLL_LINES * LINE_HEIGHT) > (messages_box.height - (padding_top_bottom * 2))) {
2023-10-14 23:36:50 +05:00
NUM_SCROLL_LINES=NUM_SCROLL_LINES-1;
}
else {
break;
}
}
2023-07-01 14:28:09 +05:00
2023-11-22 14:24:25 +05:00
for (index = LINE_WIDTH; index > 0; index--) {
if ((LINE_WIDTH * common_symbol.width) > (messages_box.width - (padding_left_right * 2))) {
LINE_WIDTH=LINE_WIDTH-1;
}
else {
break;
}
}
2023-04-17 11:56:17 +05:00
// Initialising text images and their positions
// 20 is the height(including line spacing) of each line
2023-10-14 23:36:50 +05:00
for (i=0; i < NUM_SCROLL_LINES; i++) {
2023-05-16 18:47:46 +05:00
lines[i]= Image.Text("", 0.5, 0.5, 0.5, 1, common_font); //цвет строк
2023-04-17 11:56:17 +05:00
message_sprite[i] = SpriteNew();
2023-11-24 21:30:49 +05:00
message_sprite[i].SetPosition(message_sprite_.x, message_sprite_.y + (i * LINE_HEIGHT), 13);
2023-04-17 11:56:17 +05:00
} //высота строк //отступ строк
2023-11-24 21:30:49 +05:00
2023-04-17 11:56:17 +05:00
function StringLength(string) {
index = 0;
str = String(string);
while(str.CharAt(index)) index++;
return index;
}
2023-11-24 21:30:49 +05:00
2023-04-17 11:56:17 +05:00
function scroll_message_callback(text) {
// Truncate the message if too long
if (StringLength(text) > LINE_WIDTH) {
text = text.SubString(0, LINE_WIDTH - 3);
text += "...";
}
// Shift message one up
2023-10-14 23:36:50 +05:00
for (i = 0; i < NUM_SCROLL_LINES - 1; i++) {
2023-04-17 11:56:17 +05:00
lines[i] = lines[i+1];
}
// Create the image for the latest message
2023-05-16 18:47:46 +05:00
lines[i] = Image.Text(text, 0.5, 0.5, 0.5, 1, common_font);
2023-04-17 11:56:17 +05:00
// Re-positioning the text images
2023-10-14 23:36:50 +05:00
for (i = 0; i < NUM_SCROLL_LINES; i++) {
2023-04-17 11:56:17 +05:00
message_sprite[i].SetImage(lines[i]);
}
}
Plymouth.SetUpdateStatusFunction(scroll_message_callback);
2023-07-01 14:28:09 +05:00
2023-04-17 11:56:17 +05:00
// QUIT
function quit_callback() {
progress_fade.sprite.SetOpacity (1);
progress_bar.sprite.SetOpacity (0);
if (Plymouth.GetMode() == "shutdown") {
logo.sprite.SetOpacity(0);
}
}
Plymouth.SetQuitFunction(quit_callback);