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#ifdef CONFIG_EMBED_THEME
17#include "art.h"
18#endif
19
20#define IMG_REQUIRED -1
21#define LOADPNG(img, alt_img) if (loadThemeImage(#img, alt_img) != 0) { return 1; }
22#define VIDEO(x) (bootArgs->Video.v_ ## x)
23#define vram VIDEO(baseAddr)
24
25intgDeviceCount = 0;
26intlasttime = 0; // we need this for animating maybe
27
28static const char *theme_name = kDefaultThemeName; // #define'ed on boot.h
29
30/*
31 * ATTENTION: the enum and the following array images[] MUST match !!!
32 */
33enum {
34 iBackground = 0,
35 iLogo,
36
37 iDeviceGeneric,
38 iDeviceGeneric_o,
39 iDeviceHFS,
40 iDeviceHFS_o,
41 iDeviceHFSRAID,
42 iDeviceHFSRAID_o,
43 iDeviceEXT3,
44 iDeviceEXT3_o,
45 iDeviceFAT,
46 iDeviceFAT_o,
47 iDeviceFAT16,
48 iDeviceFAT16_o,
49 iDeviceFAT32,
50 iDeviceFAT32_o,
51 iDeviceNTFS,
52 iDeviceNTFS_o,
53 iDeviceCDROM,
54 iDeviceCDROM_o,
55
56 iSelection,
57 iDeviceScrollPrev,
58 iDeviceScrollNext,
59
60 iMenuBoot,
61 iMenuVerbose,
62 iMenuIgnoreCaches,
63 iMenuSingleUser,
64 iMenuMemoryInfo,
65 iMenuVideoInfo,
66 iMenuHelp,
67 iMenuVerboseDisabled,
68 iMenuIgnoreCachesDisabled,
69 iMenuSingleUserDisabled,
70 iMenuSelection,
71
72 iProgressBar,
73 iProgressBarBackground,
74
75 iTextScrollPrev,
76 iTextScrollNext,
77
78 iFontConsole,
79 iFontSmall,
80};
81
82image_t images[] = {
83 {.name = "background", .image = NULL},
84 {.name = "logo", .image = NULL},
85
86 {.name = "device_generic", .image = NULL},
87 {.name = "device_generic_o", .image = NULL},
88 {.name = "device_hfsplus", .image = NULL},
89 {.name = "device_hfsplus_o", .image = NULL},
90 {.name = "device_hfsraid", .image = NULL},
91 {.name = "device_hfsraid_o", .image = NULL},
92 {.name = "device_ext3", .image = NULL},
93 {.name = "device_ext3_o", .image = NULL},
94 {.name = "device_fat", .image = NULL},
95 {.name = "device_fat_o", .image = NULL},
96 {.name = "device_fat16", .image = NULL},
97 {.name = "device_fat16_o", .image = NULL},
98 {.name = "device_fat32", .image = NULL},
99 {.name = "device_fat32_o", .image = NULL},
100 {.name = "device_ntfs", .image = NULL},
101 {.name = "device_ntfs_o", .image = NULL},
102 {.name = "device_cdrom", .image = NULL},
103 {.name = "device_cdrom_o", .image = NULL},
104
105 {.name = "device_selection", .image = NULL},
106 {.name = "device_scroll_prev", .image = NULL},
107 {.name = "device_scroll_next", .image = NULL},
108
109 {.name = "menu_boot", .image = NULL},
110 {.name = "menu_verbose", .image = NULL},
111 {.name = "menu_ignore_caches", .image = NULL},
112 {.name = "menu_single_user", .image = NULL},
113 {.name = "menu_memory_info", .image = NULL},
114 {.name = "menu_video_info", .image = NULL},
115 {.name = "menu_help", .image = NULL},
116 {.name = "menu_verbose_disabled", .image = NULL},
117 {.name = "menu_ignore_caches_disabled", .image = NULL},
118 {.name = "menu_single_user_disabled", .image = NULL},
119 {.name = "menu_selection", .image = NULL},
120
121 {.name = "progress_bar", .image = NULL},
122 {.name = "progress_bar_background", .image = NULL},
123
124 {.name = "text_scroll_prev", .image = NULL},
125 {.name = "text_scroll_next", .image = NULL},
126
127 {.name = "font_console", .image = NULL},
128 {.name = "font_small", .image = NULL},
129};
130
131int imageCnt = 0;
132
133//extern intgDeviceCount;
134//extern intselectIndex; Azi: not in use
135
136extern MenuItem *menuItems;
137
138//char prompt[BOOT_STRING_LEN];
139extern char gBootArgs[BOOT_STRING_LEN];
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 CONFIG_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
187// generated manualy, 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[128]; //Azi: testing
222int i;
223#ifdef CONFIG_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, "bt(0,0)/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 CONFIG_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 CONFIG_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; //Azi: allocation error while testing "nVidia GT 220"
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{
675intvalW, valH, len; //Azi: messing... AR
676chardirspec[128]; //Azi: testing
677
678getValueForKey( kThemeNameKey, &theme_name, &len, &bootInfo->bootConfig );
679if ((strlen(theme_name) + 27) > sizeof(dirspec))
680{
681return 1;
682}
683
684sprintf(dirspec, "bt(0,0)/Extra/Themes/%s/theme.plist", theme_name);
685
686if (loadConfigFile(dirspec, &bootInfo->themeConfig) != 0)
687{
688#ifdef CONFIG_EMBED_THEME
689config_file_t*config;
690
691config = &bootInfo->themeConfig;
692if (ParseXMLFile((char *)__theme_plist, &config->dictionary) != 0)
693{
694return 1;
695}
696#else
697return 1;
698#endif
699}
700else
701{
702//Azi: just messing around...
703getIntForKey("screen_width", &valW, &bootInfo->themeConfig);
704getIntForKey("screen_height", &valH, &bootInfo->themeConfig);
705}
706
707// AutoResolution
708if (gAutoResolution == true)
709{
710screen_params[0] = paramsAR[0];
711screen_params[1] = paramsAR[1];
712}
713else
714{
715if (valW > 0)
716{
717screen_params[0] = valW;
718}
719
720if (valH > 0)
721{
722screen_params[1] = valH;
723}
724/* parse screen size parameters
725if (getIntForKey("screen_width", &val, &bootInfo->themeConfig) && val > 0)
726{
727screen_params[0] = val;
728}
729
730if (getIntForKey("screen_height", &val, &bootInfo->themeConfig) && val > 0)
731{
732screen_params[1] = val;
733}*/
734//Azi: how about using default values? - think Azi...
735}
736
737// Initalizing GUI strucutre.
738bzero(&gui, sizeof(gui_t));
739
740// find best matching vesa mode for our requested width & height
741//loadConfigFile(dirspec, &bootInfo->themeConfig); //Azi:autoresolution - check this later.
742getGraphicModeParams(screen_params);
743
744// set our screen structure with the mode width & height
745gui.screen.width = screen_params[0];
746gui.screen.height = screen_params[1];
747
748PRINT("Theme resolution: %dx%d (theme.plist)\n", valW, valH);
749PRINT("Found mode %dx%d in VESA Table\n", gui.screen.width, gui.screen.height);
750//Azi: check why is this printing... (reloadAutoRes/debug)
751
752// load graphics otherwise fail and return
753if (loadGraphics() == 0)
754{
755loadThemeValues(&bootInfo->themeConfig);
756colorFont(&font_small, gui.screen.font_small_color);
757colorFont(&font_console, gui.screen.font_console_color);
758
759// create the screen & window buffers
760if (createBackBuffer(&gui.screen) == 0)
761{
762if (createWindowBuffer(&gui.screen) == 0)
763{
764if (createWindowBuffer(&gui.devicelist) == 0)
765{
766if (createWindowBuffer(&gui.bootprompt) == 0)
767{
768if (createWindowBuffer(&gui.infobox) == 0)
769{
770if (createWindowBuffer(&gui.menu) == 0)
771{
772
773#ifdef AUTORES_DEBUG
774pause();
775#endif
776gui.logo.draw = true;
777drawBackground();
778// lets copy the screen into the back buffer
779memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 );
780setVideoMode( GRAPHICS_MODE, 0 );
781gui.initialised = true;
782return 0;
783}
784else printf("createWindowBuffer(&gui.menu) Failed\n");
785}
786else printf("createWindowBuffer(&gui.infobox) Failed\n");
787}
788else printf("createWindowBuffer(&gui.bootprompt) Failed\n");
789}
790else printf("createWindowBuffer(&gui.devicelist) Failed\n");
791}
792else printf("createWindowBuffer(&gui.screen) Failed\n");
793}
794else printf("createBackBuffer(&gui.screen) Failed\n");
795}
796else printf("loadGraphics() Failed\n");
797
798return 1;
799}
800
801void drawDeviceIcon(BVRef device, pixmap_t *buffer, position_t p, bool isSelected)
802{
803int devicetype;
804
805if( diskIsCDROM(device) )
806devicetype = iDeviceCDROM;// Use CDROM icon
807else
808{
809switch (device->part_type)
810{
811case kPartitionTypeHFS:
812
813// Use HFS or HFSRAID icon depending on bvr flags.
814devicetype = (device->flags & kBVFlagBooter) ? iDeviceHFSRAID : iDeviceHFS;
815break;
816
817case kPartitionTypeHPFS:
818devicetype = iDeviceNTFS;// Use HPFS / NTFS icon
819break;
820
821case kPartitionTypeFAT16:
822devicetype = iDeviceFAT16;// Use FAT16 icon
823break;
824
825case kPartitionTypeFAT32:
826devicetype = iDeviceFAT32;// Use FAT32 icon
827break;
828
829case kPartitionTypeEXT3:
830devicetype = iDeviceEXT3;// Use EXT2/3 icon
831break;
832
833default:
834devicetype = iDeviceGeneric;// Use Generic icon
835break;
836}
837}
838
839// Draw the selection image and use the next (device_*_o) image for the selected item.
840 if (isSelected)
841{
842blend(images[iSelection].image, buffer, centeredAt(images[iSelection].image, p));
843devicetype++;
844}
845
846// draw icon
847blend( images[devicetype].image, buffer, centeredAt( images[devicetype].image, p ));
848
849p.y += (images[iSelection].image->height / 2) + font_console.chars[0]->height;
850
851// draw volume label
852drawStrCenteredAt( device->label, &font_small, buffer, p);
853
854}
855
856void drawDeviceList (int start, int end, int selection)
857{
858inti;
859booldebugInfo = false; //Azi:debuginfo
860extern bool showBootBanner; //||
861position_tp, p_prev, p_next;
862
863//uint8_tmaxDevices = MIN( gui.maxdevices, menucount );
864
865fillPixmapWithColor( gui.devicelist.pixmap, gui.devicelist.bgcolor);
866
867makeRoundedCorners( gui.devicelist.pixmap);
868
869switch (gui.layout)
870{
871
872case VerticalLayout:
873p.x = (gui.devicelist.width /2);
874p.y = ( ( images[iSelection].image->height / 2 ) + images[iDeviceScrollPrev].image->height + gui.devicelist.iconspacing );
875
876// place scroll indicators at top & bottom edges
877p_prev = pos ( gui.devicelist.width / 2 , gui.devicelist.iconspacing );
878p_next = pos ( p_prev.x, gui.devicelist.height - gui.devicelist.iconspacing );
879
880break;
881
882default:// use Horizontal layout as the default
883
884case HorizontalLayout:
885p.x = (gui.devicelist.width - ( gui.devicelist.width / gui.maxdevices ) * gui.maxdevices ) / 2 + ( images[iSelection].image->width / 2) + images[iDeviceScrollPrev].image->width + gui.devicelist.iconspacing;
886p.y = ((gui.devicelist.height - font_console.chars[0]->height ) - images[iSelection].image->height) / 2 + ( images[iSelection].image->height / 2 );
887
888// place scroll indicators at left & right edges
889p_prev = pos ( images[iDeviceScrollPrev].image->width / 2 + gui.devicelist.iconspacing / 2, gui.devicelist.height / 2 );
890p_next = pos ( gui.devicelist.width - ( images[iDeviceScrollNext].image->width / 2 + gui.devicelist.iconspacing / 2), gui.devicelist.height / 2 );
891
892break;
893
894}
895
896// draw visible device icons
897for (i = 0; i < gui.maxdevices; i++)
898{
899BVRef param = menuItems[start + i].param;
900
901 bool isSelected = ((start + i) == selection) ? true : false;
902if (isSelected)
903{
904 if (param->flags & kBVFlagNativeBoot)
905 {
906 infoMenuNativeBoot = true;
907 }
908 else
909 {
910 infoMenuNativeBoot = false;
911 if(infoMenuSelection >= INFOMENU_NATIVEBOOT_START && infoMenuSelection <= INFOMENU_NATIVEBOOT_END)
912 infoMenuSelection = 0;
913 }
914
915if(gui.menu.draw)
916drawInfoMenuItems();
917
918//Azi: make this info more accessible.
919getBoolForKey(kDebugInfoKey, &debugInfo, &bootInfo->bootConfig);
920
921if (debugInfo && showBootBanner)
922{
923gui.debug.cursor = pos( 10, 100);
924dprintf( &gui.screen, "label: %s\n", param->label );
925dprintf( &gui.screen, "biosdev: 0x%x\n", param->biosdev );
926dprintf( &gui.screen, "type: 0x%x\n", param->type );
927dprintf( &gui.screen, "flags: 0x%x\n", param->flags );
928dprintf( &gui.screen, "part_no: %d\n", param->part_no );
929dprintf( &gui.screen, "part_boff: 0x%x\n", param->part_boff );
930dprintf( &gui.screen, "part_type: 0x%x\n", param->part_type );
931dprintf( &gui.screen, "bps: 0x%x\n", param->bps );
932dprintf( &gui.screen, "name: %s\n", param->name );
933dprintf( &gui.screen, "type_name: %s\n", param->type_name );
934dprintf( &gui.screen, "modtime: %d\n", param->modTime );
935dprintf( &gui.screen, "width: %d\n", gui.screen.width );
936dprintf( &gui.screen, "height: %d\n", gui.screen.height );
937dprintf( &gui.screen, "attr: 0x%x\n", gui.screen.attr );
938dprintf( &gui.screen, "mm: %d\n", gui.screen.mm );
939}
940}
941
942drawDeviceIcon( param, gui.devicelist.pixmap, p, isSelected);
943
944if (gui.layout == HorizontalLayout)
945{
946p.x += images[iSelection].image->width + gui.devicelist.iconspacing;
947}
948if (gui.layout == VerticalLayout)
949{
950p.y += ( images[iSelection].image->height + font_console.chars[0]->height + gui.devicelist.iconspacing );
951}
952}
953
954// draw prev indicator
955if(start)
956blend( images[iDeviceScrollPrev].image, gui.devicelist.pixmap, centeredAt( images[iDeviceScrollPrev].image, p_prev ) );
957
958// draw next indicator
959if( end < gDeviceCount - 1 )
960blend( images[iDeviceScrollNext].image, gui.devicelist.pixmap, centeredAt( images[iDeviceScrollNext].image, p_next ) );
961
962gui.redraw = true;
963
964updateVRAM();
965
966}
967
968void clearGraphicBootPrompt()
969{
970// clear text buffer
971//prompt[0] = '\0';
972//prompt_pos=0;
973
974
975if(gui.bootprompt.draw == true )
976{
977gui.bootprompt.draw = false;
978gui.redraw = true;
979// this causes extra frames to be drawn
980//updateVRAM();
981}
982
983return;
984}
985
986void updateGraphicBootPrompt()
987{
988fillPixmapWithColor( gui.bootprompt.pixmap, gui.bootprompt.bgcolor);
989
990makeRoundedCorners( gui.bootprompt.pixmap);
991
992position_t p_text = pos( gui.bootprompt.hborder , ( ( gui.bootprompt.height - font_console.chars[0]->height) ) / 2 );
993
994// print the boot prompt text
995drawStr(prompt_text, &font_console, gui.bootprompt.pixmap, p_text);
996
997// get the position of the end of the boot prompt text to display user input
998position_t p_prompt = pos( p_text.x + ( ( strlen(prompt_text) ) * font_console.chars[0]->width ), p_text.y );
999
1000drawStr( gBootArgs, &font_console, gui.bootprompt.pixmap, p_prompt);
1001
1002gui.menu.draw = false;
1003gui.bootprompt.draw = true;
1004gui.redraw = true;
1005
1006updateVRAM();
1007
1008return;
1009}
1010
1011inline
1012void vramwrite (void *data, int width, int height)
1013{
1014if (VIDEO (depth) == 32 && VIDEO (rowBytes) == gui.backbuffer->width * 4)
1015memcpy((uint8_t *)vram, gui.backbuffer->pixels, VIDEO (rowBytes)*VIDEO (height));
1016else
1017{
1018uint32_t r, g, b;
1019int i, j;
1020for (i = 0; i < VIDEO (height); i++)
1021for (j = 0; j < VIDEO (width); j++)
1022{
1023b = ((uint8_t *) data)[4*i*width + 4*j];
1024g = ((uint8_t *) data)[4*i*width + 4*j + 1];
1025r = ((uint8_t *) data)[4*i*width + 4*j + 2];
1026switch (VIDEO (depth))
1027{
1028case 32:
1029*(uint32_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*4) = (b&0xff) | ((g&0xff)<<8) | ((r&0xff)<<16);
1030break;
1031case 24:
1032*(uint32_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*3) = ((*(uint32_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*3))&0xff000000)
1033| (b&0xff) | ((g&0xff)<<8) | ((r&0xff)<<16);
1034break;
1035case 16:
1036// Somehow 16-bit is always 15-bits really
1037//*(uint16_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*2) = ((b&0xf8)>>3) | ((g&0xfc)<<3) | ((r&0xf8)<<8);
1038//break;
1039case 15:
1040*(uint16_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*2) = ((b&0xf8)>>3) | ((g&0xf8)<<2) | ((r&0xf8)<<7);
1041break;
1042}
1043}
1044}
1045}
1046
1047void updateVRAM()
1048{
1049if (gui.redraw)
1050{
1051if (gui.devicelist.draw)
1052blend( gui.devicelist.pixmap, gui.backbuffer, gui.devicelist.pos );
1053
1054if (gui.bootprompt.draw)
1055blend( gui.bootprompt.pixmap, gui.backbuffer, gui.bootprompt.pos );
1056
1057if (gui.menu.draw)
1058blend( gui.menu.pixmap, gui.backbuffer, gui.menu.pos );
1059
1060if (gui.infobox.draw)
1061blend( gui.infobox.pixmap, gui.backbuffer, gui.infobox.pos );
1062}
1063
1064vramwrite ( gui.backbuffer->pixels, gui.backbuffer->width, gui.backbuffer->height );
1065
1066if (gui.redraw)
1067{
1068memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 );
1069gui.redraw = false;
1070}
1071}
1072
1073struct putc_info { //Azi: exists on console.c & printf.c
1074 char * str;
1075 char * last_str;
1076};
1077
1078static int
1079sputc(int c, struct putc_info * pi) // same as above
1080{
1081 if (pi->last_str)
1082 if (pi->str == pi->last_str) {
1083 *(pi->str) = '\0';
1084 return 0;
1085 }
1086 *(pi->str)++ = c;
1087 return c;
1088}
1089
1090int gprintf( window_t * window, const char * fmt, ...)
1091{
1092char *formattedtext;
1093
1094va_list ap;
1095
1096struct putc_info pi;
1097
1098if ((formattedtext = malloc(1024)) != NULL) {
1099// format the text
1100va_start(ap, fmt);
1101pi.str = formattedtext;
1102pi.last_str = 0;
1103prf(fmt, ap, sputc, &pi);
1104*pi.str = '\0';
1105va_end(ap);
1106
1107position_torigin, cursor, bounds;
1108
1109int i;
1110int character;
1111
1112origin.x = MAX( window->cursor.x, window->hborder );
1113origin.y = MAX( window->cursor.y, window->vborder );
1114
1115bounds.x = ( window->width - window->hborder );
1116bounds.y = ( window->height - window->vborder );
1117
1118cursor = origin;
1119
1120font_t *font = &font_console;
1121
1122for( i=0; i< strlen(formattedtext); i++ )
1123{
1124character = formattedtext[i];
1125
1126character -= 32;
1127
1128// newline ?
1129if( formattedtext[i] == '\n' )
1130{
1131cursor.x = window->hborder;
1132cursor.y += font->height;
1133
1134if ( cursor.y > bounds.y )
1135cursor.y = origin.y;
1136
1137continue;
1138}
1139
1140// tab ?
1141if( formattedtext[i] == '\t' )
1142cursor.x += ( font->chars[0]->width * 5 );
1143
1144// draw the character
1145if( font->chars[character])
1146blend(font->chars[character], window->pixmap, cursor);
1147
1148cursor.x += font->chars[character]->width;
1149
1150// check x pos and do newline
1151if ( cursor.x > bounds.x )
1152{
1153cursor.x = origin.x;
1154cursor.y += font->height;
1155}
1156
1157// check y pos and reset to origin.y
1158if ( cursor.y > bounds.y )
1159cursor.y = origin.y;
1160}
1161
1162// update cursor postition
1163window->cursor = cursor;
1164
1165free(formattedtext);
1166
1167return 0;
1168
1169}
1170return 1;
1171}
1172
1173int dprintf( window_t * window, const char * fmt, ...)
1174{
1175char *formattedtext;
1176
1177va_list ap;
1178
1179//window = &gui.debug;
1180
1181struct putc_info pi;
1182
1183if ((formattedtext = malloc(1024)) != NULL) {
1184// format the text
1185va_start(ap, fmt);
1186pi.str = formattedtext;
1187pi.last_str = 0;
1188prf(fmt, ap, sputc, &pi);
1189*pi.str = '\0';
1190va_end(ap);
1191
1192position_torigin, cursor, bounds;
1193
1194int i;
1195int character;
1196
1197origin.x = MAX( gui.debug.cursor.x, window->hborder );
1198origin.y = MAX( gui.debug.cursor.y, window->vborder );
1199
1200bounds.x = ( window->width - window->hborder );
1201bounds.y = ( window->height - window->vborder );
1202
1203cursor = origin;
1204
1205font_t *font = &font_console;
1206
1207for( i=0; i< strlen(formattedtext); i++ )
1208{
1209character = formattedtext[i];
1210
1211character -= 32;
1212
1213// newline ?
1214if( formattedtext[i] == '\n' )
1215{
1216cursor.x = window->hborder;
1217cursor.y += font->height;
1218
1219if ( cursor.y > bounds.y )
1220cursor.y = origin.y;
1221
1222continue;
1223}
1224
1225// tab ?
1226if( formattedtext[i] == '\t' )
1227cursor.x += ( font->chars[0]->width * 5 );
1228
1229// draw the character
1230if( font->chars[character])
1231blend(font->chars[character], gui.backbuffer, cursor);
1232
1233cursor.x += font->chars[character]->width;
1234
1235// check x pos and do newline
1236if ( cursor.x > bounds.x )
1237{
1238cursor.x = origin.x;
1239cursor.y += font->height;
1240}
1241
1242// check y pos and reset to origin.y
1243if ( cursor.y > bounds.y )
1244cursor.y = origin.y;
1245}
1246
1247// update cursor postition
1248gui.debug.cursor = cursor;
1249
1250free(formattedtext);
1251
1252return 0;
1253
1254}
1255return 1;
1256}
1257
1258int vprf(const char * fmt, va_list ap)
1259{
1260int i;
1261int character;
1262
1263char *formattedtext;
1264window_t *window = &gui.screen;
1265struct putc_info pi;
1266
1267position_torigin, cursor, bounds;
1268font_t *font = &font_console;
1269
1270if ((formattedtext = malloc(1024)) != NULL) {
1271// format the text
1272pi.str = formattedtext;
1273pi.last_str = 0;
1274prf(fmt, ap, sputc, &pi);
1275*pi.str = '\0';
1276
1277origin.x = MAX( window->cursor.x, window->hborder );
1278origin.y = MAX( window->cursor.y, window->vborder );
1279bounds.x = ( window->width - ( window->hborder * 2 ) );
1280bounds.y = ( window->height - ( window->vborder * 2 ) );
1281cursor = origin;
1282
1283for( i=0; i< strlen(formattedtext); i++ )
1284{
1285character = formattedtext[i];
1286character -= 32;
1287
1288// newline ?
1289if( formattedtext[i] == '\n' )
1290{
1291cursor.x = window->hborder;
1292cursor.y += font->height;
1293if ( cursor.y > bounds.y )
1294{
1295gui.redraw = true;
1296updateVRAM();
1297cursor.y = window->vborder;
1298}
1299window->cursor.y = cursor.y;
1300continue;
1301}
1302
1303// tab ?
1304if( formattedtext[i] == '\t' )
1305{
1306cursor.x = ( cursor.x / ( font->chars[0]->width * 8 ) + 1 ) * ( font->chars[0]->width * 8 );
1307continue;
1308}
1309cursor.x += font->chars[character]->width;
1310
1311// check x pos and do newline
1312if ( cursor.x > bounds.x )
1313{
1314cursor.x = origin.x;
1315cursor.y += font->height;
1316}
1317
1318// check y pos and reset to origin.y
1319if ( cursor.y > ( bounds.y + font->chars[0]->height) )
1320{
1321gui.redraw = true;
1322updateVRAM();
1323cursor.y = window->vborder;
1324}
1325// draw the character
1326if( font->chars[character])
1327blend(font->chars[character], gui.backbuffer, cursor);
1328}
1329// save cursor postition
1330window->cursor.x = cursor.x;
1331updateVRAM();
1332free(formattedtext);
1333return 0;
1334}
1335return 1;
1336}
1337
1338void drawStr(char *ch, font_t *font, pixmap_t *blendInto, position_t p)
1339{
1340int i=0;
1341int y=0; // we need this to support multilines '\n'
1342int x=0;
1343
1344for(i=0;i<strlen(ch);i++)
1345{
1346int cha=(int)ch[i];
1347
1348cha-=32;
1349
1350// newline ?
1351if( ch[i] == '\n' )
1352{
1353x = 0;
1354y += font->height;
1355continue;
1356}
1357
1358// tab ?
1359if( ch[i] == '\t' )
1360x+=(font->chars[0]->width*5);
1361
1362if(font->chars[cha])
1363blend(font->chars[cha], blendInto, pos(p.x+x, p.y+y));
1364
1365x += font->chars[cha]->width;
1366}
1367}
1368
1369void drawStrCenteredAt(char *text, font_t *font, pixmap_t *blendInto, position_t p)
1370{
1371int i = 0;
1372int width = 0;
1373
1374// calculate the width in pixels
1375for(i=0;i<strlen(text);i++)
1376width += font->chars[text[i]-32]->width;
1377
1378p.x = ( p.x - ( width / 2 ) );
1379p.y = ( p.y - ( font->height / 2 ) );
1380
1381if ( p.x == -6 )
1382{
1383p.x = 0;
1384}
1385
1386for(i=0;i<strlen(text);i++)
1387{
1388int cha=(int)text[i];
1389
1390cha-=32;
1391
1392if(font->chars[cha])
1393{
1394blend(font->chars[cha], blendInto, p);
1395p.x += font->chars[cha]->width;
1396}
1397}
1398
1399}
1400
1401int initFont(font_t *font, image_t *data)
1402{
1403unsigned int x = 0, y = 0, x2 = 0, x3 = 0;
1404
1405int start = 0, end = 0, count = 0, space = 0;
1406
1407bool monospaced = false;
1408
1409font->height = data->image->height;
1410
1411for( x = 0; x < data->image->width; x++)
1412{
1413start = end;
1414
1415// if the pixel is red we've reached the end of the char
1416if( pixel( data->image, x, 0 ).value == 0xFFFF0000)
1417{
1418end = x + 1;
1419
1420if( (font->chars[count] = malloc(sizeof(pixmap_t)) ) )
1421{
1422font->chars[count]->width = ( end - start) - 1;
1423font->chars[count]->height = font->height;
1424
1425if ( ( font->chars[count]->pixels = malloc( font->chars[count]->width * data->image->height * 4) ) )
1426{
1427space += ( font->chars[count]->width * data->image->height * 4 );
1428// we skip the first line because there are just the red pixels for the char width
1429for( y = 1; y< (font->height); y++)
1430{
1431for( x2 = start, x3 = 0; x2 < end; x2++, x3++)
1432{
1433pixel( font->chars[count], x3, y ) = pixel( data->image, x2, y );
1434}
1435}
1436
1437// check if font is monospaced
1438if( ( count > 0 ) && ( font->width != font->chars[count]->width ) )
1439monospaced = true;
1440
1441font->width = font->chars[count]->width;
1442
1443count++;
1444}
1445}
1446}
1447}
1448
1449if(monospaced)
1450font->width = 0;
1451
1452return 0;
1453}
1454
1455void colorFont(font_t *font, uint32_t color)
1456{
1457if( !color )
1458return;
1459
1460int x, y, width, height;
1461int count = 0;
1462pixel_t *buff;
1463
1464while( font->chars[count++] )
1465{
1466width = font->chars[count-1]->width;
1467height = font->chars[count-1]->height;
1468for( y = 0; y < height; y++ )
1469{
1470for( x = 0; x < width; x++ )
1471{
1472buff = &(pixel( font->chars[count-1], x, y ));
1473if( buff->ch.a )
1474{
1475buff->ch.r = (color & 0xFFFF0000) >> 16;
1476buff->ch.g = (color & 0xFF00FF00) >> 8;
1477buff->ch.b = (color & 0xFF0000FF);
1478}
1479}
1480}
1481}
1482}
1483
1484void makeRoundedCorners(pixmap_t *p)
1485{
1486int x,y;
1487int width=p->width-1;
1488int height=p->height-1;
1489
1490// 10px rounded corner alpha values
1491uint8_t roundedCorner[10][10] =
1492{
1493{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x80, 0xC0, 0xFF},
1494{ 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xFF, 0xFF, 0xFF, 0xFF},
1495{ 0x00, 0x00, 0x00, 0x40, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1496{ 0x00, 0x00, 0x40, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1497{ 0x00, 0x40, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1498{ 0x00, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1499{ 0x40, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1500{ 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1501{ 0xC0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1502{ 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}
1503};
1504
1505uint8_t alpha=0;
1506
1507for( y=0; y<10; y++)
1508{
1509for( x=0; x<10; x++)
1510{
1511// skip if the pixel should be visible
1512if(roundedCorner[y][x] != 0xFF)
1513{
1514alpha = ( roundedCorner[y][x] ? (uint8_t) (roundedCorner[y][x] * pixel(p, x, y).ch.a) / 255 : 0 );
1515// Upper left corner
1516pixel(p, x, y).ch.a = alpha;
1517
1518// upper right corner
1519pixel(p, width-x,y).ch.a = alpha;
1520
1521// lower left corner
1522pixel(p, x, height-y).ch.a = alpha;
1523
1524// lower right corner
1525pixel(p, width-x, height-y).ch.a = alpha;
1526}
1527}
1528}
1529}
1530
1531void showInfoBox(char *title, char *text)
1532{
1533int i, key, lines, visiblelines;
1534
1535int currentline=0;
1536int cnt=0;
1537int offset=0;
1538
1539if( !title || !text )
1540return;
1541
1542position_t pos_title = pos ( gui.infobox.vborder, gui.infobox.vborder );
1543
1544// calculate number of lines in the title
1545for ( i = 0, lines = 1; i<strlen(title); i++ )
1546if( title[i] == '\n')
1547lines++;
1548
1549// y position of text is lines in title * height of font
1550position_t pos_text = pos( pos_title.x , pos_title.y + ( font_console.height * lines ));
1551
1552// calculate number of lines in the text
1553for ( i=0, lines = 1; i<strlen(text); i++ )
1554if( text[i] == '\n')
1555lines++;
1556
1557// if text ends with \n strip off
1558if( text[i] == '\n' || text[i] == '\0')
1559lines--;
1560
1561visiblelines = ( ( gui.infobox.height - ( gui.infobox.vborder * 2 ) ) / font_console.height ) - 1;
1562
1563// lets display the text and allow scroll thru using up down / arrows
1564while(1)
1565{
1566// move to current line in text
1567for( offset = 0, i = 0; offset < strlen(text); offset++ )
1568{
1569if( currentline == i)
1570break;
1571if( text[offset] =='\n')
1572i++;
1573}
1574
1575// find last visible line in text and place \0
1576for( i = offset, cnt = 0; i < strlen(text); i++)
1577{
1578if(text[i]=='\n')
1579cnt++;
1580if ( cnt == visiblelines )
1581{
1582text[i]='\0';
1583break;
1584}
1585}
1586
1587fillPixmapWithColor( gui.infobox.pixmap, gui.infobox.bgcolor);
1588
1589makeRoundedCorners( gui.infobox.pixmap);
1590
1591// print the title if present
1592if( title )
1593drawStr(title, &font_console, gui.infobox.pixmap, pos_title);
1594
1595// print the text
1596drawStr( text + offset, &font_console, gui.infobox.pixmap, pos_text);
1597
1598// restore \n in text
1599if ( cnt == visiblelines )
1600text[i] = '\n';
1601
1602position_t pos_indicator = pos( gui.infobox.width - ( images[iTextScrollPrev].image->width - ( gui.infobox.vborder / 2) ), pos_text.y );
1603
1604// draw prev indicator
1605if(offset)
1606{
1607blend( images[iTextScrollPrev].image, gui.infobox.pixmap, centeredAt( images[iTextScrollPrev].image, pos_indicator ));
1608}
1609
1610// draw next indicator
1611if( lines > ( currentline + visiblelines ) )
1612{
1613pos_indicator.y = ( gui.infobox.height - ( ( images[iTextScrollNext].image->width + gui.infobox.vborder ) / 2 ) );
1614blend( images[iTextScrollNext].image, gui.infobox.pixmap, centeredAt( images[iTextScrollNext].image, pos_indicator ) );
1615}
1616
1617gui.bootprompt.draw = false;
1618gui.infobox.draw = true;
1619gui.redraw = true;
1620
1621updateVRAM();
1622
1623key = getchar();
1624
1625if( key == kUpArrowkey )
1626if( currentline > 0 )
1627currentline--;
1628
1629if( key == kDownArrowkey )
1630if( lines > ( currentline + visiblelines ) )
1631currentline++;
1632
1633if( key == kEscapeKey || key == 'q' || key == 'Q')
1634{
1635gui.infobox.draw = false;
1636gui.redraw = true;
1637updateVRAM();
1638break;
1639}
1640}
1641}
1642
1643void animateProgressBar()
1644{
1645int y;
1646
1647if( time18() > lasttime)
1648{
1649lasttime = time18();
1650
1651pixmap_t *buffBar = images[iProgressBar].image;
1652
1653uint32_t buff = buffBar->pixels[0].value;
1654
1655memcpy( buffBar->pixels, buffBar->pixels + 1, ( (buffBar->width*buffBar->height) - 1 ) * 4 );
1656
1657for( y = buffBar->height - 1; y > 0; y--)
1658pixel(buffBar, buffBar->width - 1, y) = pixel(buffBar, buffBar->width - 1, y - 1);
1659
1660pixel(buffBar, buffBar->width-1, 0).value = buff;
1661}
1662}
1663
1664void drawProgressBar(pixmap_t *blendInto, uint16_t width, position_t p, uint8_t progress)
1665{
1666if(progress>100)
1667return;
1668
1669p.x = ( p.x - ( width / 2 ) );
1670
1671int todraw = (width * progress) / 100;
1672
1673pixmap_t *buff = images[iProgressBar].image;
1674pixmap_t *buffBG = images[iProgressBarBackground].image;
1675if(!buff || !buffBG)
1676return;
1677
1678pixmap_t progressbar;
1679progressbar.pixels=malloc(width * 4 * buff->height);
1680if(!progressbar.pixels)
1681return;
1682
1683progressbar.width = width;
1684progressbar.height = buff->height;
1685
1686int x=0,x2=0,y=0;
1687
1688for(y=0; y<buff->height; y++)
1689{
1690for(x=0; x<todraw; x++, x2++)
1691{
1692if(x2 == (buff->width-1)) x2=0;
1693pixel(&progressbar, x,y).value = pixel(buff, x2,y).value;
1694}
1695x2=0;
1696}
1697
1698for(y=0; y<buff->height; y++)
1699{
1700for(x=todraw, x2 = 0; x < width - 1; x++, x2++)
1701{
1702if(x2 == (buffBG->width -2 )) x2 = 0;
1703pixel(&progressbar, x,y).value = pixel(buffBG, x2,y).value;
1704}
1705if(progress < 100)
1706pixel(&progressbar, width - 1, y).value = pixel(buffBG, buffBG->width - 1, y).value;
1707if(progress == 0)
1708pixel(&progressbar, 0, y).value = pixel(buffBG, buffBG->width - 1, y).value;
1709x2=0;
1710}
1711
1712blend(&progressbar, blendInto, p);
1713animateProgressBar();
1714free(progressbar.pixels);
1715}
1716
1717void drawInfoMenuItems()
1718{
1719int i,n;
1720
1721position_t position;
1722
1723pixmap_t *selection = images[iMenuSelection].image;
1724
1725pixmap_t *pbuff;
1726
1727fillPixmapWithColor(gui.menu.pixmap, gui.menu.bgcolor);
1728
1729makeRoundedCorners(gui.menu.pixmap);
1730
1731uint8_t offset = infoMenuNativeBoot ? 0 : infoMenuItemsCount - 1;
1732
1733position = pos(0,0);
1734
1735for ( i = 0, n = iMenuBoot; i < infoMenuItemsCount; i++, n++)
1736{
1737if (i == infoMenuSelection)
1738blend(selection, gui.menu.pixmap, position);
1739
1740pbuff = images[n].image;
1741if (offset && i >= INFOMENU_NATIVEBOOT_START && i <= INFOMENU_NATIVEBOOT_END)
1742blend( images[n + (iMenuHelp - iMenuBoot)].image , gui.menu.pixmap,
1743pos((position.x + (gui.menu.hborder / 2)), position.y + ((selection->height - pbuff->height) / 2)));
1744else
1745blend( pbuff, gui.menu.pixmap,
1746pos((position.x + (gui.menu.hborder / 2)), position.y + ((selection->height - pbuff->height) / 2)));
1747
1748drawStr(infoMenuItems[i].text, &font_console, gui.menu.pixmap,
1749pos(position.x + (pbuff->width + gui.menu.hborder),
1750position.y + ((selection->height - font_console.height) / 2)));
1751position.y += images[iMenuSelection].image->height;
1752
1753}
1754
1755gui.redraw = true;
1756}
1757
1758int drawInfoMenu()
1759{
1760drawInfoMenuItems();
1761
1762gui.menu.draw = true;
1763
1764updateVRAM();
1765
1766return 1;
1767}
1768
1769int updateInfoMenu(int key)
1770{
1771switch (key)
1772{
1773
1774case kUpArrowkey:// up arrow
1775if (infoMenuSelection > 0)
1776{
1777if(!infoMenuNativeBoot && infoMenuSelection == INFOMENU_NATIVEBOOT_END + 1)
1778infoMenuSelection -= 4;
1779
1780else
1781infoMenuSelection--;
1782drawInfoMenuItems();
1783updateVRAM();
1784
1785} else {
1786
1787gui.menu.draw = false;
1788gui.redraw = true;
1789
1790updateVRAM();
1791
1792return CLOSE_INFO_MENU;
1793}
1794break;
1795
1796case kDownArrowkey:// down arrow
1797if (infoMenuSelection < infoMenuItemsCount - 1)
1798{
1799if(!infoMenuNativeBoot && infoMenuSelection == INFOMENU_NATIVEBOOT_START - 1)
1800infoMenuSelection += 4;
1801else
1802infoMenuSelection++;
1803drawInfoMenuItems();
1804updateVRAM();
1805}
1806break;
1807
1808case kReturnKey:
1809key = 0;
1810if( infoMenuSelection == MENU_SHOW_MEMORY_INFO )
1811showInfoBox( "Memory Info. Press q to quit.\n", getMemoryInfoString());
1812
1813else if( infoMenuSelection == MENU_SHOW_VIDEO_INFO )
1814showInfoBox( getVBEInfoString(), getVBEModeInfoString() );
1815
1816else if( infoMenuSelection == MENU_SHOW_HELP )
1817showHelp();
1818
1819else
1820{
1821int buff = infoMenuSelection;
1822infoMenuSelection = 0;
1823return buff;
1824}
1825break;
1826}
1827return DO_NOT_BOOT;
1828}
1829
1830uint16_t bootImageWidth = 0;
1831uint16_t bootImageHeight = 0;
1832uint8_t *bootImageData = NULL;
1833static bool usePngImage = true;
1834
1835//==========================================================================
1836// loadBootGraphics
1837static void loadBootGraphics(void)
1838{
1839if (bootImageData != NULL)
1840{
1841return;
1842}
1843
1844char dirspec[128]; //Azi: testing
1845
1846if ((strlen(theme_name) + 24) > sizeof(dirspec))
1847{
1848usePngImage = false;
1849return;
1850}
1851
1852sprintf(dirspec, "bt(0,0)/Extra/Themes/%s/boot.png", theme_name);
1853
1854if (loadPngImage(dirspec, &bootImageWidth, &bootImageHeight, &bootImageData) != 0)
1855{
1856
1857#ifdef CONFIG_EMBED_THEME
1858if ((loadEmbeddedPngImage(__boot_png, __boot_png_len,
1859&bootImageWidth, &bootImageHeight, &bootImageData)) != 0)
1860#endif
1861
1862usePngImage = false;
1863}
1864}
1865
1866//==========================================================================
1867// drawBootGraphics
1868void drawBootGraphics(void)
1869{
1870bool legacy_logo;
1871const char *dummyVal;
1872int pos, length, oldScreenWidth, oldScreenHeight;
1873uint16_t x, y;
1874
1875if (getBoolForKey(kLegacyLogoKey, &legacy_logo, &bootInfo->bootConfig) && legacy_logo)
1876{
1877usePngImage = false;
1878}
1879else if (bootImageData == NULL)
1880{
1881loadBootGraphics();
1882}
1883
1884// Save current screen resolution.
1885oldScreenWidth = gui.screen.width;
1886oldScreenHeight = gui.screen.height;
1887//printf("Res: %dx%d (drawbg: current/old)\n", oldScreenWidth, oldScreenHeight);
1888
1889// AutoResolution
1890if (gAutoResolution == true)
1891{
1892screen_params[0] = paramsAR[0];
1893screen_params[1] = paramsAR[1];
1894//printf("Res: %dx%d (drawbg: AR)\n", screen_params[0], screen_params[1]);
1895}
1896else
1897{
1898// parse boot screen size parameters
1899if (getIntForKey("boot_width", &pos, &bootInfo->themeConfig) && pos > 0)
1900{
1901screen_params[0] = pos;
1902}
1903else
1904{
1905screen_params[0] = DEFAULT_SCREEN_WIDTH;
1906}
1907
1908if (getIntForKey("boot_height", &pos, &bootInfo->themeConfig) && pos > 0)
1909{
1910screen_params[1] = pos;
1911}
1912else
1913{
1914screen_params[1] = DEFAULT_SCREEN_HEIGHT;
1915}
1916//Azi: and how about not using default values here? like on initGUI...
1917}
1918
1919gui.screen.width = screen_params[0];
1920gui.screen.height = screen_params[1];
1921//printf("Res: %dx%d (drawbg: gsw/h new)\n", gui.screen.width, gui.screen.height);
1922
1923// find best matching vesa mode for our requested width & height
1924getGraphicModeParams(screen_params);
1925
1926//Azi: isn't this sort of done on ExecKernel() ??
1927 // Set graphics mode if the booter was in text mode or the screen resolution has changed.
1928if (bootArgs->Video.v_display == VGA_TEXT_MODE
1929|| (screen_params[0] != oldScreenWidth && screen_params[1] != oldScreenHeight))
1930{
1931setVideoMode(GRAPHICS_MODE, 0);
1932}
1933
1934if (getValueForKey("-checkers", &dummyVal, &length, &bootInfo->bootConfig)) {
1935drawCheckerBoard();
1936} else {
1937// Fill the background to 75% grey (same as BootX).
1938drawColorRectangle(0, 0, screen_params[0], screen_params[1], 0x01);
1939}
1940if ((bootImageData) && (usePngImage)) {
1941x = (screen_params[0] - MIN(bootImageWidth, screen_params[0])) / 2;
1942y = (screen_params[1] - MIN(bootImageHeight, screen_params[1])) / 2;
1943
1944// Draw the image in the center of the display.
1945blendImage(x, y, bootImageWidth, bootImageHeight, bootImageData);
1946} else {
1947uint8_t *appleBootPict;
1948bootImageData = NULL;
1949bootImageWidth = kAppleBootWidth;
1950bootImageHeight = kAppleBootHeight;
1951
1952// Prepare the data for the default Apple boot image.
1953appleBootPict = (uint8_t *) decodeRLE(gAppleBootPictRLE, kAppleBootRLEBlocks, bootImageWidth * bootImageHeight);
1954if (appleBootPict) {
1955convertImage(bootImageWidth, bootImageHeight, appleBootPict, &bootImageData);
1956if (bootImageData) {
1957x = (screen_params[0] - MIN(kAppleBootWidth, screen_params[0])) / 2;
1958y = (screen_params[1] - MIN(kAppleBootHeight, screen_params[1])) / 2;
1959drawDataRectangle(x, y, kAppleBootWidth, kAppleBootHeight, bootImageData);
1960free(bootImageData);
1961}
1962free(appleBootPict);
1963}
1964}
1965}
1966

Archive Download this file

Revision: 1047