Chameleon

Chameleon Svn Source Tree

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

Archive Download this file

Revision: 693