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

Archive Download this file

Revision: 515