Chameleon

Chameleon Svn Source Tree

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

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

Archive Download this file

Revision: 709