summaryrefslogtreecommitdiffstats
path: root/common/plymouth/mga.script
blob: 32a4374bef3624a70991ede1086dee166b0d8477 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
Window.GetMaxWidth = fun (){
    i = 0;
    width = 800; # minimum
    while (Window.GetWidth(i)){
	width = Math.Max(width, Window.GetWidth(i));
	i++;
    }
    return width;
};

Window.GetMaxHeight = fun (){
    i = 0;
    height = 600; # minium
    while (Window.GetHeight(i)){
	height = Math.Max(height, Window.GetHeight(i));
	i++;
    }
    return height;
};


if (Plymouth.GetMode() == "suspend" || Plymouth.GetMode() == "resume") {
    background.original_image = ImageNew("suspend.png");
    Window.SetBackgroundTopColor(0.000, 0.000, 0.000);
    Window.SetBackgroundBottomColor(0.000, 0.000, 0.000);
}
else {
    background.original_image = ImageNew("background.png");

    Window.SetBackgroundTopColor(0.000, 0.000, 0.000);
    Window.SetBackgroundBottomColor(0.000, 0.000, 0.000);
    
    for (i = 0; i < 5; i++) {
	anim_images[i] = Image("progress-" + i + ".png");
    }

    logo_image = Image("logo.png");
    logo_sprite = Sprite(logo_image);
    offsetx = Window.GetMaxWidth() / 4 - 30 ;
    offsety = Window.GetMaxHeight() / 2 - logo_image.GetHeight() / 2 ;
    logo_sprite.SetX( offsetx );
    logo_sprite.SetY( offsety );
    
    anim_sprite = Sprite();
    anim_sprite.SetX( offsetx );
    anim_sprite.SetY( offsety );

}

# for now we just take the image as it is - no up or down scaling
# scale_factor = 1;

background.image = background.original_image.Scale(Window.GetMaxWidth() , Window.GetMaxHeight());

background.sprite = SpriteNew();
background.sprite.SetImage(background.image);

background.sprite.SetX(Window.GetMaxWidth()  / 2 - background.image.GetWidth()  / 2); # Place in the centre 
background.sprite.SetY(Window.GetMaxHeight() / 2 - background.image.GetHeight() / 2);
background.sprite.SetZ(-10000); # Place right at the back

sprite_prompt = SpriteNew();

progress = 0;
fun refresh_callback ()
{
    if (status == "normal") {
	progress++;
	anim_sprite.SetImage(anim_images[Math.Int(progress / 33) % 5]);
    }
    else
        anim.sprite.SetOpacity(0);
}
 
if (Plymouth.GetMode() != "suspend" && Plymouth.GetMode() != "resume") {
    Plymouth.SetRefreshFunction (refresh_callback);
}

#----------------------------------------- Dialog --------------------------------

status = "normal";

fun dialog_setup()
{
    local.box;
    local.lock;
    local.entry;
    local.prompt_sprite;
    
    box.image = ImageNew("box.png");
    lock.image = ImageNew("lock.png");
    entry.image = ImageNew("entry.png");
    
    box.sprite = SpriteNew();
    box.sprite.SetImage(box.image);
    box.x = Window.GetX() + Window.GetWidth()  / 2 - box.image.GetWidth()/2;
    box.y = Window.GetY() + Window.GetHeight() - box.image.GetHeight() - 20 ;
    box.z = 10000;
    box.sprite.SetPosition(box.x, box.y, box.z);
    
    lock.sprite = SpriteNew();
    lock.sprite.SetImage(lock.image);
    lock.x = box.x + box.image.GetWidth()/2 - (lock.image.GetWidth() + entry.image.GetWidth()) / 2;
    lock.y = box.y + box.image.GetHeight() - lock.image.GetHeight() - 20 ;
    lock.z = box.z + 1;
    lock.sprite.SetPosition(lock.x, lock.y, lock.z);
    
    entry.sprite = SpriteNew();
    entry.sprite.SetImage(entry.image);
    entry.x = lock.x + lock.image.GetWidth();
    entry.y = box.y + box.image.GetHeight() - entry.image.GetHeight() - 20;
    entry.z = box.z + 1;
    entry.sprite.SetPosition(entry.x, entry.y, entry.z);

    prompt_sprite = SpriteNew();
    prompt_sprite.SetPosition(box.x, box.y - 20, box.z);
    
    global.dialog.box = box;
    global.dialog.lock = lock;
    global.dialog.entry = entry;
    global.dialog.bullet_image = ImageNew("bullet.png");
    global.dialog.prompt_sprite = prompt_sprite;
    dialog_opacity (1);
}

