-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathos-update.c
132 lines (100 loc) · 2.84 KB
/
os-update.c
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
/*
* Copyright (c) 2014 - 2023 Jolla Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <stdio.h>
#include <assert.h>
#include <stdbool.h>
#include "os-update.h"
#include "minui/minui.h"
#define MARGIN 10
const char logo_filename[] = "test";
gr_surface logo;
/* ------------------------------------------------------------------------ */
int
loadLogo(const char *filename, const char *dir)
{
int ret;
freeLogo();
if ((ret = res_create_display_surface(filename, dir, &logo)) < 0) {
printf("Error while trying to load %s, retval: %i.\n",
filename, ret);
return -1;
}
return 0;
}
/* ------------------------------------------------------------------------ */
int
showLogo(void)
{
int fbw = gr_fb_width();
int fbh = gr_fb_height();
/* draw logo to middle of the screen */
if (logo) {
int logow = gr_get_width(logo);
int logoh = gr_get_height(logo);
int dx = (fbw - logow) / 2;
int dy = (fbh - logoh) / 2;
gr_blit(logo, 0, 0, logow, logoh, dx, dy);
} else {
printf("No logo loaded\n");
return -1;
}
return 0;
}
/* ------------------------------------------------------------------------ */
void
osUpdateScreenShowProgress(int percentage)
{
int fbw, fbh, splitpoint, x1, x2, y1, y2;
fbw = gr_fb_width();
fbh = gr_fb_height();
splitpoint = (fbw - 2 * MARGIN) * percentage / 100;
assert(splitpoint >= 0);
assert(splitpoint <= fbw);
x1 = MARGIN;
y1 = fbh / 2 + MARGIN;
x2 = MARGIN + splitpoint;
y2 = fbh / 2 + 20;
/* white color for the beginning of the progressbar */
gr_color(255, 255, 255, 255);
gr_fill(x1, y1, x2, y2);
/* Grey color for the end part of the progressbar */
gr_color(84, 84, 84, 255);
x1 = MARGIN + splitpoint;
x2 = fbw - MARGIN;
gr_fill(x1, y1, x2, y2);
/* draw logo on the top of the progress bar if it is loaded */
if (logo) {
int logow, logoh, dx, dy;
logow = gr_get_width(logo);
logoh = gr_get_height(logo);
dx = (fbw - logow) / 2;
dy = (fbh / 2 - logoh - 2 * MARGIN);
#ifdef DEBUG
printf("width: %i, height: %i, row_bytes: %i, pixel_bytes: "
"%i\n",
logo->width, logo->height, logo->row_bytes,
logo->pixel_bytes);
#endif /* DEBUG */
gr_blit(logo, 0, 0, logow, logoh, dx, dy);
}
}
/* ------------------------------------------------------------------------ */
void
freeLogo(void)
{
if (logo)
res_free_surface(logo), logo = 0;
}