Chameleon

Chameleon Svn Source Tree

Root/trunk/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 );
737 dprintf(&gui.screen, "width %d\n", param->width);
738 dprintf(&gui.screen, "height %d\n", param->height);
739dprintf( &gui.screen, "type 0x%x\n", param->type );
740dprintf( &gui.screen, "flags 0x%x\n", param->flags );
741dprintf( &gui.screen, "part_no %d\n", param->part_no );
742dprintf( &gui.screen, "part_boff 0x%x\n", param->part_boff );
743dprintf( &gui.screen, "part_type 0x%x\n", param->part_type );
744dprintf( &gui.screen, "bps 0x%x\n", param->bps );
745dprintf( &gui.screen, "name %s\n", param->name );
746dprintf( &gui.screen, "type_name %s\n", param->type_name );
747dprintf( &gui.screen, "modtime %d\n", param->modTime );
748#endif
749}
750
751drawDeviceIcon( param, gui.devicelist.pixmap, p );
752
753if (gui.layout == HorizontalLayout)
754{
755p.x += images[iSelection].image->width + gui.devicelist.iconspacing;
756}
757if (gui.layout == VerticalLayout)
758{
759p.y += ( images[iSelection].image->height + font_console.chars[0]->height + gui.devicelist.iconspacing );
760}
761}
762
763// draw prev indicator
764if(start)
765blend( images[iDeviceScrollPrev].image, gui.devicelist.pixmap, centeredAt( images[iDeviceScrollPrev].image, p_prev ) );
766
767// draw next indicator
768if( end < gDeviceCount - 1 )
769blend( images[iDeviceScrollNext].image, gui.devicelist.pixmap, centeredAt( images[iDeviceScrollNext].image, p_next ) );
770
771gui.redraw = true;
772
773updateVRAM();
774
775}
776
777void clearGraphicBootPrompt()
778{
779// clear text buffer
780prompt[0] = '\0';
781prompt_pos=0;
782
783
784if(gui.bootprompt.draw == true )
785{
786gui.bootprompt.draw = false;
787gui.redraw = true;
788// this causes extra frames to be drawn
789//updateVRAM();
790}
791
792return;
793}
794
795void updateGraphicBootPrompt(int key)
796{
797if ( key == kBackspaceKey )
798prompt[--prompt_pos] = '\0';
799else
800{
801prompt[prompt_pos] = key;
802prompt_pos++;
803prompt[prompt_pos] = '\0';
804}
805
806fillPixmapWithColor( gui.bootprompt.pixmap, gui.bootprompt.bgcolor);
807
808makeRoundedCorners( gui.bootprompt.pixmap);
809
810position_t p_text = pos( gui.bootprompt.hborder , ( ( gui.bootprompt.height - font_console.chars[0]->height) ) / 2 );
811
812// print the boot prompt text
813drawStr(prompt_text, &font_console, gui.bootprompt.pixmap, p_text);
814
815// get the position of the end of the boot prompt text to display user input
816position_t p_prompt = pos( p_text.x + ( ( strlen(prompt_text) ) * font_console.chars[0]->width ), p_text.y );
817
818// calculate the position of the cursor
819intoffset = ( prompt_pos - ( ( gui.bootprompt.width / font_console.chars[0]->width ) - strlen(prompt_text) - 2 ) );
820
821if ( offset < 0)
822offset = 0;
823
824drawStr( prompt+offset, &font_console, gui.bootprompt.pixmap, p_prompt);
825
826gui.menu.draw = false;
827gui.bootprompt.draw = true;
828gui.redraw = true;
829
830updateVRAM();
831
832return;
833}
834
835inline
836void vramwrite (void *data, int width, int height)
837{
838if (VIDEO (depth) == 32 && VIDEO (rowBytes) == gui.backbuffer->width * 4)
839memcpy((uint8_t *)vram, gui.backbuffer->pixels, VIDEO (rowBytes)*VIDEO (height));
840else
841{
842uint32_t r, g, b;
843int i, j;
844for (i = 0; i < VIDEO (height); i++)
845for (j = 0; j < VIDEO (width); j++)
846{
847b = ((uint8_t *) data)[4*i*width + 4*j];
848g = ((uint8_t *) data)[4*i*width + 4*j + 1];
849r = ((uint8_t *) data)[4*i*width + 4*j + 2];
850switch (VIDEO (depth))
851{
852case 32:
853*(uint32_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*4) = (b&0xff) | ((g&0xff)<<8) | ((r&0xff)<<16);
854break;
855case 24:
856*(uint32_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*3) = ((*(uint32_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*3))&0xff000000)
857| (b&0xff) | ((g&0xff)<<8) | ((r&0xff)<<16);
858break;
859case 16:
860// Somehow 16-bit is always 15-bits really
861//*(uint16_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*2) = ((b&0xf8)>>3) | ((g&0xfc)<<3) | ((r&0xf8)<<8);
862//break;
863case 15:
864*(uint16_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*2) = ((b&0xf8)>>3) | ((g&0xf8)<<2) | ((r&0xf8)<<7);
865break;
866}
867}
868}
869}
870
871void updateVRAM()
872{
873if (gui.redraw)
874{
875if (gui.devicelist.draw)
876blend( gui.devicelist.pixmap, gui.backbuffer, gui.devicelist.pos );
877
878if (gui.bootprompt.draw)
879blend( gui.bootprompt.pixmap, gui.backbuffer, gui.bootprompt.pos );
880
881if (gui.menu.draw)
882blend( gui.menu.pixmap, gui.backbuffer, gui.menu.pos );
883
884if (gui.infobox.draw)
885blend( gui.infobox.pixmap, gui.backbuffer, gui.infobox.pos );
886}
887
888vramwrite ( gui.backbuffer->pixels, gui.backbuffer->width, gui.backbuffer->height );
889
890if (gui.redraw)
891{
892memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 );
893gui.redraw = false;
894}
895}
896
897struct putc_info {
898 char * str;
899 char * last_str;
900};
901
902static void
903sputc(int c, struct putc_info * pi)
904{
905 if (pi->last_str)
906 if (pi->str == pi->last_str) {
907 *(pi->str) = '\0';
908 return;
909 }
910 *(pi->str)++ = c;
911}
912
913int gprintf( window_t * window, const char * fmt, ...)
914{
915char *formattedtext;
916
917va_list ap;
918
919struct putc_info pi;
920
921if ((formattedtext = malloc(1024)) != NULL) {
922// format the text
923va_start(ap, fmt);
924pi.str = formattedtext;
925pi.last_str = 0;
926prf(fmt, ap, sputc, &pi);
927*pi.str = '\0';
928va_end(ap);
929
930position_torigin, cursor, bounds;
931
932int i;
933int character;
934
935origin.x = MAX( window->cursor.x, window->hborder );
936origin.y = MAX( window->cursor.y, window->vborder );
937
938bounds.x = ( window->width - window->hborder );
939bounds.y = ( window->height - window->vborder );
940
941cursor = origin;
942
943font_t *font = &font_console;
944
945for( i=0; i< strlen(formattedtext); i++ )
946{
947character = formattedtext[i];
948
949character -= 32;
950
951// newline ?
952if( formattedtext[i] == '\n' )
953{
954cursor.x = window->hborder;
955cursor.y += font->height;
956
957if ( cursor.y > bounds.y )
958cursor.y = origin.y;
959
960continue;
961}
962
963// tab ?
964if( formattedtext[i] == '\t' )
965cursor.x += ( font->chars[0]->width * 5 );
966
967// draw the character
968if( font->chars[character])
969blend(font->chars[character], window->pixmap, cursor);
970
971cursor.x += font->chars[character]->width;
972
973// check x pos and do newline
974if ( cursor.x > bounds.x )
975{
976cursor.x = origin.x;
977cursor.y += font->height;
978}
979
980// check y pos and reset to origin.y
981if ( cursor.y > bounds.y )
982cursor.y = origin.y;
983}
984
985// update cursor postition
986window->cursor = cursor;
987
988free(formattedtext);
989
990return 0;
991
992}
993return 1;
994}
995
996int dprintf( window_t * window, const char * fmt, ...)
997{
998char *formattedtext;
999
1000va_list ap;
1001
1002//window = &gui.debug;
1003
1004struct putc_info pi;
1005
1006if ((formattedtext = malloc(1024)) != NULL) {
1007// format the text
1008va_start(ap, fmt);
1009pi.str = formattedtext;
1010pi.last_str = 0;
1011prf(fmt, ap, sputc, &pi);
1012*pi.str = '\0';
1013va_end(ap);
1014
1015position_torigin, cursor, bounds;
1016
1017int i;
1018int character;
1019
1020origin.x = MAX( gui.debug.cursor.x, window->hborder );
1021origin.y = MAX( gui.debug.cursor.y, window->vborder );
1022
1023bounds.x = ( window->width - window->hborder );
1024bounds.y = ( window->height - window->vborder );
1025
1026cursor = origin;
1027
1028font_t *font = &font_console;
1029
1030for( i=0; i< strlen(formattedtext); i++ )
1031{
1032character = formattedtext[i];
1033
1034character -= 32;
1035
1036// newline ?
1037if( formattedtext[i] == '\n' )
1038{
1039cursor.x = window->hborder;
1040cursor.y += font->height;
1041
1042if ( cursor.y > bounds.y )
1043cursor.y = origin.y;
1044
1045continue;
1046}
1047
1048// tab ?
1049if( formattedtext[i] == '\t' )
1050cursor.x += ( font->chars[0]->width * 5 );
1051
1052// draw the character
1053if( font->chars[character])
1054blend(font->chars[character], gui.backbuffer, cursor);
1055
1056cursor.x += font->chars[character]->width;
1057
1058// check x pos and do newline
1059if ( cursor.x > bounds.x )
1060{
1061cursor.x = origin.x;
1062cursor.y += font->height;
1063}
1064
1065// check y pos and reset to origin.y
1066if ( cursor.y > bounds.y )
1067cursor.y = origin.y;
1068}
1069
1070// update cursor postition
1071gui.debug.cursor = cursor;
1072
1073free(formattedtext);
1074
1075return 0;
1076
1077}
1078return 1;
1079}
1080
1081int vprf(const char * fmt, va_list ap)
1082{
1083int i;
1084int character;
1085
1086char *formattedtext;
1087window_t *window = &gui.screen;
1088struct putc_info pi;
1089
1090position_torigin, cursor, bounds;
1091font_t *font = &font_console;
1092
1093if ((formattedtext = malloc(1024)) != NULL) {
1094// format the text
1095pi.str = formattedtext;
1096pi.last_str = 0;
1097prf(fmt, ap, sputc, &pi);
1098*pi.str = '\0';
1099
1100origin.x = MAX( window->cursor.x, window->hborder );
1101origin.y = MAX( window->cursor.y, window->vborder );
1102bounds.x = ( window->width - ( window->hborder * 2 ) );
1103bounds.y = ( window->height - ( window->vborder * 2 ) );
1104cursor = origin;
1105
1106for( i=0; i< strlen(formattedtext); i++ )
1107{
1108character = formattedtext[i];
1109character -= 32;
1110
1111// newline ?
1112if( formattedtext[i] == '\n' )
1113{
1114cursor.x = window->hborder;
1115cursor.y += font->height;
1116if ( cursor.y > bounds.y )
1117{
1118gui.redraw = true;
1119updateVRAM();
1120cursor.y = window->vborder;
1121}
1122window->cursor.y = cursor.y;
1123continue;
1124}
1125
1126// tab ?
1127if( formattedtext[i] == '\t' )
1128{
1129cursor.x = ( cursor.x / ( font->chars[0]->width * 8 ) + 1 ) * ( font->chars[0]->width * 8 );
1130continue;
1131}
1132cursor.x += font->chars[character]->width;
1133
1134// check x pos and do newline
1135if ( cursor.x > bounds.x )
1136{
1137cursor.x = origin.x;
1138cursor.y += font->height;
1139}
1140
1141// check y pos and reset to origin.y
1142if ( cursor.y > ( bounds.y + font->chars[0]->height) )
1143{
1144gui.redraw = true;
1145updateVRAM();
1146cursor.y = window->vborder;
1147}
1148// draw the character
1149if( font->chars[character])
1150blend(font->chars[character], gui.backbuffer, cursor);
1151}
1152// save cursor postition
1153window->cursor.x = cursor.x;
1154updateVRAM();
1155free(formattedtext);
1156return 0;
1157}
1158return 1;
1159}
1160
1161void drawStr(char *ch, font_t *font, pixmap_t *blendInto, position_t p)
1162{
1163int i=0;
1164int y=0; // we need this to support multilines '\n'
1165int x=0;
1166
1167for(i=0;i<strlen(ch);i++)
1168{
1169int cha=(int)ch[i];
1170
1171cha-=32;
1172
1173// newline ?
1174if( ch[i] == '\n' )
1175{
1176x = 0;
1177y += font->height;
1178continue;
1179}
1180
1181// tab ?
1182if( ch[i] == '\t' )
1183x+=(font->chars[0]->width*5);
1184
1185if(font->chars[cha])
1186blend(font->chars[cha], blendInto, pos(p.x+x, p.y+y));
1187
1188x += font->chars[cha]->width;
1189}
1190}
1191
1192void drawStrCenteredAt(char *text, font_t *font, pixmap_t *blendInto, position_t p)
1193{
1194int i = 0;
1195int width = 0;
1196
1197// calculate the width in pixels
1198for(i=0;i<strlen(text);i++)
1199width += font->chars[text[i]-32]->width;
1200
1201p.x = ( p.x - ( width / 2 ) );
1202p.y = ( p.y - ( font->height / 2 ) );
1203
1204if ( p.x == -6 )
1205{
1206p.x = 0;
1207}
1208
1209for(i=0;i<strlen(text);i++)
1210{
1211int cha=(int)text[i];
1212
1213cha-=32;
1214
1215if(font->chars[cha])
1216{
1217blend(font->chars[cha], blendInto, p);
1218p.x += font->chars[cha]->width;
1219}
1220}
1221
1222}
1223
1224int initFont(font_t *font, image_t *data)
1225{
1226unsigned int x = 0, y = 0, x2 = 0, x3 = 0;
1227
1228int start = 0, end = 0, count = 0, space = 0;
1229
1230bool monospaced = false;
1231
1232font->height = data->image->height;
1233
1234for( x = 0; x < data->image->width; x++)
1235{
1236start = end;
1237
1238// if the pixel is red we've reached the end of the char
1239if( pixel( data->image, x, 0 ).value == 0xFFFF0000)
1240{
1241end = x + 1;
1242
1243if( (font->chars[count] = malloc(sizeof(pixmap_t)) ) )
1244{
1245font->chars[count]->width = ( end - start) - 1;
1246font->chars[count]->height = font->height;
1247
1248if ( ( font->chars[count]->pixels = malloc( font->chars[count]->width * data->image->height * 4) ) )
1249{
1250space += ( font->chars[count]->width * data->image->height * 4 );
1251// we skip the first line because there are just the red pixels for the char width
1252for( y = 1; y< (font->height); y++)
1253{
1254for( x2 = start, x3 = 0; x2 < end; x2++, x3++)
1255{
1256pixel( font->chars[count], x3, y ) = pixel( data->image, x2, y );
1257}
1258}
1259
1260// check if font is monospaced
1261if( ( count > 0 ) && ( font->width != font->chars[count]->width ) )
1262monospaced = true;
1263
1264font->width = font->chars[count]->width;
1265
1266count++;
1267}
1268}
1269}
1270}
1271
1272if(monospaced)
1273font->width = 0;
1274
1275return 0;
1276}
1277
1278void colorFont(font_t *font, uint32_t color)
1279{
1280if( !color )
1281return;
1282
1283int x, y, width, height;
1284int count = 0;
1285pixel_t *buff;
1286
1287while( font->chars[count++] )
1288{
1289width = font->chars[count-1]->width;
1290height = font->chars[count-1]->height;
1291for( y = 0; y < height; y++ )
1292{
1293for( x = 0; x < width; x++ )
1294{
1295buff = &(pixel( font->chars[count-1], x, y ));
1296if( buff->ch.a )
1297{
1298buff->ch.r = (color & 0xFFFF0000) >> 16;
1299buff->ch.g = (color & 0xFF00FF00) >> 8;
1300buff->ch.b = (color & 0xFF0000FF);
1301}
1302}
1303}
1304}
1305}
1306
1307void makeRoundedCorners(pixmap_t *p)
1308{
1309int x,y;
1310int width=p->width-1;
1311int height=p->height-1;
1312
1313// 10px rounded corner alpha values
1314uint8_t roundedCorner[10][10] =
1315{
1316{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x80, 0xC0, 0xFF},
1317{ 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xFF, 0xFF, 0xFF, 0xFF},
1318{ 0x00, 0x00, 0x00, 0x40, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1319{ 0x00, 0x00, 0x40, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1320{ 0x00, 0x40, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1321{ 0x00, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1322{ 0x40, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1323{ 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1324{ 0xC0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1325{ 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}
1326};
1327
1328uint8_t alpha=0;
1329
1330for( y=0; y<10; y++)
1331{
1332for( x=0; x<10; x++)
1333{
1334// skip if the pixel should be visible
1335if(roundedCorner[y][x] != 0xFF)
1336{
1337alpha = ( roundedCorner[y][x] ? (uint8_t) (roundedCorner[y][x] * pixel(p, x, y).ch.a) / 255 : 0 );
1338// Upper left corner
1339pixel(p, x, y).ch.a = alpha;
1340
1341// upper right corner
1342pixel(p, width-x,y).ch.a = alpha;
1343
1344// lower left corner
1345pixel(p, x, height-y).ch.a = alpha;
1346
1347// lower right corner
1348pixel(p, width-x, height-y).ch.a = alpha;
1349}
1350}
1351}
1352}
1353
1354void showInfoBox(char *title, char *text)
1355{
1356int i, key, lines, visiblelines;
1357
1358int currentline=0;
1359int cnt=0;
1360int offset=0;
1361
1362if( !title || !text )
1363return;
1364
1365position_t pos_title = pos ( gui.infobox.vborder, gui.infobox.vborder );
1366
1367// calculate number of lines in the title
1368for ( i = 0, lines = 1; i<strlen(title); i++ )
1369if( title[i] == '\n')
1370lines++;
1371
1372// y position of text is lines in title * height of font
1373position_t pos_text = pos( pos_title.x , pos_title.y + ( font_console.height * lines ));
1374
1375// calculate number of lines in the text
1376for ( i=0, lines = 1; i<strlen(text); i++ )
1377if( text[i] == '\n')
1378lines++;
1379
1380// if text ends with \n strip off
1381if( text[i] == '\n' || text[i] == '\0')
1382lines--;
1383
1384visiblelines = ( ( gui.infobox.height - ( gui.infobox.vborder * 2 ) ) / font_console.height ) - 1;
1385
1386// lets display the text and allow scroll thru using up down / arrows
1387while(1)
1388{
1389// move to current line in text
1390for( offset = 0, i = 0; offset < strlen(text); offset++ )
1391{
1392if( currentline == i)
1393break;
1394if( text[offset] =='\n')
1395i++;
1396}
1397
1398// find last visible line in text and place \0
1399for( i = offset, cnt = 0; i < strlen(text); i++)
1400{
1401if(text[i]=='\n')
1402cnt++;
1403if ( cnt == visiblelines )
1404{
1405text[i]='\0';
1406break;
1407}
1408}
1409
1410fillPixmapWithColor( gui.infobox.pixmap, gui.infobox.bgcolor);
1411
1412makeRoundedCorners( gui.infobox.pixmap);
1413
1414// print the title if present
1415if( title )
1416drawStr(title, &font_console, gui.infobox.pixmap, pos_title);
1417
1418// print the text
1419drawStr( text + offset, &font_console, gui.infobox.pixmap, pos_text);
1420
1421// restore \n in text
1422if ( cnt == visiblelines )
1423text[i] = '\n';
1424
1425position_t pos_indicator = pos( gui.infobox.width - ( images[iTextScrollPrev].image->width - ( gui.infobox.vborder / 2) ), pos_text.y );
1426
1427// draw prev indicator
1428if(offset)
1429{
1430blend( images[iTextScrollPrev].image, gui.infobox.pixmap, centeredAt( images[iTextScrollPrev].image, pos_indicator ));
1431}
1432
1433// draw next indicator
1434if( lines > ( currentline + visiblelines ) )
1435{
1436pos_indicator.y = ( gui.infobox.height - ( ( images[iTextScrollNext].image->width + gui.infobox.vborder ) / 2 ) );
1437blend( images[iTextScrollNext].image, gui.infobox.pixmap, centeredAt( images[iTextScrollNext].image, pos_indicator ) );
1438}
1439
1440gui.bootprompt.draw = false;
1441gui.infobox.draw = true;
1442gui.redraw = true;
1443
1444updateVRAM();
1445
1446key = getc();
1447
1448if( key == kUpArrowkey )
1449if( currentline > 0 )
1450currentline--;
1451
1452if( key == kDownArrowkey )
1453if( lines > ( currentline + visiblelines ) )
1454currentline++;
1455
1456if( key == kEscapeKey || key == 'q' || key == 'Q')
1457{
1458gui.infobox.draw = false;
1459gui.redraw = true;
1460updateVRAM();
1461break;
1462}
1463}
1464}
1465
1466void animateProgressBar()
1467{
1468int y;
1469
1470if( time18() > lasttime)
1471{
1472lasttime = time18();
1473
1474pixmap_t *buffBar = images[iProgressBar].image;
1475
1476uint32_t buff = buffBar->pixels[0].value;
1477
1478memcpy( buffBar->pixels, buffBar->pixels + 1, ( (buffBar->width*buffBar->height) - 1 ) * 4 );
1479
1480for( y = buffBar->height - 1; y > 0; y--)
1481pixel(buffBar, buffBar->width - 1, y) = pixel(buffBar, buffBar->width - 1, y - 1);
1482
1483pixel(buffBar, buffBar->width-1, 0).value = buff;
1484}
1485}
1486
1487void drawProgressBar(pixmap_t *blendInto, uint16_t width, position_t p, uint8_t progress)
1488{
1489if(progress>100)
1490return;
1491
1492p.x = ( p.x - ( width / 2 ) );
1493
1494int todraw = (width * progress) / 100;
1495
1496pixmap_t *buff = images[iProgressBar].image;
1497pixmap_t *buffBG = images[iProgressBarBackground].image;
1498if(!buff || !buffBG)
1499return;
1500
1501pixmap_t progressbar;
1502progressbar.pixels=malloc(width * 4 * buff->height);
1503if(!progressbar.pixels)
1504return;
1505
1506progressbar.width = width;
1507progressbar.height = buff->height;
1508
1509int x=0,x2=0,y=0;
1510
1511for(y=0; y<buff->height; y++)
1512{
1513for(x=0; x<todraw; x++, x2++)
1514{
1515if(x2 == (buff->width-1)) x2=0;
1516pixel(&progressbar, x,y).value = pixel(buff, x2,y).value;
1517}
1518x2=0;
1519}
1520
1521for(y=0; y<buff->height; y++)
1522{
1523for(x=todraw, x2 = 0; x < width - 1; x++, x2++)
1524{
1525if(x2 == (buffBG->width -2 )) x2 = 0;
1526pixel(&progressbar, x,y).value = pixel(buffBG, x2,y).value;
1527}
1528if(progress < 100)
1529pixel(&progressbar, width - 1, y).value = pixel(buffBG, buffBG->width - 1, y).value;
1530if(progress == 0)
1531pixel(&progressbar, 0, y).value = pixel(buffBG, buffBG->width - 1, y).value;
1532x2=0;
1533}
1534
1535blend(&progressbar, blendInto, p);
1536animateProgressBar();
1537free(progressbar.pixels);
1538}
1539
1540void drawInfoMenuItems()
1541{
1542int i,n;
1543
1544position_t position;
1545
1546pixmap_t *selection = images[iMenuSelection].image;
1547
1548pixmap_t *pbuff;
1549
1550fillPixmapWithColor(gui.menu.pixmap, gui.menu.bgcolor);
1551
1552makeRoundedCorners(gui.menu.pixmap);
1553
1554uint8_t offset = infoMenuNativeBoot ? 0 : infoMenuItemsCount - 1;
1555
1556position = pos(0,0);
1557
1558for ( i = 0, n = iMenuBoot; i < infoMenuItemsCount; i++, n++)
1559{
1560if (i == infoMenuSelection)
1561blend(selection, gui.menu.pixmap, position);
1562
1563pbuff = images[n].image;
1564if (offset && i >= INFOMENU_NATIVEBOOT_START && i <= INFOMENU_NATIVEBOOT_END)
1565blend( images[n + (iMenuHelp - iMenuBoot)].image , gui.menu.pixmap,
1566pos((position.x + (gui.menu.hborder / 2)), position.y + ((selection->height - pbuff->height) / 2)));
1567else
1568blend( pbuff, gui.menu.pixmap,
1569pos((position.x + (gui.menu.hborder / 2)), position.y + ((selection->height - pbuff->height) / 2)));
1570
1571drawStr(infoMenuItems[i].text, &font_console, gui.menu.pixmap,
1572pos(position.x + (pbuff->width + gui.menu.hborder),
1573position.y + ((selection->height - font_console.height) / 2)));
1574position.y += images[iMenuSelection].image->height;
1575
1576}
1577
1578gui.redraw = true;
1579}
1580
1581int drawInfoMenu()
1582{
1583drawInfoMenuItems();
1584
1585gui.menu.draw = true;
1586
1587updateVRAM();
1588
1589return 1;
1590}
1591
1592int updateInfoMenu(int key)
1593{
1594switch (key)
1595{
1596
1597case kUpArrowkey:// up arrow
1598if (infoMenuSelection > 0)
1599{
1600if(!infoMenuNativeBoot && infoMenuSelection == INFOMENU_NATIVEBOOT_END + 1)
1601infoMenuSelection -= 4;
1602
1603else
1604infoMenuSelection--;
1605drawInfoMenuItems();
1606updateVRAM();
1607
1608} else {
1609
1610gui.menu.draw = false;
1611gui.redraw = true;
1612
1613updateVRAM();
1614
1615return CLOSE_INFO_MENU;
1616}
1617break;
1618
1619case kDownArrowkey:// down arrow
1620if (infoMenuSelection < infoMenuItemsCount - 1)
1621{
1622if(!infoMenuNativeBoot && infoMenuSelection == INFOMENU_NATIVEBOOT_START - 1)
1623infoMenuSelection += 4;
1624else
1625infoMenuSelection++;
1626drawInfoMenuItems();
1627updateVRAM();
1628}
1629break;
1630
1631case kReturnKey:
1632key = 0;
1633if( infoMenuSelection == MENU_SHOW_MEMORY_INFO )
1634showInfoBox( "Memory Info. Press q to quit.\n", getMemoryInfoString());
1635
1636else if( infoMenuSelection == MENU_SHOW_VIDEO_INFO )
1637showInfoBox( getVBEInfoString(), getVBEModeInfoString() );
1638
1639else if( infoMenuSelection == MENU_SHOW_HELP )
1640showHelp();
1641
1642else
1643{
1644int buff = infoMenuSelection;
1645infoMenuSelection = 0;
1646return buff;
1647}
1648break;
1649}
1650return DO_NOT_BOOT;
1651}
1652
1653uint16_t bootImageWidth = 0;
1654uint16_t bootImageHeight = 0;
1655uint8_t *bootImageData = NULL;
1656static bool usePngImage = true;
1657
1658//==========================================================================
1659// loadBootGraphics
1660static void loadBootGraphics(void)
1661{
1662if (bootImageData != NULL) {
1663return;
1664}
1665
1666#ifdef EMBED_THEME
1667if ((loadEmbeddedPngImage(__boot_png, __boot_png_len, &bootImageWidth, &bootImageHeight, &bootImageData)) != 0) {
1668usePngImage = false;
1669}
1670#else
1671char dirspec[256];
1672
1673if ((strlen(theme_name) + 24) > sizeof(dirspec)) {
1674usePngImage = false;
1675return;
1676}
1677sprintf(dirspec, "/Extra/Themes/%s/boot.png", theme_name);
1678if (loadPngImage(dirspec, &bootImageWidth, &bootImageHeight, &bootImageData) != 0) {
1679usePngImage = false;
1680}
1681#endif
1682}
1683
1684//==========================================================================
1685// drawBootGraphics
1686void drawBootGraphics(void)
1687{
1688int pos;
1689int length;
1690const char *dummyVal;
1691bool legacy_logo;
1692uint16_t x, y;
1693
1694if (getBoolForKey("Legacy Logo", &legacy_logo, &bootInfo->bootConfig) && legacy_logo) {
1695usePngImage = false;
1696} else if (bootImageData == NULL) {
1697loadBootGraphics();
1698}
1699
1700// parse screen size parameters
1701if (getIntForKey("boot_width", &pos, &bootInfo->themeConfig)) {
1702screen_params[0] = pos;
1703} else {
1704screen_params[0] = DEFAULT_SCREEN_WIDTH;
1705}
1706if (getIntForKey("boot_height", &pos, &bootInfo->themeConfig)) {
1707screen_params[1] = pos;
1708} else {
1709screen_params[1] = DEFAULT_SCREEN_HEIGHT;
1710}
1711screen_params[2] = 32;
1712
1713gui.screen.width = screen_params[0];
1714gui.screen.height = screen_params[1];
1715
1716// find best matching vesa mode for our requested width & height
1717getGraphicModeParams(screen_params);
1718
1719setVideoMode(GRAPHICS_MODE, 0);
1720
1721if (getValueForKey("-checkers", &dummyVal, &length, &bootInfo->bootConfig)) {
1722drawCheckerBoard();
1723} else {
1724// Fill the background to 75% grey (same as BootX).
1725drawColorRectangle(0, 0, screen_params[0], screen_params[1], 0x01);
1726}
1727if ((bootImageData) && (usePngImage)) {
1728x = (screen_params[0] - MIN(bootImageWidth, screen_params[0])) / 2;
1729y = (screen_params[1] - MIN(bootImageHeight, screen_params[1])) / 2;
1730
1731// Draw the image in the center of the display.
1732blendImage(x, y, bootImageWidth, bootImageHeight, bootImageData);
1733} else {
1734uint8_t *appleBootPict;
1735bootImageData = NULL;
1736bootImageWidth = kAppleBootWidth;
1737bootImageHeight = kAppleBootHeight;
1738
1739// Prepare the data for the default Apple boot image.
1740appleBootPict = (uint8_t *) decodeRLE(gAppleBootPictRLE, kAppleBootRLEBlocks, bootImageWidth * bootImageHeight);
1741if (appleBootPict) {
1742convertImage(bootImageWidth, bootImageHeight, appleBootPict, &bootImageData);
1743if (bootImageData) {
1744x = (screen_params[0] - MIN(kAppleBootWidth, screen_params[0])) / 2;
1745y = (screen_params[1] - MIN(kAppleBootHeight, screen_params[1])) / 2;
1746drawDataRectangle(x, y, kAppleBootWidth, kAppleBootHeight, bootImageData);
1747free(bootImageData);
1748}
1749free(appleBootPict);
1750}
1751}
1752}
1753

Archive Download this file

Revision: 85