Chameleon

Chameleon Svn Source Tree

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

Archive Download this file

Revision: 180