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