Chameleon

Chameleon Svn Source Tree

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

Archive Download this file

Revision: 8