Chameleon

Chameleon Svn Source Tree

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

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

Archive Download this file

Revision: 519