Chameleon

Chameleon Svn Source Tree

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

Archive Download this file

Revision: 661