Chameleon

Chameleon Svn Source Tree

Root/branches/meklort/i386/boot2/gui.c

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

Archive Download this file

Revision: 145