Chameleon

Chameleon Svn Source Tree

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

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

Archive Download this file

Revision: 1022