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

Archive Download this file

Revision: 5