Chameleon

Chameleon Svn Source Tree

Root/branches/azimutz/Chazi/i386/boot2/gui.c

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

Archive Download this file

Revision: 472