1 | /*␊ |
2 | * gui.c␊ |
3 | * ␊ |
4 | *␊ |
5 | * Created by Jasmin Fazlic on 18.12.08.␊ |
6 | * Copyright 2008/09 Jasmin Fazlic All rights reserved.␊ |
7 | * Copyright 2008/09 iNDi All rights reserved.␊ |
8 | *␊ |
9 | */␊ |
10 | ␊ |
11 | #include "gui.h"␊ |
12 | #include "term.h"␊ |
13 | #include "appleboot.h"␊ |
14 | #include "vers.h"␊ |
15 | ␊ |
16 | #define IMG_REQUIRED -1␊ |
17 | #define THEME_NAME_DEFAULT␉"Default"␊ |
18 | static const char *theme_name = THEME_NAME_DEFAULT;␊ |
19 | ␊ |
20 | #ifdef CONFIG_EMBED_THEME␊ |
21 | #include "art.h"␊ |
22 | #endif␊ |
23 | ␊ |
24 | #define LOADPNG(img, alt_img) if (loadThemeImage(#img, alt_img) != 0) { return 1; }␊ |
25 | ␊ |
26 | #define VIDEO(x) (bootArgs->Video.v_ ## x)␊ |
27 | ␊ |
28 | #define vram VIDEO(baseAddr)␊ |
29 | ␊ |
30 | #define TAB_PIXELS_WIDTH (font->chars[0]->width * 4) // tab = 4 spaces␊ |
31 | ␊ |
32 | int lasttime = 0; // we need this for animating maybe␊ |
33 | ␊ |
34 | // ====================================================================␊ |
35 | ␊ |
36 | /*␊ |
37 | * ATTENTION: the enum and the following array images[] MUST match !!!␊ |
38 | */␊ |
39 | enum {␊ |
40 | ␉iBackground = 0,␊ |
41 | ␉iLogo,␊ |
42 | ␊ |
43 | ␉iDeviceGeneric,␊ |
44 | ␉iDeviceGeneric_o,␊ |
45 | ␉iDeviceHFS,␊ |
46 | ␉iDeviceHFS_o,␊ |
47 | ␉iDeviceHFS_yos,␊ |
48 | ␉iDeviceHFS_yos_o,␊ |
49 | ␉iDeviceHFS_mav,␊ |
50 | ␉iDeviceHFS_mav_o,␊ |
51 | ␉iDeviceHFS_ML,␊ |
52 | ␉iDeviceHFS_ML_o,␊ |
53 | ␉iDeviceHFS_Lion,␊ |
54 | ␉iDeviceHFS_Lion_o,␊ |
55 | ␉iDeviceHFS_SL,␊ |
56 | ␉iDeviceHFS_SL_o,␊ |
57 | ␉iDeviceHFS_Leo,␊ |
58 | ␉iDeviceHFS_Leo_o,␊ |
59 | ␉iDeviceHFS_Tiger,␊ |
60 | ␉iDeviceHFS_Tiger_o,␊ |
61 | ␊ |
62 | ␉iDeviceHFSRAID,␊ |
63 | ␉iDeviceHFSRAID_o,␊ |
64 | ␉iDeviceHFSRAID_yos,␊ |
65 | ␉iDeviceHFSRAID_yos_o,␊ |
66 | ␉iDeviceHFSRAID_mav,␊ |
67 | ␉iDeviceHFSRAID_mav_o,␊ |
68 | ␉iDeviceHFSRAID_ML,␊ |
69 | ␉iDeviceHFSRAID_ML_o,␊ |
70 | ␉iDeviceHFSRAID_Lion,␊ |
71 | ␉iDeviceHFSRAID_Lion_o,␊ |
72 | ␉iDeviceHFSRAID_SL,␊ |
73 | ␉iDeviceHFSRAID_SL_o,␊ |
74 | ␉iDeviceHFSRAID_Leo,␊ |
75 | ␉iDeviceHFSRAID_Leo_o,␊ |
76 | ␉iDeviceHFSRAID_Tiger,␊ |
77 | ␉iDeviceHFSRAID_Tiger_o,␊ |
78 | ␉iDeviceEXT3,␊ |
79 | ␉iDeviceEXT3_o,␊ |
80 | ␉iDeviceFreeBSD, /* FreeBSD/OpenBSD detection,nawcom's code by valv, Icon credits to blackosx */␊ |
81 | ␉iDeviceFreeBSD_o, /* FreeBSD/OpenBSD detection,nawcom's code by valv, Icon credits to blackosx */␊ |
82 | ␉iDeviceOpenBSD, /* FreeBSD/OpenBSD detection,nawcom's code by valv, Icon credits to blackosx */␊ |
83 | ␉iDeviceOpenBSD_o, /* FreeBSD/OpenBSD detection,nawcom's code by valv, Icon credits to blackosx */␊ |
84 | ␉iDeviceBEFS, /* Haiku detection and Icon credits to scorpius */␊ |
85 | ␉iDeviceBEFS_o, /* Haiku detection and Icon credits to scorpius */␊ |
86 | ␉iDeviceFAT,␊ |
87 | ␉iDeviceFAT_o,␊ |
88 | ␉iDeviceFAT16,␊ |
89 | ␉iDeviceFAT16_o,␊ |
90 | ␉iDeviceFAT32,␊ |
91 | ␉iDeviceFAT32_o,␊ |
92 | ␉iDeviceNTFS,␊ |
93 | ␉iDeviceNTFS_o,␊ |
94 | ␉iDeviceCDROM,␊ |
95 | ␉iDeviceCDROM_o,␊ |
96 | ␊ |
97 | ␉iSelection,␊ |
98 | ␉iDeviceScrollPrev,␊ |
99 | ␉iDeviceScrollNext,␊ |
100 | ␊ |
101 | ␉iMenuBoot,␊ |
102 | ␉iMenuVerbose,␊ |
103 | ␉iMenuIgnoreCaches,␊ |
104 | ␉iMenuSingleUser,␊ |
105 | ␉iMenuMemoryInfo,␊ |
106 | ␉iMenuVideoInfo,␊ |
107 | ␉iMenuHelp,␊ |
108 | ␉iMenuVerboseDisabled,␊ |
109 | ␉iMenuIgnoreCachesDisabled,␊ |
110 | ␉iMenuSingleUserDisabled,␊ |
111 | ␉iMenuSelection,␊ |
112 | ␊ |
113 | ␉iProgressBar,␊ |
114 | ␉iProgressBarBackground,␊ |
115 | ␊ |
116 | ␉iTextScrollPrev,␊ |
117 | ␉iTextScrollNext,␊ |
118 | ␊ |
119 | ␉iFontConsole,␊ |
120 | ␉iFontSmall,␊ |
121 | };␊ |
122 | ␊ |
123 | // ====================================================================␊ |
124 | ␊ |
125 | image_t images[] = {␊ |
126 | ␉{.name = "background", .image = NULL},␊ |
127 | ␉{.name = "logo", .image = NULL},␊ |
128 | ␊ |
129 | ␉{.name = "device_generic", .image = NULL},␊ |
130 | ␉{.name = "device_generic_o", .image = NULL},␊ |
131 | ␉{.name = "device_hfsplus", .image = NULL},␊ |
132 | ␉{.name = "device_hfsplus_o", .image = NULL},␊ |
133 | ␉{.name = "device_hfsplus_yos", .image = NULL},␊ |
134 | ␉{.name = "device_hfsplus_yos_o", .image = NULL},␊ |
135 | ␉{.name = "device_hfsplus_mav", .image = NULL},␊ |
136 | ␉{.name = "device_hfsplus_mav_o", .image = NULL},␊ |
137 | ␉{.name = "device_hfsplus_ml", .image = NULL},␊ |
138 | ␉{.name = "device_hfsplus_ml_o", .image = NULL},␊ |
139 | ␉{.name = "device_hfsplus_lion", .image = NULL},␊ |
140 | ␉{.name = "device_hfsplus_lion_o", .image = NULL},␊ |
141 | ␉{.name = "device_hfsplus_sl", .image = NULL},␊ |
142 | ␉{.name = "device_hfsplus_sl_o", .image = NULL},␊ |
143 | ␉{.name = "device_hfsplus_leo", .image = NULL},␊ |
144 | ␉{.name = "device_hfsplus_leo_o", .image = NULL},␊ |
145 | ␉{.name = "device_hfsplus_tiger", .image = NULL},␊ |
146 | ␉{.name = "device_hfsplus_tiger_o", .image = NULL},␊ |
147 | ␊ |
148 | ␉{.name = "device_hfsraid", .image = NULL},␊ |
149 | ␉{.name = "device_hfsraid_o", .image = NULL},␊ |
150 | ␉{.name = "device_hfsraid_yos", .image = NULL},␊ |
151 | ␉{.name = "device_hfsraid_yos_o", .image = NULL},␊ |
152 | ␉{.name = "device_hfsraid_mav", .image = NULL},␊ |
153 | ␉{.name = "device_hfsraid_mav_o", .image = NULL},␊ |
154 | ␉{.name = "device_hfsraid_ml", .image = NULL},␊ |
155 | ␉{.name = "device_hfsraid_ml_o", .image = NULL},␊ |
156 | ␉{.name = "device_hfsraid_lion", .image = NULL},␊ |
157 | ␉{.name = "device_hfsraid_lion_o", .image = NULL},␊ |
158 | ␉{.name = "device_hfsraid_sl", .image = NULL},␊ |
159 | ␉{.name = "device_hfsraid_sl_o", .image = NULL},␊ |
160 | ␉{.name = "device_hfsraid_leo", .image = NULL},␊ |
161 | ␉{.name = "device_hfsraid_leo_o", .image = NULL},␊ |
162 | ␉{.name = "device_hfsraid_tiger", .image = NULL},␊ |
163 | ␉{.name = "device_hfsraid_tiger_o", .image = NULL},␊ |
164 | ␉{.name = "device_ext3", .image = NULL},␊ |
165 | ␉{.name = "device_ext3_o", .image = NULL},␊ |
166 | ␉{.name = "device_freebsd", .image = NULL}, /* FreeBSD/OpenBSD detection,nawcom's code by valv, Icon credits to blackosx */␊ |
167 | ␉{.name = "device_freebsd_o", .image = NULL}, /* FreeBSD/OpenBSD detection,nawcom's code by valv, Icon credits to blackosx */␊ |
168 | ␉{.name = "device_openbsd", .image = NULL}, /* FreeBSD/OpenBSD detection,nawcom's code by valv, Icon credits to blackosx */␊ |
169 | ␉{.name = "device_openbsd_o", .image = NULL}, /* FreeBSD/OpenBSD detection,nawcom's code by valv, Icon credits to blackosx */␊ |
170 | ␉{.name = "device_befs", .image = NULL}, /* Haiku detection and Icon credits to scorpius */␊ |
171 | ␉{.name = "device_befs_o", .image = NULL}, /* Haiku detection and Icon credits to scorpius */␊ |
172 | ␉{.name = "device_fat", .image = NULL},␊ |
173 | ␉{.name = "device_fat_o", .image = NULL},␊ |
174 | ␉{.name = "device_fat16", .image = NULL},␊ |
175 | ␉{.name = "device_fat16_o", .image = NULL},␊ |
176 | ␉{.name = "device_fat32", .image = NULL},␊ |
177 | ␉{.name = "device_fat32_o", .image = NULL},␊ |
178 | ␉{.name = "device_ntfs", .image = NULL},␊ |
179 | ␉{.name = "device_ntfs_o", .image = NULL},␊ |
180 | ␉{.name = "device_cdrom", .image = NULL},␊ |
181 | ␉{.name = "device_cdrom_o", .image = NULL},␊ |
182 | ␊ |
183 | ␉{.name = "device_selection", .image = NULL},␊ |
184 | ␉{.name = "device_scroll_prev", .image = NULL},␊ |
185 | ␉{.name = "device_scroll_next", .image = NULL},␊ |
186 | ␊ |
187 | ␉{.name = "menu_boot", .image = NULL},␊ |
188 | ␉{.name = "menu_verbose", .image = NULL},␊ |
189 | ␉{.name = "menu_ignore_caches", .image = NULL},␊ |
190 | ␉{.name = "menu_single_user", .image = NULL},␊ |
191 | ␉{.name = "menu_memory_info", .image = NULL},␊ |
192 | ␉{.name = "menu_video_info", .image = NULL},␊ |
193 | ␉{.name = "menu_help", .image = NULL},␊ |
194 | ␉{.name = "menu_verbose_disabled", .image = NULL},␊ |
195 | ␉{.name = "menu_ignore_caches_disabled", .image = NULL},␊ |
196 | ␉{.name = "menu_single_user_disabled", .image = NULL},␊ |
197 | ␉{.name = "menu_selection", .image = NULL},␊ |
198 | ␊ |
199 | ␉{.name = "progress_bar", .image = NULL},␊ |
200 | ␉{.name = "progress_bar_background", .image = NULL},␊ |
201 | ␊ |
202 | ␉{.name = "text_scroll_prev", .image = NULL},␊ |
203 | ␉{.name = "text_scroll_next", .image = NULL},␊ |
204 | ␊ |
205 | ␉{.name = "font_console", .image = NULL},␊ |
206 | ␉{.name = "font_small", .image = NULL},␊ |
207 | };␊ |
208 | ␊ |
209 | // ====================================================================␊ |
210 | ␊ |
211 | int imageCnt = 0;␊ |
212 | ␊ |
213 | extern int␉gDeviceCount;␊ |
214 | extern int␉selectIndex;␊ |
215 | ␊ |
216 | extern MenuItem *menuItems;␊ |
217 | ␊ |
218 | //char prompt[BOOT_STRING_LEN];␊ |
219 | extern char gBootArgs[BOOT_STRING_LEN];␊ |
220 | ␊ |
221 | char prompt_text[] = "boot: ";␊ |
222 | ␊ |
223 | menuitem_t infoMenuItems[] =␊ |
224 | {␊ |
225 | ␉{ .text = "Boot" },␊ |
226 | ␉{ .text = "Boot Verbose" },␊ |
227 | ␉{ .text = "Boot Ignore Caches" },␊ |
228 | ␉{ .text = "Boot Single User" },␊ |
229 | ␉{ .text = "Memory Info" },␊ |
230 | ␉{ .text = "Video Info" },␊ |
231 | ␉{ .text = "Help" }␊ |
232 | };␊ |
233 | ␊ |
234 | int initFont(font_t *font, image_t *image);␊ |
235 | int destroyFont(font_t *font);␊ |
236 | void colorFont(font_t *font, uint32_t color);␊ |
237 | void makeRoundedCorners(pixmap_t *p);␊ |
238 | ␊ |
239 | static int infoMenuSelection = 0;␊ |
240 | static int infoMenuItemsCount = sizeof(infoMenuItems)/sizeof(infoMenuItems[0]);␊ |
241 | ␊ |
242 | static bool infoMenuNativeBoot = false;␊ |
243 | ␊ |
244 | // here we store the used screen resolution␊ |
245 | static unsigned long screen_params[4] = {DEFAULT_SCREEN_WIDTH, DEFAULT_SCREEN_HEIGHT, 32, 0};␊ |
246 | ␊ |
247 | static int getImageIndexByName(const char *name)␊ |
248 | {␊ |
249 | ␉int i;␊ |
250 | ␉for (i = 0; i < sizeof(images) / sizeof(images[0]); i++) {␊ |
251 | ␉␉if (strcmp(name, images[i].name) == 0) {␊ |
252 | ␉␉␉return i; // found the name␊ |
253 | ␉␉}␊ |
254 | ␉}␊ |
255 | ␉return -1;␊ |
256 | }␊ |
257 | ␊ |
258 | #ifdef CONFIG_EMBED_THEME␊ |
259 | static int getEmbeddedImageIndexByName(const char *name)␊ |
260 | {␊ |
261 | ␉int upperLimit = sizeof(embeddedImages) / sizeof(embeddedImages[0]) - 1;␊ |
262 | ␉int lowerLimit = 0;␊ |
263 | ␉int compareIndex = (upperLimit - lowerLimit) >> 1; // Midpoint␊ |
264 | ␉int result;␊ |
265 | ␉␊ |
266 | ␉// NOTE: This algorithm assumes that the embedded images are sorted.␊ |
267 | ␉// This is currently done using the make file. If the array is␊ |
268 | ␉// generated manualy, this *will* fail to work properly.␊ |
269 | ␉while((result = strcmp(name, embeddedImages[compareIndex].name)) != 0)␊ |
270 | ␉{␊ |
271 | ␉␉if (result > 0)␉{ // We need to search a HIGHER index␊ |
272 | ␉␉␉if (compareIndex != lowerLimit) {␊ |
273 | ␉␉␉␉lowerLimit = compareIndex;␊ |
274 | ␉␉␉} else {␊ |
275 | ␉␉␉␉return -1;␊ |
276 | ␉␉␉}␊ |
277 | ␉␉␉compareIndex = (upperLimit + lowerLimit + 1) >> 1;␉// Midpoint, round up␊ |
278 | ␉␉}␊ |
279 | ␉␉else { // We Need to search a LOWER index␊ |
280 | ␉␉␉if (compareIndex != upperLimit) {␊ |
281 | ␉␉␉␉upperLimit = compareIndex;␊ |
282 | ␉␉␉} else {␊ |
283 | ␉␉␉␉return -1;␊ |
284 | ␉␉␉}␊ |
285 | ␉␉␉compareIndex = (upperLimit + lowerLimit) >> 1;␉// Midpoint, round down␊ |
286 | ␉␉}␊ |
287 | ␉}␊ |
288 | ␉return compareIndex;␊ |
289 | }␊ |
290 | #endif␊ |
291 | ␊ |
292 | static int loadThemeImage(const char *image, int alt_image)␊ |
293 | {␊ |
294 | ␉char␉␉dirspec[256];␊ |
295 | ␉int ␉␉i;␊ |
296 | #ifdef CONFIG_EMBED_THEME␊ |
297 | ␉int ␉␉e;␊ |
298 | #endif␊ |
299 | ␉uint16_t␉width;␊ |
300 | ␉uint16_t␉height;␊ |
301 | ␉uint8_t␉␉*imagedata;␊ |
302 | ␊ |
303 | ␉if ((strlen(image) + strlen(theme_name) + 20) > sizeof(dirspec)) {␊ |
304 | ␉␉return 1;␊ |
305 | ␉}␊ |
306 | ␉if ((i = getImageIndexByName(image)) < 0) {␊ |
307 | ␉␉return 1;␊ |
308 | ␉}␊ |
309 | ␉if (!images[i].image && !(images[i].image = malloc(sizeof(pixmap_t)))) {␊ |
310 | ␉␉return 1;␊ |
311 | ␉}␊ |
312 | ␉sprintf(dirspec, "/Extra/Themes/%s/%s.png", theme_name, image);␊ |
313 | ␉width = 0;␊ |
314 | ␉height = 0;␊ |
315 | ␉imagedata = NULL;␊ |
316 | ␉if ((loadPngImage(dirspec, &width, &height, &imagedata)) == 0) {␊ |
317 | ␉␉images[i].image->width = width;␊ |
318 | ␉␉images[i].image->height = height;␊ |
319 | ␉␉images[i].image->pixels = (pixel_t *)imagedata;␊ |
320 | ␉␉flipRB(images[i].image);␊ |
321 | ␉␉return 0;␊ |
322 | ␉}␊ |
323 | #ifdef CONFIG_EMBED_THEME␊ |
324 | ␉else if ((e = getEmbeddedImageIndexByName(image)) >= 0) {␊ |
325 | ␉␉unsigned char *embed_data;␊ |
326 | ␉␉unsigned int embed_size;␊ |
327 | ␉␉embed_data = embeddedImages[e].pngdata;␊ |
328 | ␉␉embed_size = *embeddedImages[e].length;␊ |
329 | ␊ |
330 | ␉␉if (loadEmbeddedPngImage(embed_data, embed_size, &width, &height, &imagedata) == 0) {␊ |
331 | ␉␉␉images[i].image->width = width;␊ |
332 | ␉␉␉images[i].image->height = height;␊ |
333 | ␉␉␉images[i].image->pixels = (pixel_t *)imagedata;␊ |
334 | ␉␉␉flipRB(images[i].image);␊ |
335 | ␉␉␉return 0;␊ |
336 | }␊ |
337 | }␊ |
338 | #endif␊ |
339 | else if (alt_image != IMG_REQUIRED && is_image_loaded(alt_image)) {␊ |
340 | // Using the passed alternate image for non-mandatory images.␊ |
341 | // We don't clone the already existing pixmap, but using its properties instead!␊ |
342 | images[i].image->width = images[alt_image].image->width;␊ |
343 | images[i].image->height = images[alt_image].image->height;␊ |
344 | images[i].image->pixels = images[alt_image].image->pixels;␊ |
345 | return 0;␊ |
346 | }␊ |
347 | ␊ |
348 | ␉// If we got here it's an error␊ |
349 | #ifndef CONFIG_EMBED_THEME␊ |
350 | ␉printf("ERROR: GUI: could not open '%s/%s.png'!\n", theme_name, image);␊ |
351 | ␉sleep(2);␊ |
352 | #endif␊ |
353 | ␉free(images[i].image);␊ |
354 | ␉images[i].image = NULL;␊ |
355 | ␉return 1;␊ |
356 | }␊ |
357 | ␊ |
358 | // ====================================================================␊ |
359 | ␊ |
360 | static int loadGraphics(void)␊ |
361 | {␊ |
362 | ␉LOADPNG(background, IMG_REQUIRED);␊ |
363 | ␉LOADPNG(logo, IMG_REQUIRED);␊ |
364 | ␊ |
365 | ␉LOADPNG(device_generic, IMG_REQUIRED);␊ |
366 | ␉LOADPNG(device_generic_o, iDeviceGeneric);␊ |
367 | ␉LOADPNG(device_hfsplus, iDeviceGeneric);␊ |
368 | ␉LOADPNG(device_hfsplus_o, iDeviceHFS);␊ |
369 | ␉LOADPNG(device_hfsplus_yos, iDeviceHFS);␊ |
370 | ␉LOADPNG(device_hfsplus_yos_o, iDeviceHFS_yos);␊ |
371 | ␉LOADPNG(device_hfsplus_mav, iDeviceHFS);␊ |
372 | ␉LOADPNG(device_hfsplus_mav_o, iDeviceHFS_mav);␊ |
373 | ␉LOADPNG(device_hfsplus_ml, iDeviceHFS);␊ |
374 | ␉LOADPNG(device_hfsplus_ml_o, iDeviceHFS_ML);␊ |
375 | ␉LOADPNG(device_hfsplus_lion, iDeviceHFS);␊ |
376 | ␉LOADPNG(device_hfsplus_lion_o, iDeviceHFS_Lion);␊ |
377 | ␉LOADPNG(device_hfsplus_sl, iDeviceHFS);␊ |
378 | ␉LOADPNG(device_hfsplus_sl_o, iDeviceHFS_SL);␊ |
379 | ␉LOADPNG(device_hfsplus_leo, iDeviceHFS);␊ |
380 | ␉LOADPNG(device_hfsplus_leo_o, iDeviceHFS_Leo);␊ |
381 | ␉LOADPNG(device_hfsplus_tiger, iDeviceHFS);␊ |
382 | ␉LOADPNG(device_hfsplus_tiger_o, iDeviceHFS_Tiger);␊ |
383 | ␊ |
384 | ␉LOADPNG(device_hfsraid, iDeviceHFS);␊ |
385 | ␉LOADPNG(device_hfsraid_o, iDeviceHFSRAID);␊ |
386 | ␉LOADPNG(device_hfsraid_yos, iDeviceHFSRAID);␊ |
387 | ␉LOADPNG(device_hfsraid_yos_o, iDeviceHFSRAID_yos);␊ |
388 | ␉LOADPNG(device_hfsraid_mav, iDeviceHFSRAID);␊ |
389 | ␉LOADPNG(device_hfsraid_mav_o, iDeviceHFSRAID_mav);␊ |
390 | ␉LOADPNG(device_hfsraid_ml, iDeviceHFSRAID);␊ |
391 | ␉LOADPNG(device_hfsraid_ml_o, iDeviceHFSRAID_ML);␊ |
392 | ␉LOADPNG(device_hfsraid_lion, iDeviceHFSRAID);␊ |
393 | ␉LOADPNG(device_hfsraid_lion_o, iDeviceHFSRAID_Lion);␊ |
394 | ␉LOADPNG(device_hfsraid_sl, iDeviceHFSRAID);␊ |
395 | ␉LOADPNG(device_hfsraid_sl_o, iDeviceHFSRAID_SL);␊ |
396 | ␉LOADPNG(device_hfsraid_leo, iDeviceHFSRAID);␊ |
397 | ␉LOADPNG(device_hfsraid_leo_o, iDeviceHFSRAID_Leo);␊ |
398 | ␉LOADPNG(device_hfsraid_tiger, iDeviceHFSRAID);␊ |
399 | ␉LOADPNG(device_hfsraid_tiger_o, iDeviceHFSRAID_Tiger);␊ |
400 | ␉LOADPNG(device_ext3, iDeviceGeneric);␊ |
401 | ␉LOADPNG(device_ext3_o, iDeviceEXT3);␊ |
402 | ␉LOADPNG(device_freebsd, iDeviceGeneric); /* FreeBSD/OpenBSD detection,nawcom's code by valv, Icon credits to blackosx */␊ |
403 | ␉LOADPNG(device_freebsd_o, iDeviceFreeBSD); /* FreeBSD/OpenBSD detection,nawcom's code by valv, Icon credits to blackosx */␊ |
404 | ␉LOADPNG(device_openbsd, iDeviceGeneric); /* FreeBSD/OpenBSD detection,nawcom's code by valv, Icon credits to blackosx */␊ |
405 | ␉LOADPNG(device_openbsd_o, iDeviceOpenBSD); /* FreeBSD/OpenBSD detection,nawcom's code by valv, Icon credits to blackosx */␊ |
406 | ␉LOADPNG(device_befs, iDeviceGeneric); /* Haiku detection and Icon credits to scorpius */␊ |
407 | ␉LOADPNG(device_befs_o, iDeviceBEFS); /* Haiku detection and Icon credits to scorpius */␊ |
408 | ␉LOADPNG(device_fat, iDeviceGeneric);␊ |
409 | ␉LOADPNG(device_fat_o, iDeviceFAT);␊ |
410 | ␉LOADPNG(device_fat16, iDeviceFAT);␊ |
411 | ␉LOADPNG(device_fat16_o, iDeviceFAT16);␊ |
412 | ␉LOADPNG(device_fat32, iDeviceFAT);␊ |
413 | ␉LOADPNG(device_fat32_o, iDeviceFAT32);␊ |
414 | ␉LOADPNG(device_ntfs, iDeviceGeneric);␊ |
415 | ␉LOADPNG(device_ntfs_o, iDeviceNTFS);␊ |
416 | ␉LOADPNG(device_cdrom, iDeviceGeneric);␊ |
417 | ␉LOADPNG(device_cdrom_o, iDeviceCDROM);␊ |
418 | ␊ |
419 | ␉LOADPNG(device_selection, IMG_REQUIRED);␊ |
420 | ␉LOADPNG(device_scroll_prev, IMG_REQUIRED);␊ |
421 | ␉LOADPNG(device_scroll_next, IMG_REQUIRED);␊ |
422 | ␊ |
423 | ␉LOADPNG(menu_boot, IMG_REQUIRED);␊ |
424 | ␉LOADPNG(menu_verbose, IMG_REQUIRED);␊ |
425 | ␉LOADPNG(menu_ignore_caches, IMG_REQUIRED);␊ |
426 | ␉LOADPNG(menu_single_user, IMG_REQUIRED);␊ |
427 | ␉LOADPNG(menu_memory_info, IMG_REQUIRED);␊ |
428 | ␉LOADPNG(menu_video_info, IMG_REQUIRED);␊ |
429 | ␉LOADPNG(menu_help, IMG_REQUIRED);␊ |
430 | ␉LOADPNG(menu_verbose_disabled, IMG_REQUIRED);␊ |
431 | ␉LOADPNG(menu_ignore_caches_disabled, IMG_REQUIRED);␊ |
432 | ␉LOADPNG(menu_single_user_disabled, IMG_REQUIRED);␊ |
433 | ␉LOADPNG(menu_selection, IMG_REQUIRED);␊ |
434 | ␊ |
435 | ␉LOADPNG(progress_bar, IMG_REQUIRED);␊ |
436 | ␉LOADPNG(progress_bar_background, IMG_REQUIRED);␊ |
437 | ␊ |
438 | ␉LOADPNG(text_scroll_prev, IMG_REQUIRED);␊ |
439 | ␉LOADPNG(text_scroll_next, IMG_REQUIRED);␊ |
440 | ␊ |
441 | ␉LOADPNG(font_console, IMG_REQUIRED);␊ |
442 | ␉LOADPNG(font_small, IMG_REQUIRED);␊ |
443 | ␊ |
444 | ␉initFont( &font_console, &images[iFontConsole]);␊ |
445 | ␉initFont( &font_small, &images[iFontSmall]);␊ |
446 | ␊ |
447 | ␉return 0;␊ |
448 | }␊ |
449 | ␊ |
450 | // ====================================================================␊ |
451 | ␊ |
452 | static int unloadGraphics(void)␊ |
453 | {␊ |
454 | ␉int i;␊ |
455 | ␊ |
456 | ␉destroyFont(&font_console);␊ |
457 | ␉destroyFont(&font_small);␊ |
458 | ␉for (i = 0; i < sizeof(images) / sizeof(images[0]); i++) {␊ |
459 | ␉␉if (images[i].image) {␊ |
460 | ␉␉␉if (images[i].image->pixels) {␊ |
461 | ␉␉␉␉free(images[i].image->pixels);␊ |
462 | ␉␉␉}␊ |
463 | ␉␉␉free (images[i].image);␊ |
464 | ␉␉␉images[i].image = 0;␊ |
465 | ␉ }␊ |
466 | ␉}␊ |
467 | ␉return 0;␊ |
468 | }␊ |
469 | ␊ |
470 | // ====================================================================␊ |
471 | ␊ |
472 | int freeBackBuffer( window_t *window )␊ |
473 | {␊ |
474 | ␉if (gui.backbuffer && gui.backbuffer->pixels) {␊ |
475 | ␉␉free(gui.backbuffer->pixels);␊ |
476 | ␉␉free(gui.backbuffer);␊ |
477 | ␉␉gui.backbuffer = 0;␊ |
478 | ␉␉return 0;␊ |
479 | ␉}␊ |
480 | ␊ |
481 | ␉return 1;␊ |
482 | }␊ |
483 | ␊ |
484 | // ====================================================================␊ |
485 | ␊ |
486 | pixmap_t *getCroppedPixmapAtPosition( pixmap_t *from, position_t pos, uint16_t width, uint16_t height )␊ |
487 | {␊ |
488 | ␉pixmap_t *cropped = malloc( sizeof( pixmap_t ) );␊ |
489 | ␉if( !cropped ) {␊ |
490 | ␉␉return 0;␊ |
491 | ␉}␊ |
492 | ␉cropped->pixels = malloc( width * height * 4 );␊ |
493 | ␉if ( !cropped->pixels ) {␊ |
494 | ␉␉return 0;␊ |
495 | ␉}␊ |
496 | ␉cropped->width = width;␊ |
497 | ␉cropped->height = height;␊ |
498 | ␉␊ |
499 | ␉int destx = 0, desty = 0;␊ |
500 | ␉int srcx = pos.x, srcy = pos.y;␊ |
501 | ␉␊ |
502 | ␉for( ; desty < height; desty++, srcy++) {␊ |
503 | ␉␉for( destx = 0, srcx = pos.x; destx < width; destx++, srcx++ ) {␊ |
504 | ␉␉␉pixel( cropped, destx, desty ).value = pixel( from, srcx, srcy ).value;␊ |
505 | ␉␉}␊ |
506 | ␉}␊ |
507 | ␉return cropped;␊ |
508 | }␊ |
509 | ␊ |
510 | // ====================================================================␊ |
511 | ␊ |
512 | int createBackBuffer( window_t *window )␊ |
513 | {␊ |
514 | ␉gui.backbuffer = malloc(sizeof(pixmap_t));␊ |
515 | ␉if(!gui.backbuffer) {␊ |
516 | ␉␉return 1;␊ |
517 | ␉}␊ |
518 | ␉gui.backbuffer->pixels = malloc( window->width * window->height * 4 );␊ |
519 | ␉if(!gui.backbuffer->pixels) {␊ |
520 | ␉␉free(gui.backbuffer);␊ |
521 | ␉␉gui.backbuffer = 0;␊ |
522 | ␉␉return 1;␊ |
523 | ␉}␊ |
524 | ␉␊ |
525 | ␉gui.backbuffer->width = gui.screen.width;␊ |
526 | ␉gui.backbuffer->height = gui.screen.height;␊ |
527 | ␊ |
528 | ␉return 0;␊ |
529 | }␊ |
530 | ␊ |
531 | // ====================================================================␊ |
532 | ␊ |
533 | int createWindowBuffer( window_t *window )␊ |
534 | {␊ |
535 | ␉window->pixmap = malloc(sizeof(pixmap_t));␊ |
536 | ␉if(!window->pixmap) {␊ |
537 | ␉␉return 1;␊ |
538 | ␉}␊ |
539 | ␊ |
540 | ␉window->pixmap->pixels = malloc( window->width * window->height * 4 );␊ |
541 | ␉if(!window->pixmap->pixels) {␊ |
542 | ␉␉free(window->pixmap);␊ |
543 | ␉␉window->pixmap = 0;␊ |
544 | ␉␉return 1;␊ |
545 | ␉}␊ |
546 | ␉␊ |
547 | ␉window->pixmap->width = window->width;␊ |
548 | ␉window->pixmap->height = window->height;␊ |
549 | ␊ |
550 | ␉return 0;␊ |
551 | }␊ |
552 | ␊ |
553 | // ====================================================================␊ |
554 | ␊ |
555 | int freeWindowBuffer( window_t *window )␊ |
556 | {␊ |
557 | ␉if (window->pixmap && window->pixmap->pixels) {␊ |
558 | ␉␉free(window->pixmap->pixels);␊ |
559 | ␉␉free(window->pixmap);␊ |
560 | ␉␉return 0;␊ |
561 | ␉}␊ |
562 | ␉return 1;␊ |
563 | }␊ |
564 | ␊ |
565 | // ====================================================================␊ |
566 | ␊ |
567 | void fillPixmapWithColor(pixmap_t *pm, uint32_t color)␊ |
568 | {␊ |
569 | ␉int x,y;␊ |
570 | ␉␊ |
571 | ␉// fill with given color AARRGGBB␊ |
572 | ␉for( x=0; x < pm->width; x++ ) {␊ |
573 | ␉␉for( y=0; y< pm->height; y++) {␊ |
574 | ␉␉␉pixel(pm,x,y).value = color;␊ |
575 | ␉␉}␊ |
576 | ␉}␊ |
577 | }␊ |
578 | ␊ |
579 | // ====================================================================␊ |
580 | ␊ |
581 | void drawBackground()␊ |
582 | {␊ |
583 | ␉// reset text cursor␊ |
584 | ␉gui.screen.cursor.x = gui.screen.hborder;␊ |
585 | ␉gui.screen.cursor.y = gui.screen.vborder;␊ |
586 | ␉␊ |
587 | ␉fillPixmapWithColor( gui.screen.pixmap, gui.screen.bgcolor);␊ |
588 | ␉␊ |
589 | ␉// draw background.png into background buffer␊ |
590 | ␉blend( images[iBackground].image, gui.screen.pixmap, gui.background.pos );␊ |
591 | ␉␊ |
592 | ␉// draw logo.png into background buffer␊ |
593 | ␉if (gui.logo.draw)␊ |
594 | ␉{␊ |
595 | ␉␉blend( images[iLogo].image, gui.screen.pixmap, gui.logo.pos);␊ |
596 | ␉}␊ |
597 | ␉␊ |
598 | ␉memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 );␊ |
599 | }␊ |
600 | ␊ |
601 | // ====================================================================␊ |
602 | ␊ |
603 | void setupDeviceList(config_file_t *theme)␊ |
604 | {␊ |
605 | ␉unsigned int pixel;␊ |
606 | ␉int␉alpha;␉␉␉// transparency level 0 (obligue) - 255 (transparent)␊ |
607 | ␉uint32_t color;␉␉␉// color value formatted RRGGBB␊ |
608 | ␉int val, len;␊ |
609 | ␉const char *string;␉␊ |
610 | ␊ |
611 | ␉if(getIntForKey("devices_max_visible", &val, theme )) {␊ |
612 | ␉␉gui.maxdevices = MIN( val, gDeviceCount );␊ |
613 | ␉}␊ |
614 | ␊ |
615 | ␉if(getIntForKey("devices_iconspacing", &val, theme )) {␊ |
616 | ␉␉gui.devicelist.iconspacing = val;␊ |
617 | ␉}␊ |
618 | ␊ |
619 | ␉// check layout for horizontal or vertical␊ |
620 | ␉gui.layout = HorizontalLayout;␊ |
621 | ␉if(getValueForKey( "devices_layout", &string, &len, theme)) {␊ |
622 | ␉␉if (!strcmp (string, "vertical")) {␊ |
623 | ␉␉␉gui.layout = VerticalLayout;␊ |
624 | ␉␉}␊ |
625 | ␉}␊ |
626 | ␊ |
627 | ␉switch (gui.layout) {␊ |
628 | ␉case VerticalLayout:␊ |
629 | ␉␉gui.devicelist.height = ((images[iSelection].image->height + font_console.chars[0]->height + gui.devicelist.iconspacing) * MIN(gui.maxdevices, gDeviceCount) + (images[iDeviceScrollPrev].image->height + images[iDeviceScrollNext].image->height) + gui.devicelist.iconspacing);␊ |
630 | ␉␉gui.devicelist.width = (images[iSelection].image->width + gui.devicelist.iconspacing);␊ |
631 | ␊ |
632 | ␉␉if(getDimensionForKey("devices_pos_x", &pixel, theme, gui.screen.width , images[iSelection].image->width ) ) {␊ |
633 | ␉␉␉gui.devicelist.pos.x = pixel;␊ |
634 | ␉␉}␊ |
635 | ␊ |
636 | ␉␉if(getDimensionForKey("devices_pos_y", &pixel, theme, gui.screen.height , gui.devicelist.height ) ) {␊ |
637 | ␉␉␉gui.devicelist.pos.y = pixel;␊ |
638 | ␉␉}␊ |
639 | ␉␉break;␊ |
640 | ␊ |
641 | ␉case HorizontalLayout:␊ |
642 | ␉default:␊ |
643 | ␉␉gui.devicelist.width = ((images[iSelection].image->width + gui.devicelist.iconspacing) * MIN(gui.maxdevices, gDeviceCount) + (images[iDeviceScrollPrev].image->width + images[iDeviceScrollNext].image->width) + gui.devicelist.iconspacing);␊ |
644 | ␉␉gui.devicelist.height = (images[iSelection].image->height + font_console.chars[0]->height + gui.devicelist.iconspacing);␊ |
645 | ␊ |
646 | ␉␉if(getDimensionForKey("devices_pos_x", &pixel, theme, gui.screen.width , gui.devicelist.width ) ) {␊ |
647 | ␉␉␉gui.devicelist.pos.x = pixel;␊ |
648 | ␉␉} else {␊ |
649 | ␉␉␉gui.devicelist.pos.x = ( gui.screen.width - gui.devicelist.width ) / 2;␊ |
650 | ␉␉}␊ |
651 | ␊ |
652 | ␉␉if(getDimensionForKey("devices_pos_y", &pixel, theme, gui.screen.height , images[iSelection].image->height ) )␊ |
653 | ␉␉{␊ |
654 | ␉␉␉gui.devicelist.pos.y = pixel;␊ |
655 | ␉␉} else {␊ |
656 | ␉␉␉gui.devicelist.pos.y = ( gui.screen.height - gui.devicelist.height ) / 2;␊ |
657 | ␉␉}␊ |
658 | ␉␉break;␊ |
659 | ␉}␊ |
660 | ␊ |
661 | ␉if(getColorForKey("devices_bgcolor", &color, theme)) {␊ |
662 | ␉␉gui.devicelist.bgcolor = (color & 0x00FFFFFF);␊ |
663 | ␉}␊ |
664 | ␊ |
665 | ␉if(getIntForKey("devices_transparency", &alpha, theme)) {␊ |
666 | ␉␉gui.devicelist.bgcolor = gui.devicelist.bgcolor | (( 255 - ( alpha & 0xFF) ) << 24);␊ |
667 | ␉}␊ |
668 | ␊ |
669 | ␉if (gui.devicelist.pixmap) {␊ |
670 | ␉␉freeWindowBuffer(&gui.devicelist);␊ |
671 | ␉␉createWindowBuffer(&gui.devicelist);␊ |
672 | ␉}␊ |
673 | }␊ |
674 | ␊ |
675 | // ====================================================================␊ |
676 | ␊ |
677 | void loadThemeValues(config_file_t *theme)␊ |
678 | {␊ |
679 | ␉unsigned int screen_width = gui.screen.width;␊ |
680 | ␉unsigned int screen_height = gui.screen.height;␊ |
681 | ␉unsigned int pixel;␊ |
682 | ␉int␉alpha;␉␉␉// transparency level 0 (obligue) - 255 (transparent)␊ |
683 | ␉uint32_t color;␉␉␉// color value formatted RRGGBB␊ |
684 | ␉int val;␊ |
685 | ␊ |
686 | ␉/*␊ |
687 | ␉ * Parse screen parameters␊ |
688 | ␉ */␊ |
689 | ␉if(getColorForKey("screen_bgcolor", &color, theme )) {␊ |
690 | ␉␉gui.screen.bgcolor = (color & 0x00FFFFFF);␊ |
691 | ␉}␊ |
692 | ␉if(getIntForKey("screen_textmargin_h", &val, theme)) {␊ |
693 | ␉␉gui.screen.hborder = MIN( gui.screen.width , val );␊ |
694 | ␉}␊ |
695 | ␉if(getIntForKey("screen_textmargin_v", &val, theme)) {␊ |
696 | ␉␉gui.screen.vborder = MIN( gui.screen.height , val );␊ |
697 | ␉}␊ |
698 | ␊ |
699 | ␉/*␊ |
700 | ␉ * Parse background parameters␊ |
701 | ␉ */␊ |
702 | ␉if(getDimensionForKey("background_pos_x", &pixel, theme, screen_width , images[iBackground].image->width ) )␊ |
703 | ␉␉gui.background.pos.x = pixel;␊ |
704 | ␊ |
705 | ␉if(getDimensionForKey("background_pos_y", &pixel, theme, screen_height , images[iBackground].image->height ) ) {␊ |
706 | ␉␉gui.background.pos.y = pixel;␊ |
707 | ␉}␊ |
708 | ␊ |
709 | ␉/*␊ |
710 | ␉ * Parse logo parameters␊ |
711 | ␉ */␊ |
712 | ␉if(getDimensionForKey("logo_pos_x", &pixel, theme, screen_width , images[iLogo].image->width ) ) {␊ |
713 | ␉␉gui.logo.pos.x = pixel;␊ |
714 | ␉}␊ |
715 | ␊ |
716 | ␉if(getDimensionForKey("logo_pos_y", &pixel, theme, screen_height , images[iLogo].image->height ) )␊ |
717 | ␉{␊ |
718 | ␉␉gui.logo.pos.y = pixel;␊ |
719 | ␉}␊ |
720 | ␊ |
721 | ␉/*␊ |
722 | ␉ * Parse progress bar parameters␊ |
723 | ␉ */␊ |
724 | ␉if(getDimensionForKey("progressbar_pos_x", &pixel, theme, screen_width , 0 ) )␊ |
725 | ␉{␊ |
726 | ␉␉gui.progressbar.pos.x = pixel;␊ |
727 | ␉}␊ |
728 | ␊ |
729 | ␉if(getDimensionForKey("progressbar_pos_y", &pixel, theme, screen_height , 0 ) )␊ |
730 | ␉{␊ |
731 | ␉␉gui.progressbar.pos.y = pixel;␊ |
732 | ␉}␊ |
733 | ␊ |
734 | ␉/*␊ |
735 | ␉ * Parse countdown text parameters␊ |
736 | ␉ */␊ |
737 | ␉if(getDimensionForKey("countdown_pos_x", &pixel, theme, screen_width , 0 ) )␊ |
738 | ␉{␊ |
739 | ␉␉gui.countdown.pos.x = pixel;␊ |
740 | ␉}␊ |
741 | ␊ |
742 | ␉if(getDimensionForKey("countdown_pos_y", &pixel, theme, screen_height , 0 ) )␊ |
743 | ␉{␊ |
744 | ␉␉gui.countdown.pos.y = pixel;␊ |
745 | ␉}␊ |
746 | ␊ |
747 | /*␊ |
748 | ␉ * Parse devicelist parameters␊ |
749 | ␉ */␊ |
750 | ␉setupDeviceList(theme);␊ |
751 | ␊ |
752 | ␉/*␊ |
753 | ␉ * Parse infobox parameters␊ |
754 | ␉ */␊ |
755 | ␉if(getIntForKey("infobox_width", &val, theme))␊ |
756 | ␉{␊ |
757 | ␉␉gui.infobox.width = MIN( screen_width , val );␊ |
758 | ␉}␊ |
759 | ␉if(getIntForKey("infobox_height", &val, theme))␊ |
760 | ␉{␊ |
761 | ␉␉gui.infobox.height = MIN( screen_height , val );␊ |
762 | ␉}␊ |
763 | ␉if(getDimensionForKey("infobox_pos_x", &pixel, theme, screen_width , gui.infobox.width ) )␊ |
764 | ␉{␊ |
765 | ␉␉gui.infobox.pos.x = pixel;␊ |
766 | ␉}␊ |
767 | ␉if(getDimensionForKey("infobox_pos_y", &pixel, theme, screen_height , gui.infobox.height ) )␊ |
768 | ␉{␊ |
769 | ␉␉gui.infobox.pos.y = pixel;␊ |
770 | ␉}␊ |
771 | ␉if(getIntForKey("infobox_textmargin_h", &val, theme))␊ |
772 | ␉{␊ |
773 | ␉␉gui.infobox.hborder = MIN( gui.infobox.width , val );␊ |
774 | ␉}␊ |
775 | ␉if(getIntForKey("infobox_textmargin_v", &val, theme))␊ |
776 | ␉{␊ |
777 | ␉␉gui.infobox.vborder = MIN( gui.infobox.height , val );␊ |
778 | ␉}␊ |
779 | ␉if(getColorForKey("infobox_bgcolor", &color, theme))␊ |
780 | ␉{␊ |
781 | ␉␉gui.infobox.bgcolor = (color & 0x00FFFFFF);␊ |
782 | ␉}␊ |
783 | ␉if(getIntForKey("infobox_transparency", &alpha, theme))␊ |
784 | ␉{␊ |
785 | ␉␉gui.infobox.bgcolor = gui.infobox.bgcolor | (( 255 - ( alpha & 0xFF) ) << 24);␊ |
786 | ␉}␊ |
787 | ␉/*␊ |
788 | ␉ * Parse menu parameters␊ |
789 | ␉ */␊ |
790 | ␉if(getDimensionForKey("menu_width", &pixel, theme, gui.screen.width , 0 ) )␊ |
791 | ␉{␊ |
792 | ␉␉gui.menu.width = pixel;␊ |
793 | ␉}␊ |
794 | ␉else␊ |
795 | ␉{␊ |
796 | ␉␉gui.menu.width = images[iMenuSelection].image->width;␊ |
797 | ␉}␊ |
798 | ␉if(getDimensionForKey("menu_height", &pixel, theme, gui.screen.height , 0 ) )␊ |
799 | ␉{␊ |
800 | ␉␉gui.menu.height = pixel;␊ |
801 | ␉}␊ |
802 | ␉else␊ |
803 | ␉{␊ |
804 | ␉␉gui.menu.height = (infoMenuItemsCount) * images[iMenuSelection].image->height;␊ |
805 | ␉}␊ |
806 | ␉if(getDimensionForKey("menu_pos_x", &pixel, theme, screen_width , gui.menu.width ) )␊ |
807 | ␉{␊ |
808 | ␉␉gui.menu.pos.x = pixel;␊ |
809 | ␉}␊ |
810 | ␉if(getDimensionForKey("menu_pos_y", &pixel, theme, screen_height , gui.menu.height ) )␊ |
811 | ␉{␊ |
812 | ␉␉gui.menu.pos.y = pixel;␊ |
813 | ␉}␊ |
814 | ␉if(getIntForKey("menu_textmargin_h", &val, theme))␊ |
815 | ␉{␊ |
816 | ␉␉gui.menu.hborder = MIN( gui.menu.width , val );␊ |
817 | ␉}␊ |
818 | ␉if(getIntForKey("menu_textmargin_v", &val, theme))␊ |
819 | ␉{␊ |
820 | ␉␉gui.menu.vborder = MIN( gui.menu.height , val );␊ |
821 | ␉}␊ |
822 | ␉if(getColorForKey("menu_bgcolor", &color, theme))␊ |
823 | ␉{␊ |
824 | ␉␉gui.menu.bgcolor = (color & 0x00FFFFFF);␊ |
825 | ␉}␊ |
826 | ␉if(getIntForKey("menu_transparency", &alpha, theme))␊ |
827 | ␉{␊ |
828 | ␉␉gui.menu.bgcolor = gui.menu.bgcolor | (( 255 - ( alpha & 0xFF) ) << 24);␉␉␊ |
829 | ␉}␊ |
830 | ␊ |
831 | ␉/*␊ |
832 | ␉ * Parse bootprompt parameters␊ |
833 | ␉ */␊ |
834 | ␉if(getDimensionForKey("bootprompt_width", &pixel, theme, screen_width , 0 ) )␊ |
835 | ␉{␊ |
836 | ␉␉gui.bootprompt.width = pixel;␊ |
837 | ␉}␊ |
838 | ␉if(getIntForKey("bootprompt_height", &val, theme))␊ |
839 | ␉{␊ |
840 | ␉␉gui.bootprompt.height = MIN( screen_height , val );␊ |
841 | ␉}␊ |
842 | ␉if(getDimensionForKey("bootprompt_pos_x", &pixel, theme, screen_width , gui.bootprompt.width ) )␊ |
843 | ␉{␊ |
844 | ␉␉gui.bootprompt.pos.x = pixel;␊ |
845 | ␉}␊ |
846 | ␉if(getDimensionForKey("bootprompt_pos_y", &pixel, theme, screen_height , gui.bootprompt.height ) )␊ |
847 | ␉{␊ |
848 | ␉␉gui.bootprompt.pos.y = pixel;␊ |
849 | ␉}␊ |
850 | ␉if(getIntForKey("bootprompt_textmargin_h", &val, theme))␊ |
851 | ␉{␊ |
852 | ␉␉gui.bootprompt.hborder = MIN( gui.bootprompt.width , val );␊ |
853 | ␉}␊ |
854 | ␉if(getIntForKey("bootprompt_textmargin_v", &val, theme))␊ |
855 | ␉{␊ |
856 | ␉␉gui.bootprompt.vborder = MIN( gui.bootprompt.height , val );␊ |
857 | ␉}␊ |
858 | ␉if(getColorForKey("bootprompt_bgcolor", &color, theme))␊ |
859 | ␉{␊ |
860 | ␉␉gui.bootprompt.bgcolor = (color & 0x00FFFFFF);␊ |
861 | ␉}␊ |
862 | ␉if(getIntForKey("bootprompt_transparency", &alpha, theme))␊ |
863 | ␉{␊ |
864 | ␉␉gui.bootprompt.bgcolor = gui.bootprompt.bgcolor | (( 255 - ( alpha & 0xFF) ) << 24);␊ |
865 | ␉}␊ |
866 | ␉if(getColorForKey("font_small_color", &color, theme))␊ |
867 | ␉{␊ |
868 | ␉␉gui.screen.font_small_color = (color & 0x00FFFFFF);␊ |
869 | ␉}␊ |
870 | ␉if(getColorForKey("font_console_color", &color, theme))␊ |
871 | ␉{␊ |
872 | ␉␉gui.screen.font_console_color = (color & 0x00FFFFFF);␊ |
873 | ␉}␊ |
874 | }␊ |
875 | ␊ |
876 | // ====================================================================␊ |
877 | ␊ |
878 | int initGUI(void)␊ |
879 | {␊ |
880 | ␉int␉␉val;␊ |
881 | ␉int␉len;␊ |
882 | ␉char␉dirspec[256];␊ |
883 | ␊ |
884 | ␉getValueForKey( "Theme", &theme_name, &len, &bootInfo->chameleonConfig );␊ |
885 | ␉if ((strlen(theme_name) + 27) > sizeof(dirspec)) {␊ |
886 | ␉␉return 1;␊ |
887 | ␉}␊ |
888 | ␉sprintf(dirspec, "/Extra/Themes/%s/theme.plist", theme_name);␊ |
889 | ␉if (loadConfigFile(dirspec, &bootInfo->themeConfig) != 0) {␊ |
890 | #ifdef CONFIG_EMBED_THEME␊ |
891 | ␉config_file_t␉*config;␊ |
892 | ␊ |
893 | ␉config = &bootInfo->themeConfig;␊ |
894 | ␉if (ParseXMLFile((char *)__theme_plist, &config->dictionary) != 0) {␊ |
895 | ␉return 1;␊ |
896 | ␉}␊ |
897 | #else␊ |
898 | ␉␉return 1;␊ |
899 | #endif␊ |
900 | ␉}␊ |
901 | ␉// parse display size parameters␊ |
902 | ␉if (getIntForKey("screen_width", &val, &bootInfo->themeConfig) && val > 0) {␊ |
903 | ␉␉screen_params[0] = val;␊ |
904 | ␉}␊ |
905 | ␉if (getIntForKey("screen_height", &val, &bootInfo->themeConfig) && val > 0) {␊ |
906 | ␉␉screen_params[1] = val;␊ |
907 | ␉}␊ |
908 | ␊ |
909 | ␉// Initalizing GUI strucutre.␊ |
910 | ␉bzero(&gui, sizeof(gui_t));␊ |
911 | ␉␊ |
912 | ␉// find best matching vesa mode for our requested width & height␊ |
913 | ␉getGraphicModeParams(screen_params);␊ |
914 | ␊ |
915 | ␉// set our screen structure with the mode width & height␊ |
916 | ␉gui.screen.width = screen_params[0];␉␊ |
917 | ␉gui.screen.height = screen_params[1];␊ |
918 | ␊ |
919 | ␉// load graphics otherwise fail and return␊ |
920 | ␉if (loadGraphics() == 0) {␊ |
921 | ␉␉loadThemeValues(&bootInfo->themeConfig);␊ |
922 | ␉␉colorFont(&font_small, gui.screen.font_small_color);␊ |
923 | ␉␉colorFont(&font_console, gui.screen.font_console_color);␊ |
924 | ␊ |
925 | ␉␉// create the screen & window buffers␊ |
926 | ␉␉if (createBackBuffer(&gui.screen) == 0) {␊ |
927 | ␉␉␉if (createWindowBuffer(&gui.screen) == 0) {␊ |
928 | ␉␉␉␉if (createWindowBuffer(&gui.devicelist) == 0) {␊ |
929 | ␉␉␉␉␉if (createWindowBuffer(&gui.bootprompt) == 0) {␊ |
930 | ␉␉␉␉␉␉if (createWindowBuffer(&gui.infobox) == 0) {␊ |
931 | ␉␉␉␉␉␉␉if (createWindowBuffer(&gui.menu) == 0) {␊ |
932 | ␉␉␉␉␉␉␉␉gui.logo.draw = true;␊ |
933 | ␉␉␉␉␉␉␉␉drawBackground();␊ |
934 | ␉␉␉␉␉␉␉␉// lets copy the screen into the back buffer␊ |
935 | ␉␉␉␉␉␉␉␉memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 );␊ |
936 | ␉␉␉␉␉␉␉␉setVideoMode( GRAPHICS_MODE, 0 );␊ |
937 | ␉␉␉␉␉␉␉␉gui.initialised = true;␊ |
938 | ␉␉␉␉␉␉␉␉return 0;␊ |
939 | ␉␉␉␉␉␉␉}␊ |
940 | ␉␉␉␉␉␉}␊ |
941 | ␉␉␉␉␉}␊ |
942 | ␉␉␉␉}␊ |
943 | ␉␉␉}␊ |
944 | ␉␉}␊ |
945 | ␉}␊ |
946 | ␊ |
947 | // not available memory, freeing resources␊ |
948 | freeWindowBuffer(&gui.menu);␊ |
949 | freeWindowBuffer(&gui.infobox);␊ |
950 | freeWindowBuffer(&gui.bootprompt);␊ |
951 | freeWindowBuffer(&gui.devicelist);␊ |
952 | freeWindowBuffer(&gui.screen);␊ |
953 | freeBackBuffer(&gui.screen);␊ |
954 | unloadGraphics();␊ |
955 | ␊ |
956 | ␉return 1;␊ |
957 | }␊ |
958 | ␊ |
959 | // ====================================================================␊ |
960 | ␊ |
961 | bool is_image_loaded(int i)␊ |
962 | {␉␊ |
963 | ␉return (images[i].image != NULL) ? true : false;␊ |
964 | }␊ |
965 | ␊ |
966 | // ====================================================================␊ |
967 | ␊ |
968 | void drawDeviceIcon(BVRef device, pixmap_t *buffer, position_t p, bool isSelected)␊ |
969 | {␊ |
970 | ␉int devicetype;␊ |
971 | ␊ |
972 | ␉if( diskIsCDROM(device) ) {␊ |
973 | ␉␉devicetype = iDeviceCDROM;␉␉␉␉// Use CDROM icon␊ |
974 | ␉} else {␊ |
975 | ␉␉switch (device->part_type)␊ |
976 | ␉␉{␊ |
977 | ␉␉␉case kPartitionTypeHFS:␊ |
978 | ␉␉␉{␊ |
979 | ␉␉␉␉// Use HFS or HFSRAID icon depending on bvr flags. Fallbacks are handled by alt_image above.␊ |
980 | ␉␉␉␉switch (device->OSVersion[3]) {␊ |
981 | ␉␉␉␉␉case '9':␊ |
982 | ␉␉␉␉␉␉devicetype = (device->flags & kBVFlagBooter ? iDeviceHFSRAID_mav : iDeviceHFS_mav);␊ |
983 | ␉␉␉␉␉␉break;␊ |
984 | ␉␉␉␉␉case '8':␊ |
985 | ␉␉␉␉␉␉devicetype = (device->flags & kBVFlagBooter ? iDeviceHFSRAID_ML : iDeviceHFS_ML);␊ |
986 | ␉␉␉␉␉␉break;␊ |
987 | ␉␉␉␉␉case '7':␊ |
988 | ␉␉␉␉␉␉devicetype = (device->flags & kBVFlagBooter ? iDeviceHFSRAID_Lion : iDeviceHFS_Lion);␊ |
989 | ␉␉␉␉␉␉break;␊ |
990 | ␉␉␉␉␉case '6':␊ |
991 | ␉␉␉␉␉␉devicetype = (device->flags & kBVFlagBooter ? iDeviceHFSRAID_SL : iDeviceHFS_SL);␊ |
992 | ␉␉␉␉␉␉break;␊ |
993 | ␉␉␉␉␉case '5':␊ |
994 | ␉␉␉␉␉␉devicetype = (device->flags & kBVFlagBooter ? iDeviceHFSRAID_Leo : iDeviceHFS_Leo);␊ |
995 | ␉␉␉␉␉␉break;␊ |
996 | ␉␉␉␉␉case '4':␊ |
997 | ␉␉␉␉␉␉devicetype = (device->flags & kBVFlagBooter ? iDeviceHFSRAID_Tiger : iDeviceHFS_Tiger);␊ |
998 | ␉␉␉␉␉␉break;␊ |
999 | ␉␉␉␉␉case '1':␊ |
1000 | ␉␉␉␉␉␉if (device->OSVersion[4] == '0') { // 10.10␊ |
1001 | ␉␉␉␉␉␉␉devicetype = (device->flags & kBVFlagBooter ? iDeviceHFSRAID_yos : iDeviceHFS_yos);␊ |
1002 | ␉␉␉␉␉␉␉break;␊ |
1003 | ␉␉␉␉␉␉}␊ |
1004 | ␉␉␉␉␉␉//if (device->OSVersion[4] == '1') { // 10.11␊ |
1005 | ␉␉␉␉␉␉//␉devicetype = (device->flags & kBVFlagBooter ? iDeviceHFSRAID_??? : iDeviceHFS_???);␊ |
1006 | ␉␉␉␉␉␉//␉break;␊ |
1007 | ␉␉␉␉␉␉//}␊ |
1008 | ␉␉␉␉␉default:␊ |
1009 | ␉␉␉␉␉␉devicetype = (device->flags & kBVFlagBooter ? iDeviceHFSRAID : iDeviceHFS);␊ |
1010 | ␉␉␉␉␉␉break;␊ |
1011 | ␉␉␉␉}␊ |
1012 | ␊ |
1013 | ␉␉␉␉break;␊ |
1014 | ␊ |
1015 | ␉␉␉}␊ |
1016 | ␉␉␉case kPartitionTypeHPFS:␊ |
1017 | ␉␉␉␉devicetype = iDeviceNTFS;␉␉// Use HPFS / NTFS icon␊ |
1018 | ␉␉␉␉break;␊ |
1019 | ␊ |
1020 | ␉␉␉case kPartitionTypeFAT16:␊ |
1021 | ␉␉␉␉devicetype = iDeviceFAT16;␉␉// Use FAT16 icon␊ |
1022 | ␉␉␉␉break;␊ |
1023 | ␊ |
1024 | ␉␉␉case kPartitionTypeFAT32:␊ |
1025 | ␉␉␉␉devicetype = iDeviceFAT32;␉␉// Use FAT32 icon␊ |
1026 | ␉␉␉␉break;␊ |
1027 | ␊ |
1028 | ␉␉␉case kPartitionTypeEXT3:␊ |
1029 | ␉␉␉␉devicetype = iDeviceEXT3;␉␉// Use EXT2/3 icon␊ |
1030 | ␉␉␉␉break;␊ |
1031 | ␊ |
1032 | ␉␉␉case kPartitionTypeFreeBSD: /* FreeBSD/OpenBSD detection,nawcom's code by valv, Icon credits to blackosx */␊ |
1033 | ␉␉␉␉devicetype = iDeviceFreeBSD;␉␉// Use FreeBSD icon␊ |
1034 | ␉␉␉␉break;␊ |
1035 | ␊ |
1036 | ␉␉␉case kPartitionTypeOpenBSD: /* FreeBSD/OpenBSD detection,nawcom's code by valv, Icon credits to blackosx */␊ |
1037 | ␉␉␉␉devicetype = iDeviceOpenBSD;␉␉// Use OpenBSD icon␊ |
1038 | ␉␉␉␉break;␊ |
1039 | ␊ |
1040 | ␉␉␉case kPartitionTypeBEFS: /* Haiku detection and Icon credits to scorpius */␊ |
1041 | ␉␉␉␉devicetype = iDeviceBEFS;␉␉// Use BEFS / Haiku icon␊ |
1042 | ␉␉␉␉break;␊ |
1043 | ␊ |
1044 | ␉␉␉default:␊ |
1045 | ␉␉␉␉devicetype = iDeviceGeneric;␉␉// Use Generic icon␊ |
1046 | ␉␉␉␉break;␊ |
1047 | ␉␉}␊ |
1048 | ␉}␊ |
1049 | ␉␊ |
1050 | ␉// Draw the selection image and use the next (device_*_o) image for the selected item.␊ |
1051 | ␉if (isSelected)␊ |
1052 | ␉{␊ |
1053 | ␉␉blend(images[iSelection].image, buffer, centeredAt(images[iSelection].image, p));␊ |
1054 | ␉␉devicetype++; // select override image ␊ |
1055 | ␉}␊ |
1056 | ␊ |
1057 | ␉// draw icon␊ |
1058 | ␉blend(images[devicetype].image, buffer, centeredAt(images[devicetype].image, p));␊ |
1059 | ␉␊ |
1060 | ␉p.y += (images[iSelection].image->height / 2) + font_console.chars[0]->height;␊ |
1061 | ␉␊ |
1062 | ␉// draw volume label ␊ |
1063 | ␉drawStrCenteredAt( device->label, &font_small, buffer, p);␉␊ |
1064 | ␊ |
1065 | }␊ |
1066 | ␊ |
1067 | // ====================================================================␊ |
1068 | ␊ |
1069 | void drawDeviceList (int start, int end, int selection)␊ |
1070 | {␊ |
1071 | ␉int␉␉␉i;␊ |
1072 | ␉bool␉␉shoWinfo = false;␊ |
1073 | ␉extern bool showBootBanner;␊ |
1074 | ␉position_t␉p, p_prev, p_next;␊ |
1075 | ␊ |
1076 | ␉//uint8_t␉maxDevices = MIN( gui.maxdevices, menucount );␊ |
1077 | ␊ |
1078 | ␉fillPixmapWithColor( gui.devicelist.pixmap, gui.devicelist.bgcolor);␊ |
1079 | ␊ |
1080 | ␉makeRoundedCorners( gui.devicelist.pixmap);␊ |
1081 | ␊ |
1082 | ␉switch (gui.layout) {␊ |
1083 | ␊ |
1084 | ␉␉case VerticalLayout:␊ |
1085 | ␉␉␉p.x = (gui.devicelist.width /2);␊ |
1086 | ␉␉␉p.y = ( ( images[iSelection].image->height / 2 ) + images[iDeviceScrollPrev].image->height + gui.devicelist.iconspacing );␊ |
1087 | ␊ |
1088 | ␉␉␉// place scroll indicators at top & bottom edges␊ |
1089 | ␉␉␉p_prev = pos ( gui.devicelist.width / 2 , gui.devicelist.iconspacing );␊ |
1090 | ␉␉␉p_next = pos ( p_prev.x, gui.devicelist.height - gui.devicelist.iconspacing );␊ |
1091 | ␉␉␉␊ |
1092 | ␉␉␉break;␊ |
1093 | ␉␉␉␊ |
1094 | ␉␉default:␉// use Horizontal layout as the default␊ |
1095 | ␊ |
1096 | ␉␉case HorizontalLayout:␊ |
1097 | ␉␉␉p.x = (gui.devicelist.width - ( gui.devicelist.width / gui.maxdevices ) * gui.maxdevices ) / 2 + ( images[iSelection].image->width / 2) + images[iDeviceScrollPrev].image->width + gui.devicelist.iconspacing;␊ |
1098 | ␉␉␉p.y = ((gui.devicelist.height - font_console.chars[0]->height ) - images[iSelection].image->height) / 2 + ( images[iSelection].image->height / 2 );␊ |
1099 | ␊ |
1100 | ␉␉␉// place scroll indicators at left & right edges␊ |
1101 | ␉␉␉p_prev = pos ( images[iDeviceScrollPrev].image->width / 2 + gui.devicelist.iconspacing / 2, gui.devicelist.height / 2 );␊ |
1102 | ␉␉␉p_next = pos ( gui.devicelist.width - ( images[iDeviceScrollNext].image->width / 2 + gui.devicelist.iconspacing / 2), gui.devicelist.height / 2 );␊ |
1103 | ␉␉␉␊ |
1104 | ␉␉␉break;␊ |
1105 | ␉␉␉␊ |
1106 | ␉}␊ |
1107 | ␉␊ |
1108 | ␉// draw visible device icons␊ |
1109 | ␉for (i = 0; i < gui.maxdevices; i++) {␊ |
1110 | ␉␉BVRef param = menuItems[start + i].param;␊ |
1111 | ␊ |
1112 | ␉␉bool isSelected = ((start + i) == selection) ? true : false;␊ |
1113 | ␉␉if (isSelected) {␊ |
1114 | ␉␉␉if (param->flags & kBVFlagNativeBoot) {␊ |
1115 | ␉␉␉␉infoMenuNativeBoot = true;␊ |
1116 | ␉␉␉} else {␊ |
1117 | ␉␉␉␉infoMenuNativeBoot = false;␊ |
1118 | ␉␉␉␉if(infoMenuSelection >= INFOMENU_NATIVEBOOT_START && infoMenuSelection <= INFOMENU_NATIVEBOOT_END) {␊ |
1119 | ␉␉␉␉␉infoMenuSelection = 0;␊ |
1120 | ␉␉␉␉}␊ |
1121 | ␉␉␉}␊ |
1122 | ␊ |
1123 | ␉␉␉if (gui.menu.draw) {␊ |
1124 | ␉␉␉␉drawInfoMenuItems();␊ |
1125 | ␉␉␉}␊ |
1126 | ␉␉␉getBoolForKey(kShowInfoKey, &shoWinfo, &bootInfo->chameleonConfig);␊ |
1127 | ␉␉␉␊ |
1128 | ␉␉␉if (shoWinfo && showBootBanner) {␊ |
1129 | ␉␉␉␉gui.debug.cursor = pos( 10, 100);␊ |
1130 | ␉␉␉␉dprintf( &gui.screen, "label: %s\n", param->label );␊ |
1131 | ␉␉␉␉dprintf( &gui.screen, "biosdev: 0x%x\n", param->biosdev );␊ |
1132 | ␉␉␉␉dprintf( &gui.screen, "type: 0x%x\n", param->type );␊ |
1133 | ␉␉␉␉dprintf( &gui.screen, "flags: 0x%x\n", param->flags );␊ |
1134 | ␉␉␉␉dprintf( &gui.screen, "part_no: %d\n", param->part_no );␊ |
1135 | ␉␉␉␉dprintf( &gui.screen, "part_boff: 0x%x\n", param->part_boff );␊ |
1136 | ␉␉␉␉dprintf( &gui.screen, "part_type: 0x%x\n", param->part_type );␊ |
1137 | ␉␉␉␉dprintf( &gui.screen, "bps: 0x%x\n", param->bps );␊ |
1138 | ␉␉␉␉dprintf( &gui.screen, "name: %s\n", param->name );␊ |
1139 | ␉␉␉␉dprintf( &gui.screen, "type_name: %s\n", param->type_name );␊ |
1140 | ␉␉␉␉dprintf( &gui.screen, "modtime: %d\n", param->modTime );␊ |
1141 | //␉␉␉␉// res␊ |
1142 | ␉␉␉␉dprintf( &gui.screen, "width: %d\n", gui.screen.width );␊ |
1143 | ␉␉␉␉dprintf( &gui.screen, "height: %d\n", gui.screen.height );␊ |
1144 | //␉␉␉␉dprintf( &gui.screen, "attr: 0x%x\n", gui.screen.attr ); //Azi: reminder␊ |
1145 | //␉␉␉␉dprintf( &gui.screen, "mm: %d\n", gui.screen.mm );␊ |
1146 | ␉␉␉}␊ |
1147 | ␉␉}␊ |
1148 | ␉␉␊ |
1149 | ␉␉drawDeviceIcon( param, gui.devicelist.pixmap, p, isSelected);␊ |
1150 | ␉␉␊ |
1151 | ␉␉if (gui.layout == HorizontalLayout) {␊ |
1152 | ␉␉␉p.x += images[iSelection].image->width + gui.devicelist.iconspacing; ␊ |
1153 | ␉␉}␊ |
1154 | ␉␉if (gui.layout == VerticalLayout) {␊ |
1155 | ␉␉␉p.y += ( images[iSelection].image->height + font_console.chars[0]->height + gui.devicelist.iconspacing ); ␊ |
1156 | ␉␉}␊ |
1157 | ␉}␊ |
1158 | ␊ |
1159 | ␉// draw prev indicator␊ |
1160 | ␉if (start) {␊ |
1161 | ␉␉blend( images[iDeviceScrollPrev].image, gui.devicelist.pixmap, centeredAt( images[iDeviceScrollPrev].image, p_prev ) );␊ |
1162 | ␉}␊ |
1163 | ␉// draw next indicator␊ |
1164 | ␉if ( end < gDeviceCount - 1 ) {␊ |
1165 | ␉␉blend( images[iDeviceScrollNext].image, gui.devicelist.pixmap, centeredAt( images[iDeviceScrollNext].image, p_next ) );␊ |
1166 | ␉}␊ |
1167 | ␉gui.redraw = true;␊ |
1168 | ␉␊ |
1169 | ␉updateVRAM();␊ |
1170 | ␉␊ |
1171 | }␊ |
1172 | ␊ |
1173 | // ====================================================================␊ |
1174 | ␊ |
1175 | void clearGraphicBootPrompt()␊ |
1176 | {␊ |
1177 | ␉// clear text buffer␊ |
1178 | ␉//prompt[0] = '\0';␊ |
1179 | ␉//prompt_pos=0;␊ |
1180 | ␊ |
1181 | ␉␊ |
1182 | ␉if( gui.bootprompt.draw == true ) {␊ |
1183 | ␉␉gui.bootprompt.draw = false;␊ |
1184 | ␉␉gui.redraw = true;␊ |
1185 | ␉␉// this causes extra frames to be drawn␊ |
1186 | ␉␉//updateVRAM();␊ |
1187 | ␉}␊ |
1188 | ␊ |
1189 | ␉return;␊ |
1190 | }␊ |
1191 | ␊ |
1192 | // ====================================================================␊ |
1193 | ␊ |
1194 | void updateGraphicBootPrompt()␊ |
1195 | {␊ |
1196 | ␉fillPixmapWithColor( gui.bootprompt.pixmap, gui.bootprompt.bgcolor);␊ |
1197 | ␊ |
1198 | ␉makeRoundedCorners( gui.bootprompt.pixmap);␊ |
1199 | ␊ |
1200 | ␉position_t p_text = pos( gui.bootprompt.hborder , ( ( gui.bootprompt.height - font_console.chars[0]->height) ) / 2 );␊ |
1201 | ␊ |
1202 | ␉// print the boot prompt text␊ |
1203 | ␉drawStr(prompt_text, &font_console, gui.bootprompt.pixmap, p_text);␊ |
1204 | ␉␊ |
1205 | ␉// get the position of the end of the boot prompt text to display user input␊ |
1206 | ␉position_t p_prompt = pos( p_text.x + ( ( strlen(prompt_text) ) * font_console.chars[0]->width ), p_text.y );␊ |
1207 | ␉␊ |
1208 | ␉drawStr( gBootArgs, &font_console, gui.bootprompt.pixmap, p_prompt);␊ |
1209 | ␊ |
1210 | ␉gui.menu.draw = false;␊ |
1211 | ␉gui.bootprompt.draw = true;␊ |
1212 | ␉gui.redraw = true;␊ |
1213 | ␉␊ |
1214 | ␉updateVRAM();␊ |
1215 | ␉␊ |
1216 | ␉return;␊ |
1217 | }␊ |
1218 | ␊ |
1219 | // ====================================================================␊ |
1220 | ␊ |
1221 | static inline␊ |
1222 | void vramwrite (void *data, int width, int height)␊ |
1223 | {␊ |
1224 | ␉if (VIDEO (depth) == 32 && VIDEO (rowBytes) == gui.backbuffer->width * 4) {␊ |
1225 | ␉␉memcpy((uint8_t *)vram, gui.backbuffer->pixels, VIDEO (rowBytes)*VIDEO (height));␊ |
1226 | ␉} else {␊ |
1227 | ␉␉uint32_t r, g, b;␊ |
1228 | ␉␉int i, j;␊ |
1229 | ␉␉for (i = 0; i < VIDEO (height); i++) {␊ |
1230 | ␉␉␉for (j = 0; j < VIDEO (width); j++) {␊ |
1231 | ␉␉␉␉b = ((uint8_t *) data)[4*i*width + 4*j];␊ |
1232 | ␉␉␉␉g = ((uint8_t *) data)[4*i*width + 4*j + 1];␊ |
1233 | ␉␉␉␉r = ((uint8_t *) data)[4*i*width + 4*j + 2];␊ |
1234 | ␉␉␉␉switch (VIDEO (depth)) {␊ |
1235 | ␉␉␉␉␉case 32:␊ |
1236 | ␉␉␉␉␉␉*(uint32_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*4) = (b&0xff) | ((g&0xff)<<8) | ((r&0xff)<<16);␊ |
1237 | ␉␉␉␉␉␉break;␊ |
1238 | ␉␉␉␉␉case 24:␊ |
1239 | ␉␉␉␉␉␉*(uint32_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*3) = ((*(uint32_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*3))&0xff000000)␊ |
1240 | ␉␉␉␉␉␉| (b&0xff) | ((g&0xff)<<8) | ((r&0xff)<<16);␊ |
1241 | ␉␉␉␉␉␉break;␊ |
1242 | ␉␉␉␉␉case 16:␊ |
1243 | ␉␉␉␉␉␉// Somehow 16-bit is always 15-bits really␊ |
1244 | ␉␉␉␉␉␉//␉␉␉␉␉␉*(uint16_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*2) = ((b&0xf8)>>3) | ((g&0xfc)<<3) | ((r&0xf8)<<8);␊ |
1245 | ␉␉␉␉␉␉//␉␉␉␉␉␉break;␉␉␉␉␉␉␉␊ |
1246 | ␉␉␉␉␉case 15:␊ |
1247 | ␉␉␉␉␉␉*(uint16_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*2) = ((b&0xf8)>>3) | ((g&0xf8)<<2) | ((r&0xf8)<<7);␊ |
1248 | ␉␉␉␉␉␉break;␉␊ |
1249 | ␉␉␉␉}␊ |
1250 | ␉␉␉}␊ |
1251 | ␉␉}␊ |
1252 | ␉}␊ |
1253 | }␊ |
1254 | ␊ |
1255 | // ====================================================================␊ |
1256 | ␊ |
1257 | void updateVRAM()␊ |
1258 | {␊ |
1259 | ␉if (gui.redraw) {␊ |
1260 | ␉␉if (gui.devicelist.draw) {␊ |
1261 | ␉␉␉blend( gui.devicelist.pixmap, gui.backbuffer, gui.devicelist.pos );␊ |
1262 | ␉␉}␊ |
1263 | ␉␉if (gui.bootprompt.draw) {␊ |
1264 | ␉␉␉blend( gui.bootprompt.pixmap, gui.backbuffer, gui.bootprompt.pos );␊ |
1265 | ␉␉}␊ |
1266 | ␉␉if (gui.menu.draw) {␊ |
1267 | ␉␉␉blend( gui.menu.pixmap, gui.backbuffer, gui.menu.pos );␊ |
1268 | ␉␉}␊ |
1269 | ␉␉if (gui.infobox.draw) {␊ |
1270 | ␉␉␉blend( gui.infobox.pixmap, gui.backbuffer, gui.infobox.pos );␊ |
1271 | ␉␉}␊ |
1272 | ␉}␊ |
1273 | ␊ |
1274 | ␉vramwrite ( gui.backbuffer->pixels, gui.backbuffer->width, gui.backbuffer->height );␊ |
1275 | ␊ |
1276 | ␉if (gui.redraw) {␊ |
1277 | ␉␉memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 );␊ |
1278 | ␉␉gui.redraw = false;␊ |
1279 | ␉}␊ |
1280 | }␊ |
1281 | ␊ |
1282 | // ====================================================================␊ |
1283 | ␊ |
1284 | struct putc_info //Azi: exists on console.c & printf.c␊ |
1285 | {␊ |
1286 | ␉char * str;␊ |
1287 | ␉char * last_str;␊ |
1288 | };␊ |
1289 | ␊ |
1290 | // ====================================================================␊ |
1291 | ␊ |
1292 | static int␊ |
1293 | sputc(int c, struct putc_info * pi) //Azi: same as above␊ |
1294 | {␊ |
1295 | ␉if (pi->last_str) {␊ |
1296 | ␉␉if (pi->str == pi->last_str) {␊ |
1297 | ␉␉␉*(pi->str) = '\0';␊ |
1298 | ␉␉␉return 0;␊ |
1299 | ␉␉}␊ |
1300 | ␉}␊ |
1301 | ␉*(pi->str)++ = c;␊ |
1302 | ␉return c;␊ |
1303 | }␊ |
1304 | ␊ |
1305 | // ====================================================================␊ |
1306 | ␊ |
1307 | int gprintf( window_t * window, const char * fmt, ...)␊ |
1308 | {␊ |
1309 | ␉char *formattedtext;␊ |
1310 | ␊ |
1311 | ␉va_list ap;␊ |
1312 | ␉␊ |
1313 | ␉struct putc_info pi;␊ |
1314 | ␊ |
1315 | ␉if ((formattedtext = malloc(1024)) != NULL) {␊ |
1316 | ␉␉// format the text␊ |
1317 | ␉␉va_start(ap, fmt);␊ |
1318 | ␉␉pi.str = formattedtext;␊ |
1319 | ␉␉pi.last_str = 0;␊ |
1320 | ␉␉prf(fmt, ap, sputc, &pi);␊ |
1321 | ␉␉*pi.str = '\0';␊ |
1322 | ␉␉va_end(ap);␊ |
1323 | ␉␉␊ |
1324 | ␉␉position_t␉origin, cursor, bounds;␊ |
1325 | ␊ |
1326 | ␉␉int i;␊ |
1327 | ␉␉int character;␊ |
1328 | ␊ |
1329 | ␉␉origin.x = MAX( window->cursor.x, window->hborder );␊ |
1330 | ␉␉origin.y = MAX( window->cursor.y, window->vborder );␊ |
1331 | ␉␉␊ |
1332 | ␉␉bounds.x = ( window->width - window->hborder );␊ |
1333 | ␉␉bounds.y = ( window->height - window->vborder );␊ |
1334 | ␉␉␊ |
1335 | ␉␉cursor = origin;␊ |
1336 | ␊ |
1337 | ␉␉font_t *font = &font_console;␊ |
1338 | ␊ |
1339 | ␉␉for( i=0; i< strlen(formattedtext); i++ ) {␊ |
1340 | ␉␉␉character = formattedtext[i];␊ |
1341 | ␉␉␉␊ |
1342 | ␉␉␉character -= 32;␊ |
1343 | ␊ |
1344 | ␉␉␉// newline ?␊ |
1345 | ␉␉␉if( formattedtext[i] == '\n' ) {␊ |
1346 | ␉␉␉␉cursor.x = window->hborder;␊ |
1347 | ␉␉␉␉cursor.y += font->height;␊ |
1348 | ␊ |
1349 | ␉␉␉␉if ( cursor.y > bounds.y ) {␊ |
1350 | ␉␉␉␉␉cursor.y = origin.y;␊ |
1351 | ␉␉␉␉}␊ |
1352 | ␉␉␉␉continue;␊ |
1353 | ␉␉␉}␊ |
1354 | ␊ |
1355 | ␉␉␉// tab ?␊ |
1356 | ␉␉␉if( formattedtext[i] == '\t' ) {␊ |
1357 | ␉␉␉␉cursor.x += ( font->chars[0]->width * 5 );␊ |
1358 | ␉␉␉}␊ |
1359 | ␊ |
1360 | ␉␉␉// draw the character␊ |
1361 | ␉␉␉if( font->chars[character]) {␊ |
1362 | ␉␉␉␉blend(font->chars[character], window->pixmap, cursor);␊ |
1363 | ␉␉␉}␊ |
1364 | ␊ |
1365 | ␉␉␉cursor.x += font->chars[character]->width;␊ |
1366 | ␊ |
1367 | ␉␉␉// check x pos and do newline␊ |
1368 | ␉␉␉if ( cursor.x > bounds.x ) {␊ |
1369 | ␉␉␉␉cursor.x = origin.x;␊ |
1370 | ␉␉␉␉cursor.y += font->height;␊ |
1371 | ␉␉␉}␊ |
1372 | ␉␉␉␊ |
1373 | ␉␉␉// check y pos and reset to origin.y␊ |
1374 | ␉␉␉if ( cursor.y > bounds.y ) {␊ |
1375 | ␉␉␉␉cursor.y = origin.y;␊ |
1376 | ␉␉␉}␊ |
1377 | ␉␉}␊ |
1378 | ␊ |
1379 | ␉␉// update cursor postition␊ |
1380 | ␉␉window->cursor = cursor;␊ |
1381 | ␉␉␊ |
1382 | ␉␉free(formattedtext);␊ |
1383 | ␉␉␊ |
1384 | ␉␉return 0;␊ |
1385 | ␉}␊ |
1386 | ␉return 1;␊ |
1387 | }␊ |
1388 | ␊ |
1389 | // ====================================================================␊ |
1390 | ␊ |
1391 | int dprintf( window_t * window, const char * fmt, ...)␊ |
1392 | {␊ |
1393 | ␉char *formattedtext;␊ |
1394 | ␉␊ |
1395 | ␉va_list ap;␊ |
1396 | ␉␊ |
1397 | ␉//window = &gui.debug;␊ |
1398 | ␉␊ |
1399 | ␉struct putc_info pi;␊ |
1400 | ␉␊ |
1401 | ␉if ((formattedtext = malloc(1024)) != NULL) {␊ |
1402 | ␉␉// format the text␊ |
1403 | ␉␉va_start(ap, fmt);␊ |
1404 | ␉␉pi.str = formattedtext;␊ |
1405 | ␉␉pi.last_str = 0;␊ |
1406 | ␉␉prf(fmt, ap, sputc, &pi);␊ |
1407 | ␉␉*pi.str = '\0';␊ |
1408 | ␉␉va_end(ap);␊ |
1409 | ␉␉␊ |
1410 | ␉␉position_t␉origin, cursor, bounds;␊ |
1411 | ␉␉␊ |
1412 | ␉␉int i;␊ |
1413 | ␉␉int character;␊ |
1414 | ␉␉␊ |
1415 | ␉␉origin.x = MAX( gui.debug.cursor.x, window->hborder );␊ |
1416 | ␉␉origin.y = MAX( gui.debug.cursor.y, window->vborder );␊ |
1417 | ␉␉␊ |
1418 | ␉␉bounds.x = ( window->width - window->hborder );␊ |
1419 | ␉␉bounds.y = ( window->height - window->vborder );␊ |
1420 | ␉␉␊ |
1421 | ␉␉cursor = origin;␊ |
1422 | ␉␉␊ |
1423 | ␉␉font_t *font = &font_console;␊ |
1424 | ␉␉␊ |
1425 | ␉␉for( i=0; i< strlen(formattedtext); i++ ) {␊ |
1426 | ␉␉␉character = formattedtext[i];␊ |
1427 | ␉␉␉␊ |
1428 | ␉␉␉character -= 32;␊ |
1429 | ␉␉␉␊ |
1430 | ␉␉␉// newline ?␊ |
1431 | ␉␉␉if( formattedtext[i] == '\n' ) {␊ |
1432 | ␉␉␉␉cursor.x = window->hborder;␊ |
1433 | ␉␉␉␉cursor.y += font->height;␊ |
1434 | ␉␉␉␉␊ |
1435 | ␉␉␉␉if ( cursor.y > bounds.y ) {␊ |
1436 | ␉␉␉␉␉cursor.y = origin.y;␊ |
1437 | ␉␉␉␉}␊ |
1438 | ␉␉␉␉continue;␊ |
1439 | ␉␉␉}␊ |
1440 | ␉␉␉␊ |
1441 | ␉␉␉// tab ?␊ |
1442 | ␉␉␉if( formattedtext[i] == '\t' ) {␊ |
1443 | ␉␉␉␉cursor.x += ( font->chars[0]->width * 5 );␊ |
1444 | ␉␉␉}␊ |
1445 | ␉␉␉// draw the character␊ |
1446 | ␉␉␉if( font->chars[character]) {␊ |
1447 | ␉␉␉␉blend(font->chars[character], gui.backbuffer, cursor);␊ |
1448 | ␉␉␉}␊ |
1449 | ␉␉␉cursor.x += font->chars[character]->width;␊ |
1450 | ␉␉␉␊ |
1451 | ␉␉␉// check x pos and do newline␊ |
1452 | ␉␉␉if ( cursor.x > bounds.x ) {␊ |
1453 | ␉␉␉␉cursor.x = origin.x;␊ |
1454 | ␉␉␉␉cursor.y += font->height;␊ |
1455 | ␉␉␉}␊ |
1456 | ␉␉␉␊ |
1457 | ␉␉␉// check y pos and reset to origin.y␊ |
1458 | ␉␉␉if ( cursor.y > bounds.y ) {␊ |
1459 | ␉␉␉␉cursor.y = origin.y;␊ |
1460 | ␉␉␉}␊ |
1461 | ␉␉}␊ |
1462 | ␉␉␊ |
1463 | ␉␉// update cursor postition␊ |
1464 | ␉␉gui.debug.cursor = cursor;␊ |
1465 | ␉␉␊ |
1466 | ␉␉free(formattedtext);␊ |
1467 | ␉␉␊ |
1468 | ␉␉return 0;␊ |
1469 | ␉␉␊ |
1470 | ␉}␊ |
1471 | ␉return 1;␊ |
1472 | }␊ |
1473 | ␊ |
1474 | // ====================================================================␊ |
1475 | ␊ |
1476 | int vprf(const char * fmt, va_list ap)␊ |
1477 | {␊ |
1478 | ␉int i;␊ |
1479 | ␉int character;␊ |
1480 | ␊ |
1481 | ␉char *formattedtext;␊ |
1482 | ␉window_t *window = &gui.screen;␊ |
1483 | ␉struct putc_info pi;␊ |
1484 | ␉␊ |
1485 | ␉position_t␉origin, cursor, bounds;␊ |
1486 | ␉font_t *font = &font_console;␊ |
1487 | ␉␊ |
1488 | ␉if ((formattedtext = malloc(1024)) != NULL) {␊ |
1489 | ␉␉// format the text␊ |
1490 | ␉␉pi.str = formattedtext;␊ |
1491 | ␉␉pi.last_str = 0;␊ |
1492 | ␉␉prf(fmt, ap, sputc, &pi);␊ |
1493 | ␉␉*pi.str = '\0';␊ |
1494 | ␉␉␊ |
1495 | ␉␉origin.x = MAX( window->cursor.x, window->hborder );␊ |
1496 | ␉␉origin.y = MAX( window->cursor.y, window->vborder );␊ |
1497 | ␉␉bounds.x = ( window->width - ( window->hborder * 2 ) );␊ |
1498 | ␉␉bounds.y = ( window->height - ( window->vborder * 2 ) );␊ |
1499 | ␉␉cursor = origin;␊ |
1500 | ␊ |
1501 | ␉␉for( i=0; i< strlen(formattedtext); i++ ) {␊ |
1502 | ␉␉␉character = formattedtext[i];␊ |
1503 | ␉␉␉character -= 32;␊ |
1504 | ␉␉␉␊ |
1505 | ␉␉␉// newline ?␊ |
1506 | ␉␉␉if( formattedtext[i] == '\n' ) {␊ |
1507 | ␉␉␉␉cursor.x = window->hborder;␊ |
1508 | ␉␉␉␉cursor.y += font->height;␊ |
1509 | ␉␉␉␉if ( cursor.y > bounds.y ) {␊ |
1510 | ␉␉␉␉␉gui.redraw = true;␊ |
1511 | ␉␉␉␉␉updateVRAM();␊ |
1512 | ␉␉␉␉␉cursor.y = window->vborder;␊ |
1513 | ␉␉␉␉}␊ |
1514 | ␉␉␉␉window->cursor.y = cursor.y;␊ |
1515 | ␉␉␉␉continue;␊ |
1516 | ␉␉␉}␊ |
1517 | ␊ |
1518 | ␉␉␉// tab ?␊ |
1519 | ␉␉␉if( formattedtext[i] == '\t' ) {␊ |
1520 | ␉␉␉␉cursor.x = ( cursor.x / ( font->chars[0]->width * 8 ) + 1 ) * ( font->chars[0]->width * 8 );␊ |
1521 | ␉␉␉␉continue;␊ |
1522 | ␉␉␉}␊ |
1523 | ␉␉␉cursor.x += font->chars[character]->width;␊ |
1524 | ␉␉␉␊ |
1525 | ␉␉␉// check x pos and do newline␊ |
1526 | ␉␉␉if ( cursor.x > bounds.x ) {␊ |
1527 | ␉␉␉␉cursor.x = origin.x;␊ |
1528 | ␉␉␉␉cursor.y += font->height;␊ |
1529 | ␉␉␉}␊ |
1530 | ␊ |
1531 | ␉␉␉// check y pos and reset to origin.y␊ |
1532 | ␉␉␉if ( cursor.y > ( bounds.y + font->chars[0]->height) ) {␊ |
1533 | ␉␉␉␉gui.redraw = true;␊ |
1534 | ␉␉␉␉updateVRAM();␊ |
1535 | ␉␉␉␉cursor.y = window->vborder;␊ |
1536 | ␉␉␉}␊ |
1537 | ␉␉␉// draw the character␊ |
1538 | ␉␉␉if( font->chars[character]) {␊ |
1539 | ␉␉␉␉blend(font->chars[character], gui.backbuffer, cursor);␊ |
1540 | ␉␉␉}␊ |
1541 | ␉␉}␊ |
1542 | ␉␉// save cursor postition␊ |
1543 | ␉␉window->cursor.x = cursor.x;␊ |
1544 | ␉␉updateVRAM();␊ |
1545 | ␉␉free(formattedtext);␊ |
1546 | ␉␉return 0;␊ |
1547 | ␉}␊ |
1548 | ␉return 1;␊ |
1549 | }␊ |
1550 | ␊ |
1551 | // ====================================================================␊ |
1552 | ␊ |
1553 | pixmap_t* charToPixmap(unsigned char ch, font_t *font) {␊ |
1554 | ␉unsigned int cha = (unsigned int)ch - 32;␊ |
1555 | ␉if (cha >= font->count) {␊ |
1556 | ␉␉// return ? if the font for the char doesn't exists␊ |
1557 | ␉␉cha = '?' - 32;␊ |
1558 | ␉}␊ |
1559 | ␉return font->chars[cha] ? font->chars[cha] : NULL;␊ |
1560 | }␊ |
1561 | ␊ |
1562 | // ====================================================================␊ |
1563 | ␊ |
1564 | position_t drawChar(unsigned char ch, font_t *font, pixmap_t *blendInto, position_t p) {␊ |
1565 | ␉pixmap_t* pm = charToPixmap(ch, font);␊ |
1566 | ␉if (pm && ((p.x + pm->width) < blendInto->width)) {␊ |
1567 | ␉␉blend(pm, blendInto, p);␊ |
1568 | ␉␉return pos(p.x + pm->width, p.y);␊ |
1569 | ␉} else {␊ |
1570 | ␉␉return p;␊ |
1571 | ␉}␊ |
1572 | }␊ |
1573 | ␊ |
1574 | // ====================================================================␊ |
1575 | ␊ |
1576 | void drawStr(char *ch, font_t *font, pixmap_t *blendInto, position_t p)␊ |
1577 | {␊ |
1578 | ␉int i=0;␊ |
1579 | ␉position_t current_pos = pos(p.x, p.y);␊ |
1580 | ␉␊ |
1581 | ␉for (i=0; i < strlen(ch); i++) {␊ |
1582 | ␉␉// newline ?␊ |
1583 | ␉␉if ( ch[i] == '\n' ) {␊ |
1584 | ␉␉␉current_pos.x = p.x;␊ |
1585 | ␉␉␉current_pos.y += font->height;␊ |
1586 | ␉␉␉continue;␊ |
1587 | ␉␉}␊ |
1588 | ␉␉␊ |
1589 | ␉␉// tab ?␊ |
1590 | ␉␉if ( ch[i] == '\t' ) {␊ |
1591 | ␉␉␉current_pos.x += TAB_PIXELS_WIDTH;␊ |
1592 | ␉␉␉continue;␊ |
1593 | ␉␉}␊ |
1594 | ␉␉␊ |
1595 | ␉␉current_pos = drawChar(ch[i], font, blendInto, current_pos);␊ |
1596 | ␉}␊ |
1597 | }␊ |
1598 | ␊ |
1599 | // ====================================================================␊ |
1600 | ␊ |
1601 | void drawStrCenteredAt(char *text, font_t *font, pixmap_t *blendInto, position_t p)␊ |
1602 | {␊ |
1603 | ␉int i = 0;␊ |
1604 | ␉int width = 0;␊ |
1605 | ␉int max_width = 0;␊ |
1606 | ␉int height = font->height;␊ |
1607 | ␊ |
1608 | ␉// calculate the width in pixels␊ |
1609 | ␉for (i=0; i < strlen(text); i++) {␊ |
1610 | ␉␉if (text[i] == '\n') {␊ |
1611 | ␉␉␉width = 0;␊ |
1612 | ␉␉␉height += font->height;␊ |
1613 | ␉␉} else if (text[i] == '\t') {␊ |
1614 | ␉␉␉width += TAB_PIXELS_WIDTH;␊ |
1615 | ␉␉} else {␊ |
1616 | ␉␉␉pixmap_t* pm = charToPixmap(text[i], font);␊ |
1617 | ␉␉␉if (pm)␉{␊ |
1618 | ␉␉␉␉width += pm->width;␊ |
1619 | ␉␉␉}␊ |
1620 | ␉␉}␊ |
1621 | ␉␉if (width > max_width) {␊ |
1622 | ␉␉␉max_width = width;␊ |
1623 | ␉␉}␊ |
1624 | ␉}␊ |
1625 | ␊ |
1626 | ␉p.x = ( p.x - ( max_width / 2 ) );␊ |
1627 | ␉p.y = ( p.y - ( height / 2 ) );␊ |
1628 | ␉␊ |
1629 | ␉drawStr(text, font, blendInto, p);␊ |
1630 | }␊ |
1631 | ␊ |
1632 | // ====================================================================␊ |
1633 | ␊ |
1634 | int destroyFont(font_t *font)␊ |
1635 | {␊ |
1636 | ␉int i;␊ |
1637 | ␉for (i = 0; i < CHARACTERS_COUNT; i++) {␊ |
1638 | ␉␉if (font->chars[i]) {␊ |
1639 | ␉␉␉if (font->chars[i]->pixels) {␊ |
1640 | ␉␉␉␉free (font->chars[i]->pixels);␊ |
1641 | ␉␉␉}␊ |
1642 | ␉␉␉free (font->chars[i]);␊ |
1643 | ␉␉␉font->chars[i] = 0;␊ |
1644 | ␉␉}␊ |
1645 | ␉}␊ |
1646 | ␉return 0;␊ |
1647 | }␊ |
1648 | ␊ |
1649 | // ====================================================================␊ |
1650 | ␊ |
1651 | int initFont(font_t *font, image_t *data)␊ |
1652 | {␊ |
1653 | ␉unsigned int x = 0, y = 0, x2 = 0, x3 = 0;␊ |
1654 | ␉␊ |
1655 | ␉int start = 0, end = 0, count = 0, space = 0;␊ |
1656 | ␉␊ |
1657 | ␉bool monospaced = false;␊ |
1658 | ␉␊ |
1659 | ␉font->height = data->image->height;␊ |
1660 | ␊ |
1661 | ␉for( x = 0; x < data->image->width && count < CHARACTERS_COUNT; x++) {␊ |
1662 | ␉␉start = end;␊ |
1663 | ␊ |
1664 | ␉␉// if the pixel is red we've reached the end of the char␊ |
1665 | ␉␉if( pixel( data->image, x, 0 ).value == 0xFFFF0000) {␊ |
1666 | ␉␉␉end = x + 1;␊ |
1667 | ␊ |
1668 | ␉␉␉if( (font->chars[count] = malloc(sizeof(pixmap_t)) ) ) {␊ |
1669 | ␉␉␉␉font->chars[count]->width = ( end - start) - 1;␊ |
1670 | ␉␉␉␉font->chars[count]->height = font->height;␊ |
1671 | ␉␉␉␊ |
1672 | ␉␉␉␉if ( ( font->chars[count]->pixels = malloc( font->chars[count]->width * data->image->height * 4) ) ) {␊ |
1673 | ␉␉␉␉␉space += ( font->chars[count]->width * data->image->height * 4 );␊ |
1674 | ␉␉␉␉␉// we skip the first line because there are just the red pixels for the char width␊ |
1675 | ␉␉␉␉␉for( y = 1; y< (font->height); y++) {␊ |
1676 | ␉␉␉␉␉␉for( x2 = start, x3 = 0; x2 < end; x2++, x3++) {␊ |
1677 | ␉␉␉␉␉␉␉pixel( font->chars[count], x3, y ) = pixel( data->image, x2, y );␊ |
1678 | ␉␉␉␉␉␉}␉␊ |
1679 | ␉␉␉␉␉}␊ |
1680 | ␉␉␉␉␉␊ |
1681 | ␉␉␉␉␉// check if font is monospaced␊ |
1682 | ␉␉␉␉␉if( ( count > 0 ) && ( font->width != font->chars[count]->width ) ) {␊ |
1683 | ␉␉␉␉␉␉monospaced = true;␊ |
1684 | ␉␉␉␉␉}␊ |
1685 | ␊ |
1686 | ␉␉␉␉␉font->width = font->chars[count]->width;␊ |
1687 | ␉␉␉␉␉␊ |
1688 | ␉␉␉␉␉count++;␊ |
1689 | ␉␉␉␉}␊ |
1690 | ␉␉␉}␊ |
1691 | ␉␉}␊ |
1692 | ␉}␊ |
1693 | ␊ |
1694 | ␉for (x = count; x < CHARACTERS_COUNT; x++) {␊ |
1695 | ␉␉font->chars[x] = NULL;␊ |
1696 | ␉}␊ |
1697 | ␊ |
1698 | ␉if(monospaced) {␊ |
1699 | ␉␉font->width = 0;␊ |
1700 | ␉}␊ |
1701 | ␊ |
1702 | ␉font->count = count;␊ |
1703 | ␊ |
1704 | ␉return 0;␊ |
1705 | }␊ |
1706 | ␊ |
1707 | // ====================================================================␊ |
1708 | ␊ |
1709 | void colorFont(font_t *font, uint32_t color)␊ |
1710 | {␊ |
1711 | ␉if( !color ) {␊ |
1712 | ␉␉return;␊ |
1713 | ␉}␊ |
1714 | ␊ |
1715 | ␉int x, y, width, height;␊ |
1716 | ␉int count = 0;␊ |
1717 | ␉pixel_t *buff;␊ |
1718 | ␉␊ |
1719 | ␉while( font->chars[count++] ) {␊ |
1720 | ␉␉width = font->chars[count-1]->width;␊ |
1721 | ␉␉height = font->chars[count-1]->height;␊ |
1722 | ␉␉for( y = 0; y < height; y++ ) {␊ |
1723 | ␉␉␉for( x = 0; x < width; x++ ) {␊ |
1724 | ␉␉␉␉buff = &(pixel( font->chars[count-1], x, y ));␊ |
1725 | ␉␉␉␉if( buff->ch.a ) {␊ |
1726 | ␉␉␉␉␉buff->ch.r = (color & 0xFFFF0000) >> 16;␊ |
1727 | ␉␉␉␉␉buff->ch.g = (color & 0xFF00FF00) >> 8;␊ |
1728 | ␉␉␉␉␉buff->ch.b = (color & 0xFF0000FF);␊ |
1729 | ␉␉␉␉}␊ |
1730 | ␉␉␉}␊ |
1731 | ␉␉}␊ |
1732 | ␉}␊ |
1733 | }␊ |
1734 | ␊ |
1735 | // ====================================================================␊ |
1736 | ␊ |
1737 | void makeRoundedCorners(pixmap_t *p)␊ |
1738 | {␊ |
1739 | ␉int x,y;␊ |
1740 | ␉int width=p->width-1;␊ |
1741 | ␉int height=p->height-1;␊ |
1742 | ␉␊ |
1743 | ␉// 10px rounded corner alpha values␊ |
1744 | ␉uint8_t roundedCorner[10][10] =␊ |
1745 | ␉{␊ |
1746 | ␉␉{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x80, 0xC0, 0xFF},␊ |
1747 | ␉␉{ 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xFF, 0xFF, 0xFF, 0xFF},␊ |
1748 | ␉␉{ 0x00, 0x00, 0x00, 0x40, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},␊ |
1749 | ␉␉{ 0x00, 0x00, 0x40, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},␊ |
1750 | ␉␉{ 0x00, 0x40, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},␊ |
1751 | ␉␉{ 0x00, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},␊ |
1752 | ␉␉{ 0x40, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},␊ |
1753 | ␉␉{ 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},␊ |
1754 | ␉␉{ 0xC0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},␊ |
1755 | ␉␉{ 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}␊ |
1756 | ␉};␊ |
1757 | ␉␊ |
1758 | ␉uint8_t alpha=0;␊ |
1759 | ␉␊ |
1760 | ␉for( y=0; y<10; y++) {␊ |
1761 | ␉␉for( x=0; x<10; x++) {␊ |
1762 | ␉␉␉// skip if the pixel should be visible␊ |
1763 | ␉␉␉if(roundedCorner[y][x] != 0xFF)␉{ ␊ |
1764 | ␉␉␉␉alpha = ( roundedCorner[y][x] ? (uint8_t) (roundedCorner[y][x] * pixel(p, x, y).ch.a) / 255 : 0 );␊ |
1765 | ␉␉␉␉// Upper left corner␊ |
1766 | ␉␉␉␉pixel(p, x, y).ch.a = alpha;␊ |
1767 | ␊ |
1768 | ␉␉␉␉// upper right corner␊ |
1769 | ␉␉␉␉pixel(p, width-x,y).ch.a = alpha;␊ |
1770 | ␊ |
1771 | ␉␉␉␉// lower left corner␊ |
1772 | ␉␉␉␉pixel(p, x, height-y).ch.a = alpha;␊ |
1773 | ␊ |
1774 | ␉␉␉␉// lower right corner␊ |
1775 | ␉␉␉␉pixel(p, width-x, height-y).ch.a = alpha;␊ |
1776 | ␉␉␉}␊ |
1777 | ␉␉}␊ |
1778 | ␉}␊ |
1779 | }␊ |
1780 | ␊ |
1781 | // ====================================================================␊ |
1782 | ␊ |
1783 | void showInfoBox(char *title, char *text_orig)␊ |
1784 | {␊ |
1785 | ␉char* text;␊ |
1786 | ␉int i, key, lines, visiblelines;␊ |
1787 | ␊ |
1788 | ␉int currentline=0;␊ |
1789 | ␉int cnt=0;␊ |
1790 | ␉int offset=0;␊ |
1791 | ␉␊ |
1792 | ␉if( !title || !text_orig ) {␊ |
1793 | ␉␉return;␊ |
1794 | ␉}␊ |
1795 | ␊ |
1796 | ␉// Create a copy so that we don't mangle the original␊ |
1797 | ␉text = malloc(strlen(text_orig) + 1);␊ |
1798 | ␉strcpy(text, text_orig);␊ |
1799 | ␊ |
1800 | ␉position_t pos_title = pos ( gui.infobox.vborder, gui.infobox.vborder );␊ |
1801 | ␊ |
1802 | ␉// calculate number of lines in the title␊ |
1803 | ␉for ( i = 0, lines = 1; i<strlen(title); i++ ) {␊ |
1804 | ␉␉if( title[i] == '\n') {␊ |
1805 | ␉␉␉lines++;␊ |
1806 | ␉␉}␊ |
1807 | ␉}␊ |
1808 | ␉// y position of text is lines in title * height of font␊ |
1809 | ␉position_t pos_text = pos( pos_title.x , pos_title.y + ( font_console.height * lines ));␊ |
1810 | ␉␊ |
1811 | ␉// calculate number of lines in the text␊ |
1812 | ␉for ( i=0, lines = 1; i<strlen(text); i++ ) {␊ |
1813 | ␉␉if( text[i] == '\n') {␊ |
1814 | ␉␉␉lines++;␊ |
1815 | ␉␉}␊ |
1816 | ␉}␊ |
1817 | ␉// if text ends with \n strip off␊ |
1818 | ␉if( text[i] == '\n' || text[i] == '\0') {␊ |
1819 | ␉␉lines--;␊ |
1820 | ␉}␊ |
1821 | ␉visiblelines = ( ( gui.infobox.height - ( gui.infobox.vborder * 2 ) ) / font_console.height ) - 1;␊ |
1822 | ␉␊ |
1823 | ␉// lets display the text and allow scroll thru using up down / arrows␊ |
1824 | ␉while(1) {␊ |
1825 | ␉␉// move to current line in text␊ |
1826 | ␉␉for( offset = 0, i = 0; offset < strlen(text); offset++ ) {␊ |
1827 | ␉␉␉if( currentline == i) {␊ |
1828 | ␉␉␉␉break;␊ |
1829 | ␉␉␉}␊ |
1830 | ␉␉␉if( text[offset] =='\n') {␊ |
1831 | ␉␉␉␉i++;␊ |
1832 | ␉␉␉}␊ |
1833 | ␉␉}␊ |
1834 | ␊ |
1835 | ␉␉// find last visible line in text and place \0␊ |
1836 | ␉␉for( i = offset, cnt = 0; i < strlen(text); i++) {␊ |
1837 | ␉␉␉if(text[i]=='\n') {␊ |
1838 | ␉␉␉␉cnt++;␊ |
1839 | ␉␉␉}␊ |
1840 | ␉␉␉if ( cnt == visiblelines ) {␊ |
1841 | ␉␉␉␉text[i]='\0';␊ |
1842 | ␉␉␉␉break;␊ |
1843 | ␉␉␉}␊ |
1844 | ␉␉}␊ |
1845 | ␊ |
1846 | ␉␉fillPixmapWithColor( gui.infobox.pixmap, gui.infobox.bgcolor);␊ |
1847 | ␊ |
1848 | ␉␉makeRoundedCorners( gui.infobox.pixmap);␊ |
1849 | ␊ |
1850 | ␉␉// print the title if present␊ |
1851 | ␉␉if( title ) {␊ |
1852 | ␉␉␉drawStr(title, &font_console, gui.infobox.pixmap, pos_title);␊ |
1853 | ␉␉}␊ |
1854 | ␉␉// print the text␊ |
1855 | ␉␉drawStr( text + offset, &font_console, gui.infobox.pixmap, pos_text);␊ |
1856 | ␊ |
1857 | ␉␉// restore \n in text␊ |
1858 | ␉␉if ( cnt == visiblelines ) {␊ |
1859 | ␉␉␉text[i] = '\n';␊ |
1860 | ␉␉}␊ |
1861 | ␉␉position_t pos_indicator = pos( gui.infobox.width - ( images[iTextScrollPrev].image->width - ( gui.infobox.vborder / 2) ), pos_text.y );␊ |
1862 | ␉␉␊ |
1863 | ␉␉// draw prev indicator␊ |
1864 | ␉␉if(offset) {␊ |
1865 | ␉␉␉blend( images[iTextScrollPrev].image, gui.infobox.pixmap, centeredAt( images[iTextScrollPrev].image, pos_indicator ));␊ |
1866 | ␉␉}␊ |
1867 | ␉␉␊ |
1868 | ␉␉// draw next indicator␊ |
1869 | ␉␉if( lines > ( currentline + visiblelines ) ) {␊ |
1870 | ␉␉␉pos_indicator.y = ( gui.infobox.height - ( ( images[iTextScrollNext].image->width + gui.infobox.vborder ) / 2 ) );␊ |
1871 | ␉␉␉blend( images[iTextScrollNext].image, gui.infobox.pixmap, centeredAt( images[iTextScrollNext].image, pos_indicator ) );␊ |
1872 | ␉␉}␊ |
1873 | ␊ |
1874 | ␉␉gui.bootprompt.draw = false;␊ |
1875 | ␉␉gui.infobox.draw = true;␊ |
1876 | ␉␉gui.redraw = true;␊ |
1877 | ␉␉␊ |
1878 | ␉␉updateVRAM();␊ |
1879 | ␉␉␊ |
1880 | ␉␉key = getchar();␊ |
1881 | ␉␉␉␊ |
1882 | ␉␉if( key == KEY_UP ) {␊ |
1883 | ␉␉␉if( currentline > 0 ) {␊ |
1884 | ␉␉␉␉currentline--;␊ |
1885 | ␉␉␉}␊ |
1886 | ␉␉}␊ |
1887 | ␊ |
1888 | ␉␉if( key == KEY_DOWN ) {␊ |
1889 | ␉␉␉if( lines > ( currentline + visiblelines ) ) {␊ |
1890 | ␉␉␉␉currentline++;␊ |
1891 | ␉␉␉}␊ |
1892 | ␉␉}␊ |
1893 | ␊ |
1894 | ␉␉if( key == KEY_ESC || key == 'q' || key == 'Q') {␊ |
1895 | ␉␉␉gui.infobox.draw = false;␊ |
1896 | ␉␉␉gui.redraw = true;␊ |
1897 | ␉␉␉updateVRAM();␊ |
1898 | ␉␉␉break;␊ |
1899 | ␉␉}␊ |
1900 | ␊ |
1901 | ␉␉if(key == ' ') { // spacebar = next page␊ |
1902 | ␉␉␉if( lines > ( currentline + visiblelines ) ) {␊ |
1903 | ␉␉␉␉currentline += visiblelines;␊ |
1904 | ␉␉␉}␊ |
1905 | ␉␉␉if(lines < (currentline + visiblelines)) {␊ |
1906 | ␉␉␉␉currentline = lines - visiblelines;␊ |
1907 | ␉␉␉}␊ |
1908 | ␉␉}␊ |
1909 | ␉}␊ |
1910 | ␉free(text);␊ |
1911 | }␊ |
1912 | ␊ |
1913 | // ====================================================================␊ |
1914 | ␊ |
1915 | void animateProgressBar()␊ |
1916 | {␊ |
1917 | ␉int y;␊ |
1918 | ␉␊ |
1919 | ␉if( time18() > lasttime) {␊ |
1920 | ␉␉lasttime = time18();␊ |
1921 | ␊ |
1922 | ␉␉pixmap_t *buffBar = images[iProgressBar].image;␊ |
1923 | ␊ |
1924 | ␉␉uint32_t buff = buffBar->pixels[0].value;␊ |
1925 | ␉␊ |
1926 | ␉␉memcpy( buffBar->pixels, buffBar->pixels + 1, ( (buffBar->width*buffBar->height) - 1 ) * 4 );␊ |
1927 | ␊ |
1928 | ␉␉for( y = buffBar->height - 1; y > 0; y--) {␊ |
1929 | ␉␉␉pixel(buffBar, buffBar->width - 1, y) = pixel(buffBar, buffBar->width - 1, y - 1);␊ |
1930 | ␉␉}␊ |
1931 | ␉␉pixel(buffBar, buffBar->width-1, 0).value = buff;␊ |
1932 | ␉}␊ |
1933 | }␊ |
1934 | ␊ |
1935 | // ====================================================================␊ |
1936 | ␊ |
1937 | void drawProgressBar(pixmap_t *blendInto, uint16_t width, position_t p, uint8_t progress)␊ |
1938 | {␊ |
1939 | ␉if(progress>100) {␊ |
1940 | ␉␉return;␊ |
1941 | ␉}␊ |
1942 | ␊ |
1943 | ␉p.x = ( p.x - ( width / 2 ) );␊ |
1944 | ␊ |
1945 | ␉int todraw = (width * progress) / 100;␊ |
1946 | ␊ |
1947 | ␉pixmap_t *buff = images[iProgressBar].image;␊ |
1948 | ␉pixmap_t *buffBG = images[iProgressBarBackground].image;␊ |
1949 | ␉if(!buff || !buffBG) {␊ |
1950 | ␉␉return;␊ |
1951 | ␉}␊ |
1952 | ␊ |
1953 | ␉pixmap_t progressbar;␊ |
1954 | ␉progressbar.pixels=malloc(width * 4 * buff->height);␊ |
1955 | ␉if(!progressbar.pixels) {␊ |
1956 | ␉␉return; ␊ |
1957 | ␉}␊ |
1958 | ␊ |
1959 | ␉progressbar.width = width;␊ |
1960 | ␉progressbar.height = buff->height;␊ |
1961 | ␊ |
1962 | ␉int x=0,x2=0,y=0;␊ |
1963 | ␉␊ |
1964 | ␉for(y=0; y<buff->height; y++) {␊ |
1965 | ␉␉for(x=0; x<todraw; x++, x2++) {␊ |
1966 | ␉␉␉if(x2 == (buff->width-1)) {␊ |
1967 | ␉␉␉␉x2=0;␊ |
1968 | ␉␉␉}␊ |
1969 | ␉␉␉pixel(&progressbar, x,y).value = pixel(buff, x2,y).value;␊ |
1970 | ␉␉}␊ |
1971 | ␉␉x2=0;␊ |
1972 | ␉}␊ |
1973 | ␊ |
1974 | ␉for(y=0; y<buff->height; y++) {␊ |
1975 | ␉␉for(x=todraw, x2 = 0; x < width - 1; x++, x2++) {␊ |
1976 | ␉␉␉if(x2 == (buffBG->width -2 )) {␊ |
1977 | ␉␉␉␉x2 = 0;␊ |
1978 | ␉␉␉}␊ |
1979 | ␉␉␉pixel(&progressbar, x,y).value = pixel(buffBG, x2,y).value;␊ |
1980 | ␉␉}␊ |
1981 | ␉␉if(progress < 100) {␊ |
1982 | ␉␉␉pixel(&progressbar, width - 1, y).value = pixel(buffBG, buffBG->width - 1, y).value;␊ |
1983 | ␉␉}␊ |
1984 | ␊ |
1985 | ␉␉if(progress == 0) {␊ |
1986 | ␉␉␉pixel(&progressbar, 0, y).value = pixel(buffBG, buffBG->width - 1, y).value;␊ |
1987 | ␉␉}␊ |
1988 | ␊ |
1989 | ␉␉x2=0;␊ |
1990 | ␉}␊ |
1991 | ␊ |
1992 | ␉blend(&progressbar, blendInto, p);␊ |
1993 | ␉animateProgressBar();␊ |
1994 | ␉free(progressbar.pixels);␊ |
1995 | }␊ |
1996 | ␊ |
1997 | // ====================================================================␊ |
1998 | ␊ |
1999 | void drawInfoMenuItems()␊ |
2000 | {␊ |
2001 | ␉int i,n;␊ |
2002 | ␉␊ |
2003 | ␉position_t position;␊ |
2004 | ␉␊ |
2005 | ␉pixmap_t *selection = images[iMenuSelection].image;␊ |
2006 | ␉␊ |
2007 | ␉pixmap_t *pbuff;␊ |
2008 | ␊ |
2009 | ␉fillPixmapWithColor(gui.menu.pixmap, gui.menu.bgcolor);␊ |
2010 | ␊ |
2011 | ␉makeRoundedCorners(gui.menu.pixmap);␊ |
2012 | ␉␊ |
2013 | ␉uint8_t offset = infoMenuNativeBoot ? 0 : infoMenuItemsCount - 1;␊ |
2014 | ␊ |
2015 | ␉position = pos(0,0);␊ |
2016 | ␉␊ |
2017 | ␉for ( i = 0, n = iMenuBoot; i < infoMenuItemsCount; i++, n++) {␊ |
2018 | ␉␉if (i == infoMenuSelection) {␊ |
2019 | ␉␉␉blend(selection, gui.menu.pixmap, position);␊ |
2020 | ␉␉}␊ |
2021 | ␊ |
2022 | ␉␉pbuff = images[n].image;␊ |
2023 | ␉␉if (offset && i >= INFOMENU_NATIVEBOOT_START && i <= INFOMENU_NATIVEBOOT_END) {␊ |
2024 | ␉␉␉blend( images[n + (iMenuHelp - iMenuBoot)].image , gui.menu.pixmap, ␊ |
2025 | ␉␉␉␉pos((position.x + (gui.menu.hborder / 2)), position.y + ((selection->height - pbuff->height) / 2)));␊ |
2026 | ␉␉} else {␊ |
2027 | ␉␉␉blend( pbuff, gui.menu.pixmap, ␊ |
2028 | ␉␉␉␉pos((position.x + (gui.menu.hborder / 2)), position.y + ((selection->height - pbuff->height) / 2)));␊ |
2029 | ␉␉}␊ |
2030 | ␊ |
2031 | ␉␉drawStr(infoMenuItems[i].text, &font_console, gui.menu.pixmap, ␊ |
2032 | ␉␉␉pos(position.x + (pbuff->width + gui.menu.hborder), ␊ |
2033 | ␉␉␉␉position.y + ((selection->height - font_console.height) / 2)));␊ |
2034 | ␉␉position.y += images[iMenuSelection].image->height;␊ |
2035 | ␉␊ |
2036 | ␉}␊ |
2037 | ␉␊ |
2038 | ␉gui.redraw = true;␊ |
2039 | }␊ |
2040 | ␊ |
2041 | // ====================================================================␊ |
2042 | ␊ |
2043 | int drawInfoMenu()␊ |
2044 | {␊ |
2045 | ␉drawInfoMenuItems();␊ |
2046 | ␊ |
2047 | ␉gui.menu.draw = true;␊ |
2048 | ␊ |
2049 | ␉updateVRAM();␊ |
2050 | ␉␊ |
2051 | ␉return 1;␊ |
2052 | }␊ |
2053 | ␊ |
2054 | // ====================================================================␊ |
2055 | ␊ |
2056 | int updateInfoMenu(int key)␊ |
2057 | {␊ |
2058 | ␉switch (key)␊ |
2059 | ␉{␊ |
2060 | ␊ |
2061 | ␉␉case KEY_UP:␉// up arrow␊ |
2062 | ␉␉␉if (infoMenuSelection > 0) {␊ |
2063 | ␉␉␉␉if(!infoMenuNativeBoot && infoMenuSelection == INFOMENU_NATIVEBOOT_END + 1) {␊ |
2064 | ␉␉␉␉␉infoMenuSelection -= 4;␊ |
2065 | ␉␉␉␉} else {␊ |
2066 | ␉␉␉␉␉infoMenuSelection--;␊ |
2067 | ␉␉␉␉}␊ |
2068 | ␉␉␉␉drawInfoMenuItems();␊ |
2069 | ␉␉␉␉updateVRAM();␊ |
2070 | ␊ |
2071 | ␉␉␉} else {␊ |
2072 | ␊ |
2073 | ␉␉␉␉gui.menu.draw = false;␊ |
2074 | ␉␉␉␉gui.redraw = true;␊ |
2075 | ␊ |
2076 | ␉␉␉␉updateVRAM();␊ |
2077 | ␉␉␉␉␊ |
2078 | ␉␉␉␉return CLOSE_INFO_MENU;␊ |
2079 | ␉␉␉}␊ |
2080 | ␉␉␉break;␊ |
2081 | ␊ |
2082 | ␉␉case KEY_DOWN:␉// down arrow␊ |
2083 | ␉␉␉if (infoMenuSelection < infoMenuItemsCount - 1) {␊ |
2084 | ␉␉␉␉if(!infoMenuNativeBoot && infoMenuSelection == INFOMENU_NATIVEBOOT_START - 1)␊ |
2085 | ␉␉␉␉{␊ |
2086 | ␉␉␉␉␉infoMenuSelection += 4;␊ |
2087 | ␉␉␉␉} else {␊ |
2088 | ␉␉␉␉␉infoMenuSelection++;␊ |
2089 | ␉␉␉␉}␊ |
2090 | ␉␉␉␉drawInfoMenuItems();␊ |
2091 | ␉␉␉␉updateVRAM();␊ |
2092 | ␉␉␉}␊ |
2093 | ␉␉␉break;␊ |
2094 | ␊ |
2095 | ␉␉case KEY_ENTER:␊ |
2096 | ␉␉␉key = 0;␊ |
2097 | ␉␉␉if( infoMenuSelection == MENU_SHOW_MEMORY_INFO ) {␊ |
2098 | ␉␉␉␉showInfoBox( "Memory Info. Press q to quit.\n", getMemoryInfoString());␊ |
2099 | ␉␉␉} else if( infoMenuSelection == MENU_SHOW_VIDEO_INFO ) {␊ |
2100 | ␉␉␉␉showInfoBox( getVBEInfoString(), getVBEModeInfoString() );␊ |
2101 | ␉␉␉} else if( infoMenuSelection == MENU_SHOW_HELP ) {␊ |
2102 | ␉␉␉␉showHelp();␊ |
2103 | ␉␉␉} else {␊ |
2104 | ␉␉␉␉int buff = infoMenuSelection;␊ |
2105 | ␉␉␉␉infoMenuSelection = 0;␊ |
2106 | ␉␉␉␉return buff;␊ |
2107 | ␉␉␉}␊ |
2108 | ␉␉␉break;␊ |
2109 | ␉}␊ |
2110 | ␉return DO_NOT_BOOT;␊ |
2111 | }␊ |
2112 | ␊ |
2113 | // ====================================================================␊ |
2114 | ␊ |
2115 | uint16_t bootImageWidth = 0; ␊ |
2116 | uint16_t bootImageHeight = 0; ␊ |
2117 | uint8_t *bootImageData = NULL; ␊ |
2118 | static bool usePngImage = true;␊ |
2119 | ␊ |
2120 | //==========================================================================␊ |
2121 | // loadBootGraphics␊ |
2122 | static void loadBootGraphics(void)␊ |
2123 | {␊ |
2124 | ␉if (bootImageData != NULL) {␊ |
2125 | ␉␉return;␊ |
2126 | ␉}␊ |
2127 | ␊ |
2128 | ␉char dirspec[256];␊ |
2129 | ␊ |
2130 | ␉if ((strlen(theme_name) + 24) > sizeof(dirspec)) {␊ |
2131 | ␉␉usePngImage = false; ␊ |
2132 | ␉␉return;␊ |
2133 | ␉}␊ |
2134 | ␉sprintf(dirspec, "/Extra/Themes/%s/boot.png", theme_name);␊ |
2135 | ␉if (loadPngImage(dirspec, &bootImageWidth, &bootImageHeight, &bootImageData) != 0) {␊ |
2136 | #ifdef CONFIG_EMBED_THEME␊ |
2137 | ␉␉if ((loadEmbeddedPngImage(__boot_png, __boot_png_len, &bootImageWidth, &bootImageHeight, &bootImageData)) != 0)␊ |
2138 | #endif␊ |
2139 | ␉␉usePngImage = false; ␊ |
2140 | ␉}␊ |
2141 | }␊ |
2142 | ␊ |
2143 | //==========================================================================␊ |
2144 | // drawBootGraphics␊ |
2145 | void drawBootGraphics(void)␊ |
2146 | {␊ |
2147 | ␉int pos;␊ |
2148 | ␉int length;␊ |
2149 | ␉const char *dummyVal;␊ |
2150 | ␉int oldScreenWidth, oldScreenHeight;␊ |
2151 | ␉bool legacy_logo;␊ |
2152 | ␉uint16_t x, y; ␊ |
2153 | ␉␊ |
2154 | ␉if (getBoolForKey("Legacy Logo", &legacy_logo, &bootInfo->chameleonConfig) && legacy_logo) {␊ |
2155 | ␉␉usePngImage = false; ␊ |
2156 | ␉} else if (bootImageData == NULL) {␊ |
2157 | ␉␉loadBootGraphics();␊ |
2158 | ␉}␊ |
2159 | ␊ |
2160 | ␉// parse screen size parameters␊ |
2161 | ␉if (getIntForKey("boot_width", &pos, &bootInfo->themeConfig) && pos > 0) {␊ |
2162 | ␉␉screen_params[0] = pos;␊ |
2163 | ␉} else {␊ |
2164 | ␉␉screen_params[0] = DEFAULT_SCREEN_WIDTH;␊ |
2165 | ␉}␊ |
2166 | ␉if (getIntForKey("boot_height", &pos, &bootInfo->themeConfig) && pos > 0) {␊ |
2167 | ␉␉screen_params[1] = pos;␊ |
2168 | ␉} else {␊ |
2169 | ␉␉screen_params[1] = DEFAULT_SCREEN_HEIGHT;␊ |
2170 | ␉}␊ |
2171 | ␊ |
2172 | ␉// Save current screen resolution.␊ |
2173 | ␉oldScreenWidth = gui.screen.width;␊ |
2174 | ␉oldScreenHeight = gui.screen.height;␊ |
2175 | ␊ |
2176 | ␉gui.screen.width = screen_params[0];␊ |
2177 | ␉gui.screen.height = screen_params[1];␊ |
2178 | ␊ |
2179 | ␉// find best matching vesa mode for our requested width & height␊ |
2180 | ␉getGraphicModeParams(screen_params);␊ |
2181 | ␊ |
2182 | ␉// Set graphics mode if the booter was in text mode or the screen resolution has changed.␊ |
2183 | ␉if (bootArgs->Video.v_display == VGA_TEXT_MODE || (screen_params[0] != oldScreenWidth && screen_params[1] != oldScreenHeight) ) {␊ |
2184 | ␉␉setVideoMode(GRAPHICS_MODE, 0);␊ |
2185 | ␉}␊ |
2186 | ␊ |
2187 | ␉if (getValueForKey("-checkers", &dummyVal, &length, &bootInfo->chameleonConfig)) {␊ |
2188 | ␉␉drawCheckerBoard();␊ |
2189 | ␉} else {␊ |
2190 | ␉␉// Fill the background to 75% grey (same as BootX). ␊ |
2191 | ␉␉drawColorRectangle(0, 0, screen_params[0], screen_params[1], 0x01); ␊ |
2192 | ␉}␊ |
2193 | ␉if ((bootImageData) && (usePngImage)) { ␊ |
2194 | ␉␉x = (screen_params[0] - MIN(bootImageWidth, screen_params[0])) / 2; ␊ |
2195 | ␉␉y = (screen_params[1] - MIN(bootImageHeight, screen_params[1])) / 2; ␊ |
2196 | ␊ |
2197 | ␉␉// Draw the image in the center of the display. ␊ |
2198 | ␉␉blendImage(x, y, bootImageWidth, bootImageHeight, bootImageData); ␊ |
2199 | ␉} else { ␊ |
2200 | ␉␉uint8_t *appleBootPict; ␊ |
2201 | ␉␉bootImageData = NULL; ␊ |
2202 | ␉␉bootImageWidth = kAppleBootWidth; ␊ |
2203 | ␉␉bootImageHeight = kAppleBootHeight; ␊ |
2204 | ␊ |
2205 | ␉␉// Prepare the data for the default Apple boot image. ␊ |
2206 | ␉␉appleBootPict = (uint8_t *) decodeRLE(gAppleBootPictRLE, kAppleBootRLEBlocks, bootImageWidth * bootImageHeight); ␊ |
2207 | ␉␉if (appleBootPict) { ␊ |
2208 | ␉␉␉convertImage(bootImageWidth, bootImageHeight, appleBootPict, &bootImageData); ␊ |
2209 | ␉␉␉if (bootImageData) {␉␊ |
2210 | ␉␉␉␉x = (screen_params[0] - MIN(kAppleBootWidth, screen_params[0])) / 2; ␊ |
2211 | ␉␉␉␉y = (screen_params[1] - MIN(kAppleBootHeight, screen_params[1])) / 2; ␊ |
2212 | ␉␉␉␉drawDataRectangle(x, y, kAppleBootWidth, kAppleBootHeight, bootImageData);␊ |
2213 | ␉␉␉␉free(bootImageData);␊ |
2214 | ␉␉␉}␊ |
2215 | ␉␉␉free(appleBootPict); ␊ |
2216 | ␉␉} ␊ |
2217 | ␉}␊ |
2218 | }␊ |
2219 | // ====================================================================␊ |
2220 | |