forked from sailfishos/yamui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathos-update.c
155 lines (116 loc) · 3.11 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*
* Copyright (C) 2014 The Android Open Source Project
* Copyright (c) 2023, Roberto A. Foglietta <[email protected]>
*
* 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";
extern long long int v_shift;
static gr_surface logo;
/* ------------------------------------------------------------------------ */
int
osUpdateScreenInit(bool blank)
{
if (gr_init(blank)) {
printf("Failed gr_init!\n");
return -1;
}
if(blank) {
/* Clear the screen */
gr_color(0, 0, 0, 255);
gr_clear();
}
return 0;
}
/* ------------------------------------------------------------------------ */
int
loadLogo(const char *filename, const char *dir)
{
int ret = 0;
if (logo)
res_free_surface(logo);
if ((ret = res_create_display_surface(filename, dir, &logo)) < 0)
fprintf(stderr, "ERROR: %s(%s), returned: %d.\n",
__func__, filename, ret);
return ret;
}
/* ------------------------------------------------------------------------ */
int
gr_logo(void)
{
if (!logo) {
printf("No logo loaded\n");
return -1;
}
/* draw logo to middle of the screen */
int fbw = gr_fb_width();
int fbh = gr_fb_height();
int logow = gr_get_width(logo);
int logoh = gr_get_height(logo);
int dx = (fbw - logow) >> 1;
int dy = (fbh - logoh) >> 1;
gr_blit(logo, 0, 0, logow, logoh, dx, dy + v_shift);
return 0;
}
int
showLogo(void)
{
if (!logo) {
printf("No logo loaded\n");
return -1;
}
gr_logo();
gr_flip();
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) gr_logo();
/* And finally draw everything */
gr_flip();
}
/* ------------------------------------------------------------------------ */
void
osUpdateScreenExit(void)
{
if (logo)
res_free_surface(logo);
gr_exit();
}