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

Archive Download this file

Revision: 705