fun dialog_opacity(opacity)
{
    dialog.box.sprite.SetOpacity(opacity);
    dialog.lock.sprite.SetOpacity(opacity);
    dialog.entry.sprite.SetOpacity(opacity);
    dialog.prompt_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);
    
    anim.sprite.SetOpacity(0);
	
#   dialog.prompt_sprite.SetImage(Image.Text(prompt, 0.71764706, 0.90588235 , 0.58431373));
    dialog.prompt_sprite.SetImage(Image.Text(prompt, 1, 1, 1));
    for (index = 0; dialog.bullet[index] || index < bullets; index++)
    { 
        if (!dialog.bullet[index])
          {
            dialog.bullet[index].sprite = SpriteNew();
            dialog.bullet[index].sprite.SetImage(dialog.bullet_image);
            dialog.bullet[index].x = dialog.entry.x + index * dialog.bullet_image.GetWidth();
            dialog.bullet[index].y = dialog.entry.y + dialog.entry.image.GetHeight() / 2 - dialog.bullet_image.GetHeight() / 2;
            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);
    }
}

fun display_message_callback (prompt)
{
  
    #prompt = Image.Text(prompt, 0.71764706, 0.90588235, 0.58431373);
    # Change the text to white for better readability
    prompt = Image.Text(prompt, 1, 1, 1);
    sprite_prompt.SetImage(prompt);
    #sprite_prompt.SetPosition(Window.GetX() + (Window.GetWidth() - prompt.GetWidth()) / 2, Window.GetY() + Window.GetHeight() * 0.93, 2);
    sprite_prompt.SetPosition(Window.GetX() + (Window.GetWidth() - prompt.GetWidth()) / 2, Window.GetY() + 20, 2);
  }

/* instantiate dialog at startup, to ensure all icons are loaded in memory before initrd is unmounted, in case /usr isn't mounted yet */
dialog_setup();
dialog_opacity(0);
Plymouth.SetDisplayNormalFunction(display_normal_callback);
Plymouth.SetDisplayPasswordFunction(display_password_callback);
Plymouth.SetMessageFunction(display_message_callback);

#----------------------------------------- Progress Bar --------------------------------

if (Plymouth.GetMode() == "suspend" || Plymouth.GetMode() == "resume") {
    progress_box.original_image = ImageNew("progress_box_background.png");
    progress_box.image = progress_box.original_image.Scale(Window.GetMaxWidth() * 0.44, progress_box.original_image.GetHeight());
    progress_box.edge = ImageNew("progress_box_edge.png");
    progress_box.left_edge_sprite = SpriteNew();
    progress_box.right_edge_sprite = SpriteNew();
    progress_box.sprite = SpriteNew();
    progress_box.sprite.SetImage(progress_box.image);
    progress_box.left_edge_sprite.SetImage(progress_box.edge);
    progress_box.right_edge_sprite.SetImage(progress_box.edge);
    
    progress_box.x = Window.GetX() + Window.GetWidth()  / 2 -    progress_box.image.GetWidth()  / 2;
    progress_box.y = Window.GetY() + Window.GetHeight() * 0.86 - progress_box.image.GetHeight() / 2;
    
    progress_box.sprite.SetPosition(progress_box.x, progress_box.y, 0);
    progress_box.left_edge_sprite.SetPosition(progress_box.x-1, progress_box.y, 0);
    progress_box.right_edge_sprite.SetPosition(progress_box.x + progress_box.image.GetWidth() , progress_box.y, 0);
    
    progress_bar.original_image = ImageNew("progress_bar.png");
    progress_bar.sprite = SpriteNew();
    
    progress_bar.sprite.SetPosition(progress_box.x + 1, progress_box.y + 2, 1);
}

fun progress_callback (duration, progress)
{
    if (Plymouth.GetMode() == "suspend" || Plymouth.GetMode() == "resume") {
	new_width = (progress_box.image.GetWidth() - 2) * progress;
	if (progress_bar.image.GetWidth() != Math.Int (new_width))
	{
            progress_bar.image = progress_bar.original_image.Scale(new_width, progress_bar.original_image.GetHeight());
            progress_bar.sprite.SetImage(progress_bar.image);
	}
    }
    else {
      # Be super careful with opacity. All values are modded by 1,
      # so if we go above 1 we will begin fading in again.
    }
}

Plymouth.SetBootProgressFunction(progress_callback);
    
#----------------------------------------- Quit --------------------------------

fun quit_callback ()
{
    anim.sprite.SetOpacity (0);
}

Plymouth.SetQuitFunction(quit_callback);