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

Archive Download this file

Revision: 2922