Chameleon

Chameleon Svn Source Tree

Root/branches/ErmaC/Enoch/i386/boot2/gui.c

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

Archive Download this file

Revision: 2910