Chameleon

Chameleon Svn Source Tree

Root/trunk/i386/boot2/gui.c

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

Archive Download this file

Revision: 1440