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

Archive Download this file

Revision: 2